Browse Source

Handlers created for bank interaction

combat-2
MagicBot 8 months ago
parent
commit
e971674465
  1. 33
      src/engine/gameManager/NPCManager.java
  2. 96
      src/engine/net/client/ClientMessagePump.java
  3. 4
      src/engine/net/client/Protocol.java
  4. 100
      src/engine/net/client/handlers/TransferItemFromBankMsgHandler.java
  5. 93
      src/engine/net/client/handlers/TransferItemToBankMsgHandler.java
  6. 16
      src/engine/net/client/msg/TransferItemFromBankMsg.java
  7. 16
      src/engine/net/client/msg/TransferItemToBankMsg.java
  8. 9
      src/engine/objects/Account.java

33
src/engine/gameManager/NPCManager.java

@ -7,10 +7,13 @@ import engine.math.Vector3f; @@ -7,10 +7,13 @@ import engine.math.Vector3f;
import engine.math.Vector3fImmutable;
import engine.net.Dispatch;
import engine.net.DispatchMessage;
import engine.net.client.ClientConnection;
import engine.net.client.msg.ErrorPopupMsg;
import engine.net.client.msg.PetMsg;
import engine.objects.*;
import engine.powers.EffectsBase;
import engine.powers.RuneSkillAdjustEntry;
import engine.server.MBServerStatics;
import org.pmw.tinylog.Logger;
import java.util.ArrayList;
@ -474,4 +477,34 @@ public enum NPCManager { @@ -474,4 +477,34 @@ public enum NPCManager {
}
}
}
public static Boolean NPCVaultBankRangeCheck(PlayerCharacter pc, ClientConnection origin, String bankorvault) {
if (pc == null)
return false;
NPC npc = pc.getLastNPCDialog();
if (npc == null)
return false;
// System.out.println(npc.getContract().getName());
// last npc must be either a banker or vault keeper
if (bankorvault.equals("vault")) {
if (npc.getContract().getContractID() != 861)
return false;
} else
// assuming banker
if (!npc.getContract().getName().equals("Bursar"))
return false;
if (pc.getLoc().distanceSquared2D(npc.getLoc()) > MBServerStatics.NPC_TALK_RANGE * MBServerStatics.NPC_TALK_RANGE) {
ErrorPopupMsg.sendErrorPopup(pc, 14);
return false;
} else
return true;
}
}

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

@ -156,37 +156,7 @@ public class ClientMessagePump implements NetMsgHandler { @@ -156,37 +156,7 @@ public class ClientMessagePump implements NetMsgHandler {
DispatchMessage.dispatchMsgToInterestArea(pc, msg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, true);
}
public static Boolean NPCVaultBankRangeCheck(PlayerCharacter pc, ClientConnection origin, String bankorvault) {
if (pc == null)
return false;
NPC npc = pc.getLastNPCDialog();
if (npc == null)
return false;
// System.out.println(npc.getContract().getName());
// last npc must be either a banker or vault keeper
if (bankorvault.equals("vault")) {
if (npc.getContract().getContractID() != 861)
return false;
} else
// assuming banker
if (!npc.getContract().getName().equals("Bursar"))
return false;
if (pc.getLoc().distanceSquared2D(npc.getLoc()) > MBServerStatics.NPC_TALK_RANGE * MBServerStatics.NPC_TALK_RANGE) {
ErrorPopupMsg.sendErrorPopup(pc, 14);
return false;
} else
return true;
}
private static void transferItemFromInventoryToBank(TransferItemFromInventoryToBankMsg msg, ClientConnection origin) {
private static void transferItemFromBankToInventory(TransferItemFromBankMsg msg, ClientConnection origin) {
PlayerCharacter player = origin.getPlayerCharacter();
Dispatch dispatch;
@ -194,64 +164,7 @@ public class ClientMessagePump implements NetMsgHandler { @@ -194,64 +164,7 @@ public class ClientMessagePump implements NetMsgHandler {
if (player == null)
return;
if (!NPCVaultBankRangeCheck(player, origin, "bank"))
return;
CharacterItemManager itemManager = player.charItemManager;
if (itemManager == null)
return;
if (itemManager.getBankWeight() > 500) {
ErrorPopupMsg.sendErrorPopup(player, 21);
return;
}
int uuid = msg.getUUID();
Item item = itemManager.getItemByUUID(uuid);
if (item == null)
return;
//dupe check WTF CHECK BUT NO LOGGING?
if (!item.validForInventory(origin, player, itemManager))
return;
if (item.containerType == ItemContainerType.INVENTORY && itemManager.isBankOpen())
if (item.template.item_type.equals(engine.Enum.ItemType.GOLD)) {
if (!itemManager.moveGoldToBank(item, msg.getNumItems()))
return;
UpdateGoldMsg goldMes = new UpdateGoldMsg(player);
goldMes.configure();
dispatch = Dispatch.borrow(player, goldMes);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
} else {
if (!itemManager.hasRoomBank(item.template.item_wt))
return;
if (!itemManager.moveItemToBank(item))
return;
dispatch = Dispatch.borrow(player, msg);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
}
}
private static void transferItemFromBankToInventory(TransferItemFromBankToInventoryMsg msg, ClientConnection origin) {
PlayerCharacter player = origin.getPlayerCharacter();
Dispatch dispatch;
if (player == null)
return;
if (!NPCVaultBankRangeCheck(player, origin, "bank"))
if (!NPCManager.NPCVaultBankRangeCheck(player, origin, "bank"))
return;
CharacterItemManager itemManager = player.charItemManager;
@ -1320,11 +1233,8 @@ public class ClientMessagePump implements NetMsgHandler { @@ -1320,11 +1233,8 @@ public class ClientMessagePump implements NetMsgHandler {
case SHOWCOMBATINFO:
show((ShowMsg) msg, origin);
break;
case TRANSFERITEMTOBANK:
transferItemFromInventoryToBank((TransferItemFromInventoryToBankMsg) msg, origin);
break;
case TRANSFERITEMFROMBANK:
transferItemFromBankToInventory((TransferItemFromBankToInventoryMsg) msg, origin);
transferItemFromBankToInventory((TransferItemFromBankMsg) msg, origin);
break;
case TRANSFERITEMFROMVAULTTOINVENTORY:
transferItemFromVaultToInventory((TransferItemFromVaultToInventoryMsg) msg, origin);

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

@ -222,9 +222,9 @@ public enum Protocol { @@ -222,9 +222,9 @@ public enum Protocol {
TRANSFERASSET(0x3EA1C4C9, TransferAssetMsg.class, TransferAssetMsgHandler.class), // Transfer Building
TRANSFERGOLDFROMVAULTTOINVENTORY(0x011D0123, TransferGoldFromVaultToInventoryMsg.class, null), // Transfer Gold from Vault to Inventory
TRANSFERGOLDTOFROMBUILDING(0x1B1AC8C7, TransferGoldToFromBuildingMsg.class, TransferGoldToFromBuildingMsgHandler.class), // Transfer Gold to/From Building, Transfer Error
TRANSFERITEMFROMBANK(0x9D04977B, TransferItemFromBankToInventoryMsg.class, null), // Transfer Item from Bank to Inventory
TRANSFERITEMFROMBANK(0x9D04977B, TransferItemFromBankMsg.class, TransferItemFromBankMsgHandler.class), // Transfer Item from Bank to Inventory
TRANSFERITEMFROMVAULTTOINVENTORY(0x0119A64D, TransferItemFromVaultToInventoryMsg.class, null), // Transfer Item from Vault to Inventory
TRANSFERITEMTOBANK(0xD48C46FA, TransferItemFromInventoryToBankMsg.class, null), // Transfer Item from Inventory to Bank
TRANSFERITEMTOBANK(0xD48C46FA, TransferItemToBankMsg.class, TransferItemToBankMsgHandler.class), // Transfer Item from Inventory to Bank
UNEQUIP(0xC6BFB907, TransferItemFromEquipToInventoryMsg.class, TransferItemFromEquipToInventoryHandler.class), // Transfer Item from Equip to Inventory
UNKNOWN(0x238C9259, UnknownMsg.class, null),
UPDATECHARORMOB(0xB6D78961, null, null),

100
src/engine/net/client/handlers/TransferItemFromBankMsgHandler.java

@ -0,0 +1,100 @@ @@ -0,0 +1,100 @@
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// 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.NPCManager;
import engine.net.Dispatch;
import engine.net.DispatchMessage;
import engine.net.client.ClientConnection;
import engine.net.client.msg.ClientNetMsg;
import engine.net.client.msg.TransferItemFromBankMsg;
import engine.net.client.msg.UpdateGoldMsg;
import engine.objects.CharacterItemManager;
import engine.objects.Item;
import engine.objects.PlayerCharacter;
public class TransferItemFromBankMsgHandler extends AbstractClientMsgHandler {
public TransferItemFromBankMsgHandler() {
super(TransferItemFromBankMsg.class);
}
@Override
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
PlayerCharacter player = origin.getPlayerCharacter();
Dispatch dispatch;
if (player == null)
return true;
;
TransferItemFromBankMsg msg = (TransferItemFromBankMsg) baseMsg;
if (!NPCManager.NPCVaultBankRangeCheck(player, origin, "bank"))
return true;
;
CharacterItemManager itemManager = player.charItemManager;
if (itemManager == null)
return true;
;
int uuid = msg.getUUID();
Item item = itemManager.getItemByUUID(uuid);
if (item == null)
return true;
;
//dupe check
// WTF Checking but not logging?
if (!item.validForBank(origin, player, itemManager))
return true;
;
if (item.containerType == Enum.ItemContainerType.BANK && itemManager.isBankOpen() == false)
return true;
;
if (item.template.item_type.equals(engine.Enum.ItemType.GOLD)) {
if (!itemManager.moveGoldToInventory(item, msg.getNumItems()))
return true;
;
UpdateGoldMsg goldMes = new UpdateGoldMsg(player);
goldMes.configure();
dispatch = Dispatch.borrow(player, goldMes);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
return true;
}
// Not gold, process update here
if (!itemManager.hasRoomInventory(item.template.item_wt))
return true;
if (itemManager.moveItemToInventory(item) == false)
return true;
dispatch = Dispatch.borrow(player, msg);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
return true;
}
}

93
src/engine/net/client/handlers/TransferItemToBankMsgHandler.java

@ -0,0 +1,93 @@ @@ -0,0 +1,93 @@
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// 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.NPCManager;
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.TransferItemToBankMsg;
import engine.net.client.msg.UpdateGoldMsg;
import engine.objects.CharacterItemManager;
import engine.objects.Item;
import engine.objects.PlayerCharacter;
public class TransferItemToBankMsgHandler extends AbstractClientMsgHandler {
public TransferItemToBankMsgHandler() {
super(TransferItemToBankMsg.class);
}
@Override
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
PlayerCharacter player = origin.getPlayerCharacter();
Dispatch dispatch;
if (player == null)
return true;
TransferItemToBankMsg msg = (TransferItemToBankMsg) baseMsg;
if (!NPCManager.NPCVaultBankRangeCheck(player, origin, "bank"))
return true;
CharacterItemManager itemManager = player.charItemManager;
if (itemManager == null)
return true;
if (itemManager.getBankWeight() > 500) {
ErrorPopupMsg.sendErrorPopup(player, 21);
return true;
}
int uuid = msg.getUUID();
Item item = itemManager.getItemByUUID(uuid);
if (item == null)
return true;
//dupe check WTF CHECK BUT NO LOGGING?
if (!item.validForInventory(origin, player, itemManager))
return true;
if (item.containerType == Enum.ItemContainerType.INVENTORY && itemManager.isBankOpen())
if (item.template.item_type.equals(engine.Enum.ItemType.GOLD)) {
if (!itemManager.moveGoldToBank(item, msg.getNumItems()))
return true;
UpdateGoldMsg goldMes = new UpdateGoldMsg(player);
goldMes.configure();
dispatch = Dispatch.borrow(player, goldMes);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
} else {
if (!itemManager.hasRoomBank(item.template.item_wt))
return true;
if (!itemManager.moveItemToBank(item))
return true;
dispatch = Dispatch.borrow(player, msg);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
}
return true;
}
}

16
src/engine/net/client/msg/TransferItemFromBankToInventoryMsg.java → src/engine/net/client/msg/TransferItemFromBankMsg.java

@ -22,7 +22,7 @@ import engine.net.client.Protocol; @@ -22,7 +22,7 @@ import engine.net.client.Protocol;
* @author Eighty
*/
public class TransferItemFromBankToInventoryMsg extends ClientNetMsg {
public class TransferItemFromBankMsg extends ClientNetMsg {
private long playerCompID1;
private long playerCompID2;
@ -36,9 +36,9 @@ public class TransferItemFromBankToInventoryMsg extends ClientNetMsg { @@ -36,9 +36,9 @@ public class TransferItemFromBankToInventoryMsg extends ClientNetMsg {
/**
* This is the general purpose constructor
*/
public TransferItemFromBankToInventoryMsg(long playerCompID1,
long playerCompID2, int type, int objectUUID, int unknown1,
int unknown2, int numItems, byte unknown4) {
public TransferItemFromBankMsg(long playerCompID1,
long playerCompID2, int type, int objectUUID, int unknown1,
int unknown2, int numItems, byte unknown4) {
super(Protocol.TRANSFERITEMFROMBANK);
this.playerCompID1 = playerCompID1;
this.playerCompID2 = playerCompID2;
@ -50,7 +50,7 @@ public class TransferItemFromBankToInventoryMsg extends ClientNetMsg { @@ -50,7 +50,7 @@ public class TransferItemFromBankToInventoryMsg extends ClientNetMsg {
this.unknown4 = unknown4;
}
public TransferItemFromBankToInventoryMsg(TransferItemFromInventoryToBankMsg msg) {
public TransferItemFromBankMsg(TransferItemToBankMsg msg) {
super(Protocol.TRANSFERITEMFROMBANK);
this.playerCompID1 = msg.getPlayerCompID1();
this.playerCompID2 = msg.getPlayerCompID2();
@ -65,7 +65,7 @@ public class TransferItemFromBankToInventoryMsg extends ClientNetMsg { @@ -65,7 +65,7 @@ public class TransferItemFromBankToInventoryMsg extends ClientNetMsg {
/**
* This is the general purpose constructor
*/
public TransferItemFromBankToInventoryMsg() {
public TransferItemFromBankMsg() {
super(Protocol.TRANSFERITEMFROMBANK);
}
@ -75,8 +75,8 @@ public class TransferItemFromBankToInventoryMsg extends ClientNetMsg { @@ -75,8 +75,8 @@ public class TransferItemFromBankToInventoryMsg extends ClientNetMsg {
* past the limit) then this constructor Throws that Exception to the
* caller.
*/
public TransferItemFromBankToInventoryMsg(AbstractConnection origin,
ByteBufferReader reader) {
public TransferItemFromBankMsg(AbstractConnection origin,
ByteBufferReader reader) {
super(Protocol.TRANSFERITEMFROMBANK, origin, reader);
}

16
src/engine/net/client/msg/TransferItemFromInventoryToBankMsg.java → src/engine/net/client/msg/TransferItemToBankMsg.java

@ -22,7 +22,7 @@ import engine.net.client.Protocol; @@ -22,7 +22,7 @@ import engine.net.client.Protocol;
* @author Eighty
*/
public class TransferItemFromInventoryToBankMsg extends ClientNetMsg {
public class TransferItemToBankMsg extends ClientNetMsg {
private long playerCompID1;
private long playerCompID2;
@ -36,9 +36,9 @@ public class TransferItemFromInventoryToBankMsg extends ClientNetMsg { @@ -36,9 +36,9 @@ public class TransferItemFromInventoryToBankMsg extends ClientNetMsg {
/**
* This is the general purpose constructor
*/
public TransferItemFromInventoryToBankMsg(long playerCompID1,
long playerCompID2, int type, int objectUUID, int unknown1,
int unknown2, int numItems, byte unknown4) {
public TransferItemToBankMsg(long playerCompID1,
long playerCompID2, int type, int objectUUID, int unknown1,
int unknown2, int numItems, byte unknown4) {
super(Protocol.TRANSFERITEMTOBANK);
this.playerCompID1 = playerCompID1;
this.playerCompID2 = playerCompID2;
@ -50,7 +50,7 @@ public class TransferItemFromInventoryToBankMsg extends ClientNetMsg { @@ -50,7 +50,7 @@ public class TransferItemFromInventoryToBankMsg extends ClientNetMsg {
this.unknown4 = unknown4;
}
public TransferItemFromInventoryToBankMsg(TransferItemFromBankToInventoryMsg msg) {
public TransferItemToBankMsg(TransferItemFromBankMsg msg) {
super(Protocol.TRANSFERITEMTOBANK);
this.playerCompID1 = msg.getPlayerCompID1();
this.playerCompID2 = msg.getPlayerCompID2();
@ -65,7 +65,7 @@ public class TransferItemFromInventoryToBankMsg extends ClientNetMsg { @@ -65,7 +65,7 @@ public class TransferItemFromInventoryToBankMsg extends ClientNetMsg {
/**
* This is the general purpose constructor
*/
public TransferItemFromInventoryToBankMsg() {
public TransferItemToBankMsg() {
super(Protocol.TRANSFERITEMTOBANK);
}
@ -75,8 +75,8 @@ public class TransferItemFromInventoryToBankMsg extends ClientNetMsg { @@ -75,8 +75,8 @@ public class TransferItemFromInventoryToBankMsg extends ClientNetMsg {
* past the limit) then this constructor Throws that Exception to the
* caller.
*/
public TransferItemFromInventoryToBankMsg(AbstractConnection origin,
ByteBufferReader reader) {
public TransferItemToBankMsg(AbstractConnection origin,
ByteBufferReader reader) {
super(Protocol.TRANSFERITEMTOBANK, origin, reader);
}

9
src/engine/objects/Account.java

@ -14,6 +14,7 @@ import engine.Enum.DispatchChannel; @@ -14,6 +14,7 @@ import engine.Enum.DispatchChannel;
import engine.Enum.ItemContainerType;
import engine.gameManager.ConfigManager;
import engine.gameManager.DbManager;
import engine.gameManager.NPCManager;
import engine.gameManager.SessionManager;
import engine.net.Dispatch;
import engine.net.DispatchMessage;
@ -200,7 +201,7 @@ public class Account extends AbstractGameObject { @@ -200,7 +201,7 @@ public class Account extends AbstractGameObject {
if (player == null)
return;
if (!ClientMessagePump.NPCVaultBankRangeCheck(player, origin, "vault")) {
if (!NPCManager.NPCVaultBankRangeCheck(player, origin, "vault")) {
ClientMessagePump.forceTransferFromVaultToInventory(msg, origin, "You are out of range of the vault.");
return;
}
@ -240,7 +241,7 @@ public class Account extends AbstractGameObject { @@ -240,7 +241,7 @@ public class Account extends AbstractGameObject {
if (player == null)
return;
if (!ClientMessagePump.NPCVaultBankRangeCheck(player, origin, "vault")) {
if (!NPCManager.NPCVaultBankRangeCheck(player, origin, "vault")) {
ClientMessagePump.forceTransferFromInventoryToVault(msg, origin, "You are out of range of the vault.");
return;
}
@ -292,7 +293,7 @@ public class Account extends AbstractGameObject { @@ -292,7 +293,7 @@ public class Account extends AbstractGameObject {
if (account == null)
return;
if (!ClientMessagePump.NPCVaultBankRangeCheck(player, origin, "vault"))
if (!NPCManager.NPCVaultBankRangeCheck(player, origin, "vault"))
return;
NPC npc = player.getLastNPCDialog();
@ -344,7 +345,7 @@ public class Account extends AbstractGameObject { @@ -344,7 +345,7 @@ public class Account extends AbstractGameObject {
if (account == null)
return;
if (!ClientMessagePump.NPCVaultBankRangeCheck(player, origin, "vault"))
if (!NPCManager.NPCVaultBankRangeCheck(player, origin, "vault"))
return;
CharacterItemManager itemManager = player.charItemManager;

Loading…
Cancel
Save