Browse Source

Handler created for equip message.

combat-2
MagicBot 8 months ago
parent
commit
75691aaab9
  1. 87
      src/engine/net/client/ClientMessagePump.java
  2. 2
      src/engine/net/client/Protocol.java
  3. 14
      src/engine/net/client/handlers/KeepAliveServerClientHandler.java
  4. 119
      src/engine/net/client/handlers/TransferItemFromInventoryToEquipHandler.java

87
src/engine/net/client/ClientMessagePump.java

@ -211,90 +211,6 @@ public class ClientMessagePump implements NetMsgHandler {
} }
private static void TransferItemFromInventoryToEquip(TransferItemFromInventoryToEquipMsg msg, ClientConnection origin) {
PlayerCharacter pc = origin.getPlayerCharacter();
if (pc == null)
return;
CharacterItemManager itemManager = pc.getCharItemManager();
if (itemManager == null) {
forceTransferFromEquipToInventory(msg, origin, "Can't find your item manager");
return;
}
int uuid = msg.getUUID();
int slot = msg.getSlotNumber();
//System.out.println("loading to slot: " + slot);
Item i = itemManager.getItemByUUID(uuid);
if (i == null) {
forceTransferFromEquipToInventory(msg, origin, "Item not found in your item manager");
return;
}
if (!itemManager.doesCharOwnThisItem(i.getObjectUUID())) {
forceTransferFromEquipToInventory(msg, origin, "You do not own this item");
return;
}
//dupe check
if (!i.validForInventory(origin, pc, itemManager))
return;
if (i.containerType == ItemContainerType.INVENTORY) {
if (!itemManager.equipItem(i, (byte) slot)) {
forceTransferFromEquipToInventory(msg, origin, "Failed to transfer item.");
return;
}
} else {
forceTransferFromEquipToInventory(msg, origin, "This item is not in your inventory");
return;
}
// Update player formulas
pc.applyBonuses();
DispatchMessage.dispatchMsgToInterestArea(pc, msg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false);
for (String name : i.getEffects().keySet()) {
Effect eff = i.getEffects().get(name);
if (eff == null)
return;
ApplyEffectMsg pum = new ApplyEffectMsg();
pum.setEffectID(eff.getEffectToken());
pum.setSourceType(pc.getObjectType().ordinal());
pum.setSourceID(pc.getObjectUUID());
pum.setTargetType(pc.getObjectType().ordinal());
pum.setTargetID(pc.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(pc, pum, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false);
;
}
}
//call this if the transfer fails server side to kick the item back to inventory from equip
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);
}
public static Boolean NPCVaultBankRangeCheck(PlayerCharacter pc, ClientConnection origin, String bankorvault) { public static Boolean NPCVaultBankRangeCheck(PlayerCharacter pc, ClientConnection origin, String bankorvault) {
if (pc == null) if (pc == null)
@ -1917,9 +1833,6 @@ public class ClientMessagePump implements NetMsgHandler {
case UNEQUIP: case UNEQUIP:
TransferItemFromEquipToInventory((TransferItemFromEquipToInventoryMsg) msg, origin); TransferItemFromEquipToInventory((TransferItemFromEquipToInventoryMsg) msg, origin);
break; break;
case EQUIP:
TransferItemFromInventoryToEquip((TransferItemFromInventoryToEquipMsg) msg, origin);
break;
case DELETEOBJECT: case DELETEOBJECT:
DeleteItem((DeleteItemMsg) msg, origin); DeleteItem((DeleteItemMsg) msg, origin);
break; break;

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

@ -92,7 +92,7 @@ public enum Protocol {
DISMISSGUILD(0x8D2D3D61, DismissGuildMsg.class, DismissGuildHandler.class), DISMISSGUILD(0x8D2D3D61, DismissGuildMsg.class, DismissGuildHandler.class),
DOORTRYOPEN(0xA83DD8C8, DoorTryOpenMsg.class, DoorTryOpenMsgHandler.class), // Open/Close Door DOORTRYOPEN(0xA83DD8C8, DoorTryOpenMsg.class, DoorTryOpenMsgHandler.class), // Open/Close Door
ENTERWORLD(0xB9783F85, RequestEnterWorldMsg.class, RequestEnterWorldHandler.class), // Request Enter World ENTERWORLD(0xB9783F85, RequestEnterWorldMsg.class, RequestEnterWorldHandler.class), // Request Enter World
EQUIP(0x3CB1AF8C, TransferItemFromInventoryToEquipMsg.class, null), // Transfer Item from Inventory to Equip EQUIP(0x3CB1AF8C, TransferItemFromInventoryToEquipMsg.class, TransferItemFromInventoryToEquipHandler.class), // Transfer Item from Inventory to Equip
EXPERIENCE(0xC57802A7, GrantExperienceMsg.class, null), //TODO rename once identified EXPERIENCE(0xC57802A7, GrantExperienceMsg.class, null), //TODO rename once identified
FORGETOBJECTS(0xE307A0E1, UnloadObjectsMsg.class, null), // Unload Objects FORGETOBJECTS(0xE307A0E1, UnloadObjectsMsg.class, null), // Unload Objects
FRIENDACCEPT(0xCA297870, AcceptFriendMsg.class, FriendAcceptHandler.class), FRIENDACCEPT(0xCA297870, AcceptFriendMsg.class, FriendAcceptHandler.class),

14
src/engine/net/client/handlers/KeepAliveServerClientHandler.java

@ -1,3 +1,11 @@
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
package engine.net.client.handlers; package engine.net.client.handlers;
import engine.Enum.DispatchChannel; import engine.Enum.DispatchChannel;
@ -9,12 +17,6 @@ import engine.net.client.msg.ClientNetMsg;
import engine.net.client.msg.KeepAliveServerClientMsg; import engine.net.client.msg.KeepAliveServerClientMsg;
import engine.objects.PlayerCharacter; import engine.objects.PlayerCharacter;
/*
* @Author:
* @Summary: Processes application protocol message which keeps
* client's tcp connection open.
*/
public class KeepAliveServerClientHandler extends AbstractClientMsgHandler { public class KeepAliveServerClientHandler extends AbstractClientMsgHandler {
public KeepAliveServerClientHandler() { public KeepAliveServerClientHandler() {

119
src/engine/net/client/handlers/TransferItemFromInventoryToEquipHandler.java

@ -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…
Cancel
Save