Browse Source

Handler created for CommitToTradeMsg

combat-2
MagicBot 8 months ago
parent
commit
2768980f6e
  1. 22
      src/engine/gameManager/TradeManager.java
  2. 8
      src/engine/net/client/ClientMessagePump.java
  3. 2
      src/engine/net/client/Protocol.java
  4. 77
      src/engine/net/client/handlers/CommitToTradeMsgHandler.java
  5. 41
      src/engine/objects/CharacterItemManager.java

22
src/engine/gameManager/TradeManager.java

@ -13,7 +13,6 @@ import engine.net.Dispatch;
import engine.net.DispatchMessage; import engine.net.DispatchMessage;
import engine.net.client.ClientConnection; import engine.net.client.ClientConnection;
import engine.net.client.msg.CloseTradeWindowMsg; import engine.net.client.msg.CloseTradeWindowMsg;
import engine.net.client.msg.CommitToTradeMsg;
import engine.net.client.msg.InvalidTradeRequestMsg; import engine.net.client.msg.InvalidTradeRequestMsg;
import engine.net.client.msg.UncommitToTradeMsg; import engine.net.client.msg.UncommitToTradeMsg;
import engine.objects.CharacterItemManager; import engine.objects.CharacterItemManager;
@ -24,26 +23,6 @@ public enum TradeManager {
TRADEMANAGER; TRADEMANAGER;
public static void commitToTrade(CommitToTradeMsg msg, ClientConnection origin) {
PlayerCharacter source = origin.getPlayerCharacter();
if (source == null || !source.isAlive())
return;
CharacterItemManager sourceItemMan = source.charItemManager;
if (sourceItemMan == null)
return;
try {
sourceItemMan.commitToTrade(msg);
} catch (Exception e) {
// TODO Auto-generated catch block
Logger.error(e);
}
}
public static void uncommitToTrade(UncommitToTradeMsg msg, ClientConnection origin) { public static void uncommitToTrade(UncommitToTradeMsg msg, ClientConnection origin) {
PlayerCharacter source = origin.getPlayerCharacter(); PlayerCharacter source = origin.getPlayerCharacter();
@ -65,7 +44,6 @@ public enum TradeManager {
} }
public static void closeTradeWindow(CloseTradeWindowMsg msg, ClientConnection origin) { public static void closeTradeWindow(CloseTradeWindowMsg msg, ClientConnection origin) {
PlayerCharacter source = origin.getPlayerCharacter(); PlayerCharacter source = origin.getPlayerCharacter();

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

@ -13,7 +13,10 @@ import engine.gameManager.SessionManager;
import engine.gameManager.TradeManager; import engine.gameManager.TradeManager;
import engine.net.NetMsgHandler; import engine.net.NetMsgHandler;
import engine.net.client.handlers.AbstractClientMsgHandler; import engine.net.client.handlers.AbstractClientMsgHandler;
import engine.net.client.msg.*; import engine.net.client.msg.ClientNetMsg;
import engine.net.client.msg.CloseTradeWindowMsg;
import engine.net.client.msg.InvalidTradeRequestMsg;
import engine.net.client.msg.UncommitToTradeMsg;
import engine.server.world.WorldServer; import engine.server.world.WorldServer;
import engine.session.Session; import engine.session.Session;
import engine.util.StringUtils; import engine.util.StringUtils;
@ -73,9 +76,6 @@ public class ClientMessagePump implements NetMsgHandler {
break; break;
case OPENVAULT: case OPENVAULT:
break; break;
case TRADECONFIRM:
TradeManager.commitToTrade((CommitToTradeMsg) msg, origin);
break;
case TRADEUNCONFIRM: case TRADEUNCONFIRM:
TradeManager.uncommitToTrade((UncommitToTradeMsg) msg, origin); TradeManager.uncommitToTrade((UncommitToTradeMsg) msg, origin);
break; break;

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

@ -214,7 +214,7 @@ public enum Protocol {
TRADEADDGOLD(0x654ACB45, AddGoldToTradeWindowMsg.class, AddGoldToTradeWindowMsgHandler.class), // Add Gold to Trade Window TRADEADDGOLD(0x654ACB45, AddGoldToTradeWindowMsg.class, AddGoldToTradeWindowMsgHandler.class), // Add Gold to Trade Window
TRADEADDOBJECT(0x55D363E9, AddItemToTradeWindowMsg.class, AddItemToTradeWindowMsgHandler.class), // 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, CommitToTradeMsgHandler.class), // Commit to trade
TRADECONFIRMSTATUS(0x9F85DAFC, null, null), // Other player commit/uncommit/add item TRADECONFIRMSTATUS(0x9F85DAFC, null, null), // Other player commit/uncommit/add item
TRADEUNCONFIRM(0xEBE280E0, UncommitToTradeMsg.class, null), // Uncommit to trade TRADEUNCONFIRM(0xEBE280E0, UncommitToTradeMsg.class, null), // Uncommit to trade
TRAINERLIST(0x41FABA62, TrainerInfoMsg.class, TrainerInfoMsgHandler.class), //Req/Send Trainer Info/Pricing TRAINERLIST(0x41FABA62, TrainerInfoMsg.class, TrainerInfoMsgHandler.class), //Req/Send Trainer Info/Pricing

77
src/engine/net/client/handlers/CommitToTradeMsgHandler.java

@ -0,0 +1,77 @@
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
package engine.net.client.handlers;
import engine.exception.MsgSendException;
import engine.net.client.ClientConnection;
import engine.net.client.msg.ClientNetMsg;
import engine.net.client.msg.CloseTradeWindowMsg;
import engine.net.client.msg.CommitToTradeMsg;
import engine.objects.CharacterItemManager;
import engine.objects.PlayerCharacter;
import static engine.objects.CharacterItemManager.canTrade;
public class CommitToTradeMsgHandler extends AbstractClientMsgHandler {
public CommitToTradeMsgHandler() {
super(CommitToTradeMsg.class);
}
@Override
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
PlayerCharacter source = origin.getPlayerCharacter();
// Member variable declaration
CommitToTradeMsg msg;
// Member variable assignment
msg = (CommitToTradeMsg) baseMsg;
if (source == null || !source.isAlive())
return false;
source.charItemManager.setTradeCommitted((byte) 1);
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;
source.charItemManager.modifyCommitToTrade();
if (source.charItemManager.getTradeCommitted() == (byte) 1 && tradingWith.getTradeCommitted() == (byte) 1) {
int tradeID = source.charItemManager.tradeID;
CloseTradeWindowMsg ctwm1 = new CloseTradeWindowMsg(source, tradeID);
CloseTradeWindowMsg ctwm2 = new CloseTradeWindowMsg(other, tradeID);
source.charItemManager.commitTrade();
source.charItemManager.closeTradeWindow(ctwm1, false);
other.charItemManager.closeTradeWindow(ctwm2, false);
}
return true;
}
}

41
src/engine/objects/CharacterItemManager.java

@ -474,47 +474,6 @@ public class CharacterItemManager {
return modifyCommitToTrade(); return modifyCommitToTrade();
} }
public synchronized boolean commitToTrade(CommitToTradeMsg msg) {
PlayerCharacter source = (PlayerCharacter) this.getOwner();
if (source == null || !source.isAlive())
return false;
this.setTradeCommitted((byte) 1);
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;
modifyCommitToTrade();
if (this.getTradeCommitted() == (byte) 1 && tradingWith.getTradeCommitted() == (byte) 1) {
int tradeID = this.tradeID;
CloseTradeWindowMsg ctwm1 = new CloseTradeWindowMsg(source, tradeID);
CloseTradeWindowMsg ctwm2 = new CloseTradeWindowMsg(other, tradeID);
this.commitTrade();
this.closeTradeWindow(ctwm1, false);
other.charItemManager.closeTradeWindow(ctwm2, false);
}
return true;
}
public synchronized boolean modifyCommitToTrade() { public synchronized boolean modifyCommitToTrade() {
CharacterItemManager man1 = this; CharacterItemManager man1 = this;

Loading…
Cancel
Save