Handler created for AddGoldToTradeWindowMsg
This commit is contained in:
@@ -12,7 +12,10 @@ 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.ClientConnection;
|
||||||
import engine.net.client.msg.*;
|
import engine.net.client.msg.CloseTradeWindowMsg;
|
||||||
|
import engine.net.client.msg.CommitToTradeMsg;
|
||||||
|
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;
|
||||||
@@ -21,26 +24,6 @@ public enum TradeManager {
|
|||||||
|
|
||||||
TRADEMANAGER;
|
TRADEMANAGER;
|
||||||
|
|
||||||
public static void addGoldToTradeWindow(AddGoldToTradeWindowMsg msg, ClientConnection origin) {
|
|
||||||
|
|
||||||
PlayerCharacter source = origin.getPlayerCharacter();
|
|
||||||
|
|
||||||
if (source == null || !source.isAlive())
|
|
||||||
return;
|
|
||||||
|
|
||||||
|
|
||||||
CharacterItemManager sourceItemMan = source.charItemManager;
|
|
||||||
|
|
||||||
if (sourceItemMan == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
try {
|
|
||||||
sourceItemMan.addGoldToTradeWindow(msg);
|
|
||||||
} catch (Exception e) {
|
|
||||||
Logger.error(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void commitToTrade(CommitToTradeMsg msg, ClientConnection origin) {
|
public static void commitToTrade(CommitToTradeMsg msg, ClientConnection origin) {
|
||||||
|
|
||||||
PlayerCharacter source = origin.getPlayerCharacter();
|
PlayerCharacter source = origin.getPlayerCharacter();
|
||||||
|
|||||||
@@ -73,9 +73,6 @@ public class ClientMessagePump implements NetMsgHandler {
|
|||||||
break;
|
break;
|
||||||
case OPENVAULT:
|
case OPENVAULT:
|
||||||
break;
|
break;
|
||||||
case TRADEADDGOLD:
|
|
||||||
TradeManager.addGoldToTradeWindow((AddGoldToTradeWindowMsg) msg, origin);
|
|
||||||
break;
|
|
||||||
case TRADECONFIRM:
|
case TRADECONFIRM:
|
||||||
TradeManager.commitToTrade((CommitToTradeMsg) msg, origin);
|
TradeManager.commitToTrade((CommitToTradeMsg) msg, origin);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -211,7 +211,7 @@ public enum Protocol {
|
|||||||
TELEPORT(0x23E726EA, TeleportToPointMsg.class, null), // Teleport to point
|
TELEPORT(0x23E726EA, TeleportToPointMsg.class, null), // Teleport to point
|
||||||
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, 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, null), // Commit to trade
|
||||||
|
|||||||
@@ -0,0 +1,109 @@
|
|||||||
|
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||||
|
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||||
|
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||||
|
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||||
|
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||||
|
// 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.AddGoldToTradeWindowMsg;
|
||||||
|
import engine.net.client.msg.ClientNetMsg;
|
||||||
|
import engine.net.client.msg.UpdateGoldMsg;
|
||||||
|
import engine.net.client.msg.UpdateTradeWindowMsg;
|
||||||
|
import engine.objects.CharacterItemManager;
|
||||||
|
import engine.objects.PlayerCharacter;
|
||||||
|
import engine.server.MBServerStatics;
|
||||||
|
import org.pmw.tinylog.Logger;
|
||||||
|
|
||||||
|
import static engine.objects.CharacterItemManager.canTrade;
|
||||||
|
|
||||||
|
public class AddGoldToTradeWindowMsgHandler extends AbstractClientMsgHandler {
|
||||||
|
|
||||||
|
public AddGoldToTradeWindowMsgHandler() {
|
||||||
|
super(AddGoldToTradeWindowMsg.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||||
|
|
||||||
|
PlayerCharacter source = origin.getPlayerCharacter();
|
||||||
|
|
||||||
|
// Member variable declaration
|
||||||
|
|
||||||
|
AddGoldToTradeWindowMsg msg;
|
||||||
|
|
||||||
|
// Member variable assignment
|
||||||
|
|
||||||
|
msg = (AddGoldToTradeWindowMsg) baseMsg;
|
||||||
|
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;
|
||||||
|
|
||||||
|
UpdateTradeWindowMsg utwm = new UpdateTradeWindowMsg(other, source);
|
||||||
|
UpdateTradeWindowMsg utwmOther = new UpdateTradeWindowMsg(source, other);
|
||||||
|
|
||||||
|
if (!canTrade(source, other))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
source.charItemManager.setTradeCommitted((byte) 0);
|
||||||
|
tradingWith.setTradeCommitted((byte) 0);
|
||||||
|
|
||||||
|
int amt = msg.getAmount();
|
||||||
|
|
||||||
|
if (amt <= 0) {
|
||||||
|
Logger.info(source.getFirstName() + " added negative gold to trade window. Dupe attempt FAILED!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (amt > MBServerStatics.PLAYER_GOLD_LIMIT)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (source.charItemManager.getGoldInventory().getNumOfItems() - amt < 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
source.charItemManager.addGoldToTrade(amt);
|
||||||
|
|
||||||
|
// BONUS CODE BELOW: Thanks some unknown retard!
|
||||||
|
// sourceItemMan.updateInventory(sourceItemMan.getInventory(), true);
|
||||||
|
|
||||||
|
UpdateGoldMsg ugm = new UpdateGoldMsg(source);
|
||||||
|
ugm.configure();
|
||||||
|
|
||||||
|
source.charItemManager.modifyCommitToTrade();
|
||||||
|
|
||||||
|
dispatch = Dispatch.borrow(source, utwm);
|
||||||
|
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||||
|
|
||||||
|
dispatch = Dispatch.borrow(source, ugm);
|
||||||
|
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||||
|
|
||||||
|
dispatch = Dispatch.borrow(other, utwmOther);
|
||||||
|
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -444,74 +444,6 @@ public class CharacterItemManager {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized boolean addGoldToTradeWindow(AddGoldToTradeWindowMsg 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;
|
|
||||||
|
|
||||||
UpdateTradeWindowMsg utwm = new UpdateTradeWindowMsg(other, source);
|
|
||||||
UpdateTradeWindowMsg utwmOther = new UpdateTradeWindowMsg(source, other);
|
|
||||||
|
|
||||||
if (!canTrade(source, other))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
this.setTradeCommitted((byte) 0);
|
|
||||||
tradingWith.setTradeCommitted((byte) 0);
|
|
||||||
|
|
||||||
int amt = msg.getAmount();
|
|
||||||
|
|
||||||
if (amt <= 0) {
|
|
||||||
Logger.info(source.getFirstName() + " added negative gold to trade window. Dupe attempt FAILED!");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (amt > MBServerStatics.PLAYER_GOLD_LIMIT)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (this.getGoldInventory().getNumOfItems() - amt < 0)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
this.addGoldToTrade(amt);
|
|
||||||
|
|
||||||
// BONUS CODE BELOW: Thanks some unknown retard!
|
|
||||||
// sourceItemMan.updateInventory(sourceItemMan.getInventory(), true);
|
|
||||||
|
|
||||||
UpdateGoldMsg ugm = new UpdateGoldMsg(source);
|
|
||||||
ugm.configure();
|
|
||||||
|
|
||||||
modifyCommitToTrade();
|
|
||||||
|
|
||||||
dispatch = Dispatch.borrow(source, utwm);
|
|
||||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
|
||||||
|
|
||||||
dispatch = Dispatch.borrow(source, ugm);
|
|
||||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
|
||||||
|
|
||||||
dispatch = Dispatch.borrow(other, utwmOther);
|
|
||||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
|
||||||
return true;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized boolean uncommitToTrade(UncommitToTradeMsg msg) {
|
public synchronized boolean uncommitToTrade(UncommitToTradeMsg msg) {
|
||||||
|
|
||||||
PlayerCharacter source = (PlayerCharacter) this.getOwner();
|
PlayerCharacter source = (PlayerCharacter) this.getOwner();
|
||||||
|
|||||||
Reference in New Issue
Block a user