GameData.java 12.5 KB
Newer Older
Melledy's avatar
Melledy committed
1
2
3
package emu.grasscutter.data;

import java.lang.reflect.Field;
Yazawazi's avatar
Yazawazi committed
4
import java.util.ArrayList;
Melledy's avatar
Melledy committed
5
import java.util.HashMap;
Yazawazi's avatar
Yazawazi committed
6
import java.util.List;
Melledy's avatar
Melledy committed
7
8
9
10
11
import java.util.Map;

import emu.grasscutter.Grasscutter;
import emu.grasscutter.utils.Utils;
import emu.grasscutter.data.custom.AbilityEmbryoEntry;
Melledy's avatar
Melledy committed
12
13
import emu.grasscutter.data.custom.AbilityModifier;
import emu.grasscutter.data.custom.AbilityModifierEntry;
Melledy's avatar
Melledy committed
14
import emu.grasscutter.data.custom.OpenConfigEntry;
Yazawazi's avatar
Yazawazi committed
15
import emu.grasscutter.data.custom.ScenePointEntry;
Melledy's avatar
Melledy committed
16
17
18
19
import emu.grasscutter.data.def.*;
import it.unimi.dsi.fastutil.ints.Int2ObjectLinkedOpenHashMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
20
21
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList;
Melledy's avatar
Melledy committed
22

23
public class GameData {
Melledy's avatar
Melledy committed
24
25
26
	// BinOutputs
	private static final Int2ObjectMap<String> abilityHashes = new Int2ObjectOpenHashMap<>();
	private static final Map<String, AbilityEmbryoEntry> abilityEmbryos = new HashMap<>();
Melledy's avatar
Melledy committed
27
	private static final Map<String, AbilityModifierEntry> abilityModifiers = new HashMap<>();
Melledy's avatar
Melledy committed
28
	private static final Map<String, OpenConfigEntry> openConfigEntries = new HashMap<>();
Yazawazi's avatar
Yazawazi committed
29
	private static final Map<String, ScenePointEntry> scenePointEntries = new HashMap<>();
Melledy's avatar
Melledy committed
30
31
32
33
34
35
36
37
38
	
	// ExcelConfigs
	private static final Int2ObjectMap<PlayerLevelData> playerLevelDataMap = new Int2ObjectOpenHashMap<>();
	
	private static final Int2ObjectMap<AvatarData> avatarDataMap = new Int2ObjectOpenHashMap<>();
	private static final Int2ObjectMap<AvatarLevelData> avatarLevelDataMap = new Int2ObjectOpenHashMap<>();
	private static final Int2ObjectMap<AvatarSkillDepotData> avatarSkillDepotDataMap = new Int2ObjectOpenHashMap<>();
	private static final Int2ObjectMap<AvatarSkillData> avatarSkillDataMap = new Int2ObjectOpenHashMap<>();
	private static final Int2ObjectMap<AvatarCurveData> avatarCurveDataMap = new Int2ObjectLinkedOpenHashMap<>();
Yazawazi's avatar
Yazawazi committed
39
	private static final Int2ObjectMap<AvatarFetterLevelData> avatarFetterLevelDataMap = new Int2ObjectOpenHashMap<>();
Melledy's avatar
Melledy committed
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
	private static final Int2ObjectMap<AvatarPromoteData> avatarPromoteDataMap = new Int2ObjectOpenHashMap<>();
	private static final Int2ObjectMap<AvatarTalentData> avatarTalentDataMap = new Int2ObjectOpenHashMap<>();
	private static final Int2ObjectMap<ProudSkillData> proudSkillDataMap = new Int2ObjectOpenHashMap<>();
	
	private static final Int2ObjectMap<ItemData> itemDataMap = new Int2ObjectOpenHashMap<>();
	private static final Int2ObjectMap<ReliquaryLevelData> reliquaryLevelDataMap = new Int2ObjectOpenHashMap<>();
	private static final Int2ObjectMap<ReliquaryAffixData> reliquaryAffixDataMap = new Int2ObjectOpenHashMap<>();
	private static final Int2ObjectMap<ReliquaryMainPropData> reliquaryMainPropDataMap = new Int2ObjectOpenHashMap<>();
	private static final Int2ObjectMap<ReliquarySetData> reliquarySetDataMap = new Int2ObjectOpenHashMap<>();
	private static final Int2ObjectMap<WeaponLevelData> weaponLevelDataMap = new Int2ObjectOpenHashMap<>();
	private static final Int2ObjectMap<WeaponPromoteData> weaponPromoteDataMap = new Int2ObjectOpenHashMap<>();
	private static final Int2ObjectMap<WeaponCurveData> weaponCurveDataMap = new Int2ObjectOpenHashMap<>();
	private static final Int2ObjectMap<EquipAffixData> equipAffixDataMap = new Int2ObjectOpenHashMap<>();
	
	private static final Int2ObjectMap<MonsterData> monsterDataMap = new Int2ObjectOpenHashMap<>();
	private static final Int2ObjectMap<NpcData> npcDataMap = new Int2ObjectOpenHashMap<>();
	private static final Int2ObjectMap<GadgetData> gadgetDataMap = new Int2ObjectOpenHashMap<>();
	private static final Int2ObjectMap<MonsterCurveData> monsterCurveDataMap = new Int2ObjectOpenHashMap<>();
	private static final Int2ObjectMap<MonsterDescribeData> monsterDescribeDataMap = new Int2ObjectOpenHashMap<>();
	
	private static final Int2ObjectMap<AvatarFlycloakData> avatarFlycloakDataMap = new Int2ObjectLinkedOpenHashMap<>();
	private static final Int2ObjectMap<AvatarCostumeData> avatarCostumeDataMap = new Int2ObjectLinkedOpenHashMap<>();
	private static final Int2ObjectMap<AvatarCostumeData> avatarCostumeDataItemIdMap = new Int2ObjectLinkedOpenHashMap<>();
	
Melledy's avatar
Melledy committed
64
	private static final Int2ObjectMap<SceneData> sceneDataMap = new Int2ObjectLinkedOpenHashMap<>();
Yazawazi's avatar
Yazawazi committed
65
	private static final Int2ObjectMap<FetterData> fetterDataMap = new Int2ObjectOpenHashMap<>();
Yazawazi's avatar
Yazawazi committed
66
	private static final Int2ObjectMap<FetterCharacterCardData> fetterCharacterCardDataMap = new Int2ObjectOpenHashMap<>();
Yazawazi's avatar
Yazawazi committed
67
	private static final Int2ObjectMap<RewardData> rewardDataMap = new Int2ObjectOpenHashMap<>();
Melledy's avatar
Melledy committed
68
	private static final Int2ObjectMap<WorldLevelData> worldLevelDataMap = new Int2ObjectOpenHashMap<>();
69
	private static final Int2ObjectMap<DailyDungeonData> dailyDungeonDataMap = new Int2ObjectOpenHashMap<>();
Melledy's avatar
Melledy committed
70
	private static final Int2ObjectMap<DungeonData> dungeonDataMap = new Int2ObjectOpenHashMap<>();
Kengxxiao's avatar
Kengxxiao committed
71
	private static final Int2ObjectMap<ShopGoodsData> shopGoodsDataMap = new Int2ObjectOpenHashMap<>();
Akka's avatar
Akka committed
72
	private static final Int2ObjectMap<CombineData> combineDataMap = new Int2ObjectOpenHashMap<>();
73
	private static final Int2ObjectMap<RewardPreviewData> rewardPreviewDataMap = new Int2ObjectOpenHashMap<>();
Akka's avatar
Akka committed
74
75
	private static final Int2ObjectMap<TowerFloorData> towerFloorDataMap = new Int2ObjectOpenHashMap<>();
	private static final Int2ObjectMap<TowerLevelData> towerLevelDataMap = new Int2ObjectOpenHashMap<>();
76
	private static final Int2ObjectMap<TowerScheduleData> towerScheduleDataMap = new Int2ObjectOpenHashMap<>();
Akka's avatar
Akka committed
77

Yazawazi's avatar
Yazawazi committed
78
79
	// Cache
	private static Map<Integer, List<Integer>> fetters = new HashMap<>();
Kengxxiao's avatar
Kengxxiao committed
80
	private static Map<Integer, List<ShopGoodsData>> shopGoods = new HashMap<>();
81
	private static final IntList scenePointIdList = new IntArrayList();
Melledy's avatar
Melledy committed
82
	
Melledy's avatar
Melledy committed
83
84
85
86
	public static Int2ObjectMap<?> getMapByResourceDef(Class<?> resourceDefinition) {
		Int2ObjectMap<?> map = null;
		
		try {
87
			Field field = GameData.class.getDeclaredField(Utils.lowerCaseFirstChar(resourceDefinition.getSimpleName()) + "Map");
Melledy's avatar
Melledy committed
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
			field.setAccessible(true);
			
			map = (Int2ObjectMap<?>) field.get(null);
			
			field.setAccessible(false);
		} catch (Exception e) {
			Grasscutter.getLogger().error("Error fetching resource map for " + resourceDefinition.getSimpleName(), e);
		}
		
		return map;
	}

	public static Int2ObjectMap<String> getAbilityHashes() {
		return abilityHashes;
	}
	
	public static Map<String, AbilityEmbryoEntry> getAbilityEmbryoInfo() {
		return abilityEmbryos;
	}

Melledy's avatar
Melledy committed
108
109
110
111
	public static Map<String, AbilityModifierEntry> getAbilityModifiers() {
		return abilityModifiers;
	}

Melledy's avatar
Melledy committed
112
113
114
115
	public static Map<String, OpenConfigEntry> getOpenConfigEntries() {
		return openConfigEntries;
	}

Yazawazi's avatar
Yazawazi committed
116
117
118
	public static Map<String, ScenePointEntry> getScenePointEntries() {
		return scenePointEntries;
	}
Melledy's avatar
Melledy committed
119
120
121
122
123
	
	// TODO optimize
	public static ScenePointEntry getScenePointEntryById(int sceneId, int pointId) {
		return getScenePointEntries().get(sceneId + "_" + pointId);
	}
Yazawazi's avatar
Yazawazi committed
124

Melledy's avatar
Melledy committed
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
	public static Int2ObjectMap<AvatarData> getAvatarDataMap() {
		return avatarDataMap;
	}
	
	public static Int2ObjectMap<ItemData> getItemDataMap() {
		return itemDataMap;
	}

	public static Int2ObjectMap<AvatarSkillDepotData> getAvatarSkillDepotDataMap() {
		return avatarSkillDepotDataMap;
	}
	
	public static Int2ObjectMap<AvatarSkillData> getAvatarSkillDataMap() {
		return avatarSkillDataMap;
	}

	public static Int2ObjectMap<PlayerLevelData> getPlayerLevelDataMap() {
		return playerLevelDataMap;
	}

Yazawazi's avatar
Yazawazi committed
145
146
147
148
	public static Int2ObjectMap<AvatarFetterLevelData> getAvatarFetterLevelDataMap() {
		return avatarFetterLevelDataMap;
	}

Yazawazi's avatar
Yazawazi committed
149
150
151
152
	public static Int2ObjectMap<FetterCharacterCardData> getFetterCharacterCardDataMap() {
		return fetterCharacterCardDataMap;
	}

Melledy's avatar
Melledy committed
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
	public static Int2ObjectMap<AvatarLevelData> getAvatarLevelDataMap() {
		return avatarLevelDataMap;
	}

	public static Int2ObjectMap<WeaponLevelData> getWeaponLevelDataMap() {
		return weaponLevelDataMap;
	}
	
	public static Int2ObjectMap<ReliquaryAffixData> getReliquaryAffixDataMap() {
		return reliquaryAffixDataMap;
	}
	
	public static Int2ObjectMap<ReliquaryMainPropData> getReliquaryMainPropDataMap() {
		return reliquaryMainPropDataMap;
	}

	public static Int2ObjectMap<WeaponPromoteData> getWeaponPromoteDataMap() {
		return weaponPromoteDataMap;
	}

	public static Int2ObjectMap<WeaponCurveData> getWeaponCurveDataMap() {
		return weaponCurveDataMap;
	}
	
	public static Int2ObjectMap<AvatarCurveData> getAvatarCurveDataMap() {
		return avatarCurveDataMap;
	}

	public static int getRelicExpRequired(int rankLevel, int level) {
		ReliquaryLevelData levelData = reliquaryLevelDataMap.get((rankLevel << 8) + level);
		return levelData != null ? levelData.getExp() : 0;
	}
	
	public static ReliquaryLevelData getRelicLevelData(int rankLevel, int level) {
		return reliquaryLevelDataMap.get((rankLevel << 8) + level);
	}
	
	public static WeaponPromoteData getWeaponPromoteData(int promoteId, int promoteLevel) {
		return weaponPromoteDataMap.get((promoteId << 8) + promoteLevel);
	}

	public static int getWeaponExpRequired(int rankLevel, int level) {
		WeaponLevelData levelData = weaponLevelDataMap.get(level);
		if (levelData == null) {
			return 0;
		}
		try {
			return levelData.getRequiredExps()[rankLevel - 1];
		} catch (Exception e) {
			return 0;
		}
	}
	
	public static AvatarPromoteData getAvatarPromoteData(int promoteId, int promoteLevel) {
		return avatarPromoteDataMap.get((promoteId << 8) + promoteLevel);
	}

	public static int getAvatarLevelExpRequired(int level) {
		AvatarLevelData levelData = avatarLevelDataMap.get(level);
		return levelData != null ? levelData.getExp() : 0;
	}
Yazawazi's avatar
Yazawazi committed
214
215
216
217
218

	public static int getAvatarFetterLevelExpRequired(int level) {
		AvatarFetterLevelData levelData = avatarFetterLevelDataMap.get(level);
		return levelData != null ? levelData.getExp() : 0;
	}
Melledy's avatar
Melledy committed
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
	
	public static Int2ObjectMap<ProudSkillData> getProudSkillDataMap() {
		return proudSkillDataMap;
	}

	public static Int2ObjectMap<MonsterData> getMonsterDataMap() {
		return monsterDataMap;
	}

	public static Int2ObjectMap<NpcData> getNpcDataMap() {
		return npcDataMap;
	}

	public static Int2ObjectMap<GadgetData> getGadgetDataMap() {
		return gadgetDataMap;
	}

	public static Int2ObjectMap<ReliquarySetData> getReliquarySetDataMap() {
		return reliquarySetDataMap;
	}

	public static Int2ObjectMap<EquipAffixData> getEquipAffixDataMap() {
		return equipAffixDataMap;
	}

	public static Int2ObjectMap<MonsterCurveData> getMonsterCurveDataMap() {
		return monsterCurveDataMap;
	}

	public static Int2ObjectMap<MonsterDescribeData> getMonsterDescribeDataMap() {
		return monsterDescribeDataMap;
	}

	public static Int2ObjectMap<AvatarTalentData> getAvatarTalentDataMap() {
		return avatarTalentDataMap;
	}

	public static Int2ObjectMap<AvatarFlycloakData> getAvatarFlycloakDataMap() {
		return avatarFlycloakDataMap;
	}

	public static Int2ObjectMap<AvatarCostumeData> getAvatarCostumeDataMap() {
		return avatarCostumeDataMap;
	}
	
	public static Int2ObjectMap<AvatarCostumeData> getAvatarCostumeDataItemIdMap() {
		return avatarCostumeDataItemIdMap;
	}
Melledy's avatar
Melledy committed
267
268
269
270

	public static Int2ObjectMap<SceneData> getSceneDataMap() {
		return sceneDataMap;
	}
Yazawazi's avatar
Yazawazi committed
271

Yazawazi's avatar
Yazawazi committed
272
273
274
275
	public static Int2ObjectMap<RewardData> getRewardDataMap() {
		return rewardDataMap;
	}

Yazawazi's avatar
Yazawazi committed
276
	public static Map<Integer, List<Integer>> getFetterDataEntries() {
Yazawazi's avatar
Yazawazi committed
277
278
279
280
281
282
283
284
285
		if (fetters.isEmpty()) {
			fetterDataMap.forEach((k, v) -> {
				if (!fetters.containsKey(v.getAvatarId())) {
					fetters.put(v.getAvatarId(), new ArrayList<>());
				}
				fetters.get(v.getAvatarId()).add(k);
			});
		}

Yazawazi's avatar
Yazawazi committed
286
287
		return fetters;
	}
Melledy's avatar
Melledy committed
288
289
290
291

	public static Int2ObjectMap<WorldLevelData> getWorldLevelDataMap() {
		return worldLevelDataMap;
	}
Melledy's avatar
Melledy committed
292
293
294
295

	public static Int2ObjectMap<DungeonData> getDungeonDataMap() {
		return dungeonDataMap;
	}
296
	  
297
298
299
300
	public static Int2ObjectMap<DailyDungeonData> getDailyDungeonDataMap() {
		return dailyDungeonDataMap;
	}

Kengxxiao's avatar
Kengxxiao committed
301
302
303
304
305
306
307
308
309
310
311
	public static Map<Integer, List<ShopGoodsData>> getShopGoodsDataEntries() {
		if (shopGoods.isEmpty()) {
			shopGoodsDataMap.forEach((k, v) -> {
				if (!shopGoods.containsKey(v.getShopType()))
					shopGoods.put(v.getShopType(), new ArrayList<>());
				shopGoods.get(v.getShopType()).add(v);
			});
		}

		return shopGoods;
	}
312

313
314
315
316
	public static Int2ObjectMap<RewardPreviewData> getRewardPreviewDataMap() {
		return rewardPreviewDataMap;
	}

317
318
319
	public static IntList getScenePointIdList() {
		return scenePointIdList;
	}
Akka's avatar
Akka committed
320
321
322
323

	public static Int2ObjectMap<CombineData> getCombineDataMap() {
		return combineDataMap;
	}
Akka's avatar
Akka committed
324
325
326
327
328
329
330

	public static Int2ObjectMap<TowerFloorData> getTowerFloorDataMap(){
		return towerFloorDataMap;
	}
	public static Int2ObjectMap<TowerLevelData> getTowerLevelDataMap(){
		return towerLevelDataMap;
	}
331
332
333
	public static Int2ObjectMap<TowerScheduleData> getTowerScheduleDataMap(){
		return towerScheduleDataMap;
	}
Melledy's avatar
Melledy committed
334
}