From 507ec302e77c9b82d8955365d66bf2d50bbe79c1 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Wed, 27 Mar 2024 13:34:32 -0400 Subject: [PATCH] Handler created for PromptRecallMsg --- src/engine/gameManager/MovementManager.java | 51 ----------- src/engine/net/client/ClientMessagePump.java | 15 ---- src/engine/net/client/Protocol.java | 2 +- .../handlers/PromptRecallMsgHandler.java | 85 +++++++++++++++++++ 4 files changed, 86 insertions(+), 67 deletions(-) create mode 100644 src/engine/net/client/handlers/PromptRecallMsgHandler.java diff --git a/src/engine/gameManager/MovementManager.java b/src/engine/gameManager/MovementManager.java index c8c2f657..977d424c 100644 --- a/src/engine/gameManager/MovementManager.java +++ b/src/engine/gameManager/MovementManager.java @@ -23,7 +23,6 @@ import engine.math.Vector3fImmutable; import engine.net.DispatchMessage; import engine.net.client.ClientConnection; import engine.net.client.msg.MoveToPointMsg; -import engine.net.client.msg.PromptRecallMsg; import engine.net.client.msg.TeleportToPointMsg; import engine.net.client.msg.UpdateStateMsg; import engine.objects.*; @@ -489,56 +488,6 @@ public enum MovementManager { ac.teleport(ac.getLoc()); } - public static void HandlePromptRecall(PromptRecallMsg msg, ClientConnection origin) throws MsgSendException { - - PlayerCharacter player = SessionManager.getPlayerCharacter(origin); - boolean recallAccepted; - - if (player == null) - return; - - boolean confirmed = msg.getConfirmed(); - - if (confirmed == true) { - long timeElapsed = System.currentTimeMillis() - player.getTimeStamp("PromptRecall"); - //send fail message - recallAccepted = timeElapsed < 15000; - } else - recallAccepted = false; - - if (recallAccepted == true) { - //handle recall - long type = player.getTimeStamp("LastRecallType"); - - if (type == 1) { //recall to bind - player.teleport(player.getBindLoc()); - player.setSafeMode(); - } else { //recall to rg - float dist = 9999999999f; - Building rg = null; - Vector3fImmutable rgLoc; - - for (Runegate runegate : Runegate._runegates.values()) { - - rgLoc = runegate.gateBuilding.getLoc(); - - float distanceSquaredToRunegate = player.getLoc().distanceSquared2D(rgLoc); - - if (distanceSquaredToRunegate < sqr(dist)) - rg = runegate.gateBuilding; - - } - - //nearest runegate found. teleport characterTarget - - if (rg != null) { - player.teleport(rg.getLoc()); - player.setSafeMode(); - } - } - } - } - public static void stuck(ClientConnection origin) { PlayerCharacter sourcePlayer = origin.getPlayerCharacter(); diff --git a/src/engine/net/client/ClientMessagePump.java b/src/engine/net/client/ClientMessagePump.java index f361b541..37631ff8 100644 --- a/src/engine/net/client/ClientMessagePump.java +++ b/src/engine/net/client/ClientMessagePump.java @@ -916,12 +916,6 @@ public class ClientMessagePump implements NetMsgHandler { case ARCPETCMD: petCmd((PetCmdMsg) msg, origin); break; - case MANAGENPC: - ManageNPCCmd((ManageNPCMsg) msg, origin); - break; - case ARCPROMPTRECALL: - MovementManager.HandlePromptRecall((PromptRecallMsg) msg, origin); - break; case CHANNELMUTE: break; case KEEPALIVESERVERCLIENT: @@ -947,15 +941,6 @@ public class ClientMessagePump implements NetMsgHandler { return true; } - //TODO what is this used for? - private void ManageNPCCmd(ManageNPCMsg msg, ClientConnection origin) { - } - - //call this if the transfer fails server side to kick the item back to inventory from equip - private void forceTransferFromInventoryToEquip(TransferItemFromEquipToInventoryMsg msg, ClientConnection origin, String reason) { - //TODO add this later - //PATCHED CODEZZ - } } diff --git a/src/engine/net/client/Protocol.java b/src/engine/net/client/Protocol.java index db08d515..d57a7b95 100644 --- a/src/engine/net/client/Protocol.java +++ b/src/engine/net/client/Protocol.java @@ -40,7 +40,7 @@ public enum Protocol { ARCPETATTACK(0x18CD61AD, PetAttackMsg.class, null), // Pet Attack ARCPETCMD(0x4E80E001, PetCmdMsg.class, null), // Stop ArcPetAttack, Toggle Assist, Toggle Rest ARCPOWERPROJECTILE(0xA2312D3B, null, null), - ARCPROMPTRECALL(0xE3196B6E, PromptRecallMsg.class, null), //Recall Prompt + ARCPROMPTRECALL(0xE3196B6E, PromptRecallMsg.class, PromptRecallMsgHandler.class), //Recall Prompt ARCREQUESTTRADEBUSY(0xD4BAB4DF, InvalidTradeRequestMsg.class, null), // Attempt trade with someone who is already trading ARCSERVERSTATUS(0x87BA4462, null, null), //Update Server Status ARCSIEGESPIRE(0x36A49BC6, ArcSiegeSpireMsg.class, ArcSiegeSpireMsgHandler.class), // Activate/Deactivate Spires diff --git a/src/engine/net/client/handlers/PromptRecallMsgHandler.java b/src/engine/net/client/handlers/PromptRecallMsgHandler.java new file mode 100644 index 00000000..211fe877 --- /dev/null +++ b/src/engine/net/client/handlers/PromptRecallMsgHandler.java @@ -0,0 +1,85 @@ +// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . +// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· +// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ +// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ +// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ +// Magicbane Emulator Project © 2013 - 2022 +// www.magicbane.com + +package engine.net.client.handlers; + +import engine.exception.MsgSendException; +import engine.gameManager.SessionManager; +import engine.math.Vector3fImmutable; +import engine.net.client.ClientConnection; +import engine.net.client.msg.ClientNetMsg; +import engine.net.client.msg.PromptRecallMsg; +import engine.objects.Building; +import engine.objects.PlayerCharacter; +import engine.objects.Runegate; + +import static engine.math.FastMath.sqr; + +public class PromptRecallMsgHandler extends AbstractClientMsgHandler { + + public PromptRecallMsgHandler() { + super(PromptRecallMsg.class); + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + // Member variable assignment + + PromptRecallMsg msg = (PromptRecallMsg) baseMsg; + PlayerCharacter player = SessionManager.getPlayerCharacter(origin); + boolean recallAccepted; + + if (player == null) + return true; + + boolean confirmed = msg.getConfirmed(); + + if (confirmed == true) { + long timeElapsed = System.currentTimeMillis() - player.getTimeStamp("PromptRecall"); + //send fail message + recallAccepted = timeElapsed < 15000; + } else + recallAccepted = false; + + if (recallAccepted == true) { + //handle recall + long type = player.getTimeStamp("LastRecallType"); + + if (type == 1) { //recall to bind + player.teleport(player.getBindLoc()); + player.setSafeMode(); + } else { //recall to rg + float dist = 9999999999f; + Building rg = null; + Vector3fImmutable rgLoc; + + for (Runegate runegate : Runegate._runegates.values()) { + + rgLoc = runegate.gateBuilding.getLoc(); + + float distanceSquaredToRunegate = player.getLoc().distanceSquared2D(rgLoc); + + if (distanceSquaredToRunegate < sqr(dist)) + rg = runegate.gateBuilding; + + } + + //nearest runegate found. teleport characterTarget + + if (rg != null) { + player.teleport(rg.getLoc()); + player.setSafeMode(); + } + } + } + + return true; + } + +} \ No newline at end of file