forked from MagicBane/Server
MagicBot
8 months ago
3 changed files with 142 additions and 102 deletions
@ -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…
Reference in new issue