Browse Source

Handler created for LootWindowRequestMsg

combat-2
MagicBot 8 months ago
parent
commit
06e41d5b94
  1. 101
      src/engine/net/client/ClientMessagePump.java
  2. 2
      src/engine/net/client/Protocol.java
  3. 141
      src/engine/net/client/handlers/LootWindowRequestMsgHandler.java

101
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); 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 { private static void loot(LootMsg msg, ClientConnection origin) throws MsgSendException {
PlayerCharacter player = SessionManager.getPlayerCharacter(origin); PlayerCharacter player = SessionManager.getPlayerCharacter(origin);
@ -740,9 +642,6 @@ public class ClientMessagePump implements NetMsgHandler {
case RESETAFTERDEATH: case RESETAFTERDEATH:
respawn((RespawnMsg) msg, origin); respawn((RespawnMsg) msg, origin);
break; break;
case REQUESTCONTENTS:
lootWindowRequest((LootWindowRequestMsg) msg, origin);
break;
case MOVEOBJECTTOCONTAINER: case MOVEOBJECTTOCONTAINER:
loot((LootMsg) msg, origin); loot((LootMsg) msg, origin);
break; break;

2
src/engine/net/client/Protocol.java

@ -172,7 +172,7 @@ public enum Protocol {
REMOVEFRIEND(0xE0D5DB42, RemoveFriendMessage.class, RemoveFriendHandler.class), REMOVEFRIEND(0xE0D5DB42, RemoveFriendMessage.class, RemoveFriendHandler.class),
REPAIRBUILDING(0xAF8C2560, RepairBuildingMsg.class, RepairBuildingMsgHandler.class), REPAIRBUILDING(0xAF8C2560, RepairBuildingMsg.class, RepairBuildingMsgHandler.class),
REPAIROBJECT(0x782219CE, RepairMsg.class, RepairMsgHandler.class), //Repair Window Req/Ack, RepairObject item Req/Ack 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), REQUESTGUILDLIST(0x85DCC6D7, ReqGuildListMsg.class, RequestGuildListHandler.class),
REQUESTMELEEATTACK(0x98C71545, AttackCmdMsg.class, AttackCmdMsgHandler.class), // Attack REQUESTMELEEATTACK(0x98C71545, AttackCmdMsg.class, AttackCmdMsgHandler.class), // Attack
REQUESTMEMBERLIST(0x3235E5EA, GuildControlMsg.class, GuildControlHandler.class), // Part of Promote/Demote, Also Player History REQUESTMEMBERLIST(0x3235E5EA, GuildControlMsg.class, GuildControlHandler.class), // Part of Promote/Demote, Also Player History

141
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;
}
}
Loading…
Cancel
Save