diff --git a/src/main/java/emu/grasscutter/Grasscutter.java b/src/main/java/emu/grasscutter/Grasscutter.java index f7669d30b..60d042b11 100644 --- a/src/main/java/emu/grasscutter/Grasscutter.java +++ b/src/main/java/emu/grasscutter/Grasscutter.java @@ -6,6 +6,7 @@ import java.io.FileReader; import java.io.FileWriter; import java.io.InputStreamReader; import java.net.InetSocketAddress; +import java.util.Calendar; import emu.grasscutter.command.CommandMap; import emu.grasscutter.plugin.PluginManager; @@ -32,6 +33,8 @@ public final class Grasscutter { private static final Gson gson = new GsonBuilder().setPrettyPrinting().create(); private static final File configFile = new File("./config.json"); + private static int day; // Current day of week + public static RunMode MODE = RunMode.BOTH; private static DispatchServer dispatchServer; private static GameServer gameServer; @@ -67,8 +70,10 @@ public final class Grasscutter { Grasscutter.getLogger().info("Starting Grasscutter..."); // Load all resources. + Grasscutter.updateDayOfWeek(); ResourceLoader.loadAll(); ScriptLoader.init(); + // Database DatabaseManager.initialize(); @@ -179,4 +184,13 @@ public final class Grasscutter { public static PluginManager getPluginManager() { return pluginManager; } + + public static void updateDayOfWeek() { + Calendar calendar = Calendar.getInstance(); + day = calendar.get(Calendar.DAY_OF_WEEK); + } + + public static int getCurrentDayOfWeek() { + return day; + } } diff --git a/src/main/java/emu/grasscutter/data/GameData.java b/src/main/java/emu/grasscutter/data/GameData.java index 45fad21a4..c187a1819 100644 --- a/src/main/java/emu/grasscutter/data/GameData.java +++ b/src/main/java/emu/grasscutter/data/GameData.java @@ -15,6 +15,8 @@ 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; +import it.unimi.dsi.fastutil.ints.IntArrayList; +import it.unimi.dsi.fastutil.ints.IntList; public class GameData { // BinOutputs @@ -61,12 +63,14 @@ public class GameData { private static final Int2ObjectMap fetterCharacterCardDataMap = new Int2ObjectOpenHashMap<>(); private static final Int2ObjectMap rewardDataMap = new Int2ObjectOpenHashMap<>(); private static final Int2ObjectMap worldLevelDataMap = new Int2ObjectOpenHashMap<>(); + private static final Int2ObjectMap dailyDungeonDataMap = new Int2ObjectOpenHashMap<>(); private static final Int2ObjectMap dungeonDataMap = new Int2ObjectOpenHashMap<>(); private static final Int2ObjectMap shopGoodsDataMap = new Int2ObjectOpenHashMap<>(); // Cache private static Map> fetters = new HashMap<>(); private static Map> shopGoods = new HashMap<>(); + private static final IntList scenePointIdList = new IntArrayList(); public static char EJWOA = 's'; @@ -280,6 +284,10 @@ public class GameData { return dungeonDataMap; } + public static Int2ObjectMap getDailyDungeonDataMap() { + return dailyDungeonDataMap; + } + public static Map> getShopGoodsDataEntries() { if (shopGoods.isEmpty()) { shopGoodsDataMap.forEach((k, v) -> { @@ -291,4 +299,8 @@ public class GameData { return shopGoods; } + + public static IntList getScenePointIdList() { + return scenePointIdList; + } } diff --git a/src/main/java/emu/grasscutter/data/ResourceLoader.java b/src/main/java/emu/grasscutter/data/ResourceLoader.java index 6b48645d8..180080e51 100644 --- a/src/main/java/emu/grasscutter/data/ResourceLoader.java +++ b/src/main/java/emu/grasscutter/data/ResourceLoader.java @@ -48,11 +48,12 @@ public class ResourceLoader { loadOpenConfig(); // Load resources loadResources(); - loadScenePoints(); // Process into depots GameDepot.load(); // Load spawn data loadSpawnData(); + // Load scene points - must be done AFTER resources are loaded + loadScenePoints(); // Custom - TODO move this somewhere else try { GameData.getAvatarSkillDepotDataMap().get(504).setAbilities( @@ -168,6 +169,9 @@ public class ResourceLoader { ScenePointEntry sl = new ScenePointEntry(sceneId + "_" + entry.getKey(), pointData); scenePointList.add(sl); + GameData.getScenePointIdList().add(pointData.getId()); + + pointData.updateDailyDungeon(); } for (ScenePointEntry entry : scenePointList) { diff --git a/src/main/java/emu/grasscutter/data/common/PointData.java b/src/main/java/emu/grasscutter/data/common/PointData.java index 147eee81a..fa3891d7c 100644 --- a/src/main/java/emu/grasscutter/data/common/PointData.java +++ b/src/main/java/emu/grasscutter/data/common/PointData.java @@ -1,12 +1,18 @@ package emu.grasscutter.data.common; +import emu.grasscutter.Grasscutter; +import emu.grasscutter.data.GameData; +import emu.grasscutter.data.def.DailyDungeonData; import emu.grasscutter.utils.Position; +import it.unimi.dsi.fastutil.ints.IntArrayList; +import it.unimi.dsi.fastutil.ints.IntList; public class PointData { private int id; private String $type; private Position tranPos; private int[] dungeonIds; + private int[] dungeonRandomList; public int getId() { return id; @@ -27,4 +33,31 @@ public class PointData { public int[] getDungeonIds() { return dungeonIds; } + + public int[] getDungeonRandomList() { + return dungeonRandomList; + } + + public void updateDailyDungeon() { + if (getDungeonRandomList() == null) { + return; + } + + IntList newDungeons = new IntArrayList(); + int day = Grasscutter.getCurrentDayOfWeek(); + + for (int randomId : getDungeonRandomList()) { + DailyDungeonData data = GameData.getDailyDungeonDataMap().get(randomId); + + if (data != null) { + int[] addDungeons = data.getDungeonsByDay(day); + + for (int d : addDungeons) { + newDungeons.add(d); + } + } + } + + this.dungeonIds = newDungeons.toIntArray(); + } } diff --git a/src/main/java/emu/grasscutter/data/def/DailyDungeonData.java b/src/main/java/emu/grasscutter/data/def/DailyDungeonData.java new file mode 100644 index 000000000..8cd878125 --- /dev/null +++ b/src/main/java/emu/grasscutter/data/def/DailyDungeonData.java @@ -0,0 +1,50 @@ +package emu.grasscutter.data.def; + +import java.util.Calendar; + +import emu.grasscutter.data.GameData; +import emu.grasscutter.data.GameResource; +import emu.grasscutter.data.ResourceType; + +import emu.grasscutter.game.props.SceneType; +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; + +@ResourceType(name = "DailyDungeonConfigData.json") +public class DailyDungeonData extends GameResource { + private int Id; + private int[] Monday; + private int[] Tuesday; + private int[] Wednesday; + private int[] Thursday; + private int[] Friday; + private int[] Saturday; + private int[] Sunday; + + private static final int[] empty = new int[0]; + private final Int2ObjectMap map; + + public DailyDungeonData() { + this.map = new Int2ObjectOpenHashMap<>(); + } + + @Override + public int getId() { + return this.Id; + } + + public int[] getDungeonsByDay(int day) { + return map.getOrDefault(day, empty); + } + + @Override + public void onLoad() { + map.put(Calendar.MONDAY, Monday); + map.put(Calendar.TUESDAY, Tuesday); + map.put(Calendar.WEDNESDAY, Wednesday); + map.put(Calendar.THURSDAY, Thursday); + map.put(Calendar.FRIDAY, Friday); + map.put(Calendar.SATURDAY, Saturday); + map.put(Calendar.SUNDAY, Sunday); + } +} diff --git a/src/main/java/emu/grasscutter/game/dungeons/DungeonManager.java b/src/main/java/emu/grasscutter/game/dungeons/DungeonManager.java index 6011c1f7c..4c04f86f7 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/DungeonManager.java +++ b/src/main/java/emu/grasscutter/game/dungeons/DungeonManager.java @@ -28,7 +28,7 @@ public class DungeonManager { public void getEntryInfo(Player player, int pointId) { ScenePointEntry entry = GameData.getScenePointEntryById(player.getScene().getId(), pointId); - if (entry == null || entry.getPointData().getDungeonIds() == null) { + if (entry == null) { // Error player.sendPacket(new PacketDungeonEntryInfoRsp()); return; @@ -79,4 +79,10 @@ public class DungeonManager { player.getWorld().transferPlayerToScene(player, prevScene, prevPos); player.sendPacket(new BasePacket(PacketOpcodes.PlayerQuitDungeonRsp)); } + + public void updateDailyDungeons() { + for (ScenePointEntry entry : GameData.getScenePointEntries().values()) { + entry.getPointData().updateDailyDungeon(); + } + } } diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketDungeonEntryInfoRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketDungeonEntryInfoRsp.java index a2cc052bb..5d7842fe1 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketDungeonEntryInfoRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketDungeonEntryInfoRsp.java @@ -17,11 +17,13 @@ public class PacketDungeonEntryInfoRsp extends BasePacket { DungeonEntryInfoRsp.Builder proto = DungeonEntryInfoRsp.newBuilder() .setPointId(pointData.getId()); - for (int dungeonId : pointData.getDungeonIds()) { - DungeonEntryInfo info = DungeonEntryInfo.newBuilder().setDungeonId(dungeonId).build(); - proto.addDungeonEntryList(info); + if (pointData.getDungeonIds() != null) { + for (int dungeonId : pointData.getDungeonIds()) { + DungeonEntryInfo info = DungeonEntryInfo.newBuilder().setDungeonId(dungeonId).build(); + proto.addDungeonEntryList(info); + } } - + this.setData(proto); } diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketGetScenePointRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketGetScenePointRsp.java index 85b7ab02f..b4c001831 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketGetScenePointRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketGetScenePointRsp.java @@ -1,5 +1,6 @@ package emu.grasscutter.server.packet.send; +import emu.grasscutter.data.GameData; import emu.grasscutter.net.packet.BasePacket; import emu.grasscutter.net.packet.PacketOpcodes; import emu.grasscutter.net.proto.GetScenePointRspOuterClass.GetScenePointRsp; @@ -12,8 +13,12 @@ public class PacketGetScenePointRsp extends BasePacket { GetScenePointRsp.Builder p = GetScenePointRsp.newBuilder() .setSceneId(sceneId); - for (int i = 1; i < 1000; i++) { - p.addUnlockedPointList(i); + if (GameData.getScenePointIdList().size() == 0) { + for (int i = 1; i < 1000; i++) { + p.addUnlockedPointList(i); + } + } else { + p.addAllUnlockedPointList(GameData.getScenePointIdList()); } for (int i = 1; i < 9; i++) {