diff --git a/src/engine/Enum.java b/src/engine/Enum.java index 7b5b13f4..2758e100 100644 --- a/src/engine/Enum.java +++ b/src/engine/Enum.java @@ -14,10 +14,7 @@ import engine.gameManager.PowersManager; import engine.gameManager.ZoneManager; import engine.math.Vector2f; import engine.math.Vector3fImmutable; -import engine.objects.AbstractCharacter; -import engine.objects.Item; -import engine.objects.Shrine; -import engine.objects.Zone; +import engine.objects.*; import engine.powers.EffectsBase; import org.pmw.tinylog.Logger; @@ -2690,12 +2687,14 @@ public class Enum { public static HashMap resourceLookup = new HashMap<>(); public static HashMap hashLookup = new HashMap<>(); public int templateID; + public ItemTemplate template; public int hash; public int deposit_limit; public int mine_production; ResourceType(int templateID, int hash, int deposit_limit, int mine_production) { this.templateID = templateID; + this.template = ItemTemplate.itemTemplates.get(this.templateID); this.hash = hash; this.deposit_limit = deposit_limit; this.mine_production = mine_production; diff --git a/src/engine/devcmd/cmds/SimulateBootyCmd.java b/src/engine/devcmd/cmds/SimulateBootyCmd.java index 24a78301..46cbf4e1 100644 --- a/src/engine/devcmd/cmds/SimulateBootyCmd.java +++ b/src/engine/devcmd/cmds/SimulateBootyCmd.java @@ -99,7 +99,7 @@ public class SimulateBootyCmd extends AbstractDevCmd { if (equipmentRoll > (dropChance)) continue; - MobLoot ml = new MobLoot(mob, me.getItemBase(), false); + MobLoot ml = new MobLoot(mob, me.template, false); if (ml != null) EquipmentDrops.add(ml); diff --git a/src/engine/gameManager/BuildingManager.java b/src/engine/gameManager/BuildingManager.java index 3f15b1b8..d1f24b9a 100644 --- a/src/engine/gameManager/BuildingManager.java +++ b/src/engine/gameManager/BuildingManager.java @@ -27,6 +27,7 @@ import org.pmw.tinylog.Logger; import java.time.LocalDateTime; import java.time.ZoneId; import java.util.ArrayList; +import java.util.EnumSet; import java.util.HashMap; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ThreadLocalRandom; @@ -225,24 +226,23 @@ public enum BuildingManager { if (warehouse == null) return false; - for (ItemBase resourceBase : ItemBase.getResourceList()) { + for (Enum.ResourceType resourceType : EnumSet.allOf(Enum.ResourceType.class)) { - template = ItemTemplate.itemTemplates.get(resourceBase.getUUID()); - - if (!player.getCharItemManager().hasRoomInventory(template.item_wt)) { + if (!player.getCharItemManager().hasRoomInventory(resourceType.template.item_wt)) { ChatManager.chatSystemInfo(player, "You can not carry any more of that item."); return false; } - if (warehouse.resources.get(resourceBase) == null) + + if (warehouse.resources.get(resourceType) == null) continue; - int resourceAmount = warehouse.resources.get(resourceBase); + int resourceAmount = warehouse.resources.get(resourceType); if (resourceAmount <= 0) continue; - if (Warehouse.loot(warehouse, player, resourceBase, resourceAmount, true)) { - ChatManager.chatInfoInfo(player, "You have looted " + resourceAmount + ' ' + template.item_base_name); + if (Warehouse.loot(warehouse, player, resourceType, resourceAmount, true)) { + ChatManager.chatInfoInfo(player, "You have looted " + resourceAmount + ' ' + resourceType.name()); } } diff --git a/src/engine/gameManager/LootManager.java b/src/engine/gameManager/LootManager.java index 216e859c..5b3522e0 100644 --- a/src/engine/gameManager/LootManager.java +++ b/src/engine/gameManager/LootManager.java @@ -177,10 +177,10 @@ public enum LootManager { if (ItemTemplate.itemTemplates.get(itemUUID).item_type.equals(Enum.ItemType.RESOURCE)) { int amount = ThreadLocalRandom.current().nextInt(tableRow.minSpawn, tableRow.maxSpawn + 1); - return new MobLoot(mob, ItemBase.getItemBase(itemUUID), amount, false); + return new MobLoot(mob, ItemTemplate.itemTemplates.get(itemUUID), amount, false); } - outItem = new MobLoot(mob, ItemBase.getItemBase(itemUUID), false); + outItem = new MobLoot(mob, ItemTemplate.itemTemplates.get(itemUUID), false); if(selectedRow.pModTable != 0){ try { @@ -348,7 +348,7 @@ public enum LootManager { if (equipmentRoll > dropChance) continue; - MobLoot ml = new MobLoot(mob, me.getItemBase(), false); + MobLoot ml = new MobLoot(mob, me.template, false); if (ml != null && dropCount < 1) { ml.setIsID(true); @@ -369,7 +369,7 @@ public enum LootManager { if (chanceRoll > bse.dropChance) return; - MobLoot lootItem = new MobLoot(mob, ItemBase.getItemBase(bse.itemBase), true); + MobLoot lootItem = new MobLoot(mob, ItemTemplate.itemTemplates.get(bse.itemBase), true); if (lootItem != null) mob.getCharItemManager().addItemToInventory(lootItem); @@ -417,7 +417,7 @@ public enum LootManager { //create the item from the table, quantity is always 1 - MobLoot winnings = new MobLoot(playerCharacter, ItemBase.getItemBase(selectedItem.cacheID), 1, false); + MobLoot winnings = new MobLoot(playerCharacter, ItemTemplate.itemTemplates.get(selectedItem.cacheID), 1, false); if (winnings == null) return; diff --git a/src/engine/gameManager/MaintenanceManager.java b/src/engine/gameManager/MaintenanceManager.java index 29c4c1d8..86307f92 100644 --- a/src/engine/gameManager/MaintenanceManager.java +++ b/src/engine/gameManager/MaintenanceManager.java @@ -250,7 +250,7 @@ public enum MaintenanceManager { resourceValue = warehouse.resources.get(ItemBase.getItemBase(7)); if (DbManager.WarehouseQueries.updateGold(warehouse, resourceValue - overDraft) == true) { - warehouse.resources.put(ItemBase.getItemBase(7), resourceValue - overDraft); + warehouse.resources.put(Enum.ResourceType.GOLD, resourceValue - overDraft); Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, building.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Enum.ResourceType.GOLD, overDraft); } else { Logger.error("gold update failed for warehouse of UUID:" + warehouse.getObjectUUID()); @@ -267,10 +267,10 @@ public enum MaintenanceManager { // Withdraw Stone - resourceValue = warehouse.resources.get(ItemBase.getItemBase(1580000)); + resourceValue = warehouse.resources.get(Enum.ResourceType.STONE); if (DbManager.WarehouseQueries.updateStone(warehouse, resourceValue - 1500) == true) { - warehouse.resources.put(ItemBase.getItemBase(1580000), resourceValue - 1500); + warehouse.resources.put(Enum.ResourceType.STONE, resourceValue - 1500); Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, building.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Enum.ResourceType.STONE, 1500); } else { Logger.error("stone update failed for warehouse of UUID:" + warehouse.getObjectUUID()); @@ -279,10 +279,10 @@ public enum MaintenanceManager { // Withdraw Lumber - resourceValue = warehouse.resources.get(ItemBase.getItemBase(1580004)); + resourceValue = warehouse.resources.get(Enum.ResourceType.LUMBER); if (DbManager.WarehouseQueries.updateLumber(warehouse, resourceValue - 1500) == true) { - warehouse.resources.put(ItemBase.getItemBase(1580004), resourceValue - 1500); + warehouse.resources.put(Enum.ResourceType.LUMBER, resourceValue - 1500); Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, building.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Enum.ResourceType.LUMBER, 1500); } else { Logger.error("lumber update failed for warehouse of UUID:" + warehouse.getObjectUUID()); @@ -291,20 +291,20 @@ public enum MaintenanceManager { // Withdraw Galvor - resourceValue = warehouse.resources.get(ItemBase.getItemBase(1580017)); + resourceValue = warehouse.resources.get(Enum.ResourceType.GALVOR); if (DbManager.WarehouseQueries.updateGalvor(warehouse, resourceValue - 5) == true) { - warehouse.resources.put(ItemBase.getItemBase(1580017), resourceValue - 5); + warehouse.resources.put(Enum.ResourceType.GALVOR, resourceValue - 5); Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, building.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Enum.ResourceType.GALVOR, 5); } else { Logger.error("galvor update failed for warehouse of UUID:" + warehouse.getObjectUUID()); return true; } - resourceValue = warehouse.resources.get(ItemBase.getItemBase(1580018)); + resourceValue = warehouse.resources.get(Enum.ResourceType.WORMWOOD); if (DbManager.WarehouseQueries.updateWormwood(warehouse, resourceValue - 5) == true) { - warehouse.resources.put(ItemBase.getItemBase(1580018), resourceValue - 5); + warehouse.resources.put(Enum.ResourceType.WORMWOOD, resourceValue - 5); Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, building.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Enum.ResourceType.WORMWOOD, 5); } else { Logger.error("wyrmwood update failed for warehouse of UUID:" + warehouse.getObjectUUID()); diff --git a/src/engine/net/client/msg/ViewResourcesMessage.java b/src/engine/net/client/msg/ViewResourcesMessage.java index 2897860a..b68ab8bb 100644 --- a/src/engine/net/client/msg/ViewResourcesMessage.java +++ b/src/engine/net/client/msg/ViewResourcesMessage.java @@ -91,14 +91,13 @@ public class ViewResourcesMessage extends ClientNetMsg { writer.putInt(warehouseObject.resources.size()); - for (ItemBase ib : (warehouseObject.resources.keySet())) { + for (Enum.ResourceType resourceType : (warehouseObject.resources.keySet())) { - Enum.ResourceType resourceType = Enum.ResourceType.resourceLookup.get(ib.getUUID()); writer.putInt(resourceType.hash); - writer.putInt((warehouseObject.resources.get(ib))); + writer.putInt((warehouseObject.resources.get(resourceType))); - if (Warehouse.isResourceLocked(warehouseObject, ib) == true) + if (Warehouse.isResourceLocked(warehouseObject, resourceType) == true) writer.put((byte) 1); else writer.put((byte) 0); @@ -106,11 +105,11 @@ public class ViewResourcesMessage extends ClientNetMsg { writer.putInt(warehouseObject.resources.size()); - for (ItemBase ib : warehouseObject.resources.keySet()) { - Enum.ResourceType resourceType = Enum.ResourceType.resourceLookup.get(ib.getUUID()); + for (Enum.ResourceType resourceType : warehouseObject.resources.keySet()) { + writer.putInt(resourceType.hash); writer.putInt(0); //available? - writer.putInt(Enum.ResourceType.resourceLookup.get(ib.getUUID()).deposit_limit); //max? + writer.putInt(resourceType.deposit_limit); //max? } GuildTag._serializeForDisplay(guild.getGuildTag(), writer); diff --git a/src/engine/objects/Building.java b/src/engine/objects/Building.java index 5f6c44ba..e7bd922c 100644 --- a/src/engine/objects/Building.java +++ b/src/engine/objects/Building.java @@ -1429,18 +1429,18 @@ public class Building extends AbstractWorldObject { if (this.getCity().getWarehouse() == null) return amount; - if (this.getCity().getWarehouse().resources.get(ItemBase.getGoldItemBase()) >= Enum.ResourceType.resourceLookup.get(ResourceType.GOLD.templateID).deposit_limit) + if (this.getCity().getWarehouse().resources.get(ResourceType.GOLD) >= ResourceType.GOLD.deposit_limit) return amount; int profitAmount = (int) (amount * (taxAmount * .01f)); - if (this.getCity().getWarehouse().resources.get(ItemBase.getGoldItemBase()) + profitAmount <= Enum.ResourceType.resourceLookup.get(ResourceType.GOLD.templateID).deposit_limit) { - Warehouse.depositProfitTax(ItemBase.getGoldItemBase(), profitAmount, this, this.getCity().getWarehouse()); + if (this.getCity().getWarehouse().resources.get(ResourceType.GOLD) + profitAmount <= ResourceType.GOLD.deposit_limit) { + Warehouse.depositProfitTax(ResourceType.GOLD, profitAmount, this, this.getCity().getWarehouse()); return amount - profitAmount; } //overDrafting - int warehouseDeposit = Enum.ResourceType.resourceLookup.get(ResourceType.GOLD.templateID).deposit_limit - this.getCity().getWarehouse().resources.get(ItemBase.getGoldItemBase()); - Warehouse.depositProfitTax(ItemBase.getGoldItemBase(), warehouseDeposit, this,this.getCity().getWarehouse()); + int warehouseDeposit = ResourceType.GOLD.deposit_limit - this.getCity().getWarehouse().resources.get(ResourceType.GOLD); + Warehouse.depositProfitTax(ResourceType.GOLD, warehouseDeposit, this, this.getCity().getWarehouse()); return amount - warehouseDeposit; } diff --git a/src/engine/objects/CharacterItemManager.java b/src/engine/objects/CharacterItemManager.java index 3dae6fca..bcdd7c01 100644 --- a/src/engine/objects/CharacterItemManager.java +++ b/src/engine/objects/CharacterItemManager.java @@ -359,7 +359,7 @@ public class CharacterItemManager { return false; } } else { - if (!Warehouse.withdraw(warehouse, (PlayerCharacter) this.absCharacter, this.getGoldInventory().getItemBase(), amount * -1, true, true)) { + if (!Warehouse.withdraw(warehouse, (PlayerCharacter) this.absCharacter, Enum.ResourceType.GOLD, amount * -1, true, true)) { ErrorPopupMsg.sendErrorPopup((PlayerCharacter) this.absCharacter, 203); return false; diff --git a/src/engine/objects/ItemFactory.java b/src/engine/objects/ItemFactory.java index 0269aa5e..04598be4 100644 --- a/src/engine/objects/ItemFactory.java +++ b/src/engine/objects/ItemFactory.java @@ -86,7 +86,6 @@ public class ItemFactory { boolean useWarehouse = false; - ItemBase ib = ItemBase.getItemBase(templateID); ItemTemplate template = ItemTemplate.itemTemplates.get(templateID); if (template == null) @@ -112,6 +111,7 @@ public class ItemFactory { if (city == null) return null; + MobLoot ml = null; city.transactionLock.writeLock().lock(); @@ -123,7 +123,7 @@ public class ItemFactory { // ROLL BANE SCROLL. if (templateID > 910010 && templateID < 910019) { - ConcurrentHashMap resources = cityWarehouse.resources; + ConcurrentHashMap resources = cityWarehouse.resources; int buildingWithdraw = BuildingManager.GetWithdrawAmountForRolling(forge, template.item_value); @@ -135,7 +135,7 @@ public class ItemFactory { return null; } - if (overdraft > 0 && Warehouse.isResourceLocked(cityWarehouse, ItemBase.GOLD_ITEM_BASE)) { + if (overdraft > 0 && Warehouse.isResourceLocked(cityWarehouse, Enum.ResourceType.GOLD)) { if (pc != null) ErrorPopupMsg.sendErrorMsg(pc, "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse." + " " + template.item_base_name); return null; @@ -162,12 +162,12 @@ public class ItemFactory { } if (overdraft > 0) - if (!Warehouse.withdraw(cityWarehouse, npc, ItemBase.GOLD_ITEM_BASE, overdraft, true)) { + if (!Warehouse.withdraw(cityWarehouse, npc, Enum.ResourceType.GOLD, overdraft, true)) { 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 = new MobLoot(npc, template, false); ml.containerType = Enum.ItemContainerType.FORGE; ml.setValue(0); @@ -179,7 +179,7 @@ public class ItemFactory { time = (20 - rate); time *= MBServerStatics.ONE_MINUTE; - if (ml.getItemBase().getUUID() > 910010 && ml.getItemBase().getUUID() < 910019) { + if (ml.templsteID > 910010 && ml.templsteID < 910019) { rank = ml.getTemplsteID() - 910010; time = rank * 60 * 60 * 3 * 1000; @@ -213,14 +213,13 @@ public class ItemFactory { return ml; } - int galvorAmount = 0; int wormwoodAmount = 0; int prefixCost = 0; int suffixCost = 0; - - if (template.item_type.equals(ItemType.WEAPON) && ib.getPercentRequired() == 110) { + if (template.item_type.equals(ItemType.WEAPON) && template.item_skill_required.isEmpty() == false && + template.item_skill_required.values().iterator().next() == 110) { switch (template.item_skill_used) { case "Bow": case "Crossbow": @@ -243,9 +242,6 @@ public class ItemFactory { } } - ItemBase galvor = ItemBase.getItemBase(1580017); - ItemBase wormwood = ItemBase.getItemBase(1580018); - if (galvorAmount > 0 || wormwoodAmount > 0) if (!useWarehouse) { if (pc != null) @@ -255,13 +251,13 @@ public class ItemFactory { } if (galvorAmount > 0) { - if (Warehouse.isResourceLocked(cityWarehouse, galvor)) { + if (Warehouse.isResourceLocked(cityWarehouse, Enum.ResourceType.GALVOR)) { if (pc != null) ErrorPopupMsg.sendErrorMsg(pc, "Galvor is locked." + template.item_base_name); return null; } - if (cityWarehouse.resources.get(galvor) < galvorAmount) { + if (cityWarehouse.resources.get(Enum.ResourceType.GALVOR) < galvorAmount) { if (pc != null) ErrorPopupMsg.sendErrorMsg(pc, "Not enough Galvor in warehouse to roll this item." + template.item_base_name); return null; @@ -269,21 +265,23 @@ public class ItemFactory { } if (wormwoodAmount > 0) { - if (Warehouse.isResourceLocked(cityWarehouse, wormwood)) { + if (Warehouse.isResourceLocked(cityWarehouse, Enum.ResourceType.WORMWOOD)) { if (pc != null) ErrorPopupMsg.sendErrorMsg(pc, "Wormwood is locked." + template.item_base_name); return null; } - if (cityWarehouse.resources.get(wormwood) < wormwoodAmount) { + if (cityWarehouse.resources.get(Enum.ResourceType.WORMWOOD) < wormwoodAmount) { if (pc != null) ErrorPopupMsg.sendErrorMsg(pc, "Not enough Wormwood in warehouse to roll this item." + template.item_base_name); return null; } } - ConcurrentHashMap suffixResourceCosts = null; - ConcurrentHashMap prefixResourceCosts = null; + ConcurrentHashMap suffixResourceCosts = null; + ConcurrentHashMap prefixResourceCosts = null; + EffectsBase prefix = null; + if (pToken != 0) { if (!useWarehouse) { @@ -303,7 +301,6 @@ public class ItemFactory { int total = baseCost * 10 + effectCost; prefixCost = effectCost; - int buildingWithdraw = BuildingManager.GetWithdrawAmountForRolling(forge, total); int overdraft = BuildingManager.GetOverdraft(forge, total); if (overdraft > 0 && !useWarehouse) { @@ -312,31 +309,29 @@ public class ItemFactory { return null; } - if (overdraft > 0 && Warehouse.isResourceLocked(cityWarehouse, ItemBase.GOLD_ITEM_BASE)) { + if (overdraft > 0 && Warehouse.isResourceLocked(cityWarehouse, Enum.ResourceType.GOLD)) { if (pc != null) ErrorPopupMsg.sendErrorMsg(pc, "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse." + template.item_base_name); return null; } - if (overdraft > cityWarehouse.resources.get(ItemBase.GOLD_ITEM_BASE)) { + if (overdraft > cityWarehouse.resources.get(Enum.ResourceType.GOLD)) { if (pc != null) ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse for overdraft." + template.item_base_name); return null; } prefixResourceCosts = prefix.getResourcesForEffect(); - for (ItemBase ibResources : prefixResourceCosts.keySet()) { + + for (Enum.ResourceType ibResources : prefixResourceCosts.keySet()) { int warehouseAmount = cityWarehouse.resources.get(ibResources); int creationAmount = prefixResourceCosts.get(ibResources); - //ChatManager.chatInfoError(pc, "Prefix : " + ibResources.getName() + " / " + creationAmount); - if (warehouseAmount < creationAmount) { - //ChatManager.chatInfoError(pc, "You need at least " + creationAmount + " " + ibResources.getName() + " to Create this item."); - return null; - } + if (warehouseAmount < creationAmount) + return null; } } - EffectsBase suffix = null; + if (sToken != 0) { if (!useWarehouse) { @@ -366,7 +361,7 @@ public class ItemFactory { return null; } - if (overdraft > 0 && Warehouse.isResourceLocked(cityWarehouse, ItemBase.GOLD_ITEM_BASE)) { + if (overdraft > 0 && Warehouse.isResourceLocked(cityWarehouse, Enum.ResourceType.GOLD)) { if (pc != null) ErrorPopupMsg.sendErrorMsg(pc, "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse." + template.item_base_name); return null; @@ -379,22 +374,17 @@ public class ItemFactory { } - for (ItemBase ibResources : suffixResourceCosts.keySet()) { + for (Enum.ResourceType ibResources : suffixResourceCosts.keySet()) { int warehouseAmount = cityWarehouse.resources.get(ibResources); int creationAmount = suffixResourceCosts.get(ibResources); - if (warehouseAmount < creationAmount) { - // if (pc != null) - // ChatManager.chatInfoError(pc, "You need at least " + creationAmount + " " + ibResources.getName() + " to Create this item."); - return null; - } - + if (warehouseAmount < creationAmount) + return null; } - } - //Check if Total suffix and prefix costs + itemCost can be withdrawn. + int costToCreate = suffixCost + prefixCost + template.item_value; int buildingWithdraw = BuildingManager.GetWithdrawAmountForRolling(forge, costToCreate); @@ -406,13 +396,13 @@ public class ItemFactory { return null; } - if (overdraft > 0 && useWarehouse && Warehouse.isResourceLocked(cityWarehouse, ItemBase.GOLD_ITEM_BASE)) { + if (overdraft > 0 && useWarehouse && Warehouse.isResourceLocked(cityWarehouse, Enum.ResourceType.GOLD)) { if (pc != null) ErrorPopupMsg.sendErrorMsg(pc, "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse." + template.item_base_name); return null; } - if (useWarehouse && overdraft > cityWarehouse.resources.get(ItemBase.GOLD_ITEM_BASE)) { + if (useWarehouse && overdraft > cityWarehouse.resources.get(Enum.ResourceType.GOLD)) { if (pc != null) ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse for overdraft." + template.item_base_name); return null; @@ -440,7 +430,7 @@ public class ItemFactory { } if (overdraft > 0 && useWarehouse) - if (!Warehouse.withdraw(cityWarehouse, npc, ItemBase.GOLD_ITEM_BASE, overdraft, true)) { + if (!Warehouse.withdraw(cityWarehouse, npc, Enum.ResourceType.GOLD, 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; @@ -455,7 +445,7 @@ public class ItemFactory { } - for (ItemBase ibResources : prefixResourceCosts.keySet()) { + for (Enum.ResourceType ibResources : prefixResourceCosts.keySet()) { int creationAmount = prefixResourceCosts.get(ibResources); @@ -478,7 +468,7 @@ public class ItemFactory { if (suffix != null) { - for (ItemBase ibResources : suffixResourceCosts.keySet()) { + for (Enum.ResourceType ibResources : suffixResourceCosts.keySet()) { int creationAmount = suffixResourceCosts.get(ibResources); if (Warehouse.isResourceLocked(cityWarehouse, ibResources) == true) { @@ -488,8 +478,10 @@ public class ItemFactory { int oldAmount = cityWarehouse.resources.get(ibResources); int amount = creationAmount; + if (oldAmount < amount) amount = oldAmount; + if (!Warehouse.withdraw(cityWarehouse, npc, ibResources, amount, true)) { //ChatManager.chatGuildError(pc, "Failed to create Item"); Logger.error("Warehouse With UID of " + cityWarehouse.UID + " Failed to Create Item." + template.item_base_name); @@ -514,14 +506,14 @@ public class ItemFactory { return null; } - if (overdraft > 0 && Warehouse.isResourceLocked(cityWarehouse, ItemBase.GOLD_ITEM_BASE)) { + if (overdraft > 0 && Warehouse.isResourceLocked(cityWarehouse, Enum.ResourceType.GOLD)) { if (pc != null) ErrorPopupMsg.sendErrorMsg(pc, "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse." + template.item_base_name); return null; } - if (useWarehouse && overdraft > cityWarehouse.resources.get(ItemBase.GOLD_ITEM_BASE)) { + if (useWarehouse && overdraft > cityWarehouse.resources.get(Enum.ResourceType.GOLD)) { if (pc != null) ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse for overdraft." + template.item_base_name); @@ -536,7 +528,7 @@ public class ItemFactory { ErrorPopupMsg.sendErrorMsg(pc, "Building does not have enough gold to produce this item." + template.item_base_name); return null; } else { - if (overdraft > cityWarehouse.resources.get(ItemBase.GOLD_ITEM_BASE)) { + if (overdraft > cityWarehouse.resources.get(Enum.ResourceType.GOLD)) { ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse to produce this item." + template.item_base_name); return null; } @@ -544,7 +536,7 @@ public class ItemFactory { } if (overdraft > 0) - if (!Warehouse.withdraw(cityWarehouse, npc, ItemBase.GOLD_ITEM_BASE, overdraft, true)) { + if (!Warehouse.withdraw(cityWarehouse, npc, Enum.ResourceType.GOLD, 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; @@ -553,7 +545,7 @@ public class ItemFactory { // ChatManager.chatGuildInfo(pc, "Gold Cost = " + total); if (galvorAmount > 0) { - if (!Warehouse.withdraw(cityWarehouse, npc, galvor, galvorAmount, true)) { + if (!Warehouse.withdraw(cityWarehouse, npc, Enum.ResourceType.GALVOR, galvorAmount, true)) { ErrorPopupMsg.sendErrorMsg(pc, "Failed to withdraw Galvor from warehouse!" + template.item_base_name); Logger.error("Warehouse with UID of" + cityWarehouse.getObjectUUID() + "Failed to Withdrawl "); return null; @@ -561,14 +553,14 @@ public class ItemFactory { } if (wormwoodAmount > 0) { - if (!Warehouse.withdraw(cityWarehouse, npc, wormwood, wormwoodAmount, true)) { + if (!Warehouse.withdraw(cityWarehouse, npc, Enum.ResourceType.WORMWOOD, wormwoodAmount, true)) { ErrorPopupMsg.sendErrorMsg(pc, "Failed to withdraw Wormwood from warehouse!" + template.item_base_name); Logger.error("Warehouse with UID of" + cityWarehouse.getObjectUUID() + "Failed to Withdrawl "); return null; } } - ml = new MobLoot(npc, ib, false); + ml = new MobLoot(npc, template, false); ml.containerType = Enum.ItemContainerType.FORGE; ml.setName(customName); @@ -767,18 +759,14 @@ public class ItemFactory { return toRoll; } - public static MobLoot produceRandomRoll(NPC npc, PlayerCharacter pc, String prefixString, String suffixString, int itemID) { + public static MobLoot produceRandomRoll(NPC npc, PlayerCharacter pc, String prefixString, String suffixString, int templateID) { boolean useWarehouse = false; if (npc == null) return null; - ItemBase ib = ItemBase.getItemBase(itemID); - ItemTemplate template = ItemTemplate.itemTemplates.get(itemID); - - if (ib == null) - return null; + ItemTemplate template = ItemTemplate.itemTemplates.get(templateID); Building forge = npc.getBuilding(); @@ -806,7 +794,7 @@ public class ItemFactory { if (cityWarehouse != null && forge.assetIsProtected()) useWarehouse = true; - ConcurrentHashMap resources = null; + ConcurrentHashMap resources = null; if (useWarehouse) resources = cityWarehouse.resources; @@ -814,7 +802,8 @@ public class ItemFactory { int galvorAmount = 0; int wormwoodAmount = 0; - if (template.item_type.equals(ItemType.WEAPON) && ib.getPercentRequired() == 110) { + if (template.item_type.equals(ItemType.WEAPON) && template.item_skill_required.isEmpty() == false && + template.item_skill_required.values().iterator().next() == 110) { switch (template.item_skill_used) { case "Bow": case "Crossbow": @@ -837,33 +826,30 @@ public class ItemFactory { } } - ItemBase galvor = ItemBase.getItemBase(1580017); - ItemBase wormwood = ItemBase.getItemBase(1580018); - //Cant roll 110% weapons that require resources if not allowed to use warehouse. if (galvorAmount > 0 || wormwoodAmount > 0) if (!useWarehouse) return null; if (galvorAmount > 0) { - if (Warehouse.isResourceLocked(cityWarehouse, galvor)) { + if (Warehouse.isResourceLocked(cityWarehouse, Enum.ResourceType.GALVOR)) { ErrorPopupMsg.sendErrorMsg(pc, "Galvor is locked." + template.item_base_name); return null; } - if (cityWarehouse.resources.get(galvor) < galvorAmount) { + if (cityWarehouse.resources.get(Enum.ResourceType.GALVOR) < galvorAmount) { ErrorPopupMsg.sendErrorMsg(pc, "Not enough Galvor in warehouse to roll this item." + template.item_base_name); return null; } } if (wormwoodAmount > 0) { - if (Warehouse.isResourceLocked(cityWarehouse, wormwood)) { + if (Warehouse.isResourceLocked(cityWarehouse, Enum.ResourceType.WORMWOOD)) { ErrorPopupMsg.sendErrorMsg(pc, "Galvor is locked." + template.item_base_name); return null; } - if (cityWarehouse.resources.get(wormwood) < wormwoodAmount) { + if (cityWarehouse.resources.get(Enum.ResourceType.WORMWOOD) < wormwoodAmount) { ErrorPopupMsg.sendErrorMsg(pc, "Not enough Galvor in warehouse to roll this item." + template.item_base_name); return null; } @@ -877,8 +863,6 @@ public class ItemFactory { return null; } - ItemBase goldIB = ItemBase.getGoldItemBase(); - int baseCost = template.item_value; int total = (int) (baseCost + baseCost * .10); @@ -902,13 +886,13 @@ public class ItemFactory { return null; } - if (useWarehouse && overdraft > 0 && Warehouse.isResourceLocked(cityWarehouse, ItemBase.GOLD_ITEM_BASE)) { + if (useWarehouse && overdraft > 0 && Warehouse.isResourceLocked(cityWarehouse, Enum.ResourceType.GOLD)) { if (pc != null) ErrorPopupMsg.sendErrorMsg(pc, "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse." + template.item_base_name); return null; } - if (useWarehouse && overdraft > resources.get(goldIB)) { + if (useWarehouse && overdraft > resources.get(Enum.ResourceType.GOLD)) { ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse for overdraft." + template.item_base_name); return null; } @@ -920,7 +904,7 @@ public class ItemFactory { ErrorPopupMsg.sendErrorMsg(pc, "Building does not have enough gold to produce this item." + template.item_base_name); return null; } else { - if (overdraft > resources.get(goldIB)) { + if (overdraft > resources.get(Enum.ResourceType.GOLD)) { ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse to produce this item." + template.item_base_name); return null; } @@ -930,12 +914,12 @@ public class ItemFactory { // there was an overdraft, withdraw the rest from warehouse. if (overdraft > 0) { if (pc != null) { - if (!Warehouse.withdraw(cityWarehouse, pc, ItemBase.GOLD_ITEM_BASE, overdraft, false, true)) { + if (!Warehouse.withdraw(cityWarehouse, pc, Enum.ResourceType.GOLD, overdraft, false, true)) { Logger.error("Warehouse with UID of" + cityWarehouse.getObjectUUID() + "Failed to Withdrawl "); return null; } } else { - if (!Warehouse.withdraw(cityWarehouse, npc, ItemBase.GOLD_ITEM_BASE, overdraft, true)) { + if (!Warehouse.withdraw(cityWarehouse, npc, Enum.ResourceType.GOLD, overdraft, true)) { Logger.error("Warehouse with UID of" + cityWarehouse.getObjectUUID() + "Failed to Withdrawl "); return null; } @@ -953,13 +937,13 @@ public class ItemFactory { return null; } - if (useWarehouse && overdraft > 0 && Warehouse.isResourceLocked(cityWarehouse, ItemBase.GOLD_ITEM_BASE)) { + if (useWarehouse && overdraft > 0 && Warehouse.isResourceLocked(cityWarehouse, Enum.ResourceType.GOLD)) { if (pc != null) ErrorPopupMsg.sendErrorMsg(pc, "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse." + template.item_base_name); return null; } - if (useWarehouse && overdraft > resources.get(goldIB)) { + if (useWarehouse && overdraft > resources.get(Enum.ResourceType.GOLD)) { ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse for overdraft." + template.item_base_name); return null; } @@ -971,7 +955,7 @@ public class ItemFactory { ErrorPopupMsg.sendErrorMsg(pc, "Building does not have enough gold to produce this item." + template.item_base_name); return null; } else { - if (overdraft > resources.get(goldIB)) { + if (overdraft > resources.get(Enum.ResourceType.GOLD)) { ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse to produce this item." + template.item_base_name); return null; } @@ -981,12 +965,12 @@ public class ItemFactory { if (overdraft > 0 && useWarehouse) { if (pc != null) { - if (!Warehouse.withdraw(cityWarehouse, pc, ItemBase.GOLD_ITEM_BASE, overdraft, false, true)) { + if (!Warehouse.withdraw(cityWarehouse, pc, Enum.ResourceType.GOLD, overdraft, false, true)) { Logger.error("Warehouse with UID of" + cityWarehouse.getObjectUUID() + "Failed to Withdrawl "); return null; } } else { - if (!Warehouse.withdraw(cityWarehouse, npc, ItemBase.GOLD_ITEM_BASE, overdraft, true)) { + if (!Warehouse.withdraw(cityWarehouse, npc, Enum.ResourceType.GOLD, overdraft, true)) { Logger.error("Warehouse with UID of" + cityWarehouse.getObjectUUID() + "Failed to Withdrawl "); return null; } @@ -996,7 +980,7 @@ public class ItemFactory { if (galvorAmount > 0 && useWarehouse) { //ChatManager.chatGuildInfo(pc, "Withdrawing " + galvorAmount + " galvor from warehouse"); - if (!Warehouse.withdraw(cityWarehouse, npc, galvor, galvorAmount, true)) { + if (!Warehouse.withdraw(cityWarehouse, npc, Enum.ResourceType.GALVOR, galvorAmount, true)) { ErrorPopupMsg.sendErrorMsg(pc, "Failed to withdraw Galvor from warehouse!" + template.item_base_name); Logger.error("Warehouse with UID of" + cityWarehouse.getObjectUUID() + "Failed to Withdrawl "); return null; @@ -1005,7 +989,7 @@ public class ItemFactory { if (wormwoodAmount > 0 && useWarehouse) { //ChatManager.chatGuildInfo(pc, "Withdrawing " + wormwoodAmount + " wormwood from warehouse"); - if (!Warehouse.withdraw(cityWarehouse, npc, wormwood, wormwoodAmount, true)) { + if (!Warehouse.withdraw(cityWarehouse, npc, Enum.ResourceType.WORMWOOD, wormwoodAmount, true)) { ErrorPopupMsg.sendErrorMsg(pc, "Failed to withdraw Wormwood from warehouse for " + template.item_base_name); Logger.error("Warehouse with UID of" + cityWarehouse.getObjectUUID() + "Failed to Withdrawl "); @@ -1013,7 +997,7 @@ public class ItemFactory { } } - ml = new MobLoot(npc, ib, false); + ml = new MobLoot(npc, template, false); ml.containerType = Enum.ItemContainerType.FORGE; diff --git a/src/engine/objects/Mine.java b/src/engine/objects/Mine.java index 3d710fdb..a852408d 100644 --- a/src/engine/objects/Mine.java +++ b/src/engine/objects/Mine.java @@ -482,8 +482,7 @@ public class Mine extends AbstractGameObject { if (this.owningGuild.getOwnedCity().getWarehouse() == null) return false; - ItemBase resourceIB = ItemBase.getItemBase(this.production.templateID); - return Warehouse.depositFromMine(this, resourceIB, this.getModifiedProductionAmount(),this.owningGuild.getOwnedCity().getWarehouse()); + return Warehouse.depositFromMine(this, Enum.ResourceType.resourceLookup.get(this.production.templateID), this.getModifiedProductionAmount(), this.owningGuild.getOwnedCity().getWarehouse()); } public boolean updateGuildOwner(PlayerCharacter playerCharacter) { diff --git a/src/engine/objects/MobLoot.java b/src/engine/objects/MobLoot.java index 4c158c12..c323bbd9 100644 --- a/src/engine/objects/MobLoot.java +++ b/src/engine/objects/MobLoot.java @@ -33,43 +33,22 @@ public final class MobLoot extends Item { private String prefix = ""; private String suffix = ""; - /** - * Create a new MobLoot. - * Do not use this to create Gold. - * - * @param mob Mob that owns this item - * @param ib ItemBase - */ - public MobLoot(AbstractCharacter mob, ItemBase ib, boolean noSteal) { - this(mob, ib, 0, noSteal); + public MobLoot(AbstractCharacter mob, ItemTemplate template, boolean noSteal) { + this(mob, template, 0, noSteal); } - /** - * Create a new MobLoot item to hold Gold for the Mob. - * - * @param mob Mob that owns this item - * @param qtyOfGold Quantity of gold - */ public MobLoot(AbstractCharacter mob, int qtyOfGold) { - this(mob, ItemBase.getGoldItemBase(), qtyOfGold, false); + this(mob, ItemTemplate.itemTemplates.get(Enum.ResourceType.GOLD.templateID), qtyOfGold, false); } - /** - * Create a new MobLoot. - * Primarily used for stackable items that have a quantity. - * - * @param mob Mob that owns this item - * @param ib ItemBase - * @param quantity Quantity of the item - */ - public MobLoot(AbstractCharacter mob, ItemBase ib, int quantity, boolean noSteal) { + public MobLoot(AbstractCharacter mob, ItemTemplate template, int quantity, boolean noSteal) { - super(ib.getUUID()); + super(template.template_id); this.ownerType = OwnerType.Mob; this.ownerID = mob.getObjectUUID(); this.objectUUID = generateId(); - if (quantity == 0 && ItemTemplate.itemTemplates.get(ib.getUUID()).item_type == ItemType.RESOURCE) + if (quantity == 0 && template.item_type == ItemType.RESOURCE) quantity = 1; if (quantity > 0) diff --git a/src/engine/objects/NPC.java b/src/engine/objects/NPC.java index 8373537f..354f5bd7 100644 --- a/src/engine/objects/NPC.java +++ b/src/engine/objects/NPC.java @@ -920,7 +920,7 @@ public class NPC extends AbstractCharacter { DbManager.NPCQueries.LOAD_ALL_ITEMS_TO_PRODUCE(this); for (ProducedItem producedItem : this.forgedItems) { - MobLoot ml = new MobLoot(this, ItemBase.getItemBase(producedItem.getItemBaseID()), false); + MobLoot ml = new MobLoot(this, ItemTemplate.itemTemplates.get(producedItem.getItemBaseID()), false); DbManager.NPCQueries.UPDATE_ITEM_ID(producedItem.getID(), currentID, ml.getObjectUUID()); diff --git a/src/engine/objects/Realm.java b/src/engine/objects/Realm.java index 7337cd7b..ba7e50b6 100644 --- a/src/engine/objects/Realm.java +++ b/src/engine/objects/Realm.java @@ -234,27 +234,27 @@ public class Realm { return false; } - resourceValue = warehouse.resources.get(ItemBase.getItemBase(7)); + resourceValue = warehouse.resources.get(Enum.ResourceType.GOLD); if (resourceValue < 5000000) hasResources = false; - resourceValue = warehouse.resources.get(ItemBase.getItemBase(1580000)); + resourceValue = warehouse.resources.get(Enum.ResourceType.STONE); if (resourceValue < 8000) hasResources = false; - resourceValue = warehouse.resources.get(ItemBase.getItemBase(1580004)); + resourceValue = warehouse.resources.get(Enum.ResourceType.LUMBER); if (resourceValue < 8000) hasResources = false; - resourceValue = warehouse.resources.get(ItemBase.getItemBase(1580017)); + resourceValue = warehouse.resources.get(Enum.ResourceType.GALVOR); if (resourceValue < 15) hasResources = false; - resourceValue = warehouse.resources.get(ItemBase.getItemBase(1580018)); + resourceValue = warehouse.resources.get(Enum.ResourceType.WORMWOOD); if (resourceValue < 15) hasResources = false; @@ -266,50 +266,50 @@ public class Realm { // Remove resources from warehouse before claiming realm - resourceValue = warehouse.resources.get(ItemBase.getItemBase(7)); + resourceValue = warehouse.resources.get(Enum.ResourceType.GOLD); if (DbManager.WarehouseQueries.updateGold(warehouse, resourceValue - 5000000) == true) { - warehouse.resources.put(ItemBase.getItemBase(7), resourceValue - 5000000); + warehouse.resources.put(Enum.ResourceType.GOLD, resourceValue - 5000000); Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Enum.ResourceType.GOLD, 5000000); } else { Logger.error("gold update failed for warehouse of UUID:" + warehouse.getObjectUUID()); return false; } - resourceValue = warehouse.resources.get(ItemBase.getItemBase(1580000)); + resourceValue = warehouse.resources.get(Enum.ResourceType.STONE); if (DbManager.WarehouseQueries.updateStone(warehouse, resourceValue - 8000) == true) { - warehouse.resources.put(ItemBase.getItemBase(1580000), resourceValue - 8000); + warehouse.resources.put(Enum.ResourceType.STONE, resourceValue - 8000); Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Enum.ResourceType.STONE, 8000); } else { Logger.error("stone update failed for warehouse of UUID:" + warehouse.getObjectUUID()); return false; } - resourceValue = warehouse.resources.get(ItemBase.getItemBase(1580004)); + resourceValue = warehouse.resources.get(Enum.ResourceType.LUMBER); if (DbManager.WarehouseQueries.updateLumber(warehouse, resourceValue - 8000) == true) { - warehouse.resources.put(ItemBase.getItemBase(1580004), resourceValue - 8000); + warehouse.resources.put(Enum.ResourceType.LUMBER, resourceValue - 8000); Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Enum.ResourceType.LUMBER, 8000); } else { Logger.error("lumber update failed for warehouse of UUID:" + warehouse.getObjectUUID()); return false; } - resourceValue = warehouse.resources.get(ItemBase.getItemBase(1580017)); + resourceValue = warehouse.resources.get(Enum.ResourceType.GALVOR); if (DbManager.WarehouseQueries.updateGalvor(warehouse, resourceValue - 15) == true) { - warehouse.resources.put(ItemBase.getItemBase(1580017), resourceValue - 15); + warehouse.resources.put(Enum.ResourceType.GALVOR, resourceValue - 15); Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Enum.ResourceType.GALVOR, 15); } else { Logger.error("galvor update failed for warehouse of UUID:" + warehouse.getObjectUUID()); return false; } - resourceValue = warehouse.resources.get(ItemBase.getItemBase(1580018)); + resourceValue = warehouse.resources.get(Enum.ResourceType.WORMWOOD); if (DbManager.WarehouseQueries.updateWormwood(warehouse, resourceValue - 15) == true) { - warehouse.resources.put(ItemBase.getItemBase(1580018), resourceValue - 15); + warehouse.resources.put(Enum.ResourceType.WORMWOOD, resourceValue - 15); Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Enum.ResourceType.WORMWOOD, 15); } else { Logger.error("wormwood update failed for warehouse of UUID:" + warehouse.getObjectUUID()); diff --git a/src/engine/objects/Warehouse.java b/src/engine/objects/Warehouse.java index 203166de..7a524c87 100644 --- a/src/engine/objects/Warehouse.java +++ b/src/engine/objects/Warehouse.java @@ -34,7 +34,7 @@ public class Warehouse extends AbstractWorldObject { public int UID; public int buildingUID; public ArrayList transactions = new ArrayList<>(); - public ConcurrentHashMap resources = new ConcurrentHashMap<>(); + public ConcurrentHashMap resources = new ConcurrentHashMap<>(); /** @@ -43,29 +43,29 @@ public class Warehouse extends AbstractWorldObject { public Warehouse(ResultSet rs) throws SQLException { super(rs); this.UID = rs.getInt("UID"); - this.resources.put(ItemBase.getItemBase(1580000), rs.getInt("warehouse_stone")); - this.resources.put(ItemBase.getItemBase(1580001), rs.getInt("warehouse_truesteel")); - this.resources.put(ItemBase.getItemBase(1580002), rs.getInt("warehouse_iron")); - this.resources.put(ItemBase.getItemBase(1580003), rs.getInt("warehouse_adamant")); - this.resources.put(ItemBase.getItemBase(1580004), rs.getInt("warehouse_lumber")); - this.resources.put(ItemBase.getItemBase(1580005), rs.getInt("warehouse_oak")); - this.resources.put(ItemBase.getItemBase(1580006), rs.getInt("warehouse_bronzewood")); - this.resources.put(ItemBase.getItemBase(1580007), rs.getInt("warehouse_mandrake")); - this.resources.put(ItemBase.getItemBase(1580008), rs.getInt("warehouse_coal")); - this.resources.put(ItemBase.getItemBase(1580009), rs.getInt("warehouse_agate")); - this.resources.put(ItemBase.getItemBase(1580010), rs.getInt("warehouse_diamond")); - this.resources.put(ItemBase.getItemBase(1580011), rs.getInt("warehouse_onyx")); - this.resources.put(ItemBase.getItemBase(1580012), rs.getInt("warehouse_azoth")); - this.resources.put(ItemBase.getItemBase(1580013), rs.getInt("warehouse_orichalk")); - this.resources.put(ItemBase.getItemBase(1580014), rs.getInt("warehouse_antimony")); - this.resources.put(ItemBase.getItemBase(1580015), rs.getInt("warehouse_sulfur")); - this.resources.put(ItemBase.getItemBase(1580016), rs.getInt("warehouse_quicksilver")); - this.resources.put(ItemBase.getItemBase(1580017), rs.getInt("warehouse_galvor")); - this.resources.put(ItemBase.getItemBase(1580018), rs.getInt("warehouse_wormwood")); - this.resources.put(ItemBase.getItemBase(1580019), rs.getInt("warehouse_obsidian")); - this.resources.put(ItemBase.getItemBase(1580020), rs.getInt("warehouse_bloodstone")); - this.resources.put(ItemBase.getItemBase(1580021), rs.getInt("warehouse_mithril")); - this.resources.put(ItemBase.getItemBase(7), rs.getInt("warehouse_gold")); + this.resources.put(Enum.ResourceType.STONE, rs.getInt("warehouse_stone")); + this.resources.put(Enum.ResourceType.TRUESTEEL, rs.getInt("warehouse_truesteel")); + this.resources.put(Enum.ResourceType.IRON, rs.getInt("warehouse_iron")); + this.resources.put(Enum.ResourceType.ADAMANT, rs.getInt("warehouse_adamant")); + this.resources.put(Enum.ResourceType.LUMBER, rs.getInt("warehouse_lumber")); + this.resources.put(Enum.ResourceType.OAK, rs.getInt("warehouse_oak")); + this.resources.put(Enum.ResourceType.BRONZEWOOD, rs.getInt("warehouse_bronzewood")); + this.resources.put(Enum.ResourceType.MANDRAKE, rs.getInt("warehouse_mandrake")); + this.resources.put(Enum.ResourceType.COAL, rs.getInt("warehouse_coal")); + this.resources.put(Enum.ResourceType.AGATE, rs.getInt("warehouse_agate")); + this.resources.put(Enum.ResourceType.DIAMOND, rs.getInt("warehouse_diamond")); + this.resources.put(Enum.ResourceType.ONYX, rs.getInt("warehouse_onyx")); + this.resources.put(Enum.ResourceType.AZOTH, rs.getInt("warehouse_azoth")); + this.resources.put(Enum.ResourceType.ORICHALK, rs.getInt("warehouse_orichalk")); + this.resources.put(Enum.ResourceType.ANTIMONY, rs.getInt("warehouse_antimony")); + this.resources.put(Enum.ResourceType.SULFUR, rs.getInt("warehouse_sulfur")); + this.resources.put(Enum.ResourceType.QUICKSILVER, rs.getInt("warehouse_quicksilver")); + this.resources.put(Enum.ResourceType.GALVOR, rs.getInt("warehouse_galvor")); + this.resources.put(Enum.ResourceType.WORMWOOD, rs.getInt("warehouse_wormwood")); + this.resources.put(Enum.ResourceType.OBSIDIAN, rs.getInt("warehouse_obsidian")); + this.resources.put(Enum.ResourceType.BLOODSTONE, rs.getInt("warehouse_bloodstone")); + this.resources.put(Enum.ResourceType.MITHRIL, rs.getInt("warehouse_mithril")); + this.resources.put(Enum.ResourceType.GOLD, rs.getInt("warehouse_gold")); this.lockedResourceTypes = EnumBitSet.asEnumBitSet(rs.getLong("warehouse_locks"), Enum.ResourceType.class); this.buildingUID = rs.getInt("parent"); warehouseByBuildingUUID.put(this.buildingUID, this); @@ -133,24 +133,15 @@ public class Warehouse extends AbstractWorldObject { if (warehouse == null) return; - int hashID = msg.getHashID(); - int itemBaseID = ItemBase.getItemHashIDMap().get(hashID); - ItemBase ib = ItemBase.getItemBase(itemBaseID); + Enum.ResourceType resourceType = Enum.ResourceType.hashLookup.get(msg.getHashID()); - if (ib == null) { - Logger.debug("Failed to find Resource ItemBaseID with Hash ID = " + hashID); - return; - } - - ItemTemplate template = ItemTemplate.itemTemplates.get(itemBaseID); - - if (isResourceLocked(warehouse, ib)) { + if (isResourceLocked(warehouse, resourceType)) { ChatManager.chatSystemInfo(player, "You cannot withdrawl a locked resource."); return; } - if (!withdraw(warehouse, player, ib, withdrawAmount, true, true)) { - ChatManager.chatGuildError(player, "Failed to withdrawl " + template.item_base_name + '.'); - Logger.debug(player.getName() + " Failed to withdrawl =" + template.item_base_name + " from Warehouse With ID = " + warehouseBuilding.getObjectUUID()); + if (!withdraw(warehouse, player, resourceType, withdrawAmount, true, true)) { + ChatManager.chatGuildError(player, "Failed to withdrawl " + resourceType.name() + '.'); + Logger.debug(player.getName() + " Failed to withdrawl =" + resourceType.name() + " from Warehouse With ID = " + warehouseBuilding.getObjectUUID()); return; } @@ -183,7 +174,7 @@ public class Warehouse extends AbstractWorldObject { Enum.ResourceType resourceType = Enum.ResourceType.hashLookup.get(hashID); - if (isResourceLocked(wh, ItemBase.getItemBase(resourceType.templateID))) { + if (isResourceLocked(wh, resourceType)) { boolean worked; EnumBitSet bitSet = EnumBitSet.asEnumBitSet(wh.lockedResourceTypes.toLong(), Enum.ResourceType.class); @@ -223,6 +214,7 @@ public class Warehouse extends AbstractWorldObject { public static synchronized boolean deposit(PlayerCharacter pc, Item resource, int amount, boolean removeFromInventory, boolean transaction, Warehouse warehouse) { ClientConnection origin = pc.getClientConnection(); + if (origin == null) return false; @@ -231,12 +223,9 @@ public class Warehouse extends AbstractWorldObject { return false; } - ItemBase ib = resource.getItemBase(); + Enum.ResourceType resourceType = Enum.ResourceType.resourceLookup.get(resource.templsteID); - if (ib == null) - return false; - - if (warehouse.resources.get(ib) == null) + if (warehouse.resources.get(resourceType) == null) return false; CharacterItemManager itemMan = pc.getCharItemManager(); @@ -244,7 +233,6 @@ public class Warehouse extends AbstractWorldObject { if (itemMan == null) return false; - if (itemMan.getGoldTrading() > 0) { ErrorPopupMsg.sendErrorPopup(pc, 195); return false; @@ -259,7 +247,7 @@ public class Warehouse extends AbstractWorldObject { if (resource.getNumOfItems() < amount) return false; - int oldAmount = warehouse.resources.get(ib); + int oldAmount = warehouse.resources.get(resourceType); int newAmount = oldAmount + amount; @@ -270,7 +258,7 @@ public class Warehouse extends AbstractWorldObject { if (removeFromInventory) { - if (ib.getUUID() == 7) { + if (resourceType.equals(Enum.ResourceType.GOLD)) { if (itemMan.getGoldInventory().getNumOfItems() - amount < 0) return false; @@ -297,12 +285,10 @@ public class Warehouse extends AbstractWorldObject { } itemMan.updateInventory(); - if (!DepositApproved(ib,amount,warehouse)) + if (!DepositApproved(resourceType, amount, warehouse)) return false; - warehouse.resources.put(ib, newAmount); - - Enum.ResourceType resourceType; + warehouse.resources.put(resourceType, newAmount); if (resource.template.item_type.equals(Enum.ItemType.GOLD)) resourceType = Enum.ResourceType.GOLD; @@ -315,26 +301,18 @@ public class Warehouse extends AbstractWorldObject { return true; } - public static synchronized boolean depositFromMine(Mine mine, ItemBase resource, int amount, Warehouse warehouse) { + public static synchronized boolean depositFromMine(Mine mine, Enum.ResourceType resourceType, int amount, Warehouse warehouse) { - int oldAmount = warehouse.resources.get(resource); + int oldAmount = warehouse.resources.get(resourceType); int newAmount = oldAmount + amount; - if (newAmount > Enum.ResourceType.resourceLookup.get(resource.getUUID()).deposit_limit) + if (newAmount > resourceType.deposit_limit) return false; - if (!DepositApproved(resource, amount, warehouse)) + if (!DepositApproved(resourceType, amount, warehouse)) return false; - warehouse.resources.put(resource, newAmount); - Enum.ResourceType resourceType; - - ItemTemplate template = ItemTemplate.itemTemplates.get(resource.getUUID()); - - if (resource.getUUID() == 7) - resourceType = Enum.ResourceType.GOLD; - else - resourceType = Enum.ResourceType.valueOf(template.item_base_name.toUpperCase()); + warehouse.resources.put(resourceType, newAmount); if (mine != null) AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, mine.getBuildingID(), Enum.TransactionType.MINE, resourceType, amount); @@ -342,262 +320,229 @@ public class Warehouse extends AbstractWorldObject { return true; } - public static boolean DepositApproved(ItemBase ib, int amount, Warehouse warehouse){ - if (ib == null) - return false; + public static boolean DepositApproved(Enum.ResourceType resourceType, int amount, Warehouse warehouse) { - if (warehouse.resources.get(ib) == null) + + if (warehouse.resources.get(resourceType) == null) return false; - int oldAmount = warehouse.resources.get(ib); + int oldAmount = warehouse.resources.get(resourceType); int newAmount = oldAmount + amount; - if (newAmount > Enum.ResourceType.resourceLookup.get(ib.getUUID()).deposit_limit) + if (newAmount > resourceType.deposit_limit) return false; - int itemID = ib.getUUID(); boolean worked = false; - switch (itemID) { - case 7: + switch (resourceType) { + case GOLD: worked = DbManager.WarehouseQueries.updateGold(warehouse, newAmount); break; - case 1580000: + case STONE: worked = DbManager.WarehouseQueries.updateStone(warehouse, newAmount); break; - case 1580001: + case TRUESTEEL: worked = DbManager.WarehouseQueries.updateTruesteel(warehouse, newAmount); break; - case 1580002: + case IRON: worked = DbManager.WarehouseQueries.updateIron(warehouse, newAmount); break; - case 1580003: + case ADAMANT: worked = DbManager.WarehouseQueries.updateAdamant(warehouse, newAmount); break; - case 1580004: + case LUMBER: worked = DbManager.WarehouseQueries.updateLumber(warehouse, newAmount); break; - case 1580005: + case OAK: worked = DbManager.WarehouseQueries.updateOak(warehouse, newAmount); break; - case 1580006: + case BRONZEWOOD: worked = DbManager.WarehouseQueries.updateBronzewood(warehouse, newAmount); break; - case 1580007: + case MANDRAKE: worked = DbManager.WarehouseQueries.updateMandrake(warehouse, newAmount); break; - case 1580008: + case COAL: worked = DbManager.WarehouseQueries.updateCoal(warehouse, newAmount); break; - case 1580009: + case AGATE: worked = DbManager.WarehouseQueries.updateAgate(warehouse, newAmount); break; - case 1580010: + case DIAMOND: worked = DbManager.WarehouseQueries.updateDiamond(warehouse, newAmount); break; - case 1580011: + case ONYX: worked = DbManager.WarehouseQueries.updateOnyx(warehouse, newAmount); break; - case 1580012: + case AZOTH: worked = DbManager.WarehouseQueries.updateAzoth(warehouse, newAmount); break; - case 1580013: + case ORICHALK: worked = DbManager.WarehouseQueries.updateOrichalk(warehouse, newAmount); break; - case 1580014: + case ANTIMONY: worked = DbManager.WarehouseQueries.updateAntimony(warehouse, newAmount); break; - case 1580015: + case SULFUR: worked = DbManager.WarehouseQueries.updateSulfur(warehouse, newAmount); break; - case 1580016: + case QUICKSILVER: worked = DbManager.WarehouseQueries.updateQuicksilver(warehouse, newAmount); break; - case 1580017: + case GALVOR: worked = DbManager.WarehouseQueries.updateGalvor(warehouse, newAmount); break; - case 1580018: + case WORMWOOD: worked = DbManager.WarehouseQueries.updateWormwood(warehouse, newAmount); break; - case 1580019: + case OBSIDIAN: worked = DbManager.WarehouseQueries.updateObsidian(warehouse, newAmount); break; - case 1580020: + case BLOODSTONE: worked = DbManager.WarehouseQueries.updateBloodstone(warehouse, newAmount); break; - case 1580021: + case MITHRIL: worked = DbManager.WarehouseQueries.updateMithril(warehouse, newAmount); break; } return worked; } - public static synchronized void depositRealmTaxes(PlayerCharacter taxer, ItemBase ib, int amount, Warehouse warehouse) { + public static synchronized void depositRealmTaxes(PlayerCharacter taxer, Enum.ResourceType resourceType, int amount, Warehouse warehouse) { - if (!DepositApproved(ib, amount, warehouse)) + if (!DepositApproved(resourceType, amount, warehouse)) return; - int oldAmount = warehouse.resources.get(ib); + int oldAmount = warehouse.resources.get(resourceType); int newAmount = oldAmount + amount; - warehouse.resources.put(ib, newAmount); - Enum.ResourceType resourceType; - - ItemTemplate template = ItemTemplate.itemTemplates.get(ib.getUUID()); - - if (ib.getUUID() == 7) - resourceType = Enum.ResourceType.GOLD; - else - resourceType = Enum.ResourceType.valueOf(template.item_base_name.toUpperCase()); + warehouse.resources.put(resourceType, newAmount); AddTransactionToWarehouse(warehouse, taxer.getObjectType(), taxer.getObjectUUID(), Enum.TransactionType.TAXRESOURCEDEPOSIT, resourceType, amount); } - public static synchronized void depositProfitTax(ItemBase ib, int amount, Building building, Warehouse warehouse) { - - if (ib == null) - return; - - ItemTemplate template = ItemTemplate.itemTemplates.get(ib.getUUID()); + public static synchronized void depositProfitTax(Enum.ResourceType resourceType, int amount, Building building, Warehouse warehouse) { - if (warehouse.resources.get(ib) == null) + if (warehouse.resources.get(resourceType) == null) return; - int oldAmount = warehouse.resources.get(ib); + int oldAmount = warehouse.resources.get(resourceType); int newAmount = oldAmount + amount; - if (newAmount > Enum.ResourceType.resourceLookup.get(ib.getUUID()).deposit_limit) + if (newAmount > resourceType.deposit_limit) return; - if (!DepositApproved(ib,amount,warehouse)) + if (!DepositApproved(resourceType, amount, warehouse)) return; - warehouse.resources.put(ib, newAmount); - Enum.ResourceType resourceType; - - if (ib.getUUID() == 7) - resourceType = Enum.ResourceType.GOLD; - else - resourceType = Enum.ResourceType.valueOf(template.item_base_name.toUpperCase()); + warehouse.resources.put(resourceType, newAmount); if (building != null) AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, building.getObjectUUID(), Enum.TransactionType.DEPOSIT, resourceType, amount); } - public static boolean WithdrawApproved(ItemBase ib, int amount, Warehouse warehouse){ + public static boolean WithdrawApproved(Enum.ResourceType resourceType, int amount, Warehouse warehouse) { - if (ib == null) - return false; - if (warehouse.resources.get(ib) == null) + if (warehouse.resources.get(resourceType) == null) return false; if (amount <= 0) return false; - int oldAmount = warehouse.resources.get(ib); + int oldAmount = warehouse.resources.get(resourceType); if (oldAmount < amount) return false; - Enum.ResourceType resourceType = Enum.ResourceType.resourceLookup.get(ib.getUUID()); - int hashID = resourceType.hash; int newAmount = oldAmount - amount; boolean worked = false; - switch (hashID) { - case 2308551: + switch (resourceType) { + case GOLD: worked = DbManager.WarehouseQueries.updateGold(warehouse, newAmount); break; - case 74856115: + case STONE: worked = DbManager.WarehouseQueries.updateStone(warehouse, newAmount); break; - case -317484979: + case TRUESTEEL: worked = DbManager.WarehouseQueries.updateTruesteel(warehouse, newAmount); break; - case 2504297: + case IRON: worked = DbManager.WarehouseQueries.updateIron(warehouse, newAmount); break; - case -1741189964: + case ADAMANT: worked = DbManager.WarehouseQueries.updateAdamant(warehouse, newAmount); break; - case -1603256692: + case LUMBER: worked = DbManager.WarehouseQueries.updateLumber(warehouse, newAmount); break; - case 74767: + case OAK: worked = DbManager.WarehouseQueries.updateOak(warehouse, newAmount); break; - case 1334770447: + case BRONZEWOOD: worked = DbManager.WarehouseQueries.updateBronzewood(warehouse, newAmount); break; - case 1191391799: + case MANDRAKE: worked = DbManager.WarehouseQueries.updateMandrake(warehouse, newAmount); break; - case 2559427: + case COAL: worked = DbManager.WarehouseQueries.updateCoal(warehouse, newAmount); break; - case 75173057: + case AGATE: worked = DbManager.WarehouseQueries.updateAgate(warehouse, newAmount); break; - case -1730704107: + case DIAMOND: worked = DbManager.WarehouseQueries.updateDiamond(warehouse, newAmount); break; - case 2977263: + case ONYX: worked = DbManager.WarehouseQueries.updateOnyx(warehouse, newAmount); break; - case 78329697: + case AZOTH: worked = DbManager.WarehouseQueries.updateAzoth(warehouse, newAmount); break; - case -2036290524: + case ORICHALK: worked = DbManager.WarehouseQueries.updateOrichalk(warehouse, newAmount); break; - case 452320058: + case ANTIMONY: worked = DbManager.WarehouseQueries.updateAntimony(warehouse, newAmount); break; - case -1586349421: + case SULFUR: worked = DbManager.WarehouseQueries.updateSulfur(warehouse, newAmount); break; - case -472884509: + case QUICKSILVER: worked = DbManager.WarehouseQueries.updateQuicksilver(warehouse, newAmount); break; - case -1596311545: + case GALVOR: worked = DbManager.WarehouseQueries.updateGalvor(warehouse, newAmount); break; - case 1532478436: + case WORMWOOD: worked = DbManager.WarehouseQueries.updateWormwood(warehouse, newAmount); break; - case -697973233: + case OBSIDIAN: worked = DbManager.WarehouseQueries.updateObsidian(warehouse, newAmount); break; - case -1569826353: + case BLOODSTONE: worked = DbManager.WarehouseQueries.updateBloodstone(warehouse, newAmount); break; - case -1761257186: + case MITHRIL: worked = DbManager.WarehouseQueries.updateMithril(warehouse, newAmount); break; } return worked; } - public static synchronized boolean withdraw(Warehouse warehouse, NPC npc, ItemBase ib, int amount, boolean transaction) { + public static synchronized boolean withdraw(Warehouse warehouse, NPC npc, Enum.ResourceType resourceType, int amount, boolean transaction) { - int oldAmount = warehouse.resources.get(ib); + int oldAmount = warehouse.resources.get(resourceType); int newAmount = oldAmount - amount; - if (!WithdrawApproved(ib, amount, warehouse)) + if (!WithdrawApproved(resourceType, amount, warehouse)) return false; - ItemTemplate template = ItemTemplate.itemTemplates.get(ib.getUUID()); - - warehouse.resources.put(ib, newAmount); - Enum.ResourceType resourceType; - - if (ib.getUUID() == 7) - resourceType = Enum.ResourceType.GOLD; - else - resourceType = Enum.ResourceType.valueOf(template.item_base_name.toUpperCase()); + warehouse.resources.put(resourceType, newAmount); if (transaction) AddTransactionToWarehouse(warehouse, npc.getObjectType(), npc.getObjectUUID(), Enum.TransactionType.WITHDRAWL, resourceType, amount); @@ -607,27 +552,22 @@ public class Warehouse extends AbstractWorldObject { public static synchronized void transferResources(Warehouse warehouse, PlayerCharacter taxer, TaxResourcesMsg msg, ArrayList realmResources, float taxPercent) { - for (int ibID : realmResources) { - - ItemBase ib = ItemBase.getItemBase(ibID); - - if (ib == null) - return; + for (int templateID : realmResources) { - ItemTemplate template = ItemTemplate.itemTemplates.get(ib.getUUID()); + ItemTemplate template = ItemTemplate.itemTemplates.get(templateID); + Enum.ResourceType resourceType = Enum.ResourceType.resourceLookup.get(templateID); - if (warehouse.resources.get(ib) == null) + if (warehouse.resources.get(resourceType) == null) return; - int amount = (int) (warehouse.resources.get(ib) * taxPercent); + int amount = (int) (warehouse.resources.get(resourceType) * taxPercent); if (amount <= 0) { - Enum.ResourceType resourceType = Enum.ResourceType.resourceLookup.get(ib.getUUID()); msg.getResources().put(resourceType.hash, 0); continue; } - int oldAmount = warehouse.resources.get(ib); + int oldAmount = warehouse.resources.get(resourceType); if (oldAmount < amount) amount = oldAmount; @@ -637,17 +577,15 @@ public class Warehouse extends AbstractWorldObject { if (newAmount < amount) continue; - Enum.ResourceType resourceType = Enum.ResourceType.resourceLookup.get(ib.getUUID()); - - if (!WithdrawApproved(ib, amount, warehouse)) { + if (!WithdrawApproved(resourceType, amount, warehouse)) { msg.getResources().put(resourceType.hash, 0); continue; } msg.getResources().put(resourceType.hash, amount); - warehouse.resources.put(ib, newAmount); - depositRealmTaxes(taxer, ib, amount, warehouse); + warehouse.resources.put(resourceType, newAmount); + depositRealmTaxes(taxer, resourceType, amount, warehouse); Enum.ResourceType resource; if (resourceType.equals(Enum.ResourceType.GOLD)) @@ -660,17 +598,14 @@ public class Warehouse extends AbstractWorldObject { } } - public static synchronized boolean withdraw(Warehouse warehouse, PlayerCharacter pc, ItemBase ib, int amount, boolean addToInventory, boolean transaction) { + public static synchronized boolean withdraw(Warehouse warehouse, PlayerCharacter pc, Enum.ResourceType resourceType, int amount, boolean addToInventory, boolean transaction) { if (pc == null) return false; - if (ib == null) - return false; - - ItemTemplate template = ItemTemplate.itemTemplates.get(ib.getUUID()); + ItemTemplate template = ItemTemplate.itemTemplates.get(resourceType.templateID); - if (warehouse.resources.get(ib) == null) + if (warehouse.resources.get(resourceType) == null) return false; if (amount <= 0) @@ -687,15 +622,14 @@ public class Warehouse extends AbstractWorldObject { return false; } - if (addToInventory && ib.getUUID() == ItemBase.GOLD_BASE_ID) { - if (pc.getCharItemManager().getGoldInventory().getNumOfItems() + amount > MBServerStatics.PLAYER_GOLD_LIMIT) { + if (addToInventory && resourceType.equals(Enum.ResourceType.GOLD)) { + if (pc.getCharItemManager().getGoldInventory().getNumOfItems() + amount > MBServerStatics.PLAYER_GOLD_LIMIT) return false; - } if (pc.getCharItemManager().getGoldInventory().getNumOfItems() + amount < 0) return false; } - int oldAmount = warehouse.resources.get(ib); + int oldAmount = warehouse.resources.get(resourceType); if (oldAmount < amount) return false; @@ -703,13 +637,13 @@ public class Warehouse extends AbstractWorldObject { int newAmount = oldAmount - amount; - if (!WithdrawApproved(ib,amount,warehouse)) + if (!WithdrawApproved(resourceType, amount, warehouse)) return false; - warehouse.resources.put(ib, newAmount); + warehouse.resources.put(resourceType, newAmount); if (addToInventory) { - if (ib.getUUID() == 7) { + if (resourceType.equals(Enum.ResourceType.GOLD)) { itemMan.addGoldToInventory(amount, false); UpdateGoldMsg ugm = new UpdateGoldMsg(pc); @@ -721,7 +655,7 @@ public class Warehouse extends AbstractWorldObject { } else { boolean itemWorked = false; - Item item = new Item(ib.getUUID()); + Item item = new Item(resourceType.templateID); item.ownerID = pc.getObjectUUID(); item.ownerType = Enum.OwnerType.PlayerCharacter; item.containerType = Enum.ItemContainerType.INVENTORY; @@ -739,12 +673,6 @@ public class Warehouse extends AbstractWorldObject { } } } - Enum.ResourceType resourceType; - - if (ib.getUUID() == 7) - resourceType = Enum.ResourceType.GOLD; - else - resourceType = Enum.ResourceType.valueOf(template.item_base_name.toUpperCase()); if (transaction) AddTransactionToWarehouse(warehouse, pc.getObjectType(), pc.getObjectUUID(), Enum.TransactionType.WITHDRAWL, resourceType, amount); @@ -752,17 +680,17 @@ public class Warehouse extends AbstractWorldObject { return true; } - public static synchronized boolean loot(Warehouse warehouse, PlayerCharacter pc, ItemBase ib, int amount, boolean addToInventory) { + public static synchronized boolean loot(Warehouse warehouse, PlayerCharacter pc, Enum.ResourceType resourceType, int amount, boolean addToInventory) { if (pc == null) return false; - ItemTemplate template = ItemTemplate.itemTemplates.get(ib.getUUID()); + ItemTemplate template = ItemTemplate.itemTemplates.get(resourceType); if (template == null) return false; - if (warehouse.resources.get(ib) == null) + if (warehouse.resources.get(resourceType) == null) return false; if (amount <= 0) @@ -778,17 +706,17 @@ public class Warehouse extends AbstractWorldObject { return false; } - int oldAmount = warehouse.resources.get(ib); + int oldAmount = warehouse.resources.get(resourceType); if (oldAmount < amount) return false; int newAmount = oldAmount - amount; - warehouse.resources.put(ib, newAmount); + warehouse.resources.put(resourceType, newAmount); if (addToInventory) { - if (ib.getUUID() == 7) { + if (resourceType.equals(Enum.ResourceType.GOLD)) { itemMan.addGoldToInventory(amount, false); UpdateGoldMsg ugm = new UpdateGoldMsg(pc); @@ -799,7 +727,7 @@ public class Warehouse extends AbstractWorldObject { itemMan.updateInventory(); } else { boolean itemWorked = false; - Item item = new Item(ib.getUUID()); + Item item = new Item(resourceType.templateID); item.ownerID = pc.getObjectUUID(); item.ownerType = Enum.OwnerType.PlayerCharacter; item.containerType = Enum.ItemContainerType.INVENTORY; @@ -851,12 +779,7 @@ public class Warehouse extends AbstractWorldObject { } - public static boolean isResourceLocked(Warehouse warehouse, ItemBase itemBase) { - - Enum.ResourceType resourceType; - - resourceType = Enum.ResourceType.resourceLookup.get(itemBase.getUUID()); - + public static boolean isResourceLocked(Warehouse warehouse, Enum.ResourceType resourceType) { return resourceType.elementOf(warehouse.lockedResourceTypes); } diff --git a/src/engine/powers/EffectsBase.java b/src/engine/powers/EffectsBase.java index ed6d80e0..62b8ef48 100644 --- a/src/engine/powers/EffectsBase.java +++ b/src/engine/powers/EffectsBase.java @@ -78,7 +78,7 @@ public class EffectsBase { private boolean isSuffix = false; //used by items private String name = ""; private float value = 0; - private ConcurrentHashMap resourceCosts = new ConcurrentHashMap<>(); + private ConcurrentHashMap resourceCosts = new ConcurrentHashMap<>(); private ConcurrentHashMap sourceTypes = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); /** @@ -727,11 +727,11 @@ public class EffectsBase { this.value = Value; } - public ConcurrentHashMap getResourcesForEffect() { + public ConcurrentHashMap getResourcesForEffect() { if (this.resourceCosts.isEmpty()) { ArrayList effectsCostList = DbManager.EffectsResourceCostsQueries.GET_ALL_EFFECT_RESOURCES(this.IDString); for (EffectsResourceCosts erc : effectsCostList) { - this.resourceCosts.put(ItemBase.getItemBase(erc.getResourceID()), erc.getAmount()); + this.resourceCosts.put(Enum.ResourceType.resourceLookup.get(erc.getResourceID()), erc.getAmount()); } } return this.resourceCosts;