forked from MagicBane/Server
MagicBot
8 months ago
5 changed files with 114 additions and 93 deletions
@ -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; |
||||||
|
} |
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue