From f0ac342b1f9afb1cf05cf347ca9571491b01f5fb Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 29 Mar 2024 07:36:33 -0400 Subject: [PATCH] Handler created for SendSummonsMsg --- src/engine/devcmd/cmds/SummonCmd.java | 4 +- src/engine/gameManager/PowersManager.java | 50 +---------- src/engine/net/client/ClientMessagePump.java | 5 +- src/engine/net/client/Protocol.java | 4 +- .../handlers/SendSummonsMsgHandler.java | 90 +++++++++++++++++++ ...onsRequestMsg.java => RecvSummonsMsg.java} | 6 +- ...onsRequestMsg.java => SendSummonsMsg.java} | 6 +- .../poweractions/SummonPowerAction.java | 4 +- 8 files changed, 105 insertions(+), 64 deletions(-) create mode 100644 src/engine/net/client/handlers/SendSummonsMsgHandler.java rename src/engine/net/client/msg/{RecvSummonsRequestMsg.java => RecvSummonsMsg.java} (92%) rename src/engine/net/client/msg/{SendSummonsRequestMsg.java => SendSummonsMsg.java} (94%) diff --git a/src/engine/devcmd/cmds/SummonCmd.java b/src/engine/devcmd/cmds/SummonCmd.java index 6877db2c..83c840d3 100644 --- a/src/engine/devcmd/cmds/SummonCmd.java +++ b/src/engine/devcmd/cmds/SummonCmd.java @@ -13,7 +13,7 @@ import engine.devcmd.AbstractDevCmd; import engine.gameManager.SessionManager; import engine.gameManager.ZoneManager; import engine.math.Vector3fImmutable; -import engine.net.client.msg.RecvSummonsRequestMsg; +import engine.net.client.msg.RecvSummonsMsg; import engine.objects.AbstractGameObject; import engine.objects.PlayerCharacter; import engine.objects.Zone; @@ -41,7 +41,7 @@ public class SummonCmd extends AbstractDevCmd { String location = "Somewhere"; if (zone != null) location = zone.zoneName; - RecvSummonsRequestMsg rsrm = new RecvSummonsRequestMsg(pc.getObjectType().ordinal(), pc.getObjectUUID(), pc.getFirstName(), + RecvSummonsMsg rsrm = new RecvSummonsMsg(pc.getObjectType().ordinal(), pc.getObjectUUID(), pc.getFirstName(), location, false); toSummon.getClientConnection().sendMsg(rsrm); diff --git a/src/engine/gameManager/PowersManager.java b/src/engine/gameManager/PowersManager.java index af4a4b93..f09ce82e 100644 --- a/src/engine/gameManager/PowersManager.java +++ b/src/engine/gameManager/PowersManager.java @@ -1240,53 +1240,7 @@ public enum PowersManager { return false; } - public static void summon(SendSummonsRequestMsg msg, ClientConnection origin) { - PlayerCharacter pc = SessionManager.getPlayerCharacter( - origin); - if (pc == null) - return; - - PlayerCharacter target = SessionManager - .getPlayerCharacterByLowerCaseName(msg.getTargetName()); - if (target == null || target.equals(pc) || target.isCombat()) { - - if (target == null) // Player not found. Send not found message - ChatManager.chatInfoError(pc, - "Cannot find that player to summon."); - else if (target.isCombat()) - ChatManager.chatInfoError(pc, - "Cannot summon player in combat."); - // else trying to summon self, just fail - - // recycle summon - sendRecyclePower(msg.getPowerToken(), origin); - - // TODO: client already subtracted 200 mana.. need to correct it - // end cast - PerformActionMsg pam = new PerformActionMsg(msg.getPowerToken(), - msg.getTrains(), msg.getSourceType(), msg.getSourceID(), 0, - 0, 0f, 0f, 0f, 1, 0); - sendPowerMsg(pc, 2, pam); - - return; - } - if (ConfigManager.MB_RULESET.getValue() == "LORE") { - if (pc.guild.getGuildType().equals(target.guild.getGuildType()) == false) { - ChatManager.chatInfoError(pc, - "Cannot summon player outside your charter."); - return; - } - } - PerformActionMsg pam = new PerformActionMsg(msg.getPowerToken(), msg - .getTrains(), msg.getSourceType(), msg.getSourceID(), target - .getObjectType().ordinal(), target.getObjectUUID(), 0f, 0f, 0f, 1, 0); - - // Client removes 200 mana on summon use.. so don't send message to self - target.addSummoner(pc.getObjectUUID(), System.currentTimeMillis() + MBServerStatics.FOURTYFIVE_SECONDS); - usePower(pam, origin, false); - } - - public static void recvSummon(RecvSummonsRequestMsg msg, ClientConnection origin) { + public static void recvSummon(RecvSummonsMsg msg, ClientConnection origin) { PlayerCharacter pc = SessionManager.getPlayerCharacter(origin); if (pc == null) return; @@ -1381,7 +1335,7 @@ public enum PowersManager { } } - private static void sendRecyclePower(int token, ClientConnection origin) { + public static void sendRecyclePower(int token, ClientConnection origin) { RecyclePowerMsg recyclePowerMsg = new RecyclePowerMsg(token); Dispatch dispatch = Dispatch.borrow(origin.getPlayerCharacter(), recyclePowerMsg); diff --git a/src/engine/net/client/ClientMessagePump.java b/src/engine/net/client/ClientMessagePump.java index db3aae62..15cc9df9 100644 --- a/src/engine/net/client/ClientMessagePump.java +++ b/src/engine/net/client/ClientMessagePump.java @@ -123,11 +123,8 @@ public class ClientMessagePump implements NetMsgHandler { case ARCREQUESTTRADEBUSY: TradeManager.invalidTradeRequest((InvalidTradeRequestMsg) msg); break; - case POWERTARGNAME: - PowersManager.summon((SendSummonsRequestMsg) msg, origin); - break; case ARCSUMMON: - PowersManager.recvSummon((RecvSummonsRequestMsg) msg, origin); + PowersManager.recvSummon((RecvSummonsMsg) msg, origin); break; case CHANNELMUTE: break; diff --git a/src/engine/net/client/Protocol.java b/src/engine/net/client/Protocol.java index c9b47759..c841a79a 100644 --- a/src/engine/net/client/Protocol.java +++ b/src/engine/net/client/Protocol.java @@ -44,7 +44,7 @@ public enum Protocol { 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 - ARCSUMMON(0xFD816A0A, RecvSummonsRequestMsg.class, null), // Suspect Recv Summons Request + ARCSUMMON(0xFD816A0A, RecvSummonsMsg.class, null), // Suspect Recv Summons Request ARCTRACKINGLIST(0xC89CF08B, TrackWindowMsg.class, TrackWindowMsgHandler.class), //Request/Send Track window ARCTRACKOBJECT(0x609B6BA2, TrackArrowMsg.class, null), //Send Track Arrow ARCUNTRAINABILITY(0x548DBF83, RefineMsg.class, RefineMsgHandler.class), //Refine @@ -161,7 +161,7 @@ public enum Protocol { POWERACTION(0xA0B27EEB, ApplyEffectMsg.class, null), // Apply Effect, add to effects icons POWERACTIONDD(0xD43052F8, ModifyHealthMsg.class, null), //Modify Health/Mana/Stamina using power POWERACTIONDDDIE(0xC27D446B, null, null), //Modify Health/Mana/Stamina using power and kill target - POWERTARGNAME(0x5A807CCE, SendSummonsRequestMsg.class, null), // Send Summons Request + POWERTARGNAME(0x5A807CCE, SendSummonsMsg.class, SendSummonsMsgHandler.class), // Send Summons Request RAISEATTR(0x5EEB65E0, ModifyStatMsg.class, ModifyStatMsgHandler.class), // Modify Stat RANDOM(0xAC5D0135, RandomMsg.class, RandomMsgHandler.class), //RequestSend random roll READYTOENTER(0x490E4FE0, EnterWorldReceivedMsg.class, null), //Client Ack Receive Enter World diff --git a/src/engine/net/client/handlers/SendSummonsMsgHandler.java b/src/engine/net/client/handlers/SendSummonsMsgHandler.java new file mode 100644 index 00000000..121a502e --- /dev/null +++ b/src/engine/net/client/handlers/SendSummonsMsgHandler.java @@ -0,0 +1,90 @@ +// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . +// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· +// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ +// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ +// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ +// Magicbane Emulator Project © 2013 - 2022 +// www.magicbane.com + +package engine.net.client.handlers; + +import engine.exception.MsgSendException; +import engine.gameManager.ChatManager; +import engine.gameManager.ConfigManager; +import engine.gameManager.SessionManager; +import engine.net.client.ClientConnection; +import engine.net.client.msg.ClientNetMsg; +import engine.net.client.msg.PerformActionMsg; +import engine.net.client.msg.SendSummonsMsg; +import engine.objects.PlayerCharacter; +import engine.server.MBServerStatics; + +import static engine.gameManager.PowersManager.*; + +public class SendSummonsMsgHandler extends AbstractClientMsgHandler { + + public SendSummonsMsgHandler() { + super(SendSummonsMsg.class); + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + PlayerCharacter playerCharacter = origin.getPlayerCharacter(); + + // Member variable declaration + + SendSummonsMsg msg; + + // Member variable assignment + + msg = (SendSummonsMsg) baseMsg; + + if (playerCharacter == null) + return true; + + PlayerCharacter target = SessionManager + .getPlayerCharacterByLowerCaseName(msg.getTargetName()); + + if (target == null || target.equals(playerCharacter) || target.isCombat()) { + + if (target == null) // Player not found. Send not found message + ChatManager.chatInfoError(playerCharacter, + "Cannot find that player to summon."); + else if (target.isCombat()) + ChatManager.chatInfoError(playerCharacter, + "Cannot summon player in combat."); + + // else trying to summon self, just fail + + // recycle summon + sendRecyclePower(msg.getPowerToken(), origin); + + // TODO: client already subtracted 200 mana.. need to correct it + // end cast + PerformActionMsg pam = new PerformActionMsg(msg.getPowerToken(), + msg.getTrains(), msg.getSourceType(), msg.getSourceID(), 0, + 0, 0f, 0f, 0f, 1, 0); + sendPowerMsg(playerCharacter, 2, pam); + + return true; + } + if (ConfigManager.MB_RULESET.getValue() == "LORE") { + if (playerCharacter.guild.getGuildType().equals(target.guild.getGuildType()) == false) { + ChatManager.chatInfoError(playerCharacter, + "Cannot summon player outside your charter."); + return true; + } + } + PerformActionMsg pam = new PerformActionMsg(msg.getPowerToken(), msg + .getTrains(), msg.getSourceType(), msg.getSourceID(), target + .getObjectType().ordinal(), target.getObjectUUID(), 0f, 0f, 0f, 1, 0); + + // Client removes 200 mana on summon use.. so don't send message to self + target.addSummoner(playerCharacter.getObjectUUID(), System.currentTimeMillis() + MBServerStatics.FOURTYFIVE_SECONDS); + usePower(pam, origin, false); + + return true; + } + +} \ No newline at end of file diff --git a/src/engine/net/client/msg/RecvSummonsRequestMsg.java b/src/engine/net/client/msg/RecvSummonsMsg.java similarity index 92% rename from src/engine/net/client/msg/RecvSummonsRequestMsg.java rename to src/engine/net/client/msg/RecvSummonsMsg.java index 2dd6d5d2..bf37bf96 100644 --- a/src/engine/net/client/msg/RecvSummonsRequestMsg.java +++ b/src/engine/net/client/msg/RecvSummonsMsg.java @@ -15,7 +15,7 @@ import engine.net.ByteBufferReader; import engine.net.ByteBufferWriter; import engine.net.client.Protocol; -public class RecvSummonsRequestMsg extends ClientNetMsg { +public class RecvSummonsMsg extends ClientNetMsg { private int sourceType; private int sourceID; @@ -26,7 +26,7 @@ public class RecvSummonsRequestMsg extends ClientNetMsg { /** * This is the general purpose constructor. */ - public RecvSummonsRequestMsg(int sourceType, int sourceID, String sourceName, String locationName, boolean accepted) { + public RecvSummonsMsg(int sourceType, int sourceID, String sourceName, String locationName, boolean accepted) { super(Protocol.ARCSUMMON); this.sourceType = sourceType; this.sourceID = sourceID; @@ -41,7 +41,7 @@ public class RecvSummonsRequestMsg extends ClientNetMsg { * past the limit) then this constructor Throws that Exception to the * caller. */ - public RecvSummonsRequestMsg(AbstractConnection origin, ByteBufferReader reader) { + public RecvSummonsMsg(AbstractConnection origin, ByteBufferReader reader) { super(Protocol.ARCSUMMON, origin, reader); } diff --git a/src/engine/net/client/msg/SendSummonsRequestMsg.java b/src/engine/net/client/msg/SendSummonsMsg.java similarity index 94% rename from src/engine/net/client/msg/SendSummonsRequestMsg.java rename to src/engine/net/client/msg/SendSummonsMsg.java index a634343e..6b5723b5 100644 --- a/src/engine/net/client/msg/SendSummonsRequestMsg.java +++ b/src/engine/net/client/msg/SendSummonsMsg.java @@ -15,7 +15,7 @@ import engine.net.ByteBufferReader; import engine.net.ByteBufferWriter; import engine.net.client.Protocol; -public class SendSummonsRequestMsg extends ClientNetMsg { +public class SendSummonsMsg extends ClientNetMsg { private int powerToken; private int sourceType; @@ -26,7 +26,7 @@ public class SendSummonsRequestMsg extends ClientNetMsg { /** * This is the general purpose constructor. */ - public SendSummonsRequestMsg() { + public SendSummonsMsg() { super(Protocol.POWERTARGNAME); } @@ -36,7 +36,7 @@ public class SendSummonsRequestMsg extends ClientNetMsg { * past the limit) then this constructor Throws that Exception to the * caller. */ - public SendSummonsRequestMsg(AbstractConnection origin, ByteBufferReader reader) { + public SendSummonsMsg(AbstractConnection origin, ByteBufferReader reader) { super(Protocol.POWERTARGNAME, origin, reader); } diff --git a/src/engine/powers/poweractions/SummonPowerAction.java b/src/engine/powers/poweractions/SummonPowerAction.java index 03fe028e..37c26b0d 100644 --- a/src/engine/powers/poweractions/SummonPowerAction.java +++ b/src/engine/powers/poweractions/SummonPowerAction.java @@ -16,7 +16,7 @@ import engine.math.Vector3fImmutable; import engine.net.Dispatch; import engine.net.DispatchMessage; import engine.net.client.ClientConnection; -import engine.net.client.msg.RecvSummonsRequestMsg; +import engine.net.client.msg.RecvSummonsMsg; import engine.objects.AbstractCharacter; import engine.objects.AbstractWorldObject; import engine.objects.PlayerCharacter; @@ -57,7 +57,7 @@ public class SummonPowerAction extends AbstractPowerAction { if (zone != null) location = zone.zoneName; - RecvSummonsRequestMsg rsrm = new RecvSummonsRequestMsg(source.getObjectType().ordinal(), source.getObjectUUID(), source.getFirstName(), + RecvSummonsMsg rsrm = new RecvSummonsMsg(source.getObjectType().ordinal(), source.getObjectUUID(), source.getFirstName(), location, false); Dispatch dispatch = Dispatch.borrow(target, rsrm);