From 56bc38ab734b60e0daedbd0e4937fd6403d2d008 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 29 Mar 2024 06:45:26 -0400 Subject: [PATCH] Handler created for PetAttackMsg --- src/engine/net/client/ClientMessagePump.java | 46 ------------ src/engine/net/client/Protocol.java | 2 +- .../client/handlers/PetAttackMsgHandler.java | 75 +++++++++++++++++++ 3 files changed, 76 insertions(+), 47 deletions(-) create mode 100644 src/engine/net/client/handlers/PetAttackMsgHandler.java diff --git a/src/engine/net/client/ClientMessagePump.java b/src/engine/net/client/ClientMessagePump.java index 9c02f18f..081b7851 100644 --- a/src/engine/net/client/ClientMessagePump.java +++ b/src/engine/net/client/ClientMessagePump.java @@ -9,15 +9,11 @@ package engine.net.client; -import engine.Enum.GameObjectType; -import engine.exception.MsgSendException; import engine.gameManager.*; import engine.net.NetMsgHandler; import engine.net.client.handlers.AbstractClientMsgHandler; import engine.net.client.msg.*; import engine.net.client.msg.chat.AbstractChatMsg; -import engine.objects.Mob; -import engine.objects.PlayerCharacter; import engine.server.world.WorldServer; import engine.session.Session; import engine.util.StringUtils; @@ -40,45 +36,6 @@ public class ClientMessagePump implements NetMsgHandler { this.server = server; } - protected static void petAttack(PetAttackMsg msg, ClientConnection conn) throws MsgSendException { - - PlayerCharacter pc = SessionManager.getPlayerCharacter(conn); - - if (pc == null) - return; - - Mob pet = pc.getPet(); - - if (pet == null) - return; - - if (!pet.isAlive()) - return; - - if ((pc.inSafeZone()) - && (msg.getTargetType() == GameObjectType.PlayerCharacter.ordinal())) - return; - - //CombatManager.setAttackTarget(msg, conn); - if (msg.getTargetType() == GameObjectType.Building.ordinal()) { - conn.getPlayerCharacter().getPet().setCombatTarget(PlayerCharacter.getPlayerCharacter(msg.getTargetID())); - } - switch (msg.getTargetType()) { - case 53: //player character - conn.getPlayerCharacter().getPet().setCombatTarget(PlayerCharacter.getPlayerCharacter(msg.getTargetID())); - break; - case 37://mob - conn.getPlayerCharacter().getPet().setCombatTarget(Mob.getMob(msg.getTargetID())); - break; - case 8://mob - conn.getPlayerCharacter().getPet().setCombatTarget(BuildingManager.getBuilding(msg.getTargetID())); - break; - } - - if (pet.getCombatTarget() == null) - return; - } - //Handle RepairObject Window and RepairObject Requests @Override @@ -184,9 +141,6 @@ public class ClientMessagePump implements NetMsgHandler { case STUCK: MovementManager.stuck(origin); break; - case ARCPETATTACK: - petAttack((PetAttackMsg) msg, origin); - break; case CHANNELMUTE: break; case KEEPALIVESERVERCLIENT: diff --git a/src/engine/net/client/Protocol.java b/src/engine/net/client/Protocol.java index 059dfd4c..429a8ece 100644 --- a/src/engine/net/client/Protocol.java +++ b/src/engine/net/client/Protocol.java @@ -37,7 +37,7 @@ public enum Protocol { ARCMINEWINDOWAVAILABLETIME(0x6C909DE7, ArcMineWindowAvailableTimeMsg.class, ArcMineWindowAvailableTimeHandler.class), ARCMINEWINDOWCHANGE(0x92B2148A, ArcMineWindowChangeMsg.class, MineWindowChangeHandler.class), ARCOWNEDMINESLIST(0x59184455, ArcOwnedMinesListMsg.class, ArcOwnedMinesListHandler.class), - ARCPETATTACK(0x18CD61AD, PetAttackMsg.class, null), // Pet Attack + ARCPETATTACK(0x18CD61AD, PetAttackMsg.class, PetAttackMsgHandler.class), // Pet Attack ARCPETCMD(0x4E80E001, PetCmdMsg.class, PetCmdMsgHandler.class), // Stop ArcPetAttack, Toggle Assist, Toggle Rest ARCPOWERPROJECTILE(0xA2312D3B, null, null), ARCPROMPTRECALL(0xE3196B6E, PromptRecallMsg.class, PromptRecallMsgHandler.class), //Recall Prompt diff --git a/src/engine/net/client/handlers/PetAttackMsgHandler.java b/src/engine/net/client/handlers/PetAttackMsgHandler.java new file mode 100644 index 00000000..04253fee --- /dev/null +++ b/src/engine/net/client/handlers/PetAttackMsgHandler.java @@ -0,0 +1,75 @@ +// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . +// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· +// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ +// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ +// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ +// Magicbane Emulator Project © 2013 - 2022 +// www.magicbane.com + +package engine.net.client.handlers; + +import engine.Enum; +import engine.exception.MsgSendException; +import engine.gameManager.BuildingManager; +import engine.net.client.ClientConnection; +import engine.net.client.msg.ClientNetMsg; +import engine.net.client.msg.PetAttackMsg; +import engine.objects.Mob; +import engine.objects.PlayerCharacter; + +public class PetAttackMsgHandler extends AbstractClientMsgHandler { + + public PetAttackMsgHandler() { + super(PetAttackMsg.class); + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + PlayerCharacter playerCharacter = origin.getPlayerCharacter(); + + // Member variable declaration + + PetAttackMsg msg; + + // Member variable assignment + + msg = (PetAttackMsg) baseMsg; + + if (playerCharacter == null) + return true; + + Mob pet = playerCharacter.getPet(); + + if (pet == null) + return true; + + if (!pet.isAlive()) + return true; + + if (pet.getCombatTarget() == null) + return true; + + if ((playerCharacter.inSafeZone()) + && (msg.getTargetType() == Enum.GameObjectType.PlayerCharacter.ordinal())) + return true; + + if (msg.getTargetType() == Enum.GameObjectType.Building.ordinal()) + pet.setCombatTarget(PlayerCharacter.getPlayerCharacter(msg.getTargetID())); + + switch (msg.getTargetType()) { + case 53: //player character + pet.setCombatTarget(PlayerCharacter.getPlayerCharacter(msg.getTargetID())); + break; + case 37://mob + pet.setCombatTarget(Mob.getMob(msg.getTargetID())); + break; + case 8://mob + pet.setCombatTarget(BuildingManager.getBuilding(msg.getTargetID())); + break; + } + + return true; + } + +} \ No newline at end of file