From 8b84360724680bc371b63fafb2e1575de8f40ffe Mon Sep 17 00:00:00 2001 From: KingRainbow44 Date: Mon, 1 May 2023 21:45:56 -0400 Subject: [PATCH] Invoke the 'not equal' events --- .../emu/grasscutter/game/quest/GameQuest.java | 51 ++++++++----------- .../quest/conditions/ConditionStateEqual.java | 19 ++----- .../conditions/ConditionStateNotEqual.java | 19 ++----- .../quest/content/ContentEnterMyWorld.java | 2 - 4 files changed, 31 insertions(+), 60 deletions(-) diff --git a/src/main/java/emu/grasscutter/game/quest/GameQuest.java b/src/main/java/emu/grasscutter/game/quest/GameQuest.java index ba5393ff6..962072d3f 100644 --- a/src/main/java/emu/grasscutter/game/quest/GameQuest.java +++ b/src/main/java/emu/grasscutter/game/quest/GameQuest.java @@ -104,19 +104,7 @@ public class GameQuest { // Some subQuests and talks become active when some other subQuests are unfinished (even from // different MainQuests) - getOwner() - .getQuestManager() - .queueEvent( - QuestContent.QUEST_CONTENT_QUEST_STATE_EQUAL, - getSubQuestId(), - getState().getValue(), - 0, - 0, - 0); - getOwner() - .getQuestManager() - .queueEvent( - QuestCond.QUEST_COND_STATE_EQUAL, getSubQuestId(), getState().getValue(), 0, 0, 0); + this.triggerStateEvents(); getQuestData() .getBeginExec() @@ -127,6 +115,24 @@ public class GameQuest { this.save(); } + /** + * Triggers events: + * 'QUEST_COND_STATE_EQUAL', + * 'QUEST_COND_STATE_NOT_EQUAL', + * 'QUEST_CONTENT_QUEST_STATE_EQUAL', + * 'QUEST_CONTENT_QUEST_STATE_NOT_EQUAL' + */ + public void triggerStateEvents() { + var questManager = this.getOwner().getQuestManager(); + var questId = this.getSubQuestId(); + var state = this.getState().getValue(); + + questManager.queueEvent(QuestCond.QUEST_COND_STATE_EQUAL, questId, state, 0, 0, 0); + questManager.queueEvent(QuestCond.QUEST_COND_STATE_NOT_EQUAL, questId, state, 0, 0, 0); + questManager.queueEvent(QuestContent.QUEST_CONTENT_QUEST_STATE_EQUAL, questId, state, 0, 0, 0); + questManager.queueEvent(QuestContent.QUEST_CONTENT_QUEST_STATE_NOT_EQUAL, questId, state, 0, 0, 0); + } + public String getTriggerNameById(int id) { TriggerExcelConfigData trigger = GameData.getTriggerExcelConfigDataMap().get(id); if (trigger != null) { @@ -214,10 +220,7 @@ public class GameQuest { this.getOwner() .getQuestManager() .queueEvent(QuestContent.QUEST_CONTENT_FINISH_PLOT, this.subQuestId, 0); - this.getOwner() - .getQuestManager() - .queueEvent( - QuestCond.QUEST_COND_STATE_EQUAL, this.subQuestId, this.state.getValue(), 0, 0, 0); + this.triggerStateEvents(); this.getOwner() .getScene() .triggerDungeonEvent(DungeonPassConditionType.DUNGEON_COND_FINISH_QUEST, getSubQuestId()); @@ -250,19 +253,7 @@ public class GameQuest { this.getOwner().sendPacket(new PacketQuestListUpdateNotify(this)); // Some subQuests have conditions that subQuests fail (even from different MainQuests) - this.getOwner() - .getQuestManager() - .queueEvent( - QuestContent.QUEST_CONTENT_QUEST_STATE_EQUAL, - this.subQuestId, - this.state.getValue(), - 0, - 0, - 0); - this.getOwner() - .getQuestManager() - .queueEvent( - QuestCond.QUEST_COND_STATE_EQUAL, this.subQuestId, this.state.getValue(), 0, 0, 0); + this.triggerStateEvents(); this.getQuestData() .getFailExec() diff --git a/src/main/java/emu/grasscutter/game/quest/conditions/ConditionStateEqual.java b/src/main/java/emu/grasscutter/game/quest/conditions/ConditionStateEqual.java index 0c3633665..d37b890d7 100644 --- a/src/main/java/emu/grasscutter/game/quest/conditions/ConditionStateEqual.java +++ b/src/main/java/emu/grasscutter/game/quest/conditions/ConditionStateEqual.java @@ -4,9 +4,7 @@ import static emu.grasscutter.game.quest.enums.QuestCond.QUEST_COND_STATE_EQUAL; import emu.grasscutter.data.excels.QuestData; import emu.grasscutter.game.player.Player; -import emu.grasscutter.game.quest.GameQuest; import emu.grasscutter.game.quest.QuestValueCond; -import lombok.val; @QuestValueCond(QUEST_COND_STATE_EQUAL) public class ConditionStateEqual extends BaseCondition { @@ -18,17 +16,10 @@ public class ConditionStateEqual extends BaseCondition { QuestData.QuestAcceptCondition condition, String paramStr, int... params) { - val questId = condition.getParam()[0]; - val questStateValue = condition.getParam()[1]; - GameQuest checkQuest = owner.getQuestManager().getQuestById(questId); - if (checkQuest == null) { - /* - Will spam the console - */ - // Grasscutter.getLogger().debug("Warning: quest {} hasn't been started yet!", - // condition.getParam()[0]); - return false; - } - return checkQuest.getState().getValue() == questStateValue; + var questId = condition.getParam()[0]; + var questStateValue = condition.getParam()[1]; + var checkQuest = owner.getQuestManager().getQuestById(questId); + + return checkQuest != null && checkQuest.getState().getValue() == questStateValue; } } diff --git a/src/main/java/emu/grasscutter/game/quest/conditions/ConditionStateNotEqual.java b/src/main/java/emu/grasscutter/game/quest/conditions/ConditionStateNotEqual.java index 9cc551528..e9a53cdc0 100644 --- a/src/main/java/emu/grasscutter/game/quest/conditions/ConditionStateNotEqual.java +++ b/src/main/java/emu/grasscutter/game/quest/conditions/ConditionStateNotEqual.java @@ -4,9 +4,7 @@ import static emu.grasscutter.game.quest.enums.QuestCond.QUEST_COND_STATE_NOT_EQ import emu.grasscutter.data.excels.QuestData; import emu.grasscutter.game.player.Player; -import emu.grasscutter.game.quest.GameQuest; import emu.grasscutter.game.quest.QuestValueCond; -import lombok.val; @QuestValueCond(QUEST_COND_STATE_NOT_EQUAL) public class ConditionStateNotEqual extends BaseCondition { @@ -18,18 +16,11 @@ public class ConditionStateNotEqual extends BaseCondition { QuestData.QuestAcceptCondition condition, String paramStr, int... params) { - val questId = condition.getParam()[0]; - val questStateValue = condition.getParam()[1]; - GameQuest checkQuest = owner.getQuestManager().getQuestById(questId); - if (checkQuest == null) { - /* - Will spam the console - */ - // Grasscutter.getLogger().debug("Warning: quest {} hasn't been started yet!", - // condition.getParam()[0]); + var questId = condition.getParam()[0]; + var questStateValue = condition.getParam()[1]; + var checkQuest = owner.getQuestManager().getQuestById(questId); - return false; - } - return checkQuest.getState().getValue() != questStateValue; + return checkQuest != null && + checkQuest.getState().getValue() != questStateValue; } } diff --git a/src/main/java/emu/grasscutter/game/quest/content/ContentEnterMyWorld.java b/src/main/java/emu/grasscutter/game/quest/content/ContentEnterMyWorld.java index 180e1f8d5..37eabf366 100644 --- a/src/main/java/emu/grasscutter/game/quest/content/ContentEnterMyWorld.java +++ b/src/main/java/emu/grasscutter/game/quest/content/ContentEnterMyWorld.java @@ -12,8 +12,6 @@ public class ContentEnterMyWorld extends BaseContent { @Override public boolean execute( GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { - System.out.printf("ContentEnterMyWorld, QuestData: %s; ExecParams: %s%n", - condition.getParam()[0], params[0]); return quest.getOwner().getSceneId() == params[0]; } }