From 49ba0e55e898a4f7def78e6f86a4c409dcdcb5ce Mon Sep 17 00:00:00 2001 From: Nazrin Date: Sat, 22 Jul 2023 20:17:11 -0700 Subject: [PATCH] make xxGroupVariableValueByGroup the same as xxGroupVariableValue (#2266) --- .../emu/grasscutter/scripts/ScriptLib.java | 55 +++++++++++-------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/src/main/java/emu/grasscutter/scripts/ScriptLib.java b/src/main/java/emu/grasscutter/scripts/ScriptLib.java index f266104be..cea13b4e4 100644 --- a/src/main/java/emu/grasscutter/scripts/ScriptLib.java +++ b/src/main/java/emu/grasscutter/scripts/ScriptLib.java @@ -398,12 +398,41 @@ public class ScriptLib { val old = variables.getOrDefault(var, 0); variables.put(var, old + value); - logger.debug("[LUA] Call ChangeGroupVariableValue with {},{}", - old, old+value); getSceneScriptManager().callEvent(new ScriptArgs(groupId, EventType.EVENT_VARIABLE_CHANGE, old+value, old).setEventSource(var)); return LuaValue.ZERO; } + public int GetGroupVariableValueByGroup(String var, int groupId){ + logger.debug("[LUA] Call GetGroupVariableValueByGroup with {},{}", + var,groupId); + + return getSceneScriptManager().getVariables(groupId).getOrDefault(var, 0); + } + + public int SetGroupVariableValueByGroup(String var, int value, int groupId){ + logger.debug("[LUA] Call SetGroupVariableValueByGroup with {},{},{}", + var,value,groupId); + + val variables = getSceneScriptManager().getVariables(groupId); + + val old = variables.getOrDefault(var, value); + variables.put(var, value); + getSceneScriptManager().callEvent(new ScriptArgs(groupId, EventType.EVENT_VARIABLE_CHANGE, value, old).setEventSource(var)); + return 0; + } + + public int ChangeGroupVariableValueByGroup(String var, int value, int groupId){ + logger.debug("[LUA] Call ChangeGroupVariableValueByGroup with {},{}", + var,groupId); + + val variables = getSceneScriptManager().getVariables(groupId); + + val old = variables.getOrDefault(var, 0); + variables.put(var, old + value); + getSceneScriptManager().callEvent(new ScriptArgs(groupId, EventType.EVENT_VARIABLE_CHANGE, old+value, old).setEventSource(var)); + return 0; + } + /** * Set the actions and triggers to designated group */ @@ -533,20 +562,6 @@ public class ScriptLib { return 0; } - public int GetGroupVariableValueByGroup(String name, int groupId){ - logger.debug("[LUA] Call GetGroupVariableValueByGroup with {},{}", - name,groupId); - - return getSceneScriptManager().getVariables(groupId).getOrDefault(name, 0); - } - public int ChangeGroupVariableValueByGroup(String name, int value, int groupId){ - logger.debug("[LUA] Call ChangeGroupVariableValueByGroup with {},{}", - name,groupId); - //TODO test - getSceneScriptManager().getVariables(groupId).put(name, value); - return 0; - } - public int SetIsAllowUseSkill(int canUse){ logger.debug("[LUA] Call SetIsAllowUseSkill with {}", canUse); @@ -571,14 +586,6 @@ public class ScriptLib { return 0; } - public int SetGroupVariableValueByGroup(String key, int value, int groupId){ - logger.debug("[LUA] Call SetGroupVariableValueByGroup with {},{},{}", - key,value,groupId); - - getSceneScriptManager().getVariables(groupId).put(key, value); - return 0; - } - public int CreateMonster(LuaTable table){ logger.debug("[LUA] Call CreateMonster with {}", printTable(table));