Browse Source

Handler created for CloseTradeWindow

combat-2
MagicBot 8 months ago
parent
commit
8cd613c597
  1. 24
      src/engine/gameManager/TradeManager.java
  2. 4
      src/engine/net/client/ClientMessagePump.java
  3. 2
      src/engine/net/client/Protocol.java
  4. 69
      src/engine/net/client/handlers/CloseTradeWindowMsgHandler.java

24
src/engine/gameManager/TradeManager.java

@ -11,37 +11,13 @@ package engine.gameManager;
import engine.Enum; import engine.Enum;
import engine.net.Dispatch; import engine.net.Dispatch;
import engine.net.DispatchMessage; import engine.net.DispatchMessage;
import engine.net.client.ClientConnection;
import engine.net.client.msg.CloseTradeWindowMsg;
import engine.net.client.msg.InvalidTradeRequestMsg; import engine.net.client.msg.InvalidTradeRequestMsg;
import engine.objects.CharacterItemManager;
import engine.objects.PlayerCharacter; import engine.objects.PlayerCharacter;
import org.pmw.tinylog.Logger;
public enum TradeManager { public enum TradeManager {
TRADEMANAGER; TRADEMANAGER;
public static void closeTradeWindow(CloseTradeWindowMsg msg, ClientConnection origin) {
PlayerCharacter source = origin.getPlayerCharacter();
if (source == null)
return;
CharacterItemManager sourceItemMan = source.charItemManager;
if (sourceItemMan == null)
return;
try {
sourceItemMan.closeTradeWindow(msg, true);
} catch (Exception e) {
// TODO Auto-generated catch block
Logger.error(e);
}
}
public static void invalidTradeRequest(InvalidTradeRequestMsg msg) { public static void invalidTradeRequest(InvalidTradeRequestMsg msg) {
PlayerCharacter requester = PlayerCharacter.getFromCache(msg.getRequesterID()); PlayerCharacter requester = PlayerCharacter.getFromCache(msg.getRequesterID());
Dispatch dispatch; Dispatch dispatch;

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

@ -14,7 +14,6 @@ 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.ClientNetMsg; import engine.net.client.msg.ClientNetMsg;
import engine.net.client.msg.CloseTradeWindowMsg;
import engine.net.client.msg.InvalidTradeRequestMsg; import engine.net.client.msg.InvalidTradeRequestMsg;
import engine.server.world.WorldServer; import engine.server.world.WorldServer;
import engine.session.Session; import engine.session.Session;
@ -75,9 +74,6 @@ public class ClientMessagePump implements NetMsgHandler {
break; break;
case OPENVAULT: case OPENVAULT:
break; break;
case TRADECLOSE:
TradeManager.closeTradeWindow((CloseTradeWindowMsg) msg, origin);
break;
case ARCREQUESTTRADEBUSY: case ARCREQUESTTRADEBUSY:
TradeManager.invalidTradeRequest((InvalidTradeRequestMsg) msg); TradeManager.invalidTradeRequest((InvalidTradeRequestMsg) msg);
break; break;

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

@ -213,7 +213,7 @@ public enum Protocol {
TOGGLESITSTAND(0x624F3C0F, ToggleSitStandMsg.class, ToggleSitStandMsgHandler.class), //Toggle Sit/Stand TOGGLESITSTAND(0x624F3C0F, ToggleSitStandMsg.class, ToggleSitStandMsgHandler.class), //Toggle Sit/Stand
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, CloseTradeWindowMsgHandler.class), // 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, UncommitToTradeMsgHandler.class), // Uncommit to trade TRADEUNCONFIRM(0xEBE280E0, UncommitToTradeMsg.class, UncommitToTradeMsgHandler.class), // Uncommit to trade

69
src/engine/net/client/handlers/CloseTradeWindowMsgHandler.java

@ -0,0 +1,69 @@
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// 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.ClientNetMsg;
import engine.net.client.msg.CloseTradeWindowMsg;
import engine.objects.CharacterItemManager;
import engine.objects.PlayerCharacter;
public class CloseTradeWindowMsgHandler extends AbstractClientMsgHandler {
public CloseTradeWindowMsgHandler() {
super(CloseTradeWindowMsg.class);
}
@Override
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
PlayerCharacter source = origin.getPlayerCharacter();
// Member variable declaration
CloseTradeWindowMsg msg;
// Member variable assignment
msg = (CloseTradeWindowMsg) baseMsg;
Dispatch dispatch;
if (source == null)
return false;
CharacterItemManager sourceItemMan = source.charItemManager;
if (sourceItemMan == null)
return false;
int tradeID = source.charItemManager.tradeID;
CloseTradeWindowMsg closeMsg = new CloseTradeWindowMsg(source, tradeID);
dispatch = Dispatch.borrow(source, closeMsg);
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
ClientConnection cc2 = sourceItemMan.getTradingWith();
if (cc2 == null || cc2.getPlayerCharacter() == null) {
sourceItemMan.endTrade();
return true;
}
sourceItemMan.endTrade();
cc2.getPlayerCharacter().charItemManager.closeTradeWindow(msg, false);
return true;
}
}
Loading…
Cancel
Save