Chore: Remove CombineBonusData class and update GameData (CombineBonusData not found in 4.0 resource), instead, load from CombineBonus.json in the data folder

This commit is contained in:
Phong 2024-07-25 08:06:00 +07:00
parent af1da93d68
commit d248dddc53
No known key found for this signature in database
GPG Key ID: E1E0260A8DE0C25D
5 changed files with 80 additions and 79 deletions

View File

@ -3,7 +3,7 @@ package emu.grasscutter;
import emu.grasscutter.game.world.Position; import emu.grasscutter.game.world.Position;
import emu.grasscutter.utils.objects.SparseSet; import emu.grasscutter.utils.objects.SparseSet;
import emu.grasscutter.utils.Utils; import emu.grasscutter.utils.Utils;
import java.util.Arrays; import java.util.*;
public final class GameConstants { public final class GameConstants {
public static String VERSION = "3.7.0"; public static String VERSION = "3.7.0";
@ -47,4 +47,23 @@ public final class GameConstants {
public static final int[] DEFAULT_ABILITY_HASHES = public static final int[] DEFAULT_ABILITY_HASHES =
Arrays.stream(DEFAULT_ABILITY_STRINGS).mapToInt(Utils::abilityHash).toArray(); Arrays.stream(DEFAULT_ABILITY_STRINGS).mapToInt(Utils::abilityHash).toArray();
public static final int DEFAULT_ABILITY_NAME = Utils.abilityHash("Default"); public static final int DEFAULT_ABILITY_NAME = Utils.abilityHash("Default");
public static final HashMap<Integer, Integer> YAE_MIKO_ITEM_TO_REGION_COMBINE_BONUS = new HashMap<>() {{
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);
}};
public static final HashMap<Integer, List<Integer>> YAE_MIKO_REGION_TO_ITEM_COMBINE_BONUS = new HashMap<>() {{
put(1, List.of(104304, 104307));
put(2, List.of(104310, 104313, 104316));
put(3, List.of(104320, 104323, 104326));
put(4, List.of(104329, 104332, 104335));
}};
} }

View File

@ -207,10 +207,6 @@ 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<>();

View File

@ -1,23 +0,0 @@
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;
}
}

View File

@ -0,0 +1,19 @@
package emu.grasscutter.game.combine;
import java.util.List;
import lombok.Getter;
import lombok.Setter;
@Getter @Setter
public class CombineBonusData {
private int avatarId;
private int combineType;
private BonusType bonusType;
private List<Double> paramVec;
public enum BonusType {
COMBINE_BONUS_DOUBLE,
COMBINE_BONUS_REFUND,
COMBINE_BONUS_REFUND_RANDOM,
}
}

View File

@ -1,10 +1,10 @@
package emu.grasscutter.game.combine; package emu.grasscutter.game.combine;
import emu.grasscutter.GameConstants;
import emu.grasscutter.Grasscutter; 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.avatar.Avatar;
import emu.grasscutter.game.inventory.GameItem; import emu.grasscutter.game.inventory.GameItem;
@ -21,17 +21,24 @@ import emu.grasscutter.utils.Utils;
import io.netty.util.internal.ThreadLocalRandom; 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.*;
import java.util.HashMap;
import java.util.Map;
import java.util.List;
public class CombineManger extends BaseGameSystem { public class CombineManger extends BaseGameSystem {
private static final Int2ObjectMap<List<Integer>> reliquaryDecomposeData = private static final Int2ObjectMap<List<Integer>> reliquaryDecomposeData =
new Int2ObjectOpenHashMap<>(); new Int2ObjectOpenHashMap<>();
private final Int2ObjectMap<CombineBonusData> combineBonusData = new Int2ObjectOpenHashMap<>();
public CombineManger(GameServer server) { public CombineManger(GameServer server) {
super(server); super(server);
// load combine bonus data
try {
DataLoader.loadList("CombineBonus.json", CombineBonusData.class)
.forEach(entry -> combineBonusData.put(entry.getAvatarId(), entry));
} catch (Exception ignored) {
Grasscutter.getLogger()
.error("Unable to load combine bonus data. Please place CombineBonus.json in the data folder.");
}
} }
public static void initialize() { public static void initialize() {
@ -96,10 +103,10 @@ public class CombineManger extends BaseGameSystem {
// lucky characters // lucky characters
int luckyCount = 0; int luckyCount = 0;
Avatar avatar = player.getAvatars().getAvatarByGuid(avatarGuid); Avatar avatar = player.getAvatars().getAvatarByGuid(avatarGuid);
CombineBonusData combineBonusData = GameData.getCombineBonusDataMap().get(avatar.getAvatarId()); CombineBonusData combineBonusAvatar = combineBonusData.get(avatar.getAvatarId());
if (combineBonusData != null if (combineBonusAvatar != null
&& combineData.getCombineType() == combineBonusData.getCombineType()) { && combineData.getCombineType() == combineBonusAvatar.getCombineType()) {
double luckyChange = combineBonusData.getParamVec().get(0); double luckyChange = combineBonusAvatar.getParamVec().get(0);
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
if (ThreadLocalRandom.current().nextDouble() <= luckyChange) { if (ThreadLocalRandom.current().nextDouble() <= luckyChange) {
luckyCount++; luckyCount++;
@ -113,28 +120,27 @@ public class CombineManger extends BaseGameSystem {
// add lucky items // add lucky items
if (luckyCount > 0) { if (luckyCount > 0) {
switch (combineBonusData.getBonusType()) { switch (combineBonusAvatar.getBonusType()) {
case "COMBINE_BONUS_DOUBLE" -> { case COMBINE_BONUS_DOUBLE -> {
var combineExtra = new ItemParamData(combineData.getResultItemId(), luckyCount); var combineExtra = new ItemParamData(combineData.getResultItemId(), luckyCount);
player.getInventory().addItem(combineExtra); player.getInventory().addItem(combineExtra);
result.getExtra().add(combineExtra); result.getExtra().add(combineExtra);
} }
case "COMBINE_BONUS_REFUND" -> { case COMBINE_BONUS_REFUND -> {
if (combineData.getMaterialItems().size() == 1) { if (combineData.getMaterialItems().size() == 1) {
var combineBack = var combineBack = new ItemParamData(combineData.getMaterialItems().get(0).getItemId(),
new ItemParamData(combineData.getMaterialItems().get(0).getItemId(), luckyCount); luckyCount);
player.getInventory().addItem(combineBack); player.getInventory().addItem(combineBack);
result.getBack().add(combineBack); result.getBack().add(combineBack);
} else { } else {
HashMap<Integer, Integer> mapIdCount = new HashMap<>(); HashMap<Integer, Integer> mapIdCount = new HashMap<>();
for (int i = 0; i < luckyCount; i++) { for (int i = 0; i < luckyCount; i++) {
var randomId = var randomId = combineData
combineData .getMaterialItems()
.getMaterialItems() .get(
.get( ThreadLocalRandom.current()
ThreadLocalRandom.current() .nextInt(combineData.getMaterialItems().size()))
.nextInt(combineData.getMaterialItems().size())) .getItemId();
.getItemId();
mapIdCount.put(randomId, mapIdCount.getOrDefault(randomId, 0) + 1); mapIdCount.put(randomId, mapIdCount.getOrDefault(randomId, 0) + 1);
} }
@ -145,36 +151,22 @@ public class CombineManger extends BaseGameSystem {
} }
} }
} }
case "COMBINE_BONUS_REFUND_RANDOM" -> { case COMBINE_BONUS_REFUND_RANDOM -> {
// for yae miko, "Has a 25% chance to get 1 regional Character Talent Material (base // for yae miko, "Has a 25% chance to get 1 regional Character Talent Material
// material excluded) when crafting. The rarity is that of the base material." from wiki // (base
// material excluded) when crafting. The rarity is that of the base material."
// from wiki
// map of material id to region id // map of material id to region id
Map<Integer, Integer> itemToRegion = Map.of( HashMap<Integer, Integer> itemToRegion = GameConstants.YAE_MIKO_ITEM_TO_REGION_COMBINE_BONUS;
104301, 1,
104304, 1,
104307, 1,
104310, 2,
104313, 2,
104316, 2,
104320, 3,
104323, 3,
104326, 3,
104329, 4,
104332, 4,
104335, 4
);
// get list of material id with every region // get list of material id with every region
HashMap<Integer, List<Integer>> regionToId = new HashMap<>(); HashMap<Integer, List<Integer>> regionToId = GameConstants.YAE_MIKO_REGION_TO_ITEM_COMBINE_BONUS;
for (var entry : itemToRegion.entrySet()) {
regionToId.putIfAbsent(entry.getValue(), new ArrayList<>());
regionToId.get(entry.getValue()).add(entry.getKey());
}
// check material id in itemToRegion // check material id in itemToRegion
var itemId = combineData.getMaterialItems().get(0).getItemId(); int itemId = combineData.getMaterialItems().get(0).getItemId();
int rank = 0; // rank of material int rank = 0; // rank of material
if (itemToRegion.get(itemId) != null) rank = 1; if (itemToRegion.get(itemId) != null)
rank = 1;
if (itemToRegion.get(itemId - 1) != null) { if (itemToRegion.get(itemId - 1) != null) {
rank = 2; rank = 2;
itemId -= 1; itemId -= 1;
@ -183,23 +175,21 @@ public class CombineManger extends BaseGameSystem {
if (rank >= 1) { // if material is regional if (rank >= 1) { // if material is regional
// get list of material id with same region // get list of material id with same region
List<Integer> listIdRandom = regionToId.get(itemToRegion.get(itemId)); List<Integer> listIdRandom = regionToId.get(itemToRegion.get(itemId));
// remove material id from list // remove material id from array
listIdRandom.remove(Integer.valueOf(itemId)); listIdRandom.remove(Integer.valueOf(itemId));
HashMap<Integer, Integer> mapIdCount = new HashMap<>(); HashMap<Integer, Integer> mapIdCount = new HashMap<>();
// pick random material from list with luckyCount // pick random material from list with luckyCount
for (int i = 0; i < luckyCount; i++) { for (int i = 0; i < luckyCount; i++) {
var randomId = int randomId = listIdRandom.get(ThreadLocalRandom.current().nextInt(listIdRandom.size()));
listIdRandom.get(ThreadLocalRandom.current().nextInt(listIdRandom.size()));
mapIdCount.put(randomId, mapIdCount.getOrDefault(randomId, 0) + 1); mapIdCount.put(randomId, mapIdCount.getOrDefault(randomId, 0) + 1);
} }
// add to random list // add to random list
for (var entry : mapIdCount.entrySet()) { for (var entry : mapIdCount.entrySet()) {
// if rank 2, add 1 to material id // if rank 2, add 1 to material id
var combineRandom = var combineRandom = new ItemParamData(
new ItemParamData( (rank == 2) ? entry.getKey() + 1 : entry.getKey(), entry.getValue());
(rank == 2) ? entry.getKey() + 1 : entry.getKey(), entry.getValue());
player.getInventory().addItem(combineRandom); player.getInventory().addItem(combineRandom);
result.getRandom().add(combineRandom); result.getRandom().add(combineRandom);
} }