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.utils.objects.SparseSet;
import emu.grasscutter.utils.Utils;
import java.util.Arrays;
import java.util.*;
public final class GameConstants {
public static String VERSION = "3.7.0";
@ -47,4 +47,23 @@ public final class GameConstants {
public static final int[] DEFAULT_ABILITY_HASHES =
Arrays.stream(DEFAULT_ABILITY_STRINGS).mapToInt(Utils::abilityHash).toArray();
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
private static final Int2ObjectMap<CombineData> combineDataMap = new Int2ObjectOpenHashMap<>();
@Getter
private static final Int2ObjectMap<CombineBonusData> combineBonusDataMap =
new Int2ObjectOpenHashMap<>();
@Getter
private static final Int2ObjectMap<CookBonusData> cookBonusDataMap =
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;
import emu.grasscutter.GameConstants;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.DataLoader;
import emu.grasscutter.data.GameData;
import emu.grasscutter.data.common.ItemParamData;
import emu.grasscutter.data.excels.CombineBonusData;
import emu.grasscutter.data.excels.CombineData;
import emu.grasscutter.game.avatar.Avatar;
import emu.grasscutter.game.inventory.GameItem;
@ -21,17 +21,24 @@ import emu.grasscutter.utils.Utils;
import io.netty.util.internal.ThreadLocalRandom;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.List;
import java.util.*;
public class CombineManger extends BaseGameSystem {
private static final Int2ObjectMap<List<Integer>> reliquaryDecomposeData =
new Int2ObjectOpenHashMap<>();
private final Int2ObjectMap<CombineBonusData> combineBonusData = new Int2ObjectOpenHashMap<>();
public CombineManger(GameServer 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() {
@ -96,10 +103,10 @@ public class CombineManger extends BaseGameSystem {
// lucky characters
int luckyCount = 0;
Avatar avatar = player.getAvatars().getAvatarByGuid(avatarGuid);
CombineBonusData combineBonusData = GameData.getCombineBonusDataMap().get(avatar.getAvatarId());
if (combineBonusData != null
&& combineData.getCombineType() == combineBonusData.getCombineType()) {
double luckyChange = combineBonusData.getParamVec().get(0);
CombineBonusData combineBonusAvatar = combineBonusData.get(avatar.getAvatarId());
if (combineBonusAvatar != null
&& combineData.getCombineType() == combineBonusAvatar.getCombineType()) {
double luckyChange = combineBonusAvatar.getParamVec().get(0);
for (int i = 0; i < count; i++) {
if (ThreadLocalRandom.current().nextDouble() <= luckyChange) {
luckyCount++;
@ -113,28 +120,27 @@ public class CombineManger extends BaseGameSystem {
// add lucky items
if (luckyCount > 0) {
switch (combineBonusData.getBonusType()) {
case "COMBINE_BONUS_DOUBLE" -> {
switch (combineBonusAvatar.getBonusType()) {
case COMBINE_BONUS_DOUBLE -> {
var combineExtra = new ItemParamData(combineData.getResultItemId(), luckyCount);
player.getInventory().addItem(combineExtra);
result.getExtra().add(combineExtra);
}
case "COMBINE_BONUS_REFUND" -> {
case COMBINE_BONUS_REFUND -> {
if (combineData.getMaterialItems().size() == 1) {
var combineBack =
new ItemParamData(combineData.getMaterialItems().get(0).getItemId(), luckyCount);
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();
var randomId = combineData
.getMaterialItems()
.get(
ThreadLocalRandom.current()
.nextInt(combineData.getMaterialItems().size()))
.getItemId();
mapIdCount.put(randomId, mapIdCount.getOrDefault(randomId, 0) + 1);
}
@ -145,36 +151,22 @@ public class CombineManger extends BaseGameSystem {
}
}
}
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
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
Map<Integer, Integer> itemToRegion = Map.of(
104301, 1,
104304, 1,
104307, 1,
104310, 2,
104313, 2,
104316, 2,
104320, 3,
104323, 3,
104326, 3,
104329, 4,
104332, 4,
104335, 4
);
HashMap<Integer, Integer> itemToRegion = GameConstants.YAE_MIKO_ITEM_TO_REGION_COMBINE_BONUS;
// 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());
}
HashMap<Integer, List<Integer>> regionToId = GameConstants.YAE_MIKO_REGION_TO_ITEM_COMBINE_BONUS;
// 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
if (itemToRegion.get(itemId) != null) rank = 1;
if (itemToRegion.get(itemId) != null)
rank = 1;
if (itemToRegion.get(itemId - 1) != null) {
rank = 2;
itemId -= 1;
@ -183,23 +175,21 @@ public class CombineManger extends BaseGameSystem {
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
// remove material id from array
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()));
int 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());
var combineRandom = new ItemParamData(
(rank == 2) ? entry.getKey() + 1 : entry.getKey(), entry.getValue());
player.getInventory().addItem(combineRandom);
result.getRandom().add(combineRandom);
}