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

27
src/engine/objects/Warehouse.java

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

Loading…
Cancel
Save