From 1940b22dc55dae76dd51f81ed5dab1ba1d8528aa Mon Sep 17 00:00:00 2001 From: KingRainbow44 Date: Thu, 1 Jun 2023 18:13:41 -0400 Subject: [PATCH] Fix statue unlocks, and probably other quests involving talks --- .../data/excels/TalkConfigData.java | 15 +++++-- .../emu/grasscutter/game/quest/GameQuest.java | 7 ++-- .../quest/content/ContentCompleteTalk.java | 7 ++-- .../grasscutter/game/talk/TalkManager.java | 39 +++++++++---------- 4 files changed, 37 insertions(+), 31 deletions(-) diff --git a/src/main/java/emu/grasscutter/data/excels/TalkConfigData.java b/src/main/java/emu/grasscutter/data/excels/TalkConfigData.java index 27c01116d..8a5db6f67 100644 --- a/src/main/java/emu/grasscutter/data/excels/TalkConfigData.java +++ b/src/main/java/emu/grasscutter/data/excels/TalkConfigData.java @@ -1,12 +1,11 @@ package emu.grasscutter.data.excels; import com.google.gson.annotations.SerializedName; -import emu.grasscutter.data.GameResource; -import emu.grasscutter.data.ResourceType; +import emu.grasscutter.data.*; import emu.grasscutter.game.talk.TalkExec; +import lombok.*; + import java.util.List; -import lombok.Data; -import lombok.EqualsAndHashCode; @ResourceType(name = "TalkExcelConfigData.json") @EqualsAndHashCode(callSuper = false) @@ -38,6 +37,14 @@ public final class TalkConfigData extends GameResource { this.finishExec == null ? List.of() : this.finishExec.stream().filter(x -> x.getType() != null).toList(); + + if (this.questId <= 0) { + var id = String.valueOf(this.getId()); + this.questId = Integer.parseInt( + id.length() < 5 ? "0" : + id.substring(0, 3) + ); + } } @Data diff --git a/src/main/java/emu/grasscutter/game/quest/GameQuest.java b/src/main/java/emu/grasscutter/game/quest/GameQuest.java index f3503ad48..4d3011705 100644 --- a/src/main/java/emu/grasscutter/game/quest/GameQuest.java +++ b/src/main/java/emu/grasscutter/game/quest/GameQuest.java @@ -15,10 +15,11 @@ import emu.grasscutter.scripts.data.SceneGroup; import emu.grasscutter.server.packet.send.*; import emu.grasscutter.utils.Utils; import it.unimi.dsi.fastutil.ints.IntIntImmutablePair; -import java.util.*; -import javax.script.Bindings; import lombok.*; +import javax.script.Bindings; +import java.util.*; + @Entity public class GameQuest { @Transient @Getter @Setter private GameMainQuest mainQuest; @@ -142,7 +143,7 @@ public class GameQuest { } public void setFinishProgress(int index, int value) { - finishProgressList[index] = value; + this.finishProgressList[index] = value; } public void setFailProgress(int index, int value) { diff --git a/src/main/java/emu/grasscutter/game/quest/content/ContentCompleteTalk.java b/src/main/java/emu/grasscutter/game/quest/content/ContentCompleteTalk.java index c9e38ba66..73ed389da 100644 --- a/src/main/java/emu/grasscutter/game/quest/content/ContentCompleteTalk.java +++ b/src/main/java/emu/grasscutter/game/quest/content/ContentCompleteTalk.java @@ -1,12 +1,11 @@ package emu.grasscutter.game.quest.content; -import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_COMPLETE_TALK; - import emu.grasscutter.data.excels.quest.QuestData; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValueContent; +import emu.grasscutter.game.quest.*; import lombok.val; +import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_COMPLETE_TALK; + @QuestValueContent(QUEST_CONTENT_COMPLETE_TALK) public class ContentCompleteTalk extends BaseContent { @Override diff --git a/src/main/java/emu/grasscutter/game/talk/TalkManager.java b/src/main/java/emu/grasscutter/game/talk/TalkManager.java index d35043639..0ca762842 100644 --- a/src/main/java/emu/grasscutter/game/talk/TalkManager.java +++ b/src/main/java/emu/grasscutter/game/talk/TalkManager.java @@ -1,15 +1,13 @@ package emu.grasscutter.game.talk; -import static emu.grasscutter.game.quest.enums.QuestCond.QUEST_COND_COMPLETE_TALK; -import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_COMPLETE_ANY_TALK; -import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_COMPLETE_TALK; - import emu.grasscutter.data.GameData; import emu.grasscutter.data.binout.MainQuestData.TalkData; -import emu.grasscutter.game.player.BasePlayerManager; -import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.player.*; import lombok.NonNull; +import static emu.grasscutter.game.quest.enums.QuestCond.QUEST_COND_COMPLETE_TALK; +import static emu.grasscutter.game.quest.enums.QuestContent.*; + public final class TalkManager extends BasePlayerManager { public TalkManager(@NonNull Player player) { super(player); @@ -22,30 +20,31 @@ public final class TalkManager extends BasePlayerManager { * @param npcEntityId The entity ID of the NPC being talked to. */ public void triggerTalkAction(int talkId, int npcEntityId) { - var talkData = GameData.getTalkConfigDataMap().get(talkId); - if (talkData == null) return; - var player = this.getPlayer(); - // Check if the NPC id is valid. - var entity = player.getScene().getEntityById(npcEntityId); - if (entity != null) { - // The config ID of the entity is the NPC's ID. - if (!talkData.getNpcId().contains(entity.getConfigId())) return; - } - // Execute the talk action on associated handlers. - talkData + var talkData = GameData.getTalkConfigDataMap().get(talkId); + if (talkData != null) { + // Check if the NPC id is valid. + var entity = player.getScene().getEntityById(npcEntityId); + if (entity != null) { + // The config ID of the entity is the NPC's ID. + if (!talkData.getNpcId().contains(entity.getConfigId())) return; + } + + // Execute the talk action on associated handlers. + talkData .getFinishExec() .forEach(e -> player.getServer().getTalkSystem().triggerExec(player, talkData, e)); + // Save the talk value to the quest's data. + this.saveTalkToQuest(talkId, talkData.getQuestId()); + } + // Invoke the talking events for quests. var questManager = player.getQuestManager(); questManager.queueEvent(QUEST_CONTENT_COMPLETE_ANY_TALK, talkId); questManager.queueEvent(QUEST_CONTENT_COMPLETE_TALK, talkId); questManager.queueEvent(QUEST_COND_COMPLETE_TALK, talkId); - - // Save the talk value to the quest's data. - this.saveTalkToQuest(talkId, talkData.getQuestId()); } public void saveTalkToQuest(int talkId, int mainQuestId) {