Implement QUEST_EXEC_RANDOM_QUEST_VAR (#2284)

This commit is contained in:
Nazrin 2023-08-06 21:27:13 -07:00 committed by GitHub
parent 58d2650505
commit 0b0dcf9b8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 1 deletions

View File

@ -16,6 +16,7 @@ import emu.grasscutter.net.proto.ChildQuestOuterClass.ChildQuest;
import emu.grasscutter.net.proto.ParentQuestOuterClass.ParentQuest; import emu.grasscutter.net.proto.ParentQuestOuterClass.ParentQuest;
import emu.grasscutter.server.packet.send.*; import emu.grasscutter.server.packet.send.*;
import emu.grasscutter.utils.ConversionUtils; import emu.grasscutter.utils.ConversionUtils;
import emu.grasscutter.utils.Utils;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import lombok.*; import lombok.*;
@ -120,6 +121,16 @@ public class GameMainQuest {
this.triggerQuestVarAction(i, this.questVars[i]); 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) { public void triggerQuestVarAction(int index, int value) {
var questManager = this.getQuestManager(); var questManager = this.getQuestManager();
questManager.queueEvent(QuestCond.QUEST_COND_QUEST_VAR_EQUAL, index, value); questManager.queueEvent(QuestCond.QUEST_COND_QUEST_VAR_EQUAL, index, value);

View File

@ -59,7 +59,7 @@ public enum QuestExec implements QuestTrigger {
QUEST_EXEC_SET_QUEST_VAR(48), QUEST_EXEC_SET_QUEST_VAR(48),
QUEST_EXEC_INC_QUEST_VAR(49), QUEST_EXEC_INC_QUEST_VAR(49),
QUEST_EXEC_DEC_QUEST_VAR(50), 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_ACTIVATE_SCANNING_PIC(52), // missing, currently unused
QUEST_EXEC_RELOAD_SCENE_TAG(53), // missing QUEST_EXEC_RELOAD_SCENE_TAG(53), // missing
QUEST_EXEC_REGISTER_DYNAMIC_GROUP_ONLY(54), // missing QUEST_EXEC_REGISTER_DYNAMIC_GROUP_ONLY(54), // missing

View File

@ -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;
}
}