From 749ef3ff234e05a432357f956fc9f3fcf9b33e60 Mon Sep 17 00:00:00 2001 From: ShigemoriHakura <62388797+ShigemoriHakura@users.noreply.github.com> Date: Sat, 14 May 2022 07:33:07 +0800 Subject: [PATCH] Add support for codexQuests (#870) --- .../java/emu/grasscutter/data/GameData.java | 7 ++- .../emu/grasscutter/data/def/CodexQuest.java | 42 +++++++++++++++ .../emu/grasscutter/game/player/Player.java | 1 + .../grasscutter/game/quest/GameMainQuest.java | 2 + .../emu/grasscutter/game/quest/GameQuest.java | 1 + .../grasscutter/game/quest/QuestManager.java | 6 +++ .../send/PacketCodexDataFullNotify.java | 54 +++++++++++++++++++ .../send/PacketCodexDataUpdateNotify.java | 27 ++++++++++ 8 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 src/main/java/emu/grasscutter/data/def/CodexQuest.java create mode 100644 src/main/java/emu/grasscutter/server/packet/send/PacketCodexDataFullNotify.java create mode 100644 src/main/java/emu/grasscutter/server/packet/send/PacketCodexDataUpdateNotify.java diff --git a/src/main/java/emu/grasscutter/data/GameData.java b/src/main/java/emu/grasscutter/data/GameData.java index 75b840202..ed5c469bb 100644 --- a/src/main/java/emu/grasscutter/data/GameData.java +++ b/src/main/java/emu/grasscutter/data/GameData.java @@ -9,7 +9,6 @@ import java.util.Map; import emu.grasscutter.Grasscutter; import emu.grasscutter.utils.Utils; import emu.grasscutter.data.custom.AbilityEmbryoEntry; -import emu.grasscutter.data.custom.AbilityModifier; import emu.grasscutter.data.custom.AbilityModifierEntry; import emu.grasscutter.data.custom.OpenConfigEntry; import emu.grasscutter.data.custom.MainQuestData; @@ -65,6 +64,8 @@ public class GameData { private static final Int2ObjectMap sceneDataMap = new Int2ObjectLinkedOpenHashMap<>(); private static final Int2ObjectMap fetterDataMap = new Int2ObjectOpenHashMap<>(); + private static final Int2ObjectMap codexQuestMap = new Int2ObjectOpenHashMap<>(); + private static final Int2ObjectMap codexQuestIdMap = new Int2ObjectOpenHashMap<>(); private static final Int2ObjectMap fetterCharacterCardDataMap = new Int2ObjectOpenHashMap<>(); private static final Int2ObjectMap rewardDataMap = new Int2ObjectOpenHashMap<>(); private static final Int2ObjectMap worldLevelDataMap = new Int2ObjectOpenHashMap<>(); @@ -293,6 +294,10 @@ public class GameData { return fetters; } + public static Int2ObjectMap getCodexQuestMap(){return codexQuestMap;} + + public static Int2ObjectMap getCodexQuestIdMap(){return codexQuestIdMap;} + public static Int2ObjectMap getWorldLevelDataMap() { return worldLevelDataMap; } diff --git a/src/main/java/emu/grasscutter/data/def/CodexQuest.java b/src/main/java/emu/grasscutter/data/def/CodexQuest.java new file mode 100644 index 000000000..578837e04 --- /dev/null +++ b/src/main/java/emu/grasscutter/data/def/CodexQuest.java @@ -0,0 +1,42 @@ +package emu.grasscutter.data.def; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.data.GameData; +import emu.grasscutter.data.GameResource; +import emu.grasscutter.data.ResourceType; + +@ResourceType(name = {"QuestCodexExcelConfigData.json"}, loadPriority = ResourceType.LoadPriority.HIGH) +public class CodexQuest extends GameResource { + private int Id; + private int ParentQuestId; + private int ChapterId; + private int SortOrder; + private boolean IsDisuse; + + public int getParentQuestId() { + return ParentQuestId; + } + + public int getId() { + return Id; + } + + public int getChapterId() { + return ChapterId; + } + + public int getSortOrder() { + return SortOrder; + } + + public boolean getIsDisuse() { + return IsDisuse; + } + + @Override + public void onLoad() { + if(!this.getIsDisuse()) { + GameData.getCodexQuestIdMap().put(this.getParentQuestId(), this); + } + } +} diff --git a/src/main/java/emu/grasscutter/game/player/Player.java b/src/main/java/emu/grasscutter/game/player/Player.java index 9c9f1ea56..f86e09370 100644 --- a/src/main/java/emu/grasscutter/game/player/Player.java +++ b/src/main/java/emu/grasscutter/game/player/Player.java @@ -1212,6 +1212,7 @@ public class Player { session.send(new PacketAvatarDataNotify(this)); session.send(new PacketFinishedParentQuestNotify(this)); session.send(new PacketQuestListNotify(this)); + session.send(new PacketCodexDataFullNotify(this)); session.send(new PacketServerCondMeetQuestListUpdateNotify(this)); session.send(new PacketAllWidgetDataNotify(this)); session.send(new PacketWidgetGadgetAllDataNotify()); diff --git a/src/main/java/emu/grasscutter/game/quest/GameMainQuest.java b/src/main/java/emu/grasscutter/game/quest/GameMainQuest.java index 613819d0b..c298913cc 100644 --- a/src/main/java/emu/grasscutter/game/quest/GameMainQuest.java +++ b/src/main/java/emu/grasscutter/game/quest/GameMainQuest.java @@ -3,6 +3,7 @@ package emu.grasscutter.game.quest; import java.util.HashMap; import java.util.Map; +import emu.grasscutter.server.packet.send.PacketCodexDataUpdateNotify; import org.bson.types.ObjectId; import dev.morphia.annotations.Entity; @@ -91,6 +92,7 @@ public class GameMainQuest { this.isFinished = true; this.state = ParentQuestState.PARENT_QUEST_STATE_FINISHED; this.getOwner().getSession().send(new PacketFinishedParentQuestUpdateNotify(this)); + this.getOwner().getSession().send(new PacketCodexDataUpdateNotify(this)); this.save(); } diff --git a/src/main/java/emu/grasscutter/game/quest/GameQuest.java b/src/main/java/emu/grasscutter/game/quest/GameQuest.java index 5e1126fcb..3caf950ba 100644 --- a/src/main/java/emu/grasscutter/game/quest/GameQuest.java +++ b/src/main/java/emu/grasscutter/game/quest/GameQuest.java @@ -11,6 +11,7 @@ import emu.grasscutter.game.player.Player; import emu.grasscutter.game.quest.enums.LogicType; import emu.grasscutter.game.quest.enums.QuestState; import emu.grasscutter.net.proto.QuestOuterClass.Quest; +import emu.grasscutter.server.packet.send.PacketCodexDataUpdateNotify; import emu.grasscutter.server.packet.send.PacketQuestListUpdateNotify; import emu.grasscutter.server.packet.send.PacketQuestProgressUpdateNotify; import emu.grasscutter.utils.Utils; diff --git a/src/main/java/emu/grasscutter/game/quest/QuestManager.java b/src/main/java/emu/grasscutter/game/quest/QuestManager.java index 745ce9ef8..0d81834f0 100644 --- a/src/main/java/emu/grasscutter/game/quest/QuestManager.java +++ b/src/main/java/emu/grasscutter/game/quest/QuestManager.java @@ -66,6 +66,12 @@ public class QuestManager { } } } + + public void forEachMainQuest(Consumer callback) { + for (GameMainQuest mainQuest : getQuests().values()) { + callback.accept(mainQuest); + } + } // TODO public void forEachActiveQuest(Consumer callback) { diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketCodexDataFullNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketCodexDataFullNotify.java new file mode 100644 index 000000000..760c3b3d2 --- /dev/null +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketCodexDataFullNotify.java @@ -0,0 +1,54 @@ +package emu.grasscutter.server.packet.send; + +import java.util.Collections; +import java.util.List; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.data.GameData; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.CodexDataFullNotifyOuterClass.CodexDataFullNotify; +import emu.grasscutter.net.proto.CodexTypeDataOuterClass.CodexTypeData; +import emu.grasscutter.net.proto.CodexTypeOuterClass; +import emu.grasscutter.server.game.GameSession; + +public class PacketCodexDataFullNotify extends BasePacket { + public PacketCodexDataFullNotify(Player player) { + super(PacketOpcodes.CodexDataFullNotify, true); + + //Quests + CodexTypeData.Builder questTypeData = CodexTypeData.newBuilder() + .setTypeValue(1); + + //Tips + CodexTypeData.Builder pushTipsTypeData = CodexTypeData.newBuilder() + .setTypeValue(6); + + //Views + CodexTypeData.Builder viewTypeData = CodexTypeData.newBuilder() + .setTypeValue(7); + + //Weapons + CodexTypeData.Builder weaponTypeData = CodexTypeData.newBuilder() + .setTypeValue(2); + + + player.getQuestManager().forEachMainQuest(mainQuest -> { + if(mainQuest.isFinished()){ + var codexQuest = GameData.getCodexQuestIdMap().get(mainQuest.getParentQuestId()); + if(codexQuest != null){ + questTypeData.addCodexIdList(codexQuest.getId()).addAllHaveViewedList(Collections.singleton(true)); + } + } + }); + + CodexDataFullNotify.Builder proto = CodexDataFullNotify.newBuilder() + .addTypeDataList(questTypeData.build()) + .addTypeDataList(pushTipsTypeData.build()) + .addTypeDataList(viewTypeData.build()) + .addTypeDataList(weaponTypeData); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketCodexDataUpdateNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketCodexDataUpdateNotify.java new file mode 100644 index 000000000..c7318bd91 --- /dev/null +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketCodexDataUpdateNotify.java @@ -0,0 +1,27 @@ +package emu.grasscutter.server.packet.send; + +import java.util.Collections; +import java.util.List; + +import emu.grasscutter.data.GameData; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.quest.GameMainQuest; +import emu.grasscutter.game.quest.GameQuest; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.CodexDataUpdateNotifyOuterClass.CodexDataUpdateNotify; +import emu.grasscutter.server.game.GameSession; + +public class PacketCodexDataUpdateNotify extends BasePacket { + public PacketCodexDataUpdateNotify(GameMainQuest quest) { + super(PacketOpcodes.CodexDataUpdateNotify, true); + var codexQuest = GameData.getCodexQuestIdMap().get(quest.getParentQuestId()); + if(codexQuest != null){ + CodexDataUpdateNotify proto = CodexDataUpdateNotify.newBuilder() + .setTypeValue(1) + .setId(codexQuest.getId()) + .build(); + this.setData(proto); + } + } +}