Renamed class to not conflict with the java.lang version.
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
|
||||
package engine.objects;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.mbEnums;
|
||||
import engine.gameManager.ChatManager;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.net.Dispatch;
|
||||
@@ -30,11 +30,11 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class Warehouse {
|
||||
|
||||
public EnumSet<Enum.ResourceType> locked = EnumSet.noneOf(Enum.ResourceType.class);
|
||||
public EnumSet<mbEnums.ResourceType> locked = EnumSet.noneOf(mbEnums.ResourceType.class);
|
||||
public Building building;
|
||||
public City city;
|
||||
public ArrayList<Transaction> transactions = new ArrayList<>();
|
||||
public ConcurrentHashMap<Enum.ResourceType, Integer> resources = new ConcurrentHashMap<>();
|
||||
public ConcurrentHashMap<mbEnums.ResourceType, Integer> resources = new ConcurrentHashMap<>();
|
||||
|
||||
public Warehouse(Building building) {
|
||||
|
||||
@@ -43,12 +43,12 @@ public class Warehouse {
|
||||
|
||||
// New empty warehouse
|
||||
|
||||
for (Enum.ResourceType resourceType : EnumSet.allOf(Enum.ResourceType.class))
|
||||
for (mbEnums.ResourceType resourceType : EnumSet.allOf(mbEnums.ResourceType.class))
|
||||
this.resources.put(resourceType, 0);
|
||||
|
||||
// With no locks
|
||||
|
||||
this.locked = EnumSet.noneOf(Enum.ResourceType.class);
|
||||
this.locked = EnumSet.noneOf(mbEnums.ResourceType.class);
|
||||
}
|
||||
|
||||
public Warehouse(JSONObject warehouse) throws SQLException {
|
||||
@@ -56,7 +56,7 @@ public class Warehouse {
|
||||
JSONObject resources = (JSONObject) warehouse.get("resources");
|
||||
|
||||
for (Object key : resources.keySet()) {
|
||||
Enum.ResourceType resourceType = Enum.ResourceType.valueOf((String) key);
|
||||
mbEnums.ResourceType resourceType = mbEnums.ResourceType.valueOf((String) key);
|
||||
int value = ((Long) resources.get(key)).intValue();
|
||||
this.resources.put(resourceType, value);
|
||||
}
|
||||
@@ -65,16 +65,16 @@ public class Warehouse {
|
||||
|
||||
if (lockedResources.isEmpty() == false)
|
||||
for (Object o : lockedResources)
|
||||
this.locked.add(Enum.ResourceType.valueOf((String) o));
|
||||
this.locked.add(mbEnums.ResourceType.valueOf((String) o));
|
||||
|
||||
}
|
||||
|
||||
public static HashMap<Enum.ResourceType, Integer>
|
||||
calculateWarehouseOverdraft(Warehouse warehouse, HashMap<Enum.ResourceType, Integer> costMap) {
|
||||
public static HashMap<mbEnums.ResourceType, Integer>
|
||||
calculateWarehouseOverdraft(Warehouse warehouse, HashMap<mbEnums.ResourceType, Integer> costMap) {
|
||||
|
||||
HashMap<Enum.ResourceType, Integer> overdraft = new HashMap<>();
|
||||
HashMap<mbEnums.ResourceType, Integer> overdraft = new HashMap<>();
|
||||
|
||||
for (Enum.ResourceType resourceType : costMap.keySet()) {
|
||||
for (mbEnums.ResourceType resourceType : costMap.keySet()) {
|
||||
|
||||
int cost = costMap.get(resourceType);
|
||||
|
||||
@@ -123,7 +123,7 @@ public class Warehouse {
|
||||
vrm.setWarehouseBuilding(warehouseBuilding);
|
||||
vrm.configure();
|
||||
dispatch = Dispatch.borrow(player, vrm);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY);
|
||||
}
|
||||
|
||||
public static void warehouseWithdraw(MerchantMsg msg, PlayerCharacter player, NPC npc) {
|
||||
@@ -152,7 +152,7 @@ public class Warehouse {
|
||||
if (warehouse == null)
|
||||
return;
|
||||
|
||||
Enum.ResourceType resourceType = Enum.ResourceType.hashLookup.get(msg.getHashID());
|
||||
mbEnums.ResourceType resourceType = mbEnums.ResourceType.hashLookup.get(msg.getHashID());
|
||||
|
||||
if (isResourceLocked(warehouse, resourceType)) {
|
||||
ChatManager.chatSystemInfo(player, "You cannot withdrawl a locked resource.");
|
||||
@@ -169,7 +169,7 @@ public class Warehouse {
|
||||
vrm.setWarehouseBuilding(warehouseBuilding);
|
||||
vrm.configure();
|
||||
dispatch = Dispatch.borrow(player, vrm);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY);
|
||||
}
|
||||
|
||||
public static void warehouseLock(MerchantMsg msg, PlayerCharacter player, NPC npc) {
|
||||
@@ -194,7 +194,7 @@ public class Warehouse {
|
||||
|
||||
warehouse = city.warehouse;
|
||||
|
||||
Enum.ResourceType resourceType = Enum.ResourceType.hashLookup.get(hashID);
|
||||
mbEnums.ResourceType resourceType = mbEnums.ResourceType.hashLookup.get(hashID);
|
||||
|
||||
// toggle lock
|
||||
|
||||
@@ -210,7 +210,7 @@ public class Warehouse {
|
||||
vrm.setWarehouseBuilding(warehouseBuilding);
|
||||
vrm.configure();
|
||||
dispatch = Dispatch.borrow(player, vrm);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY);
|
||||
} else
|
||||
warehouse.locked.add(resourceType);
|
||||
|
||||
@@ -227,7 +227,7 @@ public class Warehouse {
|
||||
vrm.setWarehouseBuilding(warehouseBuilding);
|
||||
vrm.configure();
|
||||
dispatch = Dispatch.borrow(player, vrm);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY);
|
||||
} else
|
||||
warehouse.locked.remove(resourceType);
|
||||
|
||||
@@ -245,7 +245,7 @@ public class Warehouse {
|
||||
return false;
|
||||
}
|
||||
|
||||
Enum.ResourceType resourceType = Enum.ResourceType.resourceLookup.get(resource.templateID);
|
||||
mbEnums.ResourceType resourceType = mbEnums.ResourceType.resourceLookup.get(resource.templateID);
|
||||
|
||||
if (warehouse.resources.get(resourceType) == null)
|
||||
return false;
|
||||
@@ -273,11 +273,11 @@ public class Warehouse {
|
||||
|
||||
int newAmount = oldAmount + amount;
|
||||
|
||||
if (newAmount > Enum.ResourceType.resourceLookup.get(resource.templateID).deposit_limit)
|
||||
if (newAmount > mbEnums.ResourceType.resourceLookup.get(resource.templateID).deposit_limit)
|
||||
return false;
|
||||
|
||||
if (removeFromInventory) {
|
||||
if (resourceType.equals(Enum.ResourceType.GOLD)) {
|
||||
if (resourceType.equals(mbEnums.ResourceType.GOLD)) {
|
||||
|
||||
if (itemMan.getGoldInventory().getNumOfItems() - amount < 0)
|
||||
return false;
|
||||
@@ -291,7 +291,7 @@ public class Warehouse {
|
||||
UpdateGoldMsg ugm = new UpdateGoldMsg(pc);
|
||||
ugm.configure();
|
||||
Dispatch dispatch = Dispatch.borrow(pc, ugm);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY);
|
||||
|
||||
itemMan.updateInventory();
|
||||
|
||||
@@ -313,18 +313,18 @@ public class Warehouse {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (resource.template.item_type.equals(Enum.ItemType.GOLD))
|
||||
resourceType = Enum.ResourceType.GOLD;
|
||||
if (resource.template.item_type.equals(mbEnums.ItemType.GOLD))
|
||||
resourceType = mbEnums.ResourceType.GOLD;
|
||||
else
|
||||
resourceType = Enum.ResourceType.valueOf(ItemTemplate.templates.get(resource.templateID).item_base_name.toUpperCase());
|
||||
resourceType = mbEnums.ResourceType.valueOf(ItemTemplate.templates.get(resource.templateID).item_base_name.toUpperCase());
|
||||
|
||||
if (transaction)
|
||||
AddTransactionToWarehouse(warehouse, pc.getObjectType(), pc.getObjectUUID(), Enum.TransactionType.DEPOSIT, resourceType, amount);
|
||||
AddTransactionToWarehouse(warehouse, pc.getObjectType(), pc.getObjectUUID(), mbEnums.TransactionType.DEPOSIT, resourceType, amount);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static synchronized boolean depositFromMine(Mine mine, Enum.ResourceType resourceType, int amount, Warehouse warehouse) {
|
||||
public static synchronized boolean depositFromMine(Mine mine, mbEnums.ResourceType resourceType, int amount, Warehouse warehouse) {
|
||||
|
||||
int oldAmount = warehouse.resources.get(resourceType);
|
||||
int newAmount = oldAmount + amount;
|
||||
@@ -340,12 +340,12 @@ public class Warehouse {
|
||||
}
|
||||
|
||||
if (mine != null)
|
||||
AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, mine.getBuildingID(), Enum.TransactionType.MINE, resourceType, amount);
|
||||
AddTransactionToWarehouse(warehouse, mbEnums.GameObjectType.Building, mine.getBuildingID(), mbEnums.TransactionType.MINE, resourceType, amount);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static synchronized void depositRealmTaxes(PlayerCharacter taxer, Enum.ResourceType resourceType, int amount, Warehouse warehouse) {
|
||||
public static synchronized void depositRealmTaxes(PlayerCharacter taxer, mbEnums.ResourceType resourceType, int amount, Warehouse warehouse) {
|
||||
|
||||
int oldAmount = warehouse.resources.get(resourceType);
|
||||
int newAmount = oldAmount + amount;
|
||||
@@ -356,11 +356,11 @@ public class Warehouse {
|
||||
return;
|
||||
}
|
||||
|
||||
AddTransactionToWarehouse(warehouse, taxer.getObjectType(), taxer.getObjectUUID(), Enum.TransactionType.TAXRESOURCEDEPOSIT, resourceType, amount);
|
||||
AddTransactionToWarehouse(warehouse, taxer.getObjectType(), taxer.getObjectUUID(), mbEnums.TransactionType.TAXRESOURCEDEPOSIT, resourceType, amount);
|
||||
|
||||
}
|
||||
|
||||
public static synchronized void depositProfitTax(Enum.ResourceType resourceType, int amount, Building building, Warehouse warehouse) {
|
||||
public static synchronized void depositProfitTax(mbEnums.ResourceType resourceType, int amount, Building building, Warehouse warehouse) {
|
||||
|
||||
if (warehouse.resources.get(resourceType) == null)
|
||||
return;
|
||||
@@ -379,11 +379,11 @@ public class Warehouse {
|
||||
}
|
||||
|
||||
if (building != null)
|
||||
AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, building.getObjectUUID(), Enum.TransactionType.DEPOSIT, resourceType, amount);
|
||||
AddTransactionToWarehouse(warehouse, mbEnums.GameObjectType.Building, building.getObjectUUID(), mbEnums.TransactionType.DEPOSIT, resourceType, amount);
|
||||
|
||||
}
|
||||
|
||||
public static synchronized boolean withdraw(Warehouse warehouse, NPC npc, Enum.ResourceType resourceType, int amount, boolean transaction) {
|
||||
public static synchronized boolean withdraw(Warehouse warehouse, NPC npc, mbEnums.ResourceType resourceType, int amount, boolean transaction) {
|
||||
|
||||
int oldAmount = warehouse.resources.get(resourceType);
|
||||
|
||||
@@ -406,14 +406,14 @@ public class Warehouse {
|
||||
}
|
||||
|
||||
if (transaction)
|
||||
AddTransactionToWarehouse(warehouse, npc.getObjectType(), npc.getObjectUUID(), Enum.TransactionType.WITHDRAWL, resourceType, amount);
|
||||
AddTransactionToWarehouse(warehouse, npc.getObjectType(), npc.getObjectUUID(), mbEnums.TransactionType.WITHDRAWL, resourceType, amount);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static synchronized void transferResources(Warehouse warehouse, PlayerCharacter taxer, TaxResourcesMsg msg, ArrayList<Enum.ResourceType> realmResources, float taxPercent) {
|
||||
public static synchronized void transferResources(Warehouse warehouse, PlayerCharacter taxer, TaxResourcesMsg msg, ArrayList<mbEnums.ResourceType> realmResources, float taxPercent) {
|
||||
|
||||
for (Enum.ResourceType resourceType : realmResources) {
|
||||
for (mbEnums.ResourceType resourceType : realmResources) {
|
||||
|
||||
if (warehouse.resources.get(resourceType) == null)
|
||||
return;
|
||||
@@ -445,14 +445,14 @@ public class Warehouse {
|
||||
|
||||
warehouse.resources.put(resourceType, newAmount);
|
||||
depositRealmTaxes(taxer, resourceType, amount, warehouse);
|
||||
Enum.ResourceType resource;
|
||||
mbEnums.ResourceType resource;
|
||||
|
||||
AddTransactionToWarehouse(warehouse, taxer.getObjectType(), taxer.getObjectUUID(), Enum.TransactionType.TAXRESOURCE, resourceType, amount);
|
||||
AddTransactionToWarehouse(warehouse, taxer.getObjectType(), taxer.getObjectUUID(), mbEnums.TransactionType.TAXRESOURCE, resourceType, amount);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized boolean withdraw(Warehouse warehouse, PlayerCharacter pc, Enum.ResourceType resourceType, int amount, boolean addToInventory, boolean transaction) {
|
||||
public static synchronized boolean withdraw(Warehouse warehouse, PlayerCharacter pc, mbEnums.ResourceType resourceType, int amount, boolean addToInventory, boolean transaction) {
|
||||
|
||||
if (pc == null)
|
||||
return false;
|
||||
@@ -476,7 +476,7 @@ public class Warehouse {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (addToInventory && resourceType.equals(Enum.ResourceType.GOLD)) {
|
||||
if (addToInventory && resourceType.equals(mbEnums.ResourceType.GOLD)) {
|
||||
if (pc.charItemManager.getGoldInventory().getNumOfItems() + amount > MBServerStatics.PLAYER_GOLD_LIMIT)
|
||||
return false;
|
||||
|
||||
@@ -498,13 +498,13 @@ public class Warehouse {
|
||||
}
|
||||
|
||||
if (addToInventory) {
|
||||
if (resourceType.equals(Enum.ResourceType.GOLD)) {
|
||||
if (resourceType.equals(mbEnums.ResourceType.GOLD)) {
|
||||
|
||||
itemMan.addGoldToInventory(amount, false);
|
||||
UpdateGoldMsg ugm = new UpdateGoldMsg(pc);
|
||||
ugm.configure();
|
||||
Dispatch dispatch = Dispatch.borrow(pc, ugm);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY);
|
||||
|
||||
itemMan.updateInventory();
|
||||
} else {
|
||||
@@ -512,8 +512,8 @@ public class Warehouse {
|
||||
|
||||
Item item = new Item(resourceType.templateID);
|
||||
item.ownerID = pc.getObjectUUID();
|
||||
item.ownerType = Enum.OwnerType.PlayerCharacter;
|
||||
item.containerType = Enum.ItemContainerType.INVENTORY;
|
||||
item.ownerType = mbEnums.OwnerType.PlayerCharacter;
|
||||
item.containerType = mbEnums.ItemContainerType.INVENTORY;
|
||||
item.numberOfItems = amount;
|
||||
|
||||
try {
|
||||
@@ -530,12 +530,12 @@ public class Warehouse {
|
||||
}
|
||||
|
||||
if (transaction)
|
||||
AddTransactionToWarehouse(warehouse, pc.getObjectType(), pc.getObjectUUID(), Enum.TransactionType.WITHDRAWL, resourceType, amount);
|
||||
AddTransactionToWarehouse(warehouse, pc.getObjectType(), pc.getObjectUUID(), mbEnums.TransactionType.WITHDRAWL, resourceType, amount);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static synchronized boolean loot(Warehouse warehouse, PlayerCharacter pc, Enum.ResourceType resourceType, int amount, boolean addToInventory) {
|
||||
public static synchronized boolean loot(Warehouse warehouse, PlayerCharacter pc, mbEnums.ResourceType resourceType, int amount, boolean addToInventory) {
|
||||
|
||||
if (pc == null)
|
||||
return false;
|
||||
@@ -571,21 +571,21 @@ public class Warehouse {
|
||||
warehouse.resources.put(resourceType, newAmount);
|
||||
|
||||
if (addToInventory) {
|
||||
if (resourceType.equals(Enum.ResourceType.GOLD)) {
|
||||
if (resourceType.equals(mbEnums.ResourceType.GOLD)) {
|
||||
|
||||
itemMan.addGoldToInventory(amount, false);
|
||||
UpdateGoldMsg ugm = new UpdateGoldMsg(pc);
|
||||
ugm.configure();
|
||||
Dispatch dispatch = Dispatch.borrow(pc, ugm);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY);
|
||||
|
||||
itemMan.updateInventory();
|
||||
} else {
|
||||
boolean itemWorked = false;
|
||||
Item item = new Item(resourceType.templateID);
|
||||
item.ownerID = pc.getObjectUUID();
|
||||
item.ownerType = Enum.OwnerType.PlayerCharacter;
|
||||
item.containerType = Enum.ItemContainerType.INVENTORY;
|
||||
item.ownerType = mbEnums.OwnerType.PlayerCharacter;
|
||||
item.containerType = mbEnums.ItemContainerType.INVENTORY;
|
||||
item.numberOfItems = amount;
|
||||
|
||||
try {
|
||||
@@ -607,7 +607,7 @@ public class Warehouse {
|
||||
public static boolean isEmpty(Warehouse warehouse) {
|
||||
int amount = 0;
|
||||
|
||||
for (Enum.ResourceType resourceType : EnumSet.allOf(Enum.ResourceType.class)) {
|
||||
for (mbEnums.ResourceType resourceType : EnumSet.allOf(mbEnums.ResourceType.class)) {
|
||||
amount += warehouse.resources.get(resourceType);
|
||||
|
||||
if (amount > 0)
|
||||
@@ -620,7 +620,7 @@ public class Warehouse {
|
||||
warehouse.transactions = DbManager.WarehouseQueries.GET_TRANSACTIONS_FOR_WAREHOUSE(warehouse.building.getObjectUUID());
|
||||
}
|
||||
|
||||
public static void AddTransactionToWarehouse(Warehouse warehouse, Enum.GameObjectType targetType, int targetUUID, Enum.TransactionType transactionType, Enum.ResourceType resource, int amount) {
|
||||
public static void AddTransactionToWarehouse(Warehouse warehouse, mbEnums.GameObjectType targetType, int targetUUID, mbEnums.TransactionType transactionType, mbEnums.ResourceType resource, int amount) {
|
||||
|
||||
|
||||
if (!DbManager.WarehouseQueries.CREATE_TRANSACTION(warehouse.building.getObjectUUID(), targetType, targetUUID, transactionType, resource, amount, DateTime.now()))
|
||||
@@ -630,13 +630,13 @@ public class Warehouse {
|
||||
warehouse.transactions.add(transaction);
|
||||
}
|
||||
|
||||
public static boolean isAboveCap(Warehouse warehouse, Enum.ResourceType resourceType, int deposit) {
|
||||
public static boolean isAboveCap(Warehouse warehouse, mbEnums.ResourceType resourceType, int deposit) {
|
||||
int newAmount = warehouse.resources.get(resourceType) + deposit;
|
||||
return newAmount > resourceType.deposit_limit;
|
||||
|
||||
}
|
||||
|
||||
public static boolean isResourceLocked(Warehouse warehouse, Enum.ResourceType resourceType) {
|
||||
public static boolean isResourceLocked(Warehouse warehouse, mbEnums.ResourceType resourceType) {
|
||||
return resourceType.elementOf(warehouse.locked);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user