Browse Source

Handler created for AddItemToTradeWindowMsg

combat-2
MagicBot 8 months ago
parent
commit
3f1385dd33
  1. 15
      src/engine/gameManager/TradeManager.java
  2. 3
      src/engine/net/client/ClientMessagePump.java
  3. 2
      src/engine/net/client/Protocol.java
  4. 106
      src/engine/net/client/handlers/AddItemToTradeWindowMsgHandler.java
  5. 67
      src/engine/objects/CharacterItemManager.java

15
src/engine/gameManager/TradeManager.java

@ -21,21 +21,6 @@ public enum TradeManager {
TRADEMANAGER; TRADEMANAGER;
public static void addItemToTradeWindow(AddItemToTradeWindowMsg msg, ClientConnection origin) {
PlayerCharacter source = origin.getPlayerCharacter();
if (source == null || !source.isAlive())
return;
try {
source.charItemManager.addItemToTradeWindow(msg);
} catch (Exception e) {
Logger.error(e);
}
}
public static void addGoldToTradeWindow(AddGoldToTradeWindowMsg msg, ClientConnection origin) { public static void addGoldToTradeWindow(AddGoldToTradeWindowMsg msg, ClientConnection origin) {
PlayerCharacter source = origin.getPlayerCharacter(); PlayerCharacter source = origin.getPlayerCharacter();

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

@ -73,9 +73,6 @@ public class ClientMessagePump implements NetMsgHandler {
break; break;
case OPENVAULT: case OPENVAULT:
break; break;
case TRADEADDOBJECT:
TradeManager.addItemToTradeWindow((AddItemToTradeWindowMsg) msg, origin);
break;
case TRADEADDGOLD: case TRADEADDGOLD:
TradeManager.addGoldToTradeWindow((AddGoldToTradeWindowMsg) msg, origin); TradeManager.addGoldToTradeWindow((AddGoldToTradeWindowMsg) msg, origin);
break; break;

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

@ -212,7 +212,7 @@ public enum Protocol {
TERRITORYCHANGE(0x6B388C8C, TerritoryChangeMessage.class, null), //Hey rich, look what I found? :) TERRITORYCHANGE(0x6B388C8C, TerritoryChangeMessage.class, null), //Hey rich, look what I found? :)
TOGGLESITSTAND(0x624F3C0F, ToggleSitStandMsg.class, ToggleSitStandMsgHandler.class), //Toggle Sit/Stand TOGGLESITSTAND(0x624F3C0F, ToggleSitStandMsg.class, ToggleSitStandMsgHandler.class), //Toggle Sit/Stand
TRADEADDGOLD(0x654ACB45, AddGoldToTradeWindowMsg.class, null), // Add Gold to Trade Window TRADEADDGOLD(0x654ACB45, AddGoldToTradeWindowMsg.class, null), // Add Gold to Trade Window
TRADEADDOBJECT(0x55D363E9, AddItemToTradeWindowMsg.class, null), // Add an Item to the Trade Window TRADEADDOBJECT(0x55D363E9, AddItemToTradeWindowMsg.class, AddItemToTradeWindowMsgHandler.class), // Add an Item to the Trade Window
TRADECLOSE(0x5008D7FC, CloseTradeWindowMsg.class, null), // Cancel trade/ACK trade complete TRADECLOSE(0x5008D7FC, CloseTradeWindowMsg.class, null), // Cancel trade/ACK trade complete
TRADECONFIRM(0x6911E65E, CommitToTradeMsg.class, null), // Commit to trade TRADECONFIRM(0x6911E65E, CommitToTradeMsg.class, null), // Commit to trade
TRADECONFIRMSTATUS(0x9F85DAFC, null, null), // Other player commit/uncommit/add item TRADECONFIRMSTATUS(0x9F85DAFC, null, null), // Other player commit/uncommit/add item

106
src/engine/net/client/handlers/AddItemToTradeWindowMsgHandler.java

@ -0,0 +1,106 @@
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
package engine.net.client.handlers;
import engine.Enum;
import engine.exception.MsgSendException;
import engine.net.Dispatch;
import engine.net.DispatchMessage;
import engine.net.client.ClientConnection;
import engine.net.client.msg.AddItemToTradeWindowMsg;
import engine.net.client.msg.ClientNetMsg;
import engine.net.client.msg.UpdateTradeWindowMsg;
import engine.objects.CharacterItemManager;
import engine.objects.Item;
import engine.objects.PlayerCharacter;
import static engine.objects.CharacterItemManager.canTrade;
public class AddItemToTradeWindowMsgHandler extends AbstractClientMsgHandler {
public AddItemToTradeWindowMsgHandler() {
super(AddItemToTradeWindowMsg.class);
}
@Override
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
// Member variable declaration
AddItemToTradeWindowMsg msg;
// Member variable assignment
msg = (AddItemToTradeWindowMsg) baseMsg;
PlayerCharacter source = origin.getPlayerCharacter();
Dispatch dispatch;
if (source == null || !source.isAlive())
return false;
ClientConnection ccOther = source.charItemManager.tradingWith;
if (ccOther == null)
return false;
PlayerCharacter other = ccOther.getPlayerCharacter();
if (other == null || !other.isAlive())
return false;
CharacterItemManager tradingWith = other.charItemManager;
if (tradingWith == null)
return false;
if (!canTrade(source, other))
return false;
Item item = Item.getFromCache(msg.getItemID());
if (item == null)
return false;
if (!source.charItemManager.doesCharOwnThisItem(item.getObjectUUID()))
return false;
//can't add item to trade window twice
if (source.charItemManager.tradingContains(item))
return false;
//dupe check
if (!item.validForInventory(source.getClientConnection(), source, source.charItemManager))
return false;
if (!tradingWith.hasRoomTrade(item.template.item_wt)) {
dispatch = Dispatch.borrow(source, msg);
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY);
return false;
}
UpdateTradeWindowMsg utwm = new UpdateTradeWindowMsg(source, other);
source.charItemManager.setTradeCommitted((byte) 0);
tradingWith.setTradeCommitted((byte) 0);
source.charItemManager.addItemToTrade(item);
dispatch = Dispatch.borrow(other, msg);
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY);
source.charItemManager.modifyCommitToTrade();
dispatch = Dispatch.borrow(other, utwm);
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY);
return true;
}
}

67
src/engine/objects/CharacterItemManager.java

@ -444,71 +444,6 @@ public class CharacterItemManager {
return true; return true;
} }
public synchronized boolean addItemToTradeWindow(AddItemToTradeWindowMsg msg) {
PlayerCharacter source = (PlayerCharacter) this.getOwner();
Dispatch dispatch;
if (source == null || !source.isAlive())
return false;
ClientConnection ccOther = this.getTradingWith();
if (ccOther == null)
return false;
PlayerCharacter other = ccOther.getPlayerCharacter();
if (other == null || !other.isAlive())
return false;
CharacterItemManager tradingWith = other.charItemManager;
if (tradingWith == null)
return false;
if (!canTrade(source, other))
return false;
Item i = Item.getFromCache(msg.getItemID());
if (i == null)
return false;
if (!this.doesCharOwnThisItem(i.getObjectUUID()))
return false;
//can't add item to trade window twice
if (this.tradingContains(i))
return false;
//dupe check
if (!i.validForInventory(source.getClientConnection(), source, this))
return false;
if (!tradingWith.hasRoomTrade(i.template.item_wt)) {
dispatch = Dispatch.borrow(source, msg);
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY);
return false;
}
UpdateTradeWindowMsg utwm = new UpdateTradeWindowMsg(source, other);
this.setTradeCommitted((byte) 0);
tradingWith.setTradeCommitted((byte) 0);
this.addItemToTrade(i);
dispatch = Dispatch.borrow(other, msg);
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY);
modifyCommitToTrade();
dispatch = Dispatch.borrow(other, utwm);
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY);
return true;
}
public synchronized boolean addGoldToTradeWindow(AddGoldToTradeWindowMsg msg) { public synchronized boolean addGoldToTradeWindow(AddGoldToTradeWindowMsg msg) {
PlayerCharacter source = (PlayerCharacter) this.getOwner(); PlayerCharacter source = (PlayerCharacter) this.getOwner();
@ -648,7 +583,7 @@ public class CharacterItemManager {
return true; return true;
} }
private synchronized boolean modifyCommitToTrade() { public synchronized boolean modifyCommitToTrade() {
CharacterItemManager man1 = this; CharacterItemManager man1 = this;
if (this.getTradingWith() == null) if (this.getTradingWith() == null)

Loading…
Cancel
Save