Refactor warehouse part two.

This commit is contained in:
2024-03-17 09:47:00 -04:00
parent b76a384e1f
commit f3bfdd8a36
15 changed files with 155 additions and 120 deletions
+6 -6
View File
@@ -1426,21 +1426,21 @@ public class Building extends AbstractWorldObject {
if (this.getCity() == null)
return amount;
if (this.getCity().getWarehouse() == null)
if (this.getCity().warehouse == null)
return amount;
if (this.getCity().getWarehouse().resources.get(ResourceType.GOLD) >= ResourceType.GOLD.deposit_limit)
if (this.getCity().warehouse.resources.get(ResourceType.GOLD) >= ResourceType.GOLD.deposit_limit)
return amount;
int profitAmount = (int) (amount * (taxAmount * .01f));
if (this.getCity().getWarehouse().resources.get(ResourceType.GOLD) + profitAmount <= ResourceType.GOLD.deposit_limit) {
Warehouse.depositProfitTax(ResourceType.GOLD, profitAmount, this, this.getCity().getWarehouse());
if (this.getCity().warehouse.resources.get(ResourceType.GOLD) + profitAmount <= ResourceType.GOLD.deposit_limit) {
Warehouse.depositProfitTax(ResourceType.GOLD, profitAmount, this, this.getCity().warehouse);
return amount - profitAmount;
}
//overDrafting
int warehouseDeposit = ResourceType.GOLD.deposit_limit - this.getCity().getWarehouse().resources.get(ResourceType.GOLD);
Warehouse.depositProfitTax(ResourceType.GOLD, warehouseDeposit, this, this.getCity().getWarehouse());
int warehouseDeposit = ResourceType.GOLD.deposit_limit - this.getCity().warehouse.resources.get(ResourceType.GOLD);
Warehouse.depositProfitTax(ResourceType.GOLD, warehouseDeposit, this, this.getCity().warehouse);
return amount - warehouseDeposit;
}
+4 -6
View File
@@ -25,10 +25,7 @@ import engine.net.client.msg.*;
import engine.server.MBServerStatics;
import org.pmw.tinylog.Logger;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ThreadLocalRandom;
@@ -350,10 +347,11 @@ public class CharacterItemManager {
break;
case Warehouse:
Warehouse warehouse = (Warehouse) object;
Building warehouseBuilding = (Building) object;
Warehouse warehouse = Objects.requireNonNull(warehouseBuilding.getCity()).warehouse;
if (amount < 0) {
if (!Warehouse.deposit((PlayerCharacter) this.absCharacter, this.getGoldInventory(), amount * -1, true, true,warehouse)) {
if (!Warehouse.deposit((PlayerCharacter) this.absCharacter, this.getGoldInventory(), amount * -1, true, true, warehouse)) {
ErrorPopupMsg.sendErrorPopup((PlayerCharacter) this.absCharacter, 203);
return false;
+15 -16
View File
@@ -116,7 +116,7 @@ public class ItemFactory {
city.transactionLock.writeLock().lock();
try {
Warehouse cityWarehouse = city.getWarehouse();
Warehouse cityWarehouse = city.warehouse;
if (cityWarehouse != null && forge.assetIsProtected())
useWarehouse = true;
@@ -163,7 +163,7 @@ public class ItemFactory {
if (overdraft > 0)
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);
Logger.error("Warehouse for city " + cityWarehouse.city.getName() + " Failed to Create Item." + template.item_base_name);
return null;
}
@@ -431,8 +431,7 @@ public class ItemFactory {
if (overdraft > 0 && useWarehouse)
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);
Logger.error("Warehouse for city " + cityWarehouse.city.getName() + " Failed to Create Item." + template.item_base_name);
return null;
}
@@ -460,7 +459,7 @@ public class ItemFactory {
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);
Logger.error("Warehouse for city " + cityWarehouse.city.getName() + " Failed to Create Item." + template.item_base_name);
return null;
}
}
@@ -484,7 +483,7 @@ public class ItemFactory {
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);
Logger.error("Warehouse for city " + cityWarehouse.city.getName() + " Failed to Create Item." + template.item_base_name);
return null;
}
}
@@ -538,7 +537,7 @@ public class ItemFactory {
if (overdraft > 0)
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);
Logger.error("Warehouse for city " + cityWarehouse.city.getName() + " Failed to Create Item." + template.item_base_name);
return null;
}
@@ -547,7 +546,7 @@ public class ItemFactory {
if (galvorAmount > 0) {
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 ");
Logger.error("Warehouse for city " + cityWarehouse.city.getName() + "Failed to Withdrawl ");
return null;
}
}
@@ -555,7 +554,7 @@ public class ItemFactory {
if (wormwoodAmount > 0) {
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 ");
Logger.error("Warehouse for city " + cityWarehouse.city.getName() + "Failed to Withdrawl ");
return null;
}
}
@@ -790,7 +789,7 @@ public class ItemFactory {
try {
Warehouse cityWarehouse = city.getWarehouse();
Warehouse cityWarehouse = city.warehouse;
if (cityWarehouse != null && forge.assetIsProtected())
useWarehouse = true;
@@ -916,12 +915,12 @@ public class ItemFactory {
if (overdraft > 0) {
if (pc != null) {
if (!Warehouse.withdraw(cityWarehouse, pc, Enum.ResourceType.GOLD, overdraft, false, true)) {
Logger.error("Warehouse with UID of" + cityWarehouse.getObjectUUID() + "Failed to Withdrawl ");
Logger.error("Warehouse for city " + cityWarehouse.city.getName() + "Failed to Withdrawl ");
return null;
}
} else {
if (!Warehouse.withdraw(cityWarehouse, npc, Enum.ResourceType.GOLD, overdraft, true)) {
Logger.error("Warehouse with UID of" + cityWarehouse.getObjectUUID() + "Failed to Withdrawl ");
Logger.error("Warehouse for city " + cityWarehouse.city.getName() + "Failed to Withdrawl ");
return null;
}
}
@@ -967,12 +966,12 @@ public class ItemFactory {
if (pc != null) {
if (!Warehouse.withdraw(cityWarehouse, pc, Enum.ResourceType.GOLD, overdraft, false, true)) {
Logger.error("Warehouse with UID of" + cityWarehouse.getObjectUUID() + "Failed to Withdrawl ");
Logger.error("Warehouse for city " + cityWarehouse.city.getName() + "Failed to Withdrawl ");
return null;
}
} else {
if (!Warehouse.withdraw(cityWarehouse, npc, Enum.ResourceType.GOLD, overdraft, true)) {
Logger.error("Warehouse with UID of" + cityWarehouse.getObjectUUID() + "Failed to Withdrawl ");
Logger.error("Warehouse for city " + cityWarehouse.city.getName() + "Failed to Withdrawl ");
return null;
}
}
@@ -983,7 +982,7 @@ public class ItemFactory {
//ChatManager.chatGuildInfo(pc, "Withdrawing " + galvorAmount + " galvor from warehouse");
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 ");
Logger.error("Warehouse for city " + cityWarehouse.city.getName() + "Failed to Withdrawl ");
return null;
}
}
@@ -992,7 +991,7 @@ public class ItemFactory {
//ChatManager.chatGuildInfo(pc, "Withdrawing " + wormwoodAmount + " wormwood from warehouse");
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 ");
Logger.error("Warehouse for city " + cityWarehouse.city.getName() + "Failed to Withdrawl ");
return null;
}
+24 -27
View File
@@ -227,7 +227,7 @@ public class Realm {
// Must have the required resources in warehouse to claim realm
warehouse = city.getWarehouse();
warehouse = city.warehouse;
if (warehouse == null) {
ErrorPopupMsg.sendErrorPopup(player, 188); // You must have a warehouse to become a capital
@@ -267,52 +267,49 @@ public class Realm {
// Remove resources from warehouse before claiming realm
resourceValue = warehouse.resources.get(Enum.ResourceType.GOLD);
warehouse.resources.put(Enum.ResourceType.GOLD, resourceValue - 5000000);
if (DbManager.WarehouseQueries.updateGold(warehouse, resourceValue - 5000000) == true) {
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());
if (!DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse)) {
Logger.error("gold update failed for warehouse of city:" + warehouse.city.getName());
warehouse.resources.put(Enum.ResourceType.GOLD, resourceValue);
return false;
}
resourceValue = warehouse.resources.get(Enum.ResourceType.STONE);
Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Enum.ResourceType.GOLD, 5000000);
if (DbManager.WarehouseQueries.updateStone(warehouse, resourceValue - 8000) == true) {
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());
resourceValue = warehouse.resources.get(Enum.ResourceType.STONE);
warehouse.resources.put(Enum.ResourceType.STONE, resourceValue - 8000);
if (!DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse)) {
Logger.error("stone update failed for warehouse of city:" + warehouse.city.getName());
warehouse.resources.put(Enum.ResourceType.STONE, resourceValue);
return false;
}
resourceValue = warehouse.resources.get(Enum.ResourceType.LUMBER);
warehouse.resources.put(Enum.ResourceType.LUMBER, resourceValue - 8000);
if (DbManager.WarehouseQueries.updateLumber(warehouse, resourceValue - 8000) == true) {
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());
if (!DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse)) {
Logger.error("lumber update failed for warehouse of city:" + warehouse.city.getName());
warehouse.resources.put(Enum.ResourceType.LUMBER, resourceValue);
return false;
}
resourceValue = warehouse.resources.get(Enum.ResourceType.GALVOR);
warehouse.resources.put(Enum.ResourceType.GALVOR, resourceValue - 15);
if (DbManager.WarehouseQueries.updateGalvor(warehouse, resourceValue - 15) == true) {
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());
if (!DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse)) {
Logger.error("GALVOR update failed for warehouse of city:" + warehouse.city.getName());
warehouse.resources.put(Enum.ResourceType.GALVOR, resourceValue);
return false;
}
resourceValue = warehouse.resources.get(Enum.ResourceType.WORMWOOD);
warehouse.resources.put(Enum.ResourceType.WORMWOOD, resourceValue - 15);
if (DbManager.WarehouseQueries.updateWormwood(warehouse, resourceValue - 15) == true) {
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());
if (!DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse)) {
Logger.error("WORMWOOD update failed for warehouse of city:" + warehouse.city.getName());
warehouse.resources.put(Enum.ResourceType.WORMWOOD, resourceValue);
return false;
}
+12 -18
View File
@@ -166,7 +166,7 @@ public class Warehouse {
boolean worked;
warehouse.lockedResourceTypes.remove(resourceType);
worked = DbManager.WarehouseQueries.updateWarehouse(warehouse);
worked = DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse);
if (worked) {
ViewResourcesMessage vrm = new ViewResourcesMessage(player);
@@ -183,7 +183,7 @@ public class Warehouse {
boolean worked;
warehouse.lockedResourceTypes.add(resourceType);
worked = DbManager.WarehouseQueries.updateWarehouse(warehouse);
worked = DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse);
if (worked) {
warehouse.lockedResourceTypes.add(resourceType);
@@ -273,7 +273,7 @@ public class Warehouse {
warehouse.resources.put(resourceType, newAmount);
if (!DbManager.WarehouseQueries.updateWarehouse(warehouse)) {
if (!DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse)) {
warehouse.resources.put(resourceType, oldAmount);
return false;
}
@@ -299,7 +299,7 @@ public class Warehouse {
warehouse.resources.put(resourceType, newAmount);
if (!DbManager.WarehouseQueries.updateWarehouse(warehouse)) {
if (!DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse)) {
warehouse.resources.put(resourceType, oldAmount);
return false;
}
@@ -316,7 +316,7 @@ public class Warehouse {
int newAmount = oldAmount + amount;
warehouse.resources.put(resourceType, newAmount);
if (!DbManager.WarehouseQueries.updateWarehouse(warehouse)) {
if (!DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse)) {
warehouse.resources.put(resourceType, oldAmount);
return;
}
@@ -338,7 +338,7 @@ public class Warehouse {
warehouse.resources.put(resourceType, newAmount);
if (!DbManager.WarehouseQueries.updateWarehouse(warehouse)) {
if (!DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse)) {
warehouse.resources.put(resourceType, oldAmount);
return;
}
@@ -365,7 +365,7 @@ public class Warehouse {
warehouse.resources.put(resourceType, newAmount);
if (!DbManager.WarehouseQueries.updateWarehouse(warehouse)) {
if (!DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse)) {
warehouse.resources.put(resourceType, oldAmount);
return false;
}
@@ -400,13 +400,14 @@ public class Warehouse {
if (newAmount < amount)
continue;
if (!WithdrawApproved(resourceType, amount, warehouse)) {
msg.getResources().put(resourceType.hash, amount);
if (!DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse)) {
msg.getResources().put(resourceType.hash, 0);
warehouse.resources.put(resourceType, oldAmount);
continue;
}
msg.getResources().put(resourceType.hash, amount);
warehouse.resources.put(resourceType, newAmount);
depositRealmTaxes(taxer, resourceType, amount, warehouse);
Enum.ResourceType resource;
@@ -456,7 +457,7 @@ public class Warehouse {
warehouse.resources.put(resourceType, newAmount);
if (!DbManager.WarehouseQueries.updateWarehouse(warehouse)) {
if (!DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse)) {
warehouse.resources.put(resourceType, oldAmount);
return false;
}
@@ -604,11 +605,4 @@ public class Warehouse {
return resourceType.elementOf(warehouse.lockedResourceTypes);
}
@Override
public void updateDatabase() {
// TODO Auto-generated method stub
}
}