From 21ac77685ce3c58923f959458cd53deed1d69bd8 Mon Sep 17 00:00:00 2001 From: scooterboo Date: Thu, 14 Sep 2023 01:42:18 -0700 Subject: [PATCH 1/2] Make platforms able to reset platforms apparently are able to run again once reaching the last point. As well, canceling a timer seems to return a 0, not a 1 --- src/main/java/emu/grasscutter/game/entity/EntityGadget.java | 6 ++++++ .../java/emu/grasscutter/scripts/SceneScriptManager.java | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/emu/grasscutter/game/entity/EntityGadget.java b/src/main/java/emu/grasscutter/game/entity/EntityGadget.java index df0eb80d5fd..8ed7020819b 100644 --- a/src/main/java/emu/grasscutter/game/entity/EntityGadget.java +++ b/src/main/java/emu/grasscutter/game/entity/EntityGadget.java @@ -256,6 +256,9 @@ public boolean startPlatform() { var route = this.getScene().getSceneRouteById(configRoute.getRouteId()); if (route != null) { var points = route.getPoints(); + if (configRoute.getStartIndex() == points.length - 1) { + configRoute.setStartIndex(0); + } val currIndex = configRoute.getStartIndex(); Position prevpos; @@ -301,6 +304,9 @@ public boolean startPlatform() { } configRoute.setStartIndex(I); this.position.set(points[I].getPos()); + if(I == points.length - 1) { + configRoute.setStarted(false); + } }, (int) time)); } diff --git a/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java b/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java index 4c461e1e0c0..33cadecf852 100644 --- a/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java +++ b/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java @@ -1180,7 +1180,7 @@ public int cancelGroupTimerEvent(int groupID, String source) { Grasscutter.getLogger() .warn("trying to cancel a timer that's not active {} {}", groupID, source); - return 1; + return 0; } // todo use killed monsters instead of spawned entites for check? From 1ed7c94585df4327ff0aa73d16508369a29fdfad Mon Sep 17 00:00:00 2001 From: scooterboo Date: Thu, 14 Sep 2023 01:51:56 -0700 Subject: [PATCH 2/2] Fix Seelies Added HandlerClientScriptEventNotify (shoutouts to Hartie!) and cleaned up the platform stuff in ScriptLib. There is a problem with HandlerClientScriptEventNotify where the client seems to only pass 0 into param1 instead of the configId. I coded in a workaround, but someone with greater access to things should check up on what is going on --- .../emu/grasscutter/scripts/ScriptLib.java | 9 +--- .../recv/HandlerClientScriptEventNotify.java | 47 +++++++++++++++++++ 2 files changed, 49 insertions(+), 7 deletions(-) create mode 100644 src/main/java/emu/grasscutter/server/packet/recv/HandlerClientScriptEventNotify.java diff --git a/src/main/java/emu/grasscutter/scripts/ScriptLib.java b/src/main/java/emu/grasscutter/scripts/ScriptLib.java index 990ac11b421..4830a4a0d93 100644 --- a/src/main/java/emu/grasscutter/scripts/ScriptLib.java +++ b/src/main/java/emu/grasscutter/scripts/ScriptLib.java @@ -1330,9 +1330,8 @@ public int SetPlatformPointArray(int entityConfigId, int pointArrayId, int[] var return -1; } - //TODO check public int SetPlatformRouteId(int entityConfigId, int routeId){ - logger.info("[LUA] Call SetPlatformRouteId {} {}", entityConfigId, routeId); + logger.debug("[LUA] Call SetPlatformRouteId {} {}", entityConfigId, routeId); val entity = getSceneScriptManager().getScene().getEntityByConfigId(entityConfigId); if(entity == null){ @@ -1365,12 +1364,9 @@ public int SetPlatformRouteId(int entityConfigId, int routeId){ return 0; } - //TODO check public int StartPlatform(int configId){ logger.debug("[LUA] Call StartPlatform {} ", configId); - val entity = sceneScriptManager.get().getScene().getEntityByConfigId(configId); - if(!(entity instanceof EntityGadget entityGadget)) { return 1; } @@ -1378,9 +1374,8 @@ public int StartPlatform(int configId){ return entityGadget.startPlatform() ? 0 : 2; } - //TODO check public int StopPlatform(int configId){ - logger.info("[LUA] Call StopPlatform {} ", configId); + logger.debug("[LUA] Call StopPlatform {} ", configId); val entity = sceneScriptManager.get().getScene().getEntityByConfigId(configId); if(!(entity instanceof EntityGadget entityGadget)) { return 1; diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerClientScriptEventNotify.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerClientScriptEventNotify.java new file mode 100644 index 00000000000..92fbb1b9971 --- /dev/null +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerClientScriptEventNotify.java @@ -0,0 +1,47 @@ +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ClientScriptEventNotifyOuterClass.ClientScriptEventNotify; +import emu.grasscutter.scripts.constants.EventType; +import emu.grasscutter.scripts.data.ScriptArgs; +import emu.grasscutter.server.game.GameSession; +import lombok.val; + +@Opcodes(PacketOpcodes.ClientScriptEventNotify) +public class HandlerClientScriptEventNotify extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + val data = ClientScriptEventNotify.parseFrom(payload); + val scriptManager = session.getPlayer().getScene().getScriptManager(); + val args = new ScriptArgs(0, data.getEventType()) + .setSourceEntityId(data.getSourceEntityId()) + .setTargetEntityId(data.getTargetEntityId()); + + for (int i = 0; i < data.getParamListCount(); i++) { + switch (i) { + case 0 -> args.setParam1(data.getParamList(i)); + case 1 -> args.setParam2(data.getParamList(i)); + case 2 -> args.setParam3(data.getParamList(i)); + } + } + + if(data.getEventType() == EventType.EVENT_AVATAR_NEAR_PLATFORM){ + if(data.getParamList(0) == 0) { + Grasscutter.getLogger().debug("Found a zero Param1 for an EVENT_AVATAR_NEAR_PLATFORM. Doing the configID workaround."); + val entity = session.getPlayer().getScene().getEntityById(data.getSourceEntityId()); + if(entity == null) { + Grasscutter.getLogger().debug("But it failed."); + } else { + args.setParam1(entity.getConfigId()); + } + } + } + + scriptManager.callEvent(args); + } + +} \ No newline at end of file