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>
This commit is contained in:
MagicBotandClaude Opus 5.5 committed 2026-10-20 07:55:28 -04:00
1 parent f39e35ac23
commit 6b4e9815e0
38 files changed
+201 -193

No files matched your search

+34 -33
View File
@@ -17,6 +17,7 @@ import engine.mbEnums.ItemType;
import engine.net.Dispatch;
import engine.net.client.ClientConnection;
import engine.net.client.msg.*;
import engine.parsers.objects.CObjectTemplate;
import engine.server.MBServerStatics;
import org.pmw.tinylog.Logger;
@@ -130,19 +131,19 @@ public class CharacterItemManager {
this.equipped.put(i.equipSlot, i);
break;
case BANK:
if (i.template.cacheTemplate.getItemType().equals(ItemType.GOLD))
if (i.template.getItemType().equals(ItemType.GOLD))
this.goldBank = i;
else if (this.bank.contains(i) == false)
this.bank.add(i);
break;
case INVENTORY:
if (i.template.cacheTemplate.getItemType().equals(ItemType.GOLD))
if (i.template.getItemType().equals(ItemType.GOLD))
this.goldInventory = i;
else if (this.inventory.contains(i) == false)
this.inventory.add(i);
break;
case VAULT:
if (i.template.cacheTemplate.getItemType().equals(ItemType.GOLD))
if (i.template.getItemType().equals(ItemType.GOLD))
this.goldVault = i;
else if (this.vault.contains(i) == false)
this.vault.add(i);
@@ -175,13 +176,13 @@ public class CharacterItemManager {
this.equipped.put(i.equipSlot, i);
break;
case BANK:
if (i.template.cacheTemplate.getItemType().equals(ItemType.GOLD))
if (i.template.getItemType().equals(ItemType.GOLD))
this.goldBank = i;
else if (this.bank.contains(i) == false)
this.bank.add(i);
break;
case INVENTORY:
if (i.template.cacheTemplate.getItemType().equals(ItemType.GOLD))
if (i.template.getItemType().equals(ItemType.GOLD))
this.goldInventory = i;
else if (this.inventory.contains(i) == false)
this.inventory.add(i);
@@ -511,7 +512,7 @@ public class CharacterItemManager {
if (i == null)
return false;
if (i.template.cacheTemplate.getItemType().equals(ItemType.GOLD)) {
if (i.template.getItemType().equals(ItemType.GOLD)) {
if (this.getGoldInventory() != null) {
if (i.getObjectUUID() == this.getGoldInventory().getObjectUUID())
this.goldInventory = null;
@@ -541,7 +542,7 @@ public class CharacterItemManager {
}
private synchronized boolean junk(Item i, boolean updateInventory) {
if (i.template.cacheTemplate.getItemType().equals(ItemType.GOLD)) {
if (i.template.getItemType().equals(ItemType.GOLD)) {
if (this.getGoldInventory().getObjectUUID() == i.getObjectUUID())
if (DbManager.ItemQueries.UPDATE_GOLD(i, 0)) {
this.getGoldInventory().setNumOfItems(0);
@@ -596,7 +597,7 @@ public class CharacterItemManager {
if (equippedContains(item)) {
fromEquip = true;
if (item.template.cacheTemplate.getItemType().equals(ItemType.GOLD))
if (item.template.getItemType().equals(ItemType.GOLD))
this.absCharacter.cancelOnUnEquip();
}
@@ -814,7 +815,7 @@ public class CharacterItemManager {
// This removes ingame item from inventory for loot.
private synchronized boolean removeItemFromInventory(Item i) {
if (i.template.cacheTemplate.getItemType().equals(ItemType.GOLD)) {
if (i.template.getItemType().equals(ItemType.GOLD)) {
if (i.getObjectUUID() != this.getGoldInventory().getObjectUUID())
return false;
if (!DbManager.ItemQueries.UPDATE_GOLD(this.goldInventory, 0)) {
@@ -837,7 +838,7 @@ public class CharacterItemManager {
// This adds item to inventory for loot. Validity checks already handled
public synchronized boolean addItemToInventory(Item i) {
if (i.template.cacheTemplate.getItemType().equals(ItemType.GOLD))
if (i.template.getItemType().equals(ItemType.GOLD))
if (this.absCharacter.getObjectType() == GameObjectType.Mob) {
if (this.goldInventory == null)
loadGoldItems();
@@ -856,7 +857,7 @@ public class CharacterItemManager {
this.itemIDtoType.put(i.getObjectUUID(), i.getObjectType().ordinal());
if (i.template != null)
this.inventoryWeight += i.template.cacheTemplate.getItemWt();
this.inventoryWeight += i.template.getItemWt();
return true;
}
@@ -1041,7 +1042,7 @@ public class CharacterItemManager {
if (npc.getContractID() >= 1900 && npc.getContractID() <= 1906)
eatItem = true;
if (itemToSell.template.cacheTemplate.getItemType().equals(ItemType.POTION))
if (itemToSell.template.getItemType().equals(ItemType.POTION))
eatItem = true;
if (eatItem) {
@@ -1085,14 +1086,14 @@ public class CharacterItemManager {
synchronized (this) {
synchronized (itemMan) {
ItemTemplate template = purchasedItem.template;
CObjectTemplate template = purchasedItem.template;
if (template == null)
return false;
//test inventory is not full
if (!hasRoomInventory(template.cacheTemplate.getItemWt()))
if (!hasRoomInventory(template.getItemWt()))
return false;
if (!itemMan.inventory.contains(purchasedItem))
@@ -1105,8 +1106,8 @@ public class CharacterItemManager {
// Reset value
purchasedItem.value = (int) (purchasedItem.template.cacheTemplate.getItemValue() * (purchasedItem.combat_health_current / purchasedItem.template.cacheTemplate.getCombatHealthFull()));
purchasedItem.magicValue = purchasedItem.template.cacheTemplate.getItemValue() + purchasedItem.calcMagicValue();
purchasedItem.value = (int) (purchasedItem.template.getItemValue() * (purchasedItem.combat_health_current / purchasedItem.template.getCombatHealthFull()));
purchasedItem.magicValue = purchasedItem.template.getItemValue() + purchasedItem.calcMagicValue();
// db transfer successfully, remove from this character
// skip this check if this is a mobLoot item (which is not in any inventory)
@@ -1184,9 +1185,9 @@ public class CharacterItemManager {
synchronized (lockFirst) {
synchronized (lockSecond) {
// make sure current player has item in inventory
if (lootItem.template.cacheTemplate.getItemType().equals(ItemType.GOLD) && lootItem.getObjectUUID() != this.getGoldInventory().getObjectUUID() && !(this.absCharacter.getObjectType().equals(GameObjectType.Mob)))
if (lootItem.template.getItemType().equals(ItemType.GOLD) && lootItem.getObjectUUID() != this.getGoldInventory().getObjectUUID() && !(this.absCharacter.getObjectType().equals(GameObjectType.Mob)))
return null;
else if (!this.inventory.contains(lootItem) && !this.equipped.containsValue(lootItem) && !lootItem.template.cacheTemplate.getItemType().equals(ItemType.GOLD))
else if (!this.inventory.contains(lootItem) && !this.equipped.containsValue(lootItem) && !lootItem.template.getItemType().equals(ItemType.GOLD))
return null;
// get weight of item
@@ -1194,13 +1195,13 @@ public class CharacterItemManager {
if (lootItem.template == null)
return null;
int weight = lootItem.template.cacheTemplate.getItemWt();
int weight = lootItem.template.getItemWt();
// make sure lootingPlayer has room for item
if (!lootItem.template.cacheTemplate.getItemType().equals(ItemType.GOLD) && !looterItems.hasRoomInventory(weight))
if (!lootItem.template.getItemType().equals(ItemType.GOLD) && !looterItems.hasRoomInventory(weight))
return null;
if (lootItem.template.cacheTemplate.getItemType().equals(ItemType.GOLD))
if (lootItem.template.getItemType().equals(ItemType.GOLD))
if (amount != -1) { //from steal
int total = lootItem.getNumOfItems();
amount = (amount > total) ? total : amount;
@@ -1263,19 +1264,19 @@ public class CharacterItemManager {
* Delegates
*/
public synchronized boolean bankContains(Item item) {
if (item.template.cacheTemplate.getItemType().equals(ItemType.GOLD))
if (item.template.getItemType().equals(ItemType.GOLD))
return (this.getGoldBank() != null && this.goldBank.getObjectUUID() == item.getObjectUUID());
return bank.contains(item);
}
public synchronized boolean inventoryContains(Item item) {
if (item.template.cacheTemplate.getItemType().equals(ItemType.GOLD))
if (item.template.getItemType().equals(ItemType.GOLD))
return (this.getGoldInventory() != null && this.goldInventory.getObjectUUID() == item.getObjectUUID());
return inventory.contains(item);
}
public synchronized boolean vaultContains(Item item) {
if (item.template.cacheTemplate.getItemType().equals(ItemType.GOLD))
if (item.template.getItemType().equals(ItemType.GOLD))
return (this.getGoldVault() != null && this.goldVault.getObjectUUID() == item.getObjectUUID());
return this.account.getVault().contains(item);
}
@@ -1518,13 +1519,13 @@ public class CharacterItemManager {
item.zeroItem();
item.containerType = mbEnums.ItemContainerType.INVENTORY;
if (item.template.cacheTemplate.getItemType().equals(ItemType.GOLD))
if (item.template.getItemType().equals(ItemType.GOLD))
//only add gold item once
if (!corpse.hasGold())
corpse.setHasGold(true);
newInventory.add(item);
} else //item
if (item.template.cacheTemplate.getItemType().equals(ItemType.GOLD)) {
if (item.template.getItemType().equals(ItemType.GOLD)) {
int amt = item.getNumOfItems();
item.setNumOfItems(0);
MobLoot ml = new MobLoot(this.absCharacter, amt);
@@ -1676,7 +1677,7 @@ public class CharacterItemManager {
if (item == null)
continue;
weight += item.template.cacheTemplate.getItemWt();
weight += item.template.getItemWt();
}
return weight;
}
@@ -1696,7 +1697,7 @@ public class CharacterItemManager {
this.bankWeight = 0;
for (Item item : this.bank) {
if (item.template != null)
this.bankWeight += item.template.cacheTemplate.getItemWt();
this.bankWeight += item.template.getItemWt();
}
}
@@ -1707,7 +1708,7 @@ public class CharacterItemManager {
while (it.hasNext()) {
Item item = it.next();
if (item.template != null)
this.equipWeight += item.template.cacheTemplate.getItemWt();
this.equipWeight += item.template.getItemWt();
}
}
@@ -1715,7 +1716,7 @@ public class CharacterItemManager {
this.inventoryWeight = 0;
for (Item item : this.inventory) {
if (item.template != null)
this.inventoryWeight += item.template.cacheTemplate.getItemWt();
this.inventoryWeight += item.template.getItemWt();
}
}
@@ -1723,7 +1724,7 @@ public class CharacterItemManager {
this.vaultWeight = 0;
for (Item item : this.vault) {
if (item.template != null)
this.vaultWeight += item.template.cacheTemplate.getItemWt();
this.vaultWeight += item.template.getItemWt();
}
}
@@ -1755,7 +1756,7 @@ public class CharacterItemManager {
return;
if (!item.moveItemToInventory(player))
Logger.error("templateL " + item.template.template_id);
Logger.error("templateL " + item.template.getTemplateId());
// remove it from other lists:
this.remItemFromLists(item);
@@ -1932,7 +1933,7 @@ public class CharacterItemManager {
return;
//don't damage noob gear, hair or beards.
if (item.template.cacheTemplate.getCombatHealthFull() == 0)
if (item.template.getCombatHealthFull() == 0)
return;
if (!item.isCanDestroy())