diff --git a/src/main/java/emu/grasscutter/game/quest/GameMainQuest.java b/src/main/java/emu/grasscutter/game/quest/GameMainQuest.java index 38cf6f154..4688c0dae 100644 --- a/src/main/java/emu/grasscutter/game/quest/GameMainQuest.java +++ b/src/main/java/emu/grasscutter/game/quest/GameMainQuest.java @@ -16,6 +16,7 @@ import emu.grasscutter.net.proto.ChildQuestOuterClass.ChildQuest; import emu.grasscutter.net.proto.ParentQuestOuterClass.ParentQuest; import emu.grasscutter.server.packet.send.*; import emu.grasscutter.utils.ConversionUtils; +import emu.grasscutter.utils.Utils; import java.util.*; import java.util.stream.Collectors; import lombok.*; @@ -120,6 +121,16 @@ public class GameMainQuest { this.triggerQuestVarAction(i, this.questVars[i]); } + public void randomQuestVar(int i, int low, int high) { + int previousValue = this.questVars[i]; + this.questVars[i] = Utils.random.nextInt(low, high); + Grasscutter.getLogger() + .debug( + "questVar {} value randomized from {} to {}", i, previousValue, this.questVars[i]); + + this.triggerQuestVarAction(i, this.questVars[i]); + } + public void triggerQuestVarAction(int index, int value) { var questManager = this.getQuestManager(); questManager.queueEvent(QuestCond.QUEST_COND_QUEST_VAR_EQUAL, index, value); diff --git a/src/main/java/emu/grasscutter/game/quest/enums/QuestExec.java b/src/main/java/emu/grasscutter/game/quest/enums/QuestExec.java index faba81e32..07c01a8b4 100644 --- a/src/main/java/emu/grasscutter/game/quest/enums/QuestExec.java +++ b/src/main/java/emu/grasscutter/game/quest/enums/QuestExec.java @@ -59,7 +59,7 @@ public enum QuestExec implements QuestTrigger { QUEST_EXEC_SET_QUEST_VAR(48), QUEST_EXEC_INC_QUEST_VAR(49), QUEST_EXEC_DEC_QUEST_VAR(50), - QUEST_EXEC_RANDOM_QUEST_VAR(51), // missing + QUEST_EXEC_RANDOM_QUEST_VAR(51), QUEST_EXEC_ACTIVATE_SCANNING_PIC(52), // missing, currently unused QUEST_EXEC_RELOAD_SCENE_TAG(53), // missing QUEST_EXEC_REGISTER_DYNAMIC_GROUP_ONLY(54), // missing diff --git a/src/main/java/emu/grasscutter/game/quest/exec/ExecRandomQuestVar.java b/src/main/java/emu/grasscutter/game/quest/exec/ExecRandomQuestVar.java new file mode 100644 index 000000000..0fa3ced33 --- /dev/null +++ b/src/main/java/emu/grasscutter/game/quest/exec/ExecRandomQuestVar.java @@ -0,0 +1,16 @@ +package emu.grasscutter.game.quest.exec; + +import emu.grasscutter.data.excels.quest.QuestData; +import emu.grasscutter.game.quest.GameQuest; +import emu.grasscutter.game.quest.QuestValueExec; +import emu.grasscutter.game.quest.enums.QuestExec; +import emu.grasscutter.game.quest.handlers.QuestExecHandler; + +@QuestValueExec(QuestExec.QUEST_EXEC_RANDOM_QUEST_VAR) +public class ExecRandomQuestVar extends QuestExecHandler { + @Override + public boolean execute(GameQuest quest, QuestData.QuestExecParam condition, String... paramStr) { + quest.getMainQuest().randomQuestVar(Integer.parseInt(paramStr[0]), Integer.parseInt(paramStr[1]), Integer.parseInt(paramStr[2])); + return true; + } +}