Files
Server/src/engine/devcmd/cmds/PrintInventoryCmd.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

115 lines
4.2 KiB
Java

// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2026
// https://www.magicbane.com
package engine.devcmd.cmds;
import engine.devcmd.AbstractDevCmd;
import engine.mbEnums.ItemType;
import engine.objects.*;
import java.text.DecimalFormat;
import java.util.ArrayList;
public class PrintInventoryCmd extends AbstractDevCmd {
public PrintInventoryCmd() {
super("printinventory");
}
@Override
protected void _doCmd(PlayerCharacter pc, String[] words,
AbstractGameObject target) {
if (target == null || (!(target instanceof AbstractCharacter) && !(target instanceof Corpse))) {
target = pc;
}
String type = target.getClass().getSimpleName();
String name = "";
ArrayList<Item> inventory = null;
Item gold = null;
DecimalFormat df = new DecimalFormat("###,###,###,##0");
if (target instanceof AbstractCharacter) {
AbstractCharacter tar = (AbstractCharacter) target;
name = tar.getFirstName();
if (tar instanceof Mob) {
Mob mob = (Mob) tar;
MobBase mb = mob.getMobBase();
if (mb != null) {
name = mb.getFirstName();
}
} else if (tar instanceof NPC) {
NPC npc = (NPC) tar;
Contract contract = npc.getContract();
if (contract != null) {
if (contract.isTrainer()) {
name = tar.getName() + ", " + contract.getName();
} else {
name = tar.getName() + " the " + contract.getName();
}
}
}
CharacterItemManager cim = tar.charItemManager;
inventory = cim.getInventory(); //this list can contain gold when tar is a PC that is dead
gold = cim.getGoldInventory();
throwbackInfo(pc, " Weight : " + (cim.getInventoryWeight() + cim.getEquipWeight()));
} else if (target instanceof Corpse) {
Corpse corpse = (Corpse) target;
name = "of " + corpse.getName();
inventory = corpse.getInventory();
}
throwbackInfo(pc, "Inventory for " + type + ' ' + name + " (" + target.getObjectUUID() + ')');
int goldCount = 0;
for (Item item : inventory) {
ItemTemplate template = ItemTemplate.templates.get(item.templateID);
if (item.template.getItemType().equals(ItemType.GOLD) == false) {
String chargeInfo = "";
int chargeMax = template.cacheTemplate.getItemInitialCharges();
if (chargeMax > 0) {
int charges = item.chargesRemaining;
chargeInfo = " charges: " + charges + '/' + chargeMax;
}
throwbackInfo(pc, " " + template.cacheTemplate.getItemBaseName() + ", count: " + item.getNumOfItems() + chargeInfo);
} else
goldCount += item.getNumOfItems();
}
if (gold != null) {
goldCount += gold.getNumOfItems();
}
if (goldCount > 0 || gold != null) {
throwbackInfo(pc, " Gold, count: " + df.format(goldCount));
} else {
throwbackInfo(pc, " NULL Gold");
}
}
@Override
protected String _getHelpString() {
return "Returns the player's current inventory";
}
@Override
protected String _getUsageString() {
return "' /printinventory'";
}
}