mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-01-07 00:33:22 +08:00
implement feature character bonuses for combine & fix num result combine the wrong
This commit is contained in:
parent
8291e366b9
commit
37c0818332
@ -207,6 +207,10 @@ public final class GameData {
|
|||||||
@Getter
|
@Getter
|
||||||
private static final Int2ObjectMap<CombineData> combineDataMap = new Int2ObjectOpenHashMap<>();
|
private static final Int2ObjectMap<CombineData> combineDataMap = new Int2ObjectOpenHashMap<>();
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private static final Int2ObjectMap<CombineBonusData> combineBonusDataMap =
|
||||||
|
new Int2ObjectOpenHashMap<>();
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private static final Int2ObjectMap<CookBonusData> cookBonusDataMap =
|
private static final Int2ObjectMap<CookBonusData> cookBonusDataMap =
|
||||||
new Int2ObjectOpenHashMap<>();
|
new Int2ObjectOpenHashMap<>();
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
package emu.grasscutter.data.excels;
|
||||||
|
|
||||||
|
import emu.grasscutter.data.GameResource;
|
||||||
|
import emu.grasscutter.data.ResourceType;
|
||||||
|
import emu.grasscutter.data.ResourceType.LoadPriority;
|
||||||
|
import java.util.List;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@ResourceType(
|
||||||
|
name = {"CombineBonusExcelConfigData.json"},
|
||||||
|
loadPriority = LoadPriority.LOW)
|
||||||
|
public class CombineBonusData extends GameResource {
|
||||||
|
@Getter @Setter private int avatarId;
|
||||||
|
@Getter @Setter private int combineType;
|
||||||
|
@Getter @Setter private String bonusType;
|
||||||
|
@Getter @Setter private List<Double> paramVec;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getId() {
|
||||||
|
return this.avatarId;
|
||||||
|
}
|
||||||
|
}
|
@ -4,7 +4,9 @@ import emu.grasscutter.Grasscutter;
|
|||||||
import emu.grasscutter.data.DataLoader;
|
import emu.grasscutter.data.DataLoader;
|
||||||
import emu.grasscutter.data.GameData;
|
import emu.grasscutter.data.GameData;
|
||||||
import emu.grasscutter.data.common.ItemParamData;
|
import emu.grasscutter.data.common.ItemParamData;
|
||||||
|
import emu.grasscutter.data.excels.CombineBonusData;
|
||||||
import emu.grasscutter.data.excels.CombineData;
|
import emu.grasscutter.data.excels.CombineData;
|
||||||
|
import emu.grasscutter.game.avatar.Avatar;
|
||||||
import emu.grasscutter.game.inventory.GameItem;
|
import emu.grasscutter.game.inventory.GameItem;
|
||||||
import emu.grasscutter.game.player.Player;
|
import emu.grasscutter.game.player.Player;
|
||||||
import emu.grasscutter.game.props.ActionReason;
|
import emu.grasscutter.game.props.ActionReason;
|
||||||
@ -16,9 +18,11 @@ import emu.grasscutter.server.packet.send.PacketCombineFormulaDataNotify;
|
|||||||
import emu.grasscutter.server.packet.send.PacketCombineRsp;
|
import emu.grasscutter.server.packet.send.PacketCombineRsp;
|
||||||
import emu.grasscutter.server.packet.send.PacketReliquaryDecomposeRsp;
|
import emu.grasscutter.server.packet.send.PacketReliquaryDecomposeRsp;
|
||||||
import emu.grasscutter.utils.Utils;
|
import emu.grasscutter.utils.Utils;
|
||||||
|
import io.netty.util.internal.ThreadLocalRandom;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class CombineManger extends BaseGameSystem {
|
public class CombineManger extends BaseGameSystem {
|
||||||
@ -53,7 +57,7 @@ public class CombineManger extends BaseGameSystem {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CombineResult combineItem(Player player, int cid, int count) {
|
public CombineResult combineItem(Player player, int cid, int count, long avatarGuid) {
|
||||||
// check config exist
|
// check config exist
|
||||||
if (!GameData.getCombineDataMap().containsKey(cid)) {
|
if (!GameData.getCombineDataMap().containsKey(cid)) {
|
||||||
player.getWorld().getHost().sendPacket(new PacketCombineRsp());
|
player.getWorld().getHost().sendPacket(new PacketCombineRsp());
|
||||||
@ -87,11 +91,124 @@ public class CombineManger extends BaseGameSystem {
|
|||||||
result.setMaterial(List.of());
|
result.setMaterial(List.of());
|
||||||
result.setResult(
|
result.setResult(
|
||||||
List.of(
|
List.of(
|
||||||
new ItemParamData(
|
new ItemParamData(combineData.getResultItemId(), combineData.getResultItemCount())));
|
||||||
combineData.getResultItemId(), combineData.getResultItemCount() * count)));
|
// lucky characters
|
||||||
// TODO lucky characters
|
int luckyCount = 0;
|
||||||
result.setExtra(List.of());
|
Avatar avatar = player.getAvatars().getAvatarByGuid(avatarGuid);
|
||||||
result.setBack(List.of());
|
CombineBonusData combineBonusData = GameData.getCombineBonusDataMap().get(avatar.getAvatarId());
|
||||||
|
if (combineBonusData != null
|
||||||
|
&& combineData.getCombineType() == combineBonusData.getCombineType()) {
|
||||||
|
double luckyChange = combineBonusData.getParamVec().get(0);
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
if (ThreadLocalRandom.current().nextDouble() <= luckyChange) {
|
||||||
|
luckyCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result.setExtra(new ArrayList<ItemParamData>());
|
||||||
|
result.setBack(new ArrayList<ItemParamData>());
|
||||||
|
result.setRandom(new ArrayList<ItemParamData>());
|
||||||
|
|
||||||
|
// add lucky items
|
||||||
|
if (luckyCount > 0) {
|
||||||
|
switch (combineBonusData.getBonusType()) {
|
||||||
|
case "COMBINE_BONUS_DOUBLE" -> {
|
||||||
|
var combineExtra = new ItemParamData(combineData.getResultItemId(), luckyCount * 2);
|
||||||
|
player.getInventory().addItem(combineExtra);
|
||||||
|
result.getExtra().add(combineExtra);
|
||||||
|
}
|
||||||
|
case "COMBINE_BONUS_REFUND" -> {
|
||||||
|
if (combineData.getMaterialItems().size() == 1) {
|
||||||
|
var combineBack =
|
||||||
|
new ItemParamData(combineData.getMaterialItems().get(0).getItemId(), luckyCount);
|
||||||
|
player.getInventory().addItem(combineBack);
|
||||||
|
result.getBack().add(combineBack);
|
||||||
|
} else {
|
||||||
|
HashMap<Integer, Integer> mapIdCount = new HashMap<>();
|
||||||
|
for (int i = 0; i < luckyCount; i++) {
|
||||||
|
var randomId =
|
||||||
|
combineData
|
||||||
|
.getMaterialItems()
|
||||||
|
.get(
|
||||||
|
ThreadLocalRandom.current()
|
||||||
|
.nextInt(combineData.getMaterialItems().size()))
|
||||||
|
.getItemId();
|
||||||
|
mapIdCount.put(randomId, mapIdCount.getOrDefault(randomId, 0) + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var entry : mapIdCount.entrySet()) {
|
||||||
|
var combineBack = new ItemParamData(entry.getKey(), entry.getValue());
|
||||||
|
player.getInventory().addItem(combineBack);
|
||||||
|
result.getBack().add(combineBack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case "COMBINE_BONUS_REFUND_RANDOM" -> {
|
||||||
|
// for yae miko, "Has a 25% chance to get 1 regional Character Talent Material (base
|
||||||
|
// material excluded) when crafting. The rarity is that of the base material." from wiki
|
||||||
|
// map of material id to region id
|
||||||
|
HashMap<Integer, Integer> itemToRegion =
|
||||||
|
new HashMap<>() {
|
||||||
|
{
|
||||||
|
put(104301, 1);
|
||||||
|
put(104304, 1);
|
||||||
|
put(104307, 1);
|
||||||
|
put(104310, 2);
|
||||||
|
put(104313, 2);
|
||||||
|
put(104316, 2);
|
||||||
|
put(104320, 3);
|
||||||
|
put(104323, 3);
|
||||||
|
put(104326, 3);
|
||||||
|
put(104329, 4);
|
||||||
|
put(104332, 4);
|
||||||
|
put(104335, 4);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// get list of material id with every region
|
||||||
|
HashMap<Integer, List<Integer>> regionToId = new HashMap<>();
|
||||||
|
for (var entry : itemToRegion.entrySet()) {
|
||||||
|
regionToId.putIfAbsent(entry.getValue(), new ArrayList<>());
|
||||||
|
regionToId.get(entry.getValue()).add(entry.getKey());
|
||||||
|
}
|
||||||
|
|
||||||
|
// check material id in itemToRegion
|
||||||
|
var itemId = combineData.getMaterialItems().get(0).getItemId();
|
||||||
|
int rank = 0; // rank of material
|
||||||
|
if (itemToRegion.get(itemId) != null) rank = 1;
|
||||||
|
if (itemToRegion.get(itemId - 1) != null) {
|
||||||
|
rank = 2;
|
||||||
|
itemId -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rank >= 1) { // if material is regional
|
||||||
|
// get list of material id with same region
|
||||||
|
List<Integer> listIdRandom = regionToId.get(itemToRegion.get(itemId));
|
||||||
|
// remove material id from list
|
||||||
|
listIdRandom.remove(Integer.valueOf(itemId));
|
||||||
|
|
||||||
|
HashMap<Integer, Integer> mapIdCount = new HashMap<>();
|
||||||
|
// pick random material from list with luckyCount
|
||||||
|
for (int i = 0; i < luckyCount; i++) {
|
||||||
|
var randomId =
|
||||||
|
listIdRandom.get(ThreadLocalRandom.current().nextInt(listIdRandom.size()));
|
||||||
|
mapIdCount.put(randomId, mapIdCount.getOrDefault(randomId, 0) + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// add to random list
|
||||||
|
for (var entry : mapIdCount.entrySet()) {
|
||||||
|
// if rank 2, add 1 to material id
|
||||||
|
var combineRandom =
|
||||||
|
new ItemParamData(
|
||||||
|
(rank == 2) ? entry.getKey() + 1 : entry.getKey(), entry.getValue());
|
||||||
|
player.getInventory().addItem(combineRandom);
|
||||||
|
result.getRandom().add(combineRandom);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -2,42 +2,13 @@ package emu.grasscutter.game.combine;
|
|||||||
|
|
||||||
import emu.grasscutter.data.common.ItemParamData;
|
import emu.grasscutter.data.common.ItemParamData;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
public class CombineResult {
|
public class CombineResult {
|
||||||
private List<ItemParamData> material;
|
@Getter @Setter private List<ItemParamData> material;
|
||||||
private List<ItemParamData> result;
|
@Getter @Setter private List<ItemParamData> result;
|
||||||
private List<ItemParamData> extra;
|
@Getter @Setter private List<ItemParamData> extra;
|
||||||
private List<ItemParamData> back;
|
@Getter @Setter private List<ItemParamData> back;
|
||||||
|
@Getter @Setter private List<ItemParamData> random;
|
||||||
public List<ItemParamData> getMaterial() {
|
|
||||||
return material;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMaterial(List<ItemParamData> material) {
|
|
||||||
this.material = material;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<ItemParamData> getResult() {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setResult(List<ItemParamData> result) {
|
|
||||||
this.result = result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<ItemParamData> getExtra() {
|
|
||||||
return extra;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setExtra(List<ItemParamData> extra) {
|
|
||||||
this.extra = extra;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<ItemParamData> getBack() {
|
|
||||||
return back;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBack(List<ItemParamData> back) {
|
|
||||||
this.back = back;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,11 @@ public class HandlerCombineReq extends PacketHandler {
|
|||||||
session
|
session
|
||||||
.getServer()
|
.getServer()
|
||||||
.getCombineSystem()
|
.getCombineSystem()
|
||||||
.combineItem(session.getPlayer(), req.getCombineId(), req.getCombineCount());
|
.combineItem(
|
||||||
|
session.getPlayer(),
|
||||||
|
req.getCombineId(),
|
||||||
|
req.getCombineCount(),
|
||||||
|
req.getAvatarGuid());
|
||||||
|
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
return;
|
return;
|
||||||
@ -36,7 +40,7 @@ public class HandlerCombineReq extends PacketHandler {
|
|||||||
toItemParamList(result.getResult()),
|
toItemParamList(result.getResult()),
|
||||||
toItemParamList(result.getExtra()),
|
toItemParamList(result.getExtra()),
|
||||||
toItemParamList(result.getBack()),
|
toItemParamList(result.getBack()),
|
||||||
toItemParamList(result.getBack())));
|
toItemParamList(result.getRandom())));
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<ItemParamOuterClass.ItemParam> toItemParamList(List<ItemParamData> list) {
|
private List<ItemParamOuterClass.ItemParam> toItemParamList(List<ItemParamData> list) {
|
||||||
|
Loading…
Reference in New Issue
Block a user