MagicBot
8 months ago
4 changed files with 128 additions and 94 deletions
@ -0,0 +1,119 @@
@@ -0,0 +1,119 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
package engine.net.client.handlers; |
||||
|
||||
import engine.Enum; |
||||
import engine.Enum.DispatchChannel; |
||||
import engine.exception.MsgSendException; |
||||
import engine.gameManager.ChatManager; |
||||
import engine.net.Dispatch; |
||||
import engine.net.DispatchMessage; |
||||
import engine.net.client.ClientConnection; |
||||
import engine.net.client.msg.ApplyEffectMsg; |
||||
import engine.net.client.msg.ClientNetMsg; |
||||
import engine.net.client.msg.TransferItemFromEquipToInventoryMsg; |
||||
import engine.net.client.msg.TransferItemFromInventoryToEquipMsg; |
||||
import engine.objects.CharacterItemManager; |
||||
import engine.objects.Effect; |
||||
import engine.objects.Item; |
||||
import engine.objects.PlayerCharacter; |
||||
import engine.server.MBServerStatics; |
||||
|
||||
public class TransferItemFromInventoryToEquipHandler extends AbstractClientMsgHandler { |
||||
|
||||
public TransferItemFromInventoryToEquipHandler() { |
||||
super(TransferItemFromInventoryToEquipMsg.class); |
||||
} |
||||
|
||||
@Override |
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { |
||||
|
||||
PlayerCharacter playerCharacter = origin.getPlayerCharacter(); |
||||
TransferItemFromInventoryToEquipMsg transferMsg = (TransferItemFromInventoryToEquipMsg) baseMsg; |
||||
CharacterItemManager itemManager = playerCharacter.getCharItemManager(); |
||||
|
||||
if (itemManager == null) { |
||||
forceTransferFromEquipToInventory(transferMsg, origin, "Can't find your item manager"); |
||||
return true; |
||||
} |
||||
|
||||
int uuid = transferMsg.getUUID(); |
||||
int slot = transferMsg.getSlotNumber(); |
||||
//System.out.println("loading to slot: " + slot);
|
||||
|
||||
Item i = itemManager.getItemByUUID(uuid); |
||||
|
||||
if (i == null) { |
||||
forceTransferFromEquipToInventory(transferMsg, origin, "Item not found in your item manager"); |
||||
return true; |
||||
} |
||||
|
||||
if (!itemManager.doesCharOwnThisItem(i.getObjectUUID())) { |
||||
forceTransferFromEquipToInventory(transferMsg, origin, "You do not own this item"); |
||||
return true; |
||||
} |
||||
|
||||
//dupe check
|
||||
if (!i.validForInventory(origin, playerCharacter, itemManager)) |
||||
return true; |
||||
|
||||
if (i.containerType == Enum.ItemContainerType.INVENTORY) { |
||||
if (!itemManager.equipItem(i, (byte) slot)) { |
||||
forceTransferFromEquipToInventory(transferMsg, origin, "Failed to transfer item."); |
||||
return true; |
||||
} |
||||
} else { |
||||
forceTransferFromEquipToInventory(transferMsg, origin, "This item is not in your inventory"); |
||||
return true; |
||||
} |
||||
|
||||
// Update player formulas
|
||||
playerCharacter.applyBonuses(); |
||||
DispatchMessage.dispatchMsgToInterestArea(playerCharacter, transferMsg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false); |
||||
|
||||
for (String name : i.getEffects().keySet()) { |
||||
Effect eff = i.getEffects().get(name); |
||||
|
||||
if (eff == null) |
||||
return true; |
||||
|
||||
ApplyEffectMsg pum = new ApplyEffectMsg(); |
||||
pum.setEffectID(eff.getEffectToken()); |
||||
pum.setSourceType(playerCharacter.getObjectType().ordinal()); |
||||
pum.setSourceID(playerCharacter.getObjectUUID()); |
||||
pum.setTargetType(playerCharacter.getObjectType().ordinal()); |
||||
pum.setTargetID(playerCharacter.getObjectUUID()); |
||||
pum.setNumTrains(eff.getTrains()); |
||||
pum.setUnknown05(1); |
||||
pum.setUnknown06((byte) 1); |
||||
pum.setEffectSourceType(i.getObjectType().ordinal()); |
||||
pum.setEffectSourceID(i.getObjectUUID()); |
||||
pum.setDuration(-1); |
||||
|
||||
DispatchMessage.dispatchMsgToInterestArea(playerCharacter, pum, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false); |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
|
||||
private static void forceTransferFromEquipToInventory(TransferItemFromInventoryToEquipMsg msg, ClientConnection origin, String reason) { |
||||
|
||||
PlayerCharacter pc = origin.getPlayerCharacter(); |
||||
|
||||
if (pc == null) |
||||
return; |
||||
|
||||
TransferItemFromEquipToInventoryMsg back = new TransferItemFromEquipToInventoryMsg(pc, msg.getSlotNumber()); |
||||
Dispatch dispatch = Dispatch.borrow(pc, back); |
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); |
||||
|
||||
ChatManager.chatInfoError(pc, "Can't equip item: " + reason); |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue