Browse Source

More refactor itembase out of warehouse

combat-2
MagicBot 8 months ago
parent
commit
a489aecb86
  1. 21
      src/engine/objects/City.java
  2. 27
      src/engine/objects/Warehouse.java

21
src/engine/objects/City.java

@ -1365,28 +1365,19 @@ public class City extends AbstractWorldObject {
ItemBase.getItemHashIDMap(); ItemBase.getItemHashIDMap();
ArrayList<Integer> resources = new ArrayList<>(); ArrayList<ResourceType> resources = new ArrayList<>();
float taxPercent = msg.getTaxPercent(); float taxPercent = msg.getTaxPercent();
if (taxPercent > 20) if (taxPercent > 20)
taxPercent = .20f; taxPercent = .20f;
for (int resourceHash : msg.getResources().keySet()) { for (int resourceHash : msg.getResources().keySet())
if (ItemBase.getItemHashIDMap().get(resourceHash) != null) resources.add(ResourceType.hashLookup.get(resourceHash));
resources.add(ItemBase.getItemHashIDMap().get(resourceHash));
}
for (Integer itemBaseID : resources) {
ItemBase ib = ItemBase.getItemBase(itemBaseID);
if (ib == null)
continue;
ItemTemplate template = ItemTemplate.itemTemplates.get(itemBaseID);
if (Warehouse.isAboveCap(ruledWarehouse, ib, (int) (city.getWarehouse().resources.get(ib) * taxPercent))) { for (ResourceType resourceType : resources) {
ErrorPopupMsg.sendErrorMsg(player, "You're warehouse has enough " + template.item_base_name + " already!"); if (Warehouse.isAboveCap(ruledWarehouse, resourceType, (int) (city.getWarehouse().resources.get(resourceType) * taxPercent))) {
ErrorPopupMsg.sendErrorMsg(player, "Your warehouse has enough " + resourceType.name() + " already!");
return true; return true;
} }

27
src/engine/objects/Warehouse.java

@ -25,6 +25,7 @@ import org.pmw.tinylog.Logger;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.EnumSet;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
public class Warehouse extends AbstractWorldObject { public class Warehouse extends AbstractWorldObject {
@ -550,12 +551,9 @@ public class Warehouse extends AbstractWorldObject {
return true; return true;
} }
public static synchronized void transferResources(Warehouse warehouse, PlayerCharacter taxer, TaxResourcesMsg msg, ArrayList<Integer> realmResources, float taxPercent) { public static synchronized void transferResources(Warehouse warehouse, PlayerCharacter taxer, TaxResourcesMsg msg, ArrayList<Enum.ResourceType> realmResources, float taxPercent) {
for (int templateID : realmResources) { for (Enum.ResourceType resourceType : realmResources) {
ItemTemplate template = ItemTemplate.itemTemplates.get(templateID);
Enum.ResourceType resourceType = Enum.ResourceType.resourceLookup.get(templateID);
if (warehouse.resources.get(resourceType) == null) if (warehouse.resources.get(resourceType) == null)
return; return;
@ -588,12 +586,7 @@ public class Warehouse extends AbstractWorldObject {
depositRealmTaxes(taxer, resourceType, amount, warehouse); depositRealmTaxes(taxer, resourceType, amount, warehouse);
Enum.ResourceType resource; Enum.ResourceType resource;
if (resourceType.equals(Enum.ResourceType.GOLD)) AddTransactionToWarehouse(warehouse, taxer.getObjectType(), taxer.getObjectUUID(), Enum.TransactionType.TAXRESOURCE, resourceType, amount);
resource = Enum.ResourceType.GOLD;
else
resource = Enum.ResourceType.valueOf(template.item_base_name.toUpperCase());
AddTransactionToWarehouse(warehouse, taxer.getObjectType(), taxer.getObjectUUID(), Enum.TransactionType.TAXRESOURCE, resource, amount);
} }
} }
@ -751,10 +744,12 @@ public class Warehouse extends AbstractWorldObject {
public static boolean isEmpty(Warehouse warehouse) { public static boolean isEmpty(Warehouse warehouse) {
int amount = 0; int amount = 0;
for (ItemBase ib : ItemBase.getResourceList()) {
for (Enum.ResourceType resourceType : EnumSet.allOf(Enum.ResourceType.class)) {
amount += warehouse.resources.get(resourceType);
if (amount > 0) if (amount > 0)
return false; return false;
amount += warehouse.resources.get(ib);
} }
return true; return true;
} }
@ -773,9 +768,9 @@ public class Warehouse extends AbstractWorldObject {
warehouse.transactions.add(transaction); warehouse.transactions.add(transaction);
} }
public static boolean isAboveCap(Warehouse warehouse, ItemBase ib, int deposit) { public static boolean isAboveCap(Warehouse warehouse, Enum.ResourceType resourceType, int deposit) {
int newAmount = warehouse.resources.get(ib) + deposit; int newAmount = warehouse.resources.get(resourceType) + deposit;
return newAmount > Enum.ResourceType.resourceLookup.get(ib.getUUID()).deposit_limit; return newAmount > resourceType.deposit_limit;
} }

Loading…
Cancel
Save