forked from MagicBane/Server
MagicBot
8 months ago
5 changed files with 108 additions and 85 deletions
@ -0,0 +1,106 @@
@@ -0,0 +1,106 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// 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.AddItemToTradeWindowMsg; |
||||
import engine.net.client.msg.ClientNetMsg; |
||||
import engine.net.client.msg.UpdateTradeWindowMsg; |
||||
import engine.objects.CharacterItemManager; |
||||
import engine.objects.Item; |
||||
import engine.objects.PlayerCharacter; |
||||
|
||||
import static engine.objects.CharacterItemManager.canTrade; |
||||
|
||||
public class AddItemToTradeWindowMsgHandler extends AbstractClientMsgHandler { |
||||
|
||||
public AddItemToTradeWindowMsgHandler() { |
||||
super(AddItemToTradeWindowMsg.class); |
||||
} |
||||
|
||||
@Override |
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { |
||||
|
||||
// Member variable declaration
|
||||
|
||||
AddItemToTradeWindowMsg msg; |
||||
|
||||
// Member variable assignment
|
||||
|
||||
msg = (AddItemToTradeWindowMsg) baseMsg; |
||||
|
||||
PlayerCharacter source = origin.getPlayerCharacter(); |
||||
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; |
||||
|
||||
if (!canTrade(source, other)) |
||||
return false; |
||||
|
||||
Item item = Item.getFromCache(msg.getItemID()); |
||||
|
||||
if (item == null) |
||||
return false; |
||||
|
||||
if (!source.charItemManager.doesCharOwnThisItem(item.getObjectUUID())) |
||||
return false; |
||||
|
||||
//can't add item to trade window twice
|
||||
if (source.charItemManager.tradingContains(item)) |
||||
return false; |
||||
|
||||
//dupe check
|
||||
if (!item.validForInventory(source.getClientConnection(), source, source.charItemManager)) |
||||
return false; |
||||
|
||||
if (!tradingWith.hasRoomTrade(item.template.item_wt)) { |
||||
dispatch = Dispatch.borrow(source, msg); |
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY); |
||||
return false; |
||||
} |
||||
|
||||
UpdateTradeWindowMsg utwm = new UpdateTradeWindowMsg(source, other); |
||||
|
||||
source.charItemManager.setTradeCommitted((byte) 0); |
||||
tradingWith.setTradeCommitted((byte) 0); |
||||
|
||||
source.charItemManager.addItemToTrade(item); |
||||
|
||||
dispatch = Dispatch.borrow(other, msg); |
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY); |
||||
|
||||
source.charItemManager.modifyCommitToTrade(); |
||||
|
||||
dispatch = Dispatch.borrow(other, utwm); |
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY); |
||||
|
||||
return true; |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue