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
+2 -2
View File
@@ -218,7 +218,7 @@ public class Account extends AbstractGameObject {
return;
if (item.containerType == Enum.ItemContainerType.INVENTORY && player.getCharItemManager().isVaultOpen()) {
if (!player.getCharItemManager().hasRoomVault(item.getItemBase().getWeight())) {
if (!player.getCharItemManager().hasRoomVault(item.template.item_wt)) {
ClientMessagePump.forceTransferFromVaultToInventory(msg, origin, "There is no room in your vault.");
return;
}
@@ -264,7 +264,7 @@ public class Account extends AbstractGameObject {
return;
if (item.containerType == Enum.ItemContainerType.VAULT && itemManager.isVaultOpen()) {
if (!itemManager.hasRoomInventory(item.getItemBase().getWeight())) {
if (!itemManager.hasRoomInventory(item.template.item_wt)) {
ClientMessagePump.forceTransferFromInventoryToVault(msg, origin, "There is no room in your inventory.");
return;
}
+44 -36
View File
@@ -90,21 +90,29 @@ public class CharacterItemManager {
}
public static void takeFromNPC(NPC npc, PlayerCharacter pc, Item take, ClientMessagePump clientMessagePump) {
ItemBase ib = take.getItemBase();
if (ib == null)
ItemTemplate template = take.template;
if (template == null)
return;
CharacterItemManager itemMan = pc.getCharItemManager();
if (itemMan == null)
return;
CharacterItemManager npcCim = npc.getCharItemManager();
if (npcCim == null)
return;
if (!npcCim.inventoryContains(take)) {
return;
}
if (!itemMan.hasRoomInventory(ib.getWeight()))
if (!npcCim.inventoryContains(take))
return;
if (!itemMan.hasRoomInventory(template.item_wt))
return;
if (take != null) {
itemMan.buyFromNPC(take, npc);
itemMan.updateInventory();
@@ -621,7 +629,7 @@ public class CharacterItemManager {
if (!i.validForInventory(source.getClientConnection(), source, this))
return false;
if (!tradingWith.hasRoomTrade(i.getItemBase().getWeight())) {
if (!tradingWith.hasRoomTrade(i.template.item_wt)) {
dispatch = Dispatch.borrow(source, msg);
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY);
return false;
@@ -1251,9 +1259,10 @@ public class CharacterItemManager {
this.inventory.add(i);
this.itemIDtoType.put(i.getObjectUUID(), i.getObjectType().ordinal());
ItemBase ib = i.getItemBase();
if (ib != null)
this.inventoryWeight += ib.getWeight();
if (i.template != null)
this.inventoryWeight += i.template.item_wt;
return true;
}
@@ -1503,18 +1512,19 @@ public class CharacterItemManager {
synchronized (this) {
synchronized (itemMan) {
itemBase = purchasedItem.getItemBase();
ItemTemplate template = purchasedItem.template;
if (itemBase == null)
if (template == null)
return false;
//test inventory is not full
if (!hasRoomInventory(itemBase.getWeight()))
if (!hasRoomInventory(template.item_wt))
return false;
if (!itemMan.inventory.contains(purchasedItem))
return false;
// attempt to transfer item in db
if (purchasedItem.getObjectType() == GameObjectType.MobLoot) {
@@ -1625,10 +1635,11 @@ public class CharacterItemManager {
return null;
// get weight of item
ItemBase ib = lootItem.getItemBase();
if (ib == null)
if (lootItem.template == null)
return null;
short weight = ib.getWeight();
int weight = lootItem.template.item_wt;
// make sure lootingPlayer has room for item
if (!lootItem.getItemBase().getType().equals(ItemType.GOLD) && !looterItems.hasRoomInventory(weight))
@@ -2106,7 +2117,7 @@ public class CharacterItemManager {
return true; // npc's need checked
}
public boolean hasRoomTrade(short itemWeight) {
public boolean hasRoomTrade(int itemWeight) {
PlayerCharacter playerCharacter;
PlayerCharacter tradeCharacter;
@@ -2134,13 +2145,15 @@ public class CharacterItemManager {
return tradeWeight <= (int) playerCharacter.statStrBase * 3;
}
public boolean hasRoomBank(short weight) {
public boolean hasRoomBank(int weight) {
if (this.absCharacter == null)
return false;
return weight <= this.absCharacter.getBankCapacityRemaining();
}
public boolean hasRoomVault(short weight) {
public boolean hasRoomVault(int weight) {
if (this.absCharacter == null)
return false;
return weight <= this.absCharacter.getVaultCapacityRemaining();
@@ -2181,8 +2194,7 @@ public class CharacterItemManager {
if (item == null)
continue;
ItemBase ib = item.getItemBase();
weight += ib.getWeight();
weight += item.template.item_wt;
}
return weight;
}
@@ -2200,10 +2212,9 @@ public class CharacterItemManager {
public void calculateBankWeight() {
this.bankWeight = 0;
for (Item i : this.bank) {
ItemBase ib = i.getItemBase();
if (ib != null)
this.bankWeight += ib.getWeight();
for (Item item : this.bank) {
if (item.template != null)
this.bankWeight += item.template.item_value;
}
}
@@ -2212,28 +2223,25 @@ public class CharacterItemManager {
Collection<Item> c = this.equipped.values();
Iterator<Item> it = c.iterator();
while (it.hasNext()) {
Item i = it.next();
ItemBase ib = i.getItemBase();
if (ib != null)
this.equipWeight += ib.getWeight();
Item item = it.next();
if (item.template != null)
this.equipWeight += item.template.item_wt;
}
}
public void calculateInventoryWeight() {
this.inventoryWeight = 0;
for (Item i : this.inventory) {
ItemBase ib = i.getItemBase();
if (ib != null)
this.inventoryWeight += ib.getWeight();
for (Item item : this.inventory) {
if (item.template != null)
this.inventoryWeight += item.template.item_wt;
}
}
public void calculateVaultWeight() {
this.vaultWeight = 0;
for (Item i : this.vault) {
ItemBase ib = i.getItemBase();
if (ib != null)
this.vaultWeight += ib.getWeight();
for (Item item : this.vault) {
if (item.template != null)
this.vaultWeight += item.template.item_wt;
}
}
+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() {
-7
View File
@@ -45,7 +45,6 @@ public class ItemBase {
public EnumSet<Enum.ClassType> requiredClasses;
public EnumSet<Enum.DisciplineType> requiredDiscs;
public EnumSet<Enum.DisciplineType> restrictedDiscs;
private final short weight;
private final short color;
private final ItemType type;
private int vendorType;
@@ -90,7 +89,6 @@ public class ItemBase {
this.uuid = rs.getInt("ID");
this.weight = rs.getShort("weight");
this.color = rs.getShort("color");
this.type = ItemType.valueOf(rs.getString("Type"));
this.useID = rs.getInt("useID");
@@ -256,11 +254,6 @@ public class ItemBase {
DbManager.ItemBaseQueries.LOAD_BAKEDINSTATS(this);
}
public short getWeight() {
return this.weight;
}
public boolean isConsumable() {
return this.isConsumable;
}
+17 -26
View File
@@ -30,33 +30,36 @@ import java.util.concurrent.ThreadLocalRandom;
public class ItemFactory {
public static void fillInventory(PlayerCharacter pc, int objectID, int count) {
public static void fillInventory(PlayerCharacter pc, int templateID, int count) {
if (pc == null)
return;
int max = 20;
CharacterItemManager itemManager = pc.getCharItemManager();
ItemBase ib = ItemBase.getItemBase(objectID);
ItemTemplate template = ItemTemplate.itemTemplates.get(templateID);
if (count > max)
count = max;
ClientConnection cc = pc.getClientConnection();
if (itemManager == null || ib == null || cc == null)
if (itemManager == null || template == null || cc == null)
return;
boolean worked;
for (int i = 0; i < count; i++) {
worked = false;
if (!itemManager.hasRoomInventory(ib.getWeight())) {
if (!itemManager.hasRoomInventory(template.item_wt)) {
if (pc != null)
ChatManager.chatSystemInfo(pc, "You can not carry any more of that item.");
break;
}
Item item = new Item(ib.getUUID());
Item item = new Item(templateID);
item.ownerID = pc.getObjectUUID();
item.ownerType = OwnerType.PlayerCharacter;
item.containerType = ItemContainerType.INVENTORY;
@@ -74,7 +77,7 @@ public class ItemFactory {
itemManager.updateInventory();
}
public static Item fillForge(NPC npc, PlayerCharacter pc, int itemsToRoll, int itemID, int pToken, int sToken, String customName) {
public static Item fillForge(NPC npc, PlayerCharacter pc, int itemsToRoll, int templateID, int pToken, int sToken, String customName) {
String prefixString = "";
String suffixString = "";
@@ -83,10 +86,10 @@ public class ItemFactory {
boolean useWarehouse = false;
ItemBase ib = ItemBase.getItemBase(itemID);
ItemTemplate template = ItemTemplate.itemTemplates.get(itemID);
ItemBase ib = ItemBase.getItemBase(templateID);
ItemTemplate template = ItemTemplate.itemTemplates.get(templateID);
if (ib == null)
if (template == null)
return null;
Building forge = npc.getBuilding();
@@ -94,8 +97,7 @@ public class ItemFactory {
if (forge == null)
return null;
if (!npc.getCharItemManager().hasRoomInventory(ib.getWeight())) {
if (!npc.getCharItemManager().hasRoomInventory(template.item_wt)) {
if (pc != null)
ErrorPopupMsg.sendErrorPopup(pc, 21);
return null;
@@ -120,12 +122,13 @@ public class ItemFactory {
useWarehouse = true;
// ROLL BANE SCROLL.
if (ib.getUUID() > 910010 && ib.getUUID() < 910019) {
if (templateID > 910010 && templateID < 910019) {
ConcurrentHashMap<ItemBase, Integer> resources = cityWarehouse.resources;
int buildingWithdraw = BuildingManager.GetWithdrawAmountForRolling(forge, template.item_value);
int overdraft = BuildingManager.GetOverdraft(forge, template.item_value);
if (overdraft > 0 && !useWarehouse) {
if (pc != null)
ErrorPopupMsg.sendErrorMsg(pc, "Not enough gold in building strongbox." + " " + template.item_base_name);
@@ -144,15 +147,6 @@ public class ItemFactory {
return null;
}
//All checks passed, lets withdraw from building first.
// if (pc != null){
// ChatManager.chatGuildInfo(pc.getGuild(), "Building withdraw = " + buildingWithdraw);
// ChatManager.chatGuildInfo(pc.getGuild(), "Warehouse overdraft withdraw = " + overdraft);
//
// ChatManager.chatGuildInfo(pc.getGuild(), "total withdraw = " + (overdraft + buildingWithdraw));
// }
if (!forge.transferGold(-buildingWithdraw, false)) {
overdraft += buildingWithdraw;
@@ -169,15 +163,12 @@ public class ItemFactory {
if (overdraft > 0)
if (!Warehouse.withdraw(cityWarehouse, npc, ItemBase.GOLD_ITEM_BASE, overdraft, true)) {
//ChatManager.chatGuildError(pc, "Failed to create Item");
Logger.error("Warehouse With UID of " + cityWarehouse.UID + " Failed to Create Item." + template.item_base_name);
return null;
}
ml = new MobLoot(npc, ib, false);
ml.containerType = Enum.ItemContainerType.FORGE;
ml.setValue(0);
ml.loadEnchantments();
@@ -660,10 +651,10 @@ public class ItemFactory {
ItemBase ib = ItemBase.getItemBase(itemBaseID);
ItemTemplate template = ItemTemplate.itemTemplates.get(itemBaseID);
if (ib == null)
if (template == null)
return null;
if (!vendor.getCharItemManager().hasRoomInventory(ib.getWeight())) {
if (!vendor.getCharItemManager().hasRoomInventory(template.item_wt)) {
if (playerCharacter != null)
ChatManager.chatSystemInfo(playerCharacter, vendor.getName() + " " + vendor.getContract().getName() + " Inventory is full.");
+5 -3
View File
@@ -715,7 +715,7 @@ public class Warehouse extends AbstractWorldObject {
return false;
if (addToInventory)
if (!itemMan.hasRoomInventory(ib.getWeight())) {
if (!itemMan.hasRoomInventory(template.item_wt)) {
ChatManager.chatSystemInfo(pc, "You can not carry any more of that item.");
return false;
}
@@ -790,7 +790,9 @@ public class Warehouse extends AbstractWorldObject {
if (pc == null)
return false;
if (ib == null)
ItemTemplate template = ItemTemplate.itemTemplates.get(ib.getUUID());
if (template == null)
return false;
if (warehouse.resources.get(ib) == null)
@@ -804,7 +806,7 @@ public class Warehouse extends AbstractWorldObject {
if (itemMan == null)
return false;
if (!itemMan.hasRoomInventory(ib.getWeight())) {
if (!itemMan.hasRoomInventory(template.item_wt)) {
ChatManager.chatSystemInfo(pc, "You can not carry any more of that item.");
return false;
}