item_wt refactored to template

This commit is contained in:
2024-03-03 15:06:44 -05:00
parent 58652ee32f
commit 4dc0f52295
12 changed files with 101 additions and 120 deletions
+11 -13
View File
@@ -281,7 +281,7 @@ public class Corpse extends AbstractWorldObject {
Logger.error("Can't find inventory for player " + belongsTo.getObjectUUID());
}
public Item lootItem(Item i, PlayerCharacter looter) {
public Item lootItem(Item item, PlayerCharacter looter) {
//make sure looter exists
if (looter == null)
return null;
@@ -294,38 +294,36 @@ public class Corpse extends AbstractWorldObject {
synchronized (this.inventory) {
//make sure player has item in inventory
if (!this.inventory.contains(i))
if (!this.inventory.contains(item))
return null;
//get weight of item
ItemBase ib = i.getItemBase();
if (ib == null)
return null;
short weight = ib.getWeight();
int weight = item.template.item_wt;
//make sure looter has room for item
if (ib.getType().equals(ItemType.GOLD) == false && !looterItems.hasRoomInventory(weight))
if (item.template.item_type.equals(ItemType.GOLD) == false && !looterItems.hasRoomInventory(weight))
return null;
//attempt to transfer item in db
if (ib.getType().equals(ItemType.GOLD)) {
if (!looterItems.moveGoldToInventory(i, i.getNumOfItems()))
if (item.template.item_type.equals(ItemType.GOLD)) {
if (!looterItems.moveGoldToInventory(item, item.getNumOfItems()))
return null;
} else if (!i.moveItemToInventory(looter))
} else if (!item.moveItemToInventory(looter))
return null;
//db transfer successful, remove from this character
this.inventory.remove(this.inventory.indexOf(i));
this.inventory.remove(this.inventory.indexOf(item));
}
//add item to looter.
if (!looterItems.addItemToInventory(i))
if (!looterItems.addItemToInventory(item))
return null;
//calculate new weights
looterItems.calculateInventoryWeight();
return i;
return item;
}
public boolean hasGold() {