From 06e41d5b945ead3607847d95eb97f6f06bdfe69d Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 29 Mar 2024 04:52:07 -0400 Subject: [PATCH] Handler created for LootWindowRequestMsg --- src/engine/net/client/ClientMessagePump.java | 101 ------------- src/engine/net/client/Protocol.java | 2 +- .../handlers/LootWindowRequestMsgHandler.java | 141 ++++++++++++++++++ 3 files changed, 142 insertions(+), 102 deletions(-) create mode 100644 src/engine/net/client/handlers/LootWindowRequestMsgHandler.java diff --git a/src/engine/net/client/ClientMessagePump.java b/src/engine/net/client/ClientMessagePump.java index 3bbfee14..cfdb9013 100644 --- a/src/engine/net/client/ClientMessagePump.java +++ b/src/engine/net/client/ClientMessagePump.java @@ -178,104 +178,6 @@ public class ClientMessagePump implements NetMsgHandler { JobScheduler.getInstance().scheduleJob(new RefreshGroupJob(sourcePlayer), MBServerStatics.LOAD_OBJECT_DELAY); } - private static void lootWindowRequest(LootWindowRequestMsg msg, ClientConnection origin) throws MsgSendException { - - PlayerCharacter pc = SessionManager.getPlayerCharacter(origin); - - if (pc == null) - return; - - if (!pc.isAlive()) - return; - - if (msg.getSourceType() != pc.getObjectType().ordinal() || msg.getSourceID() != pc.getObjectUUID()) { - Logger.error("Player " + pc.getObjectUUID() + " looting from character of id " - + msg.getSourceType() + ' ' + msg.getSourceID()); - return; - } - - if (pc.getAltitude() > 0) - return; - if (!pc.isAlive()) { - return; - } - - - LootWindowResponseMsg lwrm = null; - GameObjectType targetType = GameObjectType.values()[msg.getTargetType()]; - AbstractCharacter characterTarget = null; - Corpse corpseTarget = null; - - switch (targetType) { - case PlayerCharacter: - - characterTarget = PlayerCharacter.getFromCache(msg.getTargetID()); - if (characterTarget == null) - return; - if (characterTarget.isAlive()) - return; - if (pc.getLoc().distanceSquared2D(characterTarget.getLoc()) > sqr(MBServerStatics.LOOT_RANGE)) { - ErrorPopupMsg.sendErrorMsg(pc, "You are too far away to loot this corpse."); - - Logger.info(pc.getFirstName() + " tried looting at " + pc.getLoc().distance2D(characterTarget.getLoc()) + " distance."); - return; - } - lwrm = new LootWindowResponseMsg(characterTarget.getObjectType().ordinal(), characterTarget.getObjectUUID(), characterTarget.getInventory(true)); - break; - case NPC: - characterTarget = NPC.getFromCache(msg.getTargetID()); - if (characterTarget == null) - return; - break; - case Mob: - characterTarget = Mob.getFromCache(msg.getTargetID()); - if ((characterTarget == null) || characterTarget.isAlive()) { - return; - } - - if (pc.getLoc().distanceSquared2D(characterTarget.getLoc()) > sqr(MBServerStatics.LOOT_RANGE)) { - ErrorPopupMsg.sendErrorMsg(pc, "You are too far away to loot this corpse."); - - Logger.info(pc.getFirstName() + " tried looting at " + pc.getLoc().distance2D(characterTarget.getLoc()) + " distance."); - - if (!((Mob) characterTarget).isLootSync()) { - - ((Mob) characterTarget).setLootSync(true); - WorldGrid.updateObject(characterTarget, pc); - } - - - return; - } - - lwrm = new LootWindowResponseMsg(characterTarget.getObjectType().ordinal(), characterTarget.getObjectUUID(), characterTarget.getInventory()); - break; - case Corpse: - corpseTarget = Corpse.getCorpse(msg.getTargetID()); - - if ((corpseTarget == null)) { - return; - } - - if (pc.getLoc().distanceSquared(corpseTarget.getLoc()) > sqr(MBServerStatics.LOOT_RANGE)) { - ErrorPopupMsg.sendErrorMsg(pc, "You are too far away to loot this corpse."); - - Logger.info(pc.getFirstName() + " tried looting at " + pc.getLoc().distance2D(characterTarget.getLoc()) + " distance."); - return; - } - lwrm = new LootWindowResponseMsg(corpseTarget.getObjectType().ordinal(), msg.getTargetID(), corpseTarget.getInventory()); - break; - } - - if (lwrm == null) - return; - - DispatchMessage.dispatchMsgToInterestArea(pc, msg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false); - Dispatch dispatch = Dispatch.borrow(pc, lwrm); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); - - } - private static void loot(LootMsg msg, ClientConnection origin) throws MsgSendException { PlayerCharacter player = SessionManager.getPlayerCharacter(origin); @@ -740,9 +642,6 @@ public class ClientMessagePump implements NetMsgHandler { case RESETAFTERDEATH: respawn((RespawnMsg) msg, origin); break; - case REQUESTCONTENTS: - lootWindowRequest((LootWindowRequestMsg) msg, origin); - break; case MOVEOBJECTTOCONTAINER: loot((LootMsg) msg, origin); break; diff --git a/src/engine/net/client/Protocol.java b/src/engine/net/client/Protocol.java index a0a0db6c..609cb3fe 100644 --- a/src/engine/net/client/Protocol.java +++ b/src/engine/net/client/Protocol.java @@ -172,7 +172,7 @@ public enum Protocol { REMOVEFRIEND(0xE0D5DB42, RemoveFriendMessage.class, RemoveFriendHandler.class), REPAIRBUILDING(0xAF8C2560, RepairBuildingMsg.class, RepairBuildingMsgHandler.class), REPAIROBJECT(0x782219CE, RepairMsg.class, RepairMsgHandler.class), //Repair Window Req/Ack, RepairObject item Req/Ack - REQUESTCONTENTS(0xA786B0A2, LootWindowRequestMsg.class, null), // MoveObjectToContainer Window Request + REQUESTCONTENTS(0xA786B0A2, LootWindowRequestMsg.class, LootWindowRequestMsgHandler.class), // MoveObjectToContainer Window Request REQUESTGUILDLIST(0x85DCC6D7, ReqGuildListMsg.class, RequestGuildListHandler.class), REQUESTMELEEATTACK(0x98C71545, AttackCmdMsg.class, AttackCmdMsgHandler.class), // Attack REQUESTMEMBERLIST(0x3235E5EA, GuildControlMsg.class, GuildControlHandler.class), // Part of Promote/Demote, Also Player History diff --git a/src/engine/net/client/handlers/LootWindowRequestMsgHandler.java b/src/engine/net/client/handlers/LootWindowRequestMsgHandler.java new file mode 100644 index 00000000..fa23c31f --- /dev/null +++ b/src/engine/net/client/handlers/LootWindowRequestMsgHandler.java @@ -0,0 +1,141 @@ +// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . +// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· +// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ +// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ +// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ +// Magicbane Emulator Project © 2013 - 2022 +// www.magicbane.com + +package engine.net.client.handlers; + +import engine.Enum; +import engine.Enum.DispatchChannel; +import engine.InterestManagement.WorldGrid; +import engine.exception.MsgSendException; +import engine.net.Dispatch; +import engine.net.DispatchMessage; +import engine.net.client.ClientConnection; +import engine.net.client.msg.ClientNetMsg; +import engine.net.client.msg.ErrorPopupMsg; +import engine.net.client.msg.LootWindowRequestMsg; +import engine.net.client.msg.LootWindowResponseMsg; +import engine.objects.*; +import engine.server.MBServerStatics; +import org.pmw.tinylog.Logger; + +import static engine.math.FastMath.sqr; + +public class LootWindowRequestMsgHandler extends AbstractClientMsgHandler { + + public LootWindowRequestMsgHandler() { + super(LootWindowRequestMsg.class); + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + PlayerCharacter player = origin.getPlayerCharacter(); + + // Member variable declaration + + LootWindowRequestMsg msg; + + // Member variable assignment + + msg = (LootWindowRequestMsg) baseMsg; + + if (player == null) + return true; + + if (!player.isAlive()) + return true; + + if (msg.getSourceType() != player.getObjectType().ordinal() || msg.getSourceID() != player.getObjectUUID()) { + Logger.error("Player " + player.getObjectUUID() + " looting from character of id " + + msg.getSourceType() + ' ' + msg.getSourceID()); + return true; + } + + if (player.getAltitude() > 0) + return true; + + if (!player.isAlive()) + return true; + + LootWindowResponseMsg lwrm = null; + Enum.GameObjectType targetType = Enum.GameObjectType.values()[msg.getTargetType()]; + AbstractCharacter characterTarget = null; + Corpse corpseTarget; + + switch (targetType) { + case PlayerCharacter: + + characterTarget = PlayerCharacter.getFromCache(msg.getTargetID()); + + if (characterTarget == null) + return true; + + if (characterTarget.isAlive()) + return true; + + if (player.getLoc().distanceSquared2D(characterTarget.getLoc()) > sqr(MBServerStatics.LOOT_RANGE)) { + ErrorPopupMsg.sendErrorMsg(player, "You are too far away to loot this corpse."); + Logger.info(player.getFirstName() + " tried looting at " + player.getLoc().distance2D(characterTarget.getLoc()) + " distance."); + return true; + } + + lwrm = new LootWindowResponseMsg(characterTarget.getObjectType().ordinal(), characterTarget.getObjectUUID(), characterTarget.getInventory(true)); + break; + case NPC: + characterTarget = NPC.getFromCache(msg.getTargetID()); + + if (characterTarget == null) + return true; + break; + case Mob: + characterTarget = Mob.getFromCache(msg.getTargetID()); + + if ((characterTarget == null) || characterTarget.isAlive()) + return true; + + if (player.getLoc().distanceSquared2D(characterTarget.getLoc()) > sqr(MBServerStatics.LOOT_RANGE)) { + ErrorPopupMsg.sendErrorMsg(player, "You are too far away to loot this corpse."); + + Logger.info(player.getFirstName() + " tried looting at " + player.getLoc().distance2D(characterTarget.getLoc()) + " distance."); + + if (!((Mob) characterTarget).isLootSync()) { + ((Mob) characterTarget).setLootSync(true); + WorldGrid.updateObject(characterTarget, player); + } + + return true; + } + + lwrm = new LootWindowResponseMsg(characterTarget.getObjectType().ordinal(), characterTarget.getObjectUUID(), characterTarget.getInventory()); + break; + case Corpse: + corpseTarget = Corpse.getCorpse(msg.getTargetID()); + + if ((corpseTarget == null)) + return true; + + if (player.getLoc().distanceSquared(corpseTarget.getLoc()) > sqr(MBServerStatics.LOOT_RANGE)) { + ErrorPopupMsg.sendErrorMsg(player, "You are too far away to loot this corpse."); + Logger.info(player.getFirstName() + " tried looting at " + player.getLoc().distance2D(characterTarget.getLoc()) + " distance."); + return true; + } + lwrm = new LootWindowResponseMsg(corpseTarget.getObjectType().ordinal(), msg.getTargetID(), corpseTarget.getInventory()); + break; + } + + if (lwrm == null) + return true; + + DispatchMessage.dispatchMsgToInterestArea(player, msg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false); + Dispatch dispatch = Dispatch.borrow(player, lwrm); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); + + return true; + } + +} \ No newline at end of file