Files
Server/src/engine/net/client/handlers/AddItemToTradeWindowMsgHandler.java
T
MagicBotandClaude Opus 5.5 6b4e9815e0 Switch Item.template and MobLoot to CObjectTemplate
Item.template is now the cache template from CObjectTemplate.lookup
instead of the legacy DB ItemTemplate, so item.template.cacheTemplate.X
becomes item.template.X. MobLoot, LootManager, ItemManager.isTwoHanded/
isShield and CombatManager.getSwingAnimation take a CObjectTemplate.

No value changes: every getter already read the cache template through
the bridge, and the lookup resolves the same 7586 ids as
static_item_templates with the same item_type (offline parity p17.py,
0 differences).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 07:55:28 -04:00

105 lines
3.6 KiB
Java

// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2026
// https://www.magicbane.com
package engine.net.client.handlers;
import engine.gameManager.DispatchManager;
import engine.mbEnums;
import engine.net.Dispatch;
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();
}
@Override
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) {
// 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.getItemWt())) {
dispatch = Dispatch.borrow(source, msg);
DispatchManager.dispatchMsgDispatch(dispatch, mbEnums.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);
DispatchManager.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.PRIMARY);
source.charItemManager.modifyCommitToTrade();
dispatch = Dispatch.borrow(other, utwm);
DispatchManager.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.PRIMARY);
return true;
}
}