Handler created for AceeptTradeMsg

This commit is contained in:
2024-03-29 08:23:53 -04:00
parent d7b18dc457
commit d4e38c113b
5 changed files with 132 additions and 109 deletions
+2 -89
View File
@@ -53,12 +53,12 @@ public class CharacterItemManager {
private short inventoryWeight;
private short equipWeight;
private short vaultWeight;
private ClientConnection tradingWith;
public ClientConnection tradingWith;
private byte tradeCommitted;
private boolean tradeSuccess;
private HashSet<Integer> trading;
private int goldTradingAmount;
private int tradeID = 0;
public int tradeID = 0;
public CharacterItemManager(AbstractCharacter ac) {
super();
@@ -444,93 +444,6 @@ public class CharacterItemManager {
return true;
}
public synchronized boolean acceptTradeRequest(AcceptTradeRequestMsg msg) {
PlayerCharacter source = (PlayerCharacter) this.getOwner();
PlayerCharacter target = PlayerCharacter.getFromCache(msg.getTargetID());
Dispatch dispatch;
if (source == null || !source.isAlive())
return false;
if (target == null || !target.isAlive())
return false;
if (this.tradingWith != null)
return false;
if (!canTrade(source, target))
return false;
// verify characterTarget is in range
if (source.getLoc().distanceSquared2D(target.getLoc()) > sqr(MBServerStatics.TRADE_RANGE))
return false;
// TODO uncomment this block after we determine when we
// setBankOpen(false) and setVaultOpen(false)
/*
* CharacterItemManager cim1 = source.getCharItemManager();
* CharacterItemManager cim2 = characterTarget.getCharItemManager(); if (cim1 ==
* null) return false; if (cim2 == null) return false; if (cim1.isBankOpen())
* return false; if (cim2.isVaultOpen()) return false;
*/
ClientConnection sourceConn = source.getClientConnection();
ClientConnection targetConn = target.getClientConnection();
if (sourceConn == null)
return false;
if (targetConn == null)
return false;
CharacterItemManager toTradeWith = target.charItemManager;
if (toTradeWith == null)
return false;
Account sourceAccount = source.getAccount();
Account targetAccount = target.getAccount();
UpdateVaultMsg uvmSource = new UpdateVaultMsg(sourceAccount);
UpdateVaultMsg uvmTarget = new UpdateVaultMsg(targetAccount);
dispatch = Dispatch.borrow(source, uvmSource);
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY);
dispatch = Dispatch.borrow(target, uvmTarget);
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY);
this.setVaultOpen(false);
toTradeWith.setVaultOpen(false);
this.setBankOpen(false);
toTradeWith.setBankOpen(false);
OpenTradeWindowMsg otwm = new OpenTradeWindowMsg(msg.getUnknown01(), source, target);
// Only start trade if both players aren't already trading with
// someone
if (this.getTradingWith() != null || toTradeWith.getTradingWith() != null)
return false;
this.initializeTrade();
toTradeWith.initializeTrade();
this.setTradingWith(targetConn);
toTradeWith.setTradingWith(sourceConn);
this.tradeID = msg.getUnknown01();
toTradeWith.tradeID = msg.getUnknown01();
dispatch = Dispatch.borrow(source, otwm);
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY);
dispatch = Dispatch.borrow(target, otwm);
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY);
return true;
}
public synchronized boolean addItemToTradeWindow(AddItemToTradeWindowMsg msg) {
PlayerCharacter source = (PlayerCharacter) this.getOwner();
Dispatch dispatch;