GenshinDepot.java 2.51 KB
Newer Older
Melledy's avatar
Melledy committed
1
2
3
4
5
package emu.grasscutter.data;

import java.util.ArrayList;
import java.util.List;

Melledy's avatar
Melledy committed
6
7
8
import org.danilopianini.util.FlexibleQuadTree;
import org.danilopianini.util.SpatialIndex;

Melledy's avatar
Melledy committed
9
10
11
import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.def.ReliquaryAffixData;
import emu.grasscutter.data.def.ReliquaryMainPropData;
Melledy's avatar
Melledy committed
12
13
import emu.grasscutter.game.world.SpawnDataEntry;
import emu.grasscutter.game.world.SpawnDataEntry.SpawnGroupEntry;
Melledy's avatar
Melledy committed
14
15
16
17
18
19
20
21
import emu.grasscutter.utils.WeightedList;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;

public class GenshinDepot {
	private static Int2ObjectMap<WeightedList<ReliquaryMainPropData>> relicMainPropDepot = new Int2ObjectOpenHashMap<>();
	private static Int2ObjectMap<List<ReliquaryAffixData>> relicAffixDepot = new Int2ObjectOpenHashMap<>();
	
Melledy's avatar
Melledy committed
22
23
	private static Int2ObjectMap<SpatialIndex<SpawnGroupEntry>> spawnLists = new Int2ObjectOpenHashMap<>();
	
Melledy's avatar
Melledy committed
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
	public static void load() {
		for (ReliquaryMainPropData data : GenshinData.getReliquaryMainPropDataMap().values()) {
			if (data.getWeight() <= 0 || data.getPropDepotId() <= 0) {
				continue;
			}
			WeightedList<ReliquaryMainPropData> list = relicMainPropDepot.computeIfAbsent(data.getPropDepotId(), k -> new WeightedList<>());
			list.add(data.getWeight(), data);
		}
		for (ReliquaryAffixData data : GenshinData.getReliquaryAffixDataMap().values()) {
			if (data.getWeight() <= 0 || data.getDepotId() <= 0) {
				continue;
			}
			List<ReliquaryAffixData> list = relicAffixDepot.computeIfAbsent(data.getDepotId(), k -> new ArrayList<>());
			list.add(data);
		}
		// Let the server owner know if theyre missing weights
		if (relicMainPropDepot.size() == 0 || relicAffixDepot.size() == 0) {
			Grasscutter.getLogger().error("Relic properties are missing weights! Please check your ReliquaryMainPropExcelConfigData or ReliquaryAffixExcelConfigData files in your ExcelBinOutput folder.");
		}
	}
	
	public static ReliquaryMainPropData getRandomRelicMainProp(int depot) {
		WeightedList<ReliquaryMainPropData> depotList = relicMainPropDepot.get(depot);
		if (depotList == null) {
			return null;
		}
		return depotList.next();
	}
	
	public static List<ReliquaryAffixData> getRandomRelicAffixList(int depot) {
		return relicAffixDepot.get(depot);
	}
Melledy's avatar
Melledy committed
56
57
58
59
60
61
62
63
	
	public static Int2ObjectMap<SpatialIndex<SpawnGroupEntry>> getSpawnLists() {
		return spawnLists;
	}
	
	public static SpatialIndex<SpawnGroupEntry> getSpawnListById(int sceneId) {
		return getSpawnLists().computeIfAbsent(sceneId, id -> new FlexibleQuadTree<>());
	}
Melledy's avatar
Melledy committed
64
}