Files
Server/src/engine/objects/MobLoot.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

320 lines
7.9 KiB
Java

// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2026
// https://www.magicbane.com
package engine.objects;
import engine.gameManager.DbManager;
import engine.gameManager.ItemManager;
import engine.gameManager.PowersManager;
import engine.mbEnums;
import engine.mbEnums.ItemType;
import engine.mbEnums.OwnerType;
import engine.parsers.objects.CObjectTemplate;
import engine.powers.poweractions.AbstractPowerAction;
import org.pmw.tinylog.Logger;
/**
* An immutable, non-persistant implementation of Item
*
* @author Burfo
*/
public final class MobLoot extends Item {
private boolean isDeleted = false;
private boolean noSteal;
private String prefix = "";
private String suffix = "";
public MobLoot(AbstractCharacter mob, CObjectTemplate template, boolean noSteal) {
this(mob, template, 0, noSteal);
}
public MobLoot(AbstractCharacter mob, int qtyOfGold) {
this(mob, CObjectTemplate.lookup(mbEnums.ResourceType.GOLD.templateID), qtyOfGold, false);
}
public MobLoot(AbstractCharacter mob, CObjectTemplate template, int quantity, boolean noSteal) {
super(template.getTemplateId());
this.ownerType = OwnerType.Mob;
this.ownerID = mob.getObjectUUID();
this.objectUUID = generateId();
if (quantity == 0 && template.getItemType() == ItemType.RESOURCE)
quantity = 1;
if (quantity > 0)
this.setNumOfItems(quantity);
this.noSteal = noSteal;
// Class is 'final'; passing 'this' should be okay at the end of the constructor
DbManager.addToCache(this);
}
/**
* Get the MobLoot object from its Id number
*
* @param id Id Number
* @return MobLoot object
*/
public static MobLoot getFromCache(int id) {
return (MobLoot) DbManager.getFromCache(mbEnums.GameObjectType.MobLoot, id);
}
/**
* Get the next available Id number.
*
* @return Id number
*/
private static int generateId() {
int id = ItemManager.lastNegativeID.decrementAndGet();
//TODO Add a way to reclaim disposed IDs if this becomes a problem
if (id == (-10000))
Logger.warn("Only 10,000 Id numbers remain useable. Server restart suggested.");
else if (id < Integer.MIN_VALUE + 1000)
Logger.warn("Only " + (Integer.MIN_VALUE + id)
+ " Id numbers remain useable! Server restart suggested.");
else if (id == Integer.MIN_VALUE)
throw new UnsupportedOperationException("MobLoot has no remaining Id numbers! Restart server immediately!");
else if ((id % 10000) == 0)
Logger.info(id + " of " + Integer.MIN_VALUE + " Id numbers consumed.");
return id;
}
/**
* Converts this MotLoot to a persistable Item. Used when a MotLoot is
* looted
* from a Mob to a Player. Do not call for a Gold item.
*
* @return An orphaned Item, ready to be moved to the Player's inventory.
*/
public synchronized Item promoteToItem(PlayerCharacter looter) {
if (looter == null)
return null;
if (isDeleted)
return null;
if (this.template.getItemType().equals(ItemType.GOLD))
return null;
Item item = this;
item.setOwner(looter);
item.containerType = mbEnums.ItemContainerType.INVENTORY;
item.setValue(0);
if (this.getNumOfItems() > 1)
item.setNumOfItems(this.getNumOfItems());
try {
item = DbManager.ItemQueries.PERSIST(item);
} catch (Exception e) {
Logger.error("e");
return null;
}
//transfer enchantments to item
if (this.prefix.length() != 0)
item.addPermanentEnchantment(this.prefix, 0);
if (this.suffix.length() != 0)
item.addPermanentEnchantment(this.suffix, 0);
this.junk();
return item;
}
public synchronized void recycle(NPC vendor) {
//remove from production list for npc in db
this.removeFromCache();
isDeleted = true;
}
/**
* Junks the item and marks it as deleted
*/
@Override
protected synchronized void junk() {
this.removeFromCache();
isDeleted = true;
}
/**
* Determines if this object has been marked as deleted.
*
* @return True if deleted.
*/
public boolean isDeleted() {
return this.isDeleted;
}
public boolean noSteal() {
return this.noSteal;
}
public void addPermanentEnchantment(String enchantID, int rank, int value, boolean prefix) {
AbstractPowerAction apa = PowersManager.getPowerActionByIDString(enchantID);
if (apa == null)
return;
apa.applyEffectForItem(this, rank);
//limit to 2 effects
// if (this.effectNames.size() < 2)
// this.effectNames.add(enchantID);
if (prefix)
this.prefix = enchantID;
else
this.suffix = enchantID;
this.getEffectNames().add(enchantID);
}
/* *****
* All of the following methods are overridden from
* the superclass and intentionally not implemented.
* *****
*/
/**
* Not implemented
*/
@Override
@Deprecated
public void setOwnerID(int id) {
}
/**
* Not implemented
*/
@Override
@Deprecated
public synchronized void decrementChargesRemaining() {
}
/**
* Not implemented
*/
@Deprecated
protected boolean equipItem(NPC npc, byte slot) {
return false;
}
/**
* Not implemented
*/
@Deprecated
protected boolean equipItem(PlayerCharacter pc, byte slot) {
return false;
}
/**
* Not implemented
*/
@Override
@Deprecated
protected boolean moveItemToBank(NPC npc) {
return false;
}
/**
* Not implemented
*/
@Override
@Deprecated
protected boolean moveItemToBank(PlayerCharacter pc) {
return false;
}
/**
* Not implemented
*/
@Override
@Deprecated
protected boolean moveItemToInventory(Corpse corpse) {
return false;
}
/**
* Not implemented
*/
@Override
@Deprecated
protected boolean moveItemToInventory(NPC npc) {
return false;
}
/**
* Not implemented
*/
@Override
@Deprecated
protected boolean moveItemToInventory(PlayerCharacter pc) {
return false;
}
/**
* Not implemented
*/
@Override
@Deprecated
protected boolean moveItemToVault(Account a) {
return false;
}
/**
* Not implemented
*/
@Deprecated
public void setLastOwner(AbstractWorldObject value) {
}
/**
* Not implemented
*/
@Override
@Deprecated
public void updateDatabase() {
}
/**
* Not implemented
*/
@Override
@Deprecated
protected void validateItemContainer() {
}
public String getPrefix() {
return prefix;
}
public void setPrefix(String prefix) {
this.prefix = prefix;
}
public String getSuffix() {
return suffix;
}
public void setSuffix(String suffix) {
this.suffix = suffix;
}
}