Browse Source

Handler created for UnCommitToTradeMsg

combat-2
MagicBot 8 months ago
parent
commit
5f16289052
  1. 22
      src/engine/gameManager/TradeManager.java
  2. 4
      src/engine/net/client/ClientMessagePump.java
  3. 2
      src/engine/net/client/Protocol.java
  4. 67
      src/engine/net/client/handlers/UncommitToTradeMsgHandler.java
  5. 30
      src/engine/objects/CharacterItemManager.java

22
src/engine/gameManager/TradeManager.java

@ -14,7 +14,6 @@ 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.InvalidTradeRequestMsg; import engine.net.client.msg.InvalidTradeRequestMsg;
import engine.net.client.msg.UncommitToTradeMsg;
import engine.objects.CharacterItemManager; import engine.objects.CharacterItemManager;
import engine.objects.PlayerCharacter; import engine.objects.PlayerCharacter;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
@ -23,27 +22,6 @@ public enum TradeManager {
TRADEMANAGER; TRADEMANAGER;
public static void uncommitToTrade(UncommitToTradeMsg msg, ClientConnection origin) {
PlayerCharacter source = origin.getPlayerCharacter();
if (source == null || !source.isAlive())
return;
CharacterItemManager sourceItemMan = source.charItemManager;
if (sourceItemMan == null)
return;
try {
sourceItemMan.uncommitToTrade(msg);
} catch (Exception e) {
// TODO Auto-generated catch block
Logger.error(e);
}
}
public static void closeTradeWindow(CloseTradeWindowMsg msg, ClientConnection origin) { public static void closeTradeWindow(CloseTradeWindowMsg msg, ClientConnection origin) {
PlayerCharacter source = origin.getPlayerCharacter(); PlayerCharacter source = origin.getPlayerCharacter();

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

@ -16,7 +16,6 @@ import engine.net.client.handlers.AbstractClientMsgHandler;
import engine.net.client.msg.ClientNetMsg; import engine.net.client.msg.ClientNetMsg;
import engine.net.client.msg.CloseTradeWindowMsg; import engine.net.client.msg.CloseTradeWindowMsg;
import engine.net.client.msg.InvalidTradeRequestMsg; 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;
@ -76,9 +75,6 @@ public class ClientMessagePump implements NetMsgHandler {
break; break;
case OPENVAULT: case OPENVAULT:
break; break;
case TRADEUNCONFIRM:
TradeManager.uncommitToTrade((UncommitToTradeMsg) msg, origin);
break;
case TRADECLOSE: case TRADECLOSE:
TradeManager.closeTradeWindow((CloseTradeWindowMsg) msg, origin); TradeManager.closeTradeWindow((CloseTradeWindowMsg) msg, origin);
break; break;

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

@ -216,7 +216,7 @@ public enum Protocol {
TRADECLOSE(0x5008D7FC, CloseTradeWindowMsg.class, null), // Cancel trade/ACK trade complete TRADECLOSE(0x5008D7FC, CloseTradeWindowMsg.class, null), // Cancel trade/ACK trade complete
TRADECONFIRM(0x6911E65E, CommitToTradeMsg.class, CommitToTradeMsgHandler.class), // 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, UncommitToTradeMsgHandler.class), // 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
TRAINSKILL(0xB0BF68CD, TrainMsg.class, TrainMsgHandler.class), //Train skills/powers TRAINSKILL(0xB0BF68CD, TrainMsg.class, TrainMsgHandler.class), //Train skills/powers
TRANSFERASSET(0x3EA1C4C9, TransferAssetMsg.class, TransferAssetMsgHandler.class), // Transfer Building TRANSFERASSET(0x3EA1C4C9, TransferAssetMsg.class, TransferAssetMsgHandler.class), // Transfer Building

67
src/engine/net/client/handlers/UncommitToTradeMsgHandler.java

@ -0,0 +1,67 @@
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// 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.UncommitToTradeMsg;
import engine.objects.CharacterItemManager;
import engine.objects.PlayerCharacter;
import static engine.objects.CharacterItemManager.canTrade;
public class UncommitToTradeMsgHandler extends AbstractClientMsgHandler {
public UncommitToTradeMsgHandler() {
super(UncommitToTradeMsg.class);
}
@Override
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
PlayerCharacter source = origin.getPlayerCharacter();
// Member variable declaration
UncommitToTradeMsg msg;
// Member variable assignment
msg = (UncommitToTradeMsg) baseMsg;
if (source == null || !source.isAlive())
return true;
CharacterItemManager sourceItemMan = source.charItemManager;
if (sourceItemMan == null)
return true;
sourceItemMan.setTradeCommitted((byte) 0);
ClientConnection ccOther = sourceItemMan.getTradingWith();
if (ccOther == null)
return true;
PlayerCharacter other = ccOther.getPlayerCharacter();
if (other == null)
return true;
if (!canTrade(source, other))
return true;
source.charItemManager.modifyCommitToTrade();
return true;
}
}

30
src/engine/objects/CharacterItemManager.java

@ -444,36 +444,6 @@ public class CharacterItemManager {
return true; return true;
} }
public synchronized boolean uncommitToTrade(UncommitToTradeMsg msg) {
PlayerCharacter source = (PlayerCharacter) this.getOwner();
if (source == null || !source.isAlive())
return false;
CharacterItemManager sourceItemMan = source.charItemManager;
if (sourceItemMan == null)
return false;
sourceItemMan.setTradeCommitted((byte) 0);
ClientConnection ccOther = sourceItemMan.getTradingWith();
if (ccOther == null)
return false;
PlayerCharacter other = ccOther.getPlayerCharacter();
if (other == null)
return false;
if (!canTrade(source, other))
return false;
return modifyCommitToTrade();
}
public synchronized boolean modifyCommitToTrade() { public synchronized boolean modifyCommitToTrade() {
CharacterItemManager man1 = this; CharacterItemManager man1 = this;

Loading…
Cancel
Save