forked from MagicBane/Server
Warehosue cleanup
This commit is contained in:
@@ -19,7 +19,6 @@ import engine.db.archive.DataWarehouse;
|
||||
import engine.db.archive.MineRecord;
|
||||
import engine.gameManager.BuildingManager;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.gameManager.WarehouseManager;
|
||||
import engine.gameManager.ZoneManager;
|
||||
import engine.job.JobContainer;
|
||||
import engine.job.JobScheduler;
|
||||
@@ -1430,18 +1429,18 @@ public class Building extends AbstractWorldObject {
|
||||
if (this.getCity().getWarehouse() == null)
|
||||
return amount;
|
||||
|
||||
if (this.getCity().getWarehouse().resources.get(ItemBase.getGoldItemBase()) >= WarehouseManager.getMaxResources().get(ItemBase.getGoldItemBase().getUUID()))
|
||||
if (this.getCity().getWarehouse().resources.get(ItemBase.getGoldItemBase()) >= Warehouse.getMaxResources().get(ItemBase.getGoldItemBase().getUUID()))
|
||||
return amount;
|
||||
|
||||
int profitAmount = (int) (amount * (taxAmount * .01f));
|
||||
|
||||
if (this.getCity().getWarehouse().resources.get(ItemBase.getGoldItemBase()) + profitAmount <= WarehouseManager.getMaxResources().get(ItemBase.getGoldItemBase().getUUID())) {
|
||||
WarehouseManager.depositProfitTax(ItemBase.getGoldItemBase(), profitAmount, this,this.getCity().getWarehouse());
|
||||
if (this.getCity().getWarehouse().resources.get(ItemBase.getGoldItemBase()) + profitAmount <= Warehouse.getMaxResources().get(ItemBase.getGoldItemBase().getUUID())) {
|
||||
Warehouse.depositProfitTax(ItemBase.getGoldItemBase(), profitAmount, this,this.getCity().getWarehouse());
|
||||
return amount - profitAmount;
|
||||
}
|
||||
//overDrafting
|
||||
int warehouseDeposit = WarehouseManager.getMaxResources().get(ItemBase.getGoldItemBase().getUUID()) - this.getCity().getWarehouse().resources.get(ItemBase.getGoldItemBase());
|
||||
WarehouseManager.depositProfitTax(ItemBase.getGoldItemBase(), warehouseDeposit, this,this.getCity().getWarehouse());
|
||||
int warehouseDeposit = Warehouse.getMaxResources().get(ItemBase.getGoldItemBase().getUUID()) - this.getCity().getWarehouse().resources.get(ItemBase.getGoldItemBase());
|
||||
Warehouse.depositProfitTax(ItemBase.getGoldItemBase(), warehouseDeposit, this,this.getCity().getWarehouse());
|
||||
return amount - warehouseDeposit;
|
||||
}
|
||||
|
||||
|
||||
@@ -342,13 +342,13 @@ public class CharacterItemManager {
|
||||
Warehouse warehouse = (Warehouse) object;
|
||||
|
||||
if (amount < 0) {
|
||||
if (!WarehouseManager.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;
|
||||
}
|
||||
} else {
|
||||
if (!WarehouseManager.withdraw(warehouse, (PlayerCharacter) this.absCharacter, this.getGoldInventory().getItemBase(), amount * -1, true, true)) {
|
||||
if (!Warehouse.withdraw(warehouse, (PlayerCharacter) this.absCharacter, this.getGoldInventory().getItemBase(), amount * -1, true, true)) {
|
||||
|
||||
ErrorPopupMsg.sendErrorPopup((PlayerCharacter) this.absCharacter, 203);
|
||||
return false;
|
||||
|
||||
@@ -875,7 +875,7 @@ public class City extends AbstractWorldObject {
|
||||
if (this.warehouseBuildingID == 0)
|
||||
return null;
|
||||
|
||||
return WarehouseManager.warehouseByBuildingUUID.get(this.warehouseBuildingID);
|
||||
return Warehouse.warehouseByBuildingUUID.get(this.warehouseBuildingID);
|
||||
}
|
||||
|
||||
public Realm getRealm() {
|
||||
@@ -1358,7 +1358,7 @@ public class City extends AbstractWorldObject {
|
||||
ItemBase ib = ItemBase.getItemBase(itemBaseID);
|
||||
if (ib == null)
|
||||
continue;
|
||||
if (WarehouseManager.isAboveCap(ruledWarehouse, ib, (int) (city.getWarehouse().resources.get(ib) * taxPercent))) {
|
||||
if (Warehouse.isAboveCap(ruledWarehouse, ib, (int) (city.getWarehouse().resources.get(ib) * taxPercent))) {
|
||||
ErrorPopupMsg.sendErrorMsg(player, "You're warehouse has enough " + ib.getName() + " already!");
|
||||
return true;
|
||||
}
|
||||
@@ -1371,7 +1371,7 @@ public class City extends AbstractWorldObject {
|
||||
}
|
||||
|
||||
try {
|
||||
WarehouseManager.transferResources(city.getWarehouse(), player, msg, resources, taxPercent);
|
||||
Warehouse.transferResources(city.getWarehouse(), player, msg, resources, taxPercent);
|
||||
} catch (Exception e) {
|
||||
Logger.info(e.getMessage());
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ public class ItemFactory {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (overdraft > 0 && WarehouseManager.isResourceLocked(cityWarehouse, ItemBase.GOLD_ITEM_BASE)) {
|
||||
if (overdraft > 0 && Warehouse.isResourceLocked(cityWarehouse, ItemBase.GOLD_ITEM_BASE)) {
|
||||
if (pc != null)
|
||||
ErrorPopupMsg.sendErrorMsg(pc, "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse." + " " + ib.getName());
|
||||
return null;
|
||||
@@ -167,7 +167,7 @@ public class ItemFactory {
|
||||
}
|
||||
|
||||
if (overdraft > 0)
|
||||
if (!WarehouseManager.withdraw(cityWarehouse, npc, ItemBase.GOLD_ITEM_BASE, overdraft, true)) {
|
||||
if (!Warehouse.withdraw(cityWarehouse, npc, ItemBase.GOLD_ITEM_BASE, overdraft, true)) {
|
||||
//ChatManager.chatGuildError(pc, "Failed to create Item");
|
||||
Logger.error("Warehouse With UID of " + cityWarehouse.UID + " Failed to Create Item." + ib.getName());
|
||||
return null;
|
||||
@@ -263,7 +263,7 @@ public class ItemFactory {
|
||||
}
|
||||
|
||||
if (galvorAmount > 0) {
|
||||
if (WarehouseManager.isResourceLocked(cityWarehouse, galvor)) {
|
||||
if (Warehouse.isResourceLocked(cityWarehouse, galvor)) {
|
||||
if (pc != null)
|
||||
ErrorPopupMsg.sendErrorMsg(pc, "Galvor is locked." + ib.getName());
|
||||
return null;
|
||||
@@ -277,7 +277,7 @@ public class ItemFactory {
|
||||
}
|
||||
|
||||
if (wormwoodAmount > 0) {
|
||||
if (WarehouseManager.isResourceLocked(cityWarehouse, wormwood)) {
|
||||
if (Warehouse.isResourceLocked(cityWarehouse, wormwood)) {
|
||||
if (pc != null)
|
||||
ErrorPopupMsg.sendErrorMsg(pc, "Wormwood is locked." + ib.getName());
|
||||
return null;
|
||||
@@ -320,7 +320,7 @@ public class ItemFactory {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (overdraft > 0 && WarehouseManager.isResourceLocked(cityWarehouse, ItemBase.GOLD_ITEM_BASE)) {
|
||||
if (overdraft > 0 && Warehouse.isResourceLocked(cityWarehouse, ItemBase.GOLD_ITEM_BASE)) {
|
||||
if (pc != null)
|
||||
ErrorPopupMsg.sendErrorMsg(pc, "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse." + ib.getName());
|
||||
return null;
|
||||
@@ -374,7 +374,7 @@ public class ItemFactory {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (overdraft > 0 && WarehouseManager.isResourceLocked(cityWarehouse, ItemBase.GOLD_ITEM_BASE)) {
|
||||
if (overdraft > 0 && Warehouse.isResourceLocked(cityWarehouse, ItemBase.GOLD_ITEM_BASE)) {
|
||||
if (pc != null)
|
||||
ErrorPopupMsg.sendErrorMsg(pc, "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse." + ib.getName());
|
||||
return null;
|
||||
@@ -414,7 +414,7 @@ public class ItemFactory {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (overdraft > 0 && useWarehouse && WarehouseManager.isResourceLocked(cityWarehouse, ItemBase.GOLD_ITEM_BASE)) {
|
||||
if (overdraft > 0 && useWarehouse && Warehouse.isResourceLocked(cityWarehouse, ItemBase.GOLD_ITEM_BASE)) {
|
||||
if (pc != null)
|
||||
ErrorPopupMsg.sendErrorMsg(pc, "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse." + ib.getName());
|
||||
return null;
|
||||
@@ -448,7 +448,7 @@ public class ItemFactory {
|
||||
}
|
||||
|
||||
if (overdraft > 0 && useWarehouse)
|
||||
if (!WarehouseManager.withdraw(cityWarehouse, npc, ItemBase.GOLD_ITEM_BASE, overdraft, true)) {
|
||||
if (!Warehouse.withdraw(cityWarehouse, npc, ItemBase.GOLD_ITEM_BASE, overdraft, true)) {
|
||||
//ChatManager.chatGuildError(pc, "Failed to create Item");
|
||||
Logger.error("Warehouse With UID of " + cityWarehouse.UID + " Failed to Create Item." + ib.getName());
|
||||
return null;
|
||||
@@ -467,7 +467,7 @@ public class ItemFactory {
|
||||
|
||||
int creationAmount = prefixResourceCosts.get(ibResources);
|
||||
|
||||
if (WarehouseManager.isResourceLocked(cityWarehouse, ibResources) == true)
|
||||
if (Warehouse.isResourceLocked(cityWarehouse, ibResources) == true)
|
||||
return null;
|
||||
|
||||
int oldAmount = cityWarehouse.resources.get(ibResources);
|
||||
@@ -476,7 +476,7 @@ public class ItemFactory {
|
||||
if (oldAmount < amount)
|
||||
amount = oldAmount;
|
||||
|
||||
if (!WarehouseManager.withdraw(cityWarehouse, npc, ibResources, amount, true)) {
|
||||
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." + ib.getName());
|
||||
return null;
|
||||
@@ -489,7 +489,7 @@ public class ItemFactory {
|
||||
for (ItemBase ibResources : suffixResourceCosts.keySet()) {
|
||||
int creationAmount = suffixResourceCosts.get(ibResources);
|
||||
|
||||
if (WarehouseManager.isResourceLocked(cityWarehouse, ibResources) == true) {
|
||||
if (Warehouse.isResourceLocked(cityWarehouse, ibResources) == true) {
|
||||
ChatManager.chatSystemError(pc, ibResources.getName() + " is locked!" + ib.getName());
|
||||
return null;
|
||||
}
|
||||
@@ -498,7 +498,7 @@ public class ItemFactory {
|
||||
int amount = creationAmount;
|
||||
if (oldAmount < amount)
|
||||
amount = oldAmount;
|
||||
if (!WarehouseManager.withdraw(cityWarehouse, npc, ibResources, amount, true)) {
|
||||
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." + ib.getName());
|
||||
return null;
|
||||
@@ -522,7 +522,7 @@ public class ItemFactory {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (overdraft > 0 && WarehouseManager.isResourceLocked(cityWarehouse, ItemBase.GOLD_ITEM_BASE)) {
|
||||
if (overdraft > 0 && Warehouse.isResourceLocked(cityWarehouse, ItemBase.GOLD_ITEM_BASE)) {
|
||||
|
||||
if (pc != null)
|
||||
ErrorPopupMsg.sendErrorMsg(pc, "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse." + ib.getName());
|
||||
@@ -552,7 +552,7 @@ public class ItemFactory {
|
||||
}
|
||||
|
||||
if (overdraft > 0)
|
||||
if (!WarehouseManager.withdraw(cityWarehouse, npc, ItemBase.GOLD_ITEM_BASE, overdraft, true)) {
|
||||
if (!Warehouse.withdraw(cityWarehouse, npc, ItemBase.GOLD_ITEM_BASE, overdraft, true)) {
|
||||
//ChatManager.chatGuildError(pc, "Failed to create Item");
|
||||
Logger.error("Warehouse With UID of " + cityWarehouse.UID + " Failed to Create Item." + ib.getName());
|
||||
return null;
|
||||
@@ -561,7 +561,7 @@ public class ItemFactory {
|
||||
// ChatManager.chatGuildInfo(pc, "Gold Cost = " + total);
|
||||
|
||||
if (galvorAmount > 0) {
|
||||
if (!WarehouseManager.withdraw(cityWarehouse, npc, galvor, galvorAmount, true)) {
|
||||
if (!Warehouse.withdraw(cityWarehouse, npc, galvor, galvorAmount, true)) {
|
||||
ErrorPopupMsg.sendErrorMsg(pc, "Failed to withdraw Galvor from warehouse!" + ib.getName());
|
||||
Logger.error("Warehouse with UID of" + cityWarehouse.getObjectUUID() + "Failed to Withdrawl ");
|
||||
return null;
|
||||
@@ -569,7 +569,7 @@ public class ItemFactory {
|
||||
}
|
||||
|
||||
if (wormwoodAmount > 0) {
|
||||
if (!WarehouseManager.withdraw(cityWarehouse, npc, wormwood, wormwoodAmount, true)) {
|
||||
if (!Warehouse.withdraw(cityWarehouse, npc, wormwood, wormwoodAmount, true)) {
|
||||
ErrorPopupMsg.sendErrorMsg(pc, "Failed to withdraw Wormwood from warehouse!" + ib.getName());
|
||||
Logger.error("Warehouse with UID of" + cityWarehouse.getObjectUUID() + "Failed to Withdrawl ");
|
||||
return null;
|
||||
@@ -852,7 +852,7 @@ public class ItemFactory {
|
||||
return null;
|
||||
|
||||
if (galvorAmount > 0) {
|
||||
if (WarehouseManager.isResourceLocked(cityWarehouse, galvor)) {
|
||||
if (Warehouse.isResourceLocked(cityWarehouse, galvor)) {
|
||||
ErrorPopupMsg.sendErrorMsg(pc, "Galvor is locked." + ib.getName());
|
||||
return null;
|
||||
}
|
||||
@@ -864,7 +864,7 @@ public class ItemFactory {
|
||||
}
|
||||
|
||||
if (wormwoodAmount > 0) {
|
||||
if (WarehouseManager.isResourceLocked(cityWarehouse, wormwood)) {
|
||||
if (Warehouse.isResourceLocked(cityWarehouse, wormwood)) {
|
||||
ErrorPopupMsg.sendErrorMsg(pc, "Galvor is locked." + ib.getName());
|
||||
return null;
|
||||
}
|
||||
@@ -908,7 +908,7 @@ public class ItemFactory {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (useWarehouse && overdraft > 0 && WarehouseManager.isResourceLocked(cityWarehouse, ItemBase.GOLD_ITEM_BASE)) {
|
||||
if (useWarehouse && overdraft > 0 && Warehouse.isResourceLocked(cityWarehouse, ItemBase.GOLD_ITEM_BASE)) {
|
||||
if (pc != null)
|
||||
ErrorPopupMsg.sendErrorMsg(pc, "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse." + ib.getName());
|
||||
return null;
|
||||
@@ -936,12 +936,12 @@ public class ItemFactory {
|
||||
// there was an overdraft, withdraw the rest from warehouse.
|
||||
if (overdraft > 0) {
|
||||
if (pc != null) {
|
||||
if (!WarehouseManager.withdraw(cityWarehouse, pc, ItemBase.GOLD_ITEM_BASE, overdraft, false, true)) {
|
||||
if (!Warehouse.withdraw(cityWarehouse, pc, ItemBase.GOLD_ITEM_BASE, overdraft, false, true)) {
|
||||
Logger.error("Warehouse with UID of" + cityWarehouse.getObjectUUID() + "Failed to Withdrawl ");
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
if (!WarehouseManager.withdraw(cityWarehouse, npc, ItemBase.GOLD_ITEM_BASE, overdraft, true)) {
|
||||
if (!Warehouse.withdraw(cityWarehouse, npc, ItemBase.GOLD_ITEM_BASE, overdraft, true)) {
|
||||
Logger.error("Warehouse with UID of" + cityWarehouse.getObjectUUID() + "Failed to Withdrawl ");
|
||||
return null;
|
||||
}
|
||||
@@ -959,7 +959,7 @@ public class ItemFactory {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (useWarehouse && overdraft > 0 && WarehouseManager.isResourceLocked(cityWarehouse, ItemBase.GOLD_ITEM_BASE)) {
|
||||
if (useWarehouse && overdraft > 0 && Warehouse.isResourceLocked(cityWarehouse, ItemBase.GOLD_ITEM_BASE)) {
|
||||
if (pc != null)
|
||||
ErrorPopupMsg.sendErrorMsg(pc, "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse." + ib.getName());
|
||||
return null;
|
||||
@@ -987,12 +987,12 @@ public class ItemFactory {
|
||||
if (overdraft > 0 && useWarehouse) {
|
||||
|
||||
if (pc != null) {
|
||||
if (!WarehouseManager.withdraw(cityWarehouse, pc, ItemBase.GOLD_ITEM_BASE, overdraft, false, true)) {
|
||||
if (!Warehouse.withdraw(cityWarehouse, pc, ItemBase.GOLD_ITEM_BASE, overdraft, false, true)) {
|
||||
Logger.error("Warehouse with UID of" + cityWarehouse.getObjectUUID() + "Failed to Withdrawl ");
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
if (!WarehouseManager.withdraw(cityWarehouse, npc, ItemBase.GOLD_ITEM_BASE, overdraft, true)) {
|
||||
if (!Warehouse.withdraw(cityWarehouse, npc, ItemBase.GOLD_ITEM_BASE, overdraft, true)) {
|
||||
Logger.error("Warehouse with UID of" + cityWarehouse.getObjectUUID() + "Failed to Withdrawl ");
|
||||
return null;
|
||||
}
|
||||
@@ -1002,7 +1002,7 @@ public class ItemFactory {
|
||||
|
||||
if (galvorAmount > 0 && useWarehouse) {
|
||||
//ChatManager.chatGuildInfo(pc, "Withdrawing " + galvorAmount + " galvor from warehouse");
|
||||
if (!WarehouseManager.withdraw(cityWarehouse, npc, galvor, galvorAmount, true)) {
|
||||
if (!Warehouse.withdraw(cityWarehouse, npc, galvor, galvorAmount, true)) {
|
||||
ErrorPopupMsg.sendErrorMsg(pc, "Failed to withdraw Galvor from warehouse!" + ib.getName());
|
||||
Logger.error("Warehouse with UID of" + cityWarehouse.getObjectUUID() + "Failed to Withdrawl ");
|
||||
return null;
|
||||
@@ -1011,7 +1011,7 @@ public class ItemFactory {
|
||||
|
||||
if (wormwoodAmount > 0 && useWarehouse) {
|
||||
//ChatManager.chatGuildInfo(pc, "Withdrawing " + wormwoodAmount + " wormwood from warehouse");
|
||||
if (!WarehouseManager.withdraw(cityWarehouse, npc, wormwood, wormwoodAmount, true)) {
|
||||
if (!Warehouse.withdraw(cityWarehouse, npc, wormwood, wormwoodAmount, true)) {
|
||||
ErrorPopupMsg.sendErrorMsg(pc, "Failed to withdraw Wormwood from warehouse for " + ib.getName());
|
||||
Logger.error("Warehouse with UID of" + cityWarehouse.getObjectUUID() + "Failed to Withdrawl ");
|
||||
|
||||
|
||||
@@ -480,7 +480,7 @@ public class Mine extends AbstractGameObject {
|
||||
return false;
|
||||
|
||||
ItemBase resourceIB = ItemBase.getItemBase(this.production.UUID);
|
||||
return WarehouseManager.depositFromMine(this, resourceIB, this.getModifiedProductionAmount(),this.owningGuild.getOwnedCity().getWarehouse());
|
||||
return Warehouse.depositFromMine(this, resourceIB, this.getModifiedProductionAmount(),this.owningGuild.getOwnedCity().getWarehouse());
|
||||
}
|
||||
|
||||
public boolean updateGuildOwner(PlayerCharacter playerCharacter) {
|
||||
|
||||
@@ -12,7 +12,14 @@ package engine.objects;
|
||||
import ch.claude_martin.enumbitset.EnumBitSet;
|
||||
import engine.Enum;
|
||||
import engine.gameManager.BuildingManager;
|
||||
import engine.gameManager.WarehouseManager;
|
||||
import engine.gameManager.ChatManager;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.*;
|
||||
import engine.server.MBServerStatics;
|
||||
import org.joda.time.DateTime;
|
||||
import org.pmw.tinylog.Logger;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
@@ -22,6 +29,8 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
public class Warehouse extends AbstractWorldObject {
|
||||
|
||||
|
||||
public static ConcurrentHashMap<Integer, Integer> maxResources = new ConcurrentHashMap<>();
|
||||
public static ConcurrentHashMap<Integer, Warehouse> warehouseByBuildingUUID = new ConcurrentHashMap<>();
|
||||
public EnumBitSet<Enum.ResourceType> lockedResourceTypes;
|
||||
public int UID;
|
||||
public int buildingUID;
|
||||
@@ -35,32 +44,837 @@ public class Warehouse extends AbstractWorldObject {
|
||||
public Warehouse(ResultSet rs) throws SQLException {
|
||||
super(rs);
|
||||
this.UID = rs.getInt("UID");
|
||||
this.resources.put(WarehouseManager.stoneIB, rs.getInt("warehouse_stone"));
|
||||
this.resources.put(WarehouseManager.truesteelIB, rs.getInt("warehouse_truesteel"));
|
||||
this.resources.put(WarehouseManager.ironIB, rs.getInt("warehouse_iron"));
|
||||
this.resources.put(WarehouseManager.adamantIB, rs.getInt("warehouse_adamant"));
|
||||
this.resources.put(WarehouseManager.lumberIB, rs.getInt("warehouse_lumber"));
|
||||
this.resources.put(WarehouseManager.oakIB, rs.getInt("warehouse_oak"));
|
||||
this.resources.put(WarehouseManager.bronzewoodIB, rs.getInt("warehouse_bronzewood"));
|
||||
this.resources.put(WarehouseManager.mandrakeIB, rs.getInt("warehouse_mandrake"));
|
||||
this.resources.put(WarehouseManager.coalIB, rs.getInt("warehouse_coal"));
|
||||
this.resources.put(WarehouseManager.agateIB, rs.getInt("warehouse_agate"));
|
||||
this.resources.put(WarehouseManager.diamondIB, rs.getInt("warehouse_diamond"));
|
||||
this.resources.put(WarehouseManager.onyxIB, rs.getInt("warehouse_onyx"));
|
||||
this.resources.put(WarehouseManager.azothIB, rs.getInt("warehouse_azoth"));
|
||||
this.resources.put(WarehouseManager.orichalkIB, rs.getInt("warehouse_orichalk"));
|
||||
this.resources.put(WarehouseManager.antimonyIB, rs.getInt("warehouse_antimony"));
|
||||
this.resources.put(WarehouseManager.sulferIB, rs.getInt("warehouse_sulfur"));
|
||||
this.resources.put(WarehouseManager.quicksilverIB, rs.getInt("warehouse_quicksilver"));
|
||||
this.resources.put(WarehouseManager.galvorIB, rs.getInt("warehouse_galvor"));
|
||||
this.resources.put(WarehouseManager.wormwoodIB, rs.getInt("warehouse_wormwood"));
|
||||
this.resources.put(WarehouseManager.obsidianIB, rs.getInt("warehouse_obsidian"));
|
||||
this.resources.put(WarehouseManager.bloodstoneIB, rs.getInt("warehouse_bloodstone"));
|
||||
this.resources.put(WarehouseManager.mithrilIB, rs.getInt("warehouse_mithril"));
|
||||
this.resources.put(WarehouseManager.goldIB, rs.getInt("warehouse_gold"));
|
||||
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.lockedResourceTypes = EnumBitSet.asEnumBitSet(rs.getLong("warehouse_locks"), Enum.ResourceType.class);
|
||||
this.buildingUID = rs.getInt("parent");
|
||||
WarehouseManager.warehouseByBuildingUUID.put(this.buildingUID, this);
|
||||
warehouseByBuildingUUID.put(this.buildingUID, this);
|
||||
}
|
||||
|
||||
public static ConcurrentHashMap<Integer, Integer> getMaxResources() {
|
||||
if (maxResources.size() != 23) {
|
||||
maxResources.put(7, 100000000);
|
||||
maxResources.put(1580000, 10000);
|
||||
maxResources.put(1580001, 2000);
|
||||
maxResources.put(1580002, 2000);
|
||||
maxResources.put(1580003, 1000);
|
||||
maxResources.put(1580004, 10000);
|
||||
maxResources.put(1580005, 3000);
|
||||
maxResources.put(1580006, 3000);
|
||||
maxResources.put(1580007, 1000);
|
||||
maxResources.put(1580008, 3000);
|
||||
maxResources.put(1580009, 2000);
|
||||
maxResources.put(1580010, 2000);
|
||||
maxResources.put(1580011, 1000);
|
||||
maxResources.put(1580012, 2000);
|
||||
maxResources.put(1580013, 3000);
|
||||
maxResources.put(1580014, 1000);
|
||||
maxResources.put(1580015, 1000);
|
||||
maxResources.put(1580016, 1000);
|
||||
maxResources.put(1580017, 500);
|
||||
maxResources.put(1580018, 500);
|
||||
maxResources.put(1580019, 500);
|
||||
maxResources.put(1580020, 500);
|
||||
maxResources.put(1580021, 500);
|
||||
}
|
||||
|
||||
return maxResources;
|
||||
}
|
||||
|
||||
public static void warehouseDeposit(MerchantMsg msg, PlayerCharacter player, NPC npc) {
|
||||
|
||||
Building warehouseBuilding;
|
||||
Warehouse warehouse;
|
||||
int depositAmount;
|
||||
Dispatch dispatch;
|
||||
|
||||
Item resource = Item.getFromCache(msg.getItemID());
|
||||
|
||||
if (resource == null)
|
||||
return;
|
||||
|
||||
depositAmount = msg.getAmount();
|
||||
CharacterItemManager itemMan = player.getCharItemManager();
|
||||
|
||||
if (!itemMan.doesCharOwnThisItem(resource.getObjectUUID()))
|
||||
return;
|
||||
|
||||
warehouseBuilding = npc.getBuilding();
|
||||
|
||||
if (warehouseBuilding == null)
|
||||
return;
|
||||
|
||||
warehouse = warehouseByBuildingUUID.get(warehouseBuilding.getObjectUUID());
|
||||
|
||||
if (warehouse == null)
|
||||
return;
|
||||
|
||||
|
||||
if (!deposit(player, resource, depositAmount, true, true,warehouse)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ViewResourcesMessage vrm = new ViewResourcesMessage(player);
|
||||
vrm.setGuild(player.getGuild());
|
||||
vrm.setWarehouseBuilding(warehouseBuilding);
|
||||
vrm.configure();
|
||||
dispatch = Dispatch.borrow(player, vrm);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
}
|
||||
|
||||
public static void warehouseWithdraw(MerchantMsg msg, PlayerCharacter player, NPC npc) {
|
||||
|
||||
int withdrawAmount;
|
||||
Building warehouseBuilding;
|
||||
Warehouse warehouse;
|
||||
Dispatch dispatch;
|
||||
|
||||
withdrawAmount = msg.getAmount();
|
||||
warehouseBuilding = npc.getBuilding();
|
||||
|
||||
if (warehouseBuilding == null)
|
||||
return;
|
||||
|
||||
if (player.getGuild() != warehouseBuilding.getGuild() || !GuildStatusController.isInnerCouncil(player.getGuildStatus()))
|
||||
return;
|
||||
|
||||
warehouse = warehouseByBuildingUUID.get(warehouseBuilding.getObjectUUID());
|
||||
|
||||
if (warehouse == null)
|
||||
return;
|
||||
|
||||
int hashID = msg.getHashID();
|
||||
int itemBaseID = ItemBase.getItemHashIDMap().get(hashID);
|
||||
ItemBase ib = ItemBase.getItemBase(itemBaseID);
|
||||
|
||||
if (ib == null) {
|
||||
Logger.debug("Failed to find Resource ItemBaseID with Hash ID = " + hashID);
|
||||
return;
|
||||
}
|
||||
|
||||
if (isResourceLocked(warehouse, ib)) {
|
||||
ChatManager.chatSystemInfo(player, "You cannot withdrawl a locked resource.");
|
||||
return;
|
||||
}
|
||||
if (!withdraw(warehouse, player, ib, withdrawAmount, true, true)) {
|
||||
ChatManager.chatGuildError(player, "Failed to withdrawl " + ib.getName() + '.');
|
||||
Logger.debug(player.getName() + " Failed to withdrawl =" + ib.getName() + " from Warehouse With ID = " + warehouseBuilding.getObjectUUID());
|
||||
return;
|
||||
}
|
||||
|
||||
ViewResourcesMessage vrm = new ViewResourcesMessage(player);
|
||||
vrm.setGuild(player.getGuild());
|
||||
vrm.setWarehouseBuilding(warehouseBuilding);
|
||||
vrm.configure();
|
||||
dispatch = Dispatch.borrow(player, vrm);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
}
|
||||
|
||||
public static void warehouseLock(MerchantMsg msg, PlayerCharacter player, NPC npc) {
|
||||
Building warehouse;
|
||||
int hashID;
|
||||
Dispatch dispatch;
|
||||
|
||||
hashID = msg.getHashID();
|
||||
warehouse = npc.getBuilding();
|
||||
|
||||
if (warehouse == null)
|
||||
return;
|
||||
|
||||
if (player.getGuild() != warehouse.getGuild() || !GuildStatusController.isInnerCouncil(player.getGuildStatus()))
|
||||
return;
|
||||
|
||||
Warehouse wh = warehouseByBuildingUUID.get(warehouse.getObjectUUID());
|
||||
|
||||
if (wh == null)
|
||||
return;
|
||||
|
||||
int itemBaseID = ItemBase.getItemHashIDMap().get(hashID);
|
||||
ItemBase ib = ItemBase.getItemBase(itemBaseID);
|
||||
|
||||
if (ib == null)
|
||||
return;
|
||||
|
||||
if (isResourceLocked(wh, ib)) {
|
||||
boolean worked;
|
||||
EnumBitSet<Enum.ResourceType> bitSet = EnumBitSet.asEnumBitSet(wh.lockedResourceTypes.toLong(), Enum.ResourceType.class);
|
||||
|
||||
bitSet.remove(Enum.ResourceType.resourceLookup.get(itemBaseID));
|
||||
|
||||
worked = DbManager.WarehouseQueries.updateLocks(wh, bitSet.toLong());
|
||||
|
||||
if (worked) {
|
||||
wh.lockedResourceTypes.remove(Enum.ResourceType.resourceLookup.get(itemBaseID));
|
||||
ViewResourcesMessage vrm = new ViewResourcesMessage(player);
|
||||
vrm.setGuild(player.getGuild());
|
||||
vrm.setWarehouseBuilding(warehouse);
|
||||
vrm.configure();
|
||||
dispatch = Dispatch.borrow(player, vrm);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
EnumBitSet<Enum.ResourceType> bitSet = EnumBitSet.asEnumBitSet(wh.lockedResourceTypes.toLong(), Enum.ResourceType.class);
|
||||
|
||||
bitSet.add(Enum.ResourceType.resourceLookup.get(itemBaseID));
|
||||
|
||||
if (!DbManager.WarehouseQueries.updateLocks(wh, bitSet.toLong()))
|
||||
return;
|
||||
|
||||
wh.lockedResourceTypes.add(Enum.ResourceType.resourceLookup.get(itemBaseID));
|
||||
ViewResourcesMessage vrm = new ViewResourcesMessage(player);
|
||||
vrm.setGuild(player.getGuild());
|
||||
vrm.setWarehouseBuilding(warehouse);
|
||||
vrm.configure();
|
||||
dispatch = Dispatch.borrow(player, vrm);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
if (amount < 0) {
|
||||
Logger.info(pc.getFirstName() + " Attempting to Dupe!!!!!!");
|
||||
return false;
|
||||
}
|
||||
|
||||
ItemBase ib = resource.getItemBase();
|
||||
|
||||
if (ib == null)
|
||||
return false;
|
||||
|
||||
if (warehouse.resources.get(ib) == null)
|
||||
return false;
|
||||
|
||||
CharacterItemManager itemMan = pc.getCharItemManager();
|
||||
|
||||
if (itemMan == null)
|
||||
return false;
|
||||
|
||||
|
||||
if (itemMan.getGoldTrading() > 0) {
|
||||
ErrorPopupMsg.sendErrorPopup(pc, 195);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (!itemMan.doesCharOwnThisItem(resource.getObjectUUID()))
|
||||
return false;
|
||||
|
||||
if (!resource.validForInventory(origin, pc, itemMan))
|
||||
return false;
|
||||
|
||||
if (resource.getNumOfItems() < amount)
|
||||
return false;
|
||||
|
||||
int oldAmount = warehouse.resources.get(ib);
|
||||
|
||||
int newAmount = oldAmount + amount;
|
||||
|
||||
if (newAmount > getMaxResources().get(ib.getUUID())) {
|
||||
//ChatManager.chatSystemInfo(pc, "The Warehouse is at it's maximum for this type of resource.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (removeFromInventory) {
|
||||
if (ib.getUUID() == 7) {
|
||||
|
||||
if (itemMan.getGoldInventory().getNumOfItems() - amount < 0)
|
||||
return false;
|
||||
|
||||
if (itemMan.getGoldInventory().getNumOfItems() - amount > MBServerStatics.PLAYER_GOLD_LIMIT)
|
||||
return false;
|
||||
|
||||
if (!itemMan.modifyInventoryGold(-amount)) {
|
||||
//ChatManager.chatSystemError(pc, "You do not have this Gold.");
|
||||
return false;
|
||||
}
|
||||
|
||||
UpdateGoldMsg ugm = new UpdateGoldMsg(pc);
|
||||
ugm.configure();
|
||||
Dispatch dispatch = Dispatch.borrow(pc, ugm);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
|
||||
itemMan.updateInventory();
|
||||
|
||||
} else {
|
||||
itemMan.delete(resource);
|
||||
itemMan.updateInventory();
|
||||
}
|
||||
}
|
||||
itemMan.updateInventory();
|
||||
|
||||
if (!DepositApproved(ib,amount,warehouse))
|
||||
return false;
|
||||
|
||||
warehouse.resources.put(ib, newAmount);
|
||||
|
||||
Resource resourceType;
|
||||
|
||||
if (resource.getItemBase().getType().equals(Enum.ItemType.GOLD))
|
||||
resourceType = Resource.GOLD;
|
||||
else
|
||||
resourceType = Resource.valueOf(resource.getItemBase().getName().toUpperCase());
|
||||
|
||||
if (transaction)
|
||||
AddTransactionToWarehouse(warehouse, pc.getObjectType(), pc.getObjectUUID(), Enum.TransactionType.DEPOSIT, resourceType, amount);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static synchronized boolean depositFromMine(Mine mine, ItemBase resource, int amount, Warehouse warehouse) {
|
||||
|
||||
|
||||
|
||||
int oldAmount = warehouse.resources.get(resource);
|
||||
int newAmount = oldAmount + amount;
|
||||
|
||||
if (newAmount > getMaxResources().get(resource.getUUID()))
|
||||
return false;
|
||||
|
||||
if (!DepositApproved(resource,amount,warehouse))
|
||||
return false;
|
||||
|
||||
warehouse.resources.put(resource, newAmount);
|
||||
Resource resourceType;
|
||||
|
||||
if (resource.getUUID() == 7)
|
||||
resourceType = Resource.GOLD;
|
||||
else
|
||||
resourceType = Resource.valueOf(resource.getName().toUpperCase());
|
||||
|
||||
if (mine != null)
|
||||
AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, mine.getBuildingID(), Enum.TransactionType.MINE, resourceType, amount);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean DepositApproved(ItemBase ib, int amount, Warehouse warehouse){
|
||||
if (ib == null)
|
||||
return false;
|
||||
|
||||
if (warehouse.resources.get(ib) == null)
|
||||
return false;
|
||||
|
||||
int oldAmount = warehouse.resources.get(ib);
|
||||
int newAmount = oldAmount + amount;
|
||||
|
||||
if (newAmount > getMaxResources().get(ib.getUUID()))
|
||||
return false;
|
||||
|
||||
int itemID = ib.getUUID();
|
||||
boolean worked = false;
|
||||
|
||||
switch (itemID) {
|
||||
case 7:
|
||||
worked = DbManager.WarehouseQueries.updateGold(warehouse, newAmount);
|
||||
break;
|
||||
case 1580000:
|
||||
worked = DbManager.WarehouseQueries.updateStone(warehouse, newAmount);
|
||||
break;
|
||||
case 1580001:
|
||||
worked = DbManager.WarehouseQueries.updateTruesteel(warehouse, newAmount);
|
||||
break;
|
||||
case 1580002:
|
||||
worked = DbManager.WarehouseQueries.updateIron(warehouse, newAmount);
|
||||
break;
|
||||
case 1580003:
|
||||
worked = DbManager.WarehouseQueries.updateAdamant(warehouse, newAmount);
|
||||
break;
|
||||
case 1580004:
|
||||
worked = DbManager.WarehouseQueries.updateLumber(warehouse, newAmount);
|
||||
break;
|
||||
case 1580005:
|
||||
worked = DbManager.WarehouseQueries.updateOak(warehouse, newAmount);
|
||||
break;
|
||||
case 1580006:
|
||||
worked = DbManager.WarehouseQueries.updateBronzewood(warehouse, newAmount);
|
||||
break;
|
||||
case 1580007:
|
||||
worked = DbManager.WarehouseQueries.updateMandrake(warehouse, newAmount);
|
||||
break;
|
||||
case 1580008:
|
||||
worked = DbManager.WarehouseQueries.updateCoal(warehouse, newAmount);
|
||||
break;
|
||||
case 1580009:
|
||||
worked = DbManager.WarehouseQueries.updateAgate(warehouse, newAmount);
|
||||
break;
|
||||
case 1580010:
|
||||
worked = DbManager.WarehouseQueries.updateDiamond(warehouse, newAmount);
|
||||
break;
|
||||
case 1580011:
|
||||
worked = DbManager.WarehouseQueries.updateOnyx(warehouse, newAmount);
|
||||
break;
|
||||
case 1580012:
|
||||
worked = DbManager.WarehouseQueries.updateAzoth(warehouse, newAmount);
|
||||
break;
|
||||
case 1580013:
|
||||
worked = DbManager.WarehouseQueries.updateOrichalk(warehouse, newAmount);
|
||||
break;
|
||||
case 1580014:
|
||||
worked = DbManager.WarehouseQueries.updateAntimony(warehouse, newAmount);
|
||||
break;
|
||||
case 1580015:
|
||||
worked = DbManager.WarehouseQueries.updateSulfur(warehouse, newAmount);
|
||||
break;
|
||||
case 1580016:
|
||||
worked = DbManager.WarehouseQueries.updateQuicksilver(warehouse, newAmount);
|
||||
break;
|
||||
case 1580017:
|
||||
worked = DbManager.WarehouseQueries.updateGalvor(warehouse, newAmount);
|
||||
break;
|
||||
case 1580018:
|
||||
worked = DbManager.WarehouseQueries.updateWormwood(warehouse, newAmount);
|
||||
break;
|
||||
case 1580019:
|
||||
worked = DbManager.WarehouseQueries.updateObsidian(warehouse, newAmount);
|
||||
break;
|
||||
case 1580020:
|
||||
worked = DbManager.WarehouseQueries.updateBloodstone(warehouse, newAmount);
|
||||
break;
|
||||
case 1580021:
|
||||
worked = DbManager.WarehouseQueries.updateMithril(warehouse, newAmount);
|
||||
break;
|
||||
}
|
||||
return worked;
|
||||
}
|
||||
|
||||
public static synchronized void depositRealmTaxes(PlayerCharacter taxer, ItemBase ib, int amount, Warehouse warehouse) {
|
||||
|
||||
if (!DepositApproved(ib,amount,warehouse))
|
||||
return;
|
||||
|
||||
int oldAmount = warehouse.resources.get(ib);
|
||||
int newAmount = oldAmount + amount;
|
||||
warehouse.resources.put(ib, newAmount);
|
||||
Resource resourceType;
|
||||
|
||||
if (ib.getUUID() == 7)
|
||||
resourceType = Resource.GOLD;
|
||||
else
|
||||
resourceType = Resource.valueOf(ib.getName().toUpperCase());
|
||||
|
||||
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;
|
||||
|
||||
if (warehouse.resources.get(ib) == null)
|
||||
return;
|
||||
|
||||
int oldAmount = warehouse.resources.get(ib);
|
||||
int newAmount = oldAmount + amount;
|
||||
|
||||
if (newAmount > getMaxResources().get(ib.getUUID()))
|
||||
return;
|
||||
|
||||
if (!DepositApproved(ib,amount,warehouse))
|
||||
return;
|
||||
|
||||
warehouse.resources.put(ib, newAmount);
|
||||
Resource resourceType;
|
||||
|
||||
if (ib.getUUID() == 7)
|
||||
resourceType = Resource.GOLD;
|
||||
else
|
||||
resourceType = Resource.valueOf(ib.getName().toUpperCase());
|
||||
|
||||
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){
|
||||
|
||||
if (ib == null)
|
||||
return false;
|
||||
|
||||
if (warehouse.resources.get(ib) == null)
|
||||
return false;
|
||||
|
||||
if (amount <= 0)
|
||||
return false;
|
||||
|
||||
int oldAmount = warehouse.resources.get(ib);
|
||||
|
||||
if (oldAmount < amount)
|
||||
return false;
|
||||
|
||||
int hashID = ib.getHashID();
|
||||
int newAmount = oldAmount - amount;
|
||||
boolean worked = false;
|
||||
|
||||
switch (hashID) {
|
||||
case 2308551:
|
||||
worked = DbManager.WarehouseQueries.updateGold(warehouse, newAmount);
|
||||
break;
|
||||
case 74856115:
|
||||
worked = DbManager.WarehouseQueries.updateStone(warehouse, newAmount);
|
||||
break;
|
||||
case -317484979:
|
||||
worked = DbManager.WarehouseQueries.updateTruesteel(warehouse, newAmount);
|
||||
break;
|
||||
case 2504297:
|
||||
worked = DbManager.WarehouseQueries.updateIron(warehouse, newAmount);
|
||||
break;
|
||||
case -1741189964:
|
||||
worked = DbManager.WarehouseQueries.updateAdamant(warehouse, newAmount);
|
||||
break;
|
||||
case -1603256692:
|
||||
worked = DbManager.WarehouseQueries.updateLumber(warehouse, newAmount);
|
||||
break;
|
||||
case 74767:
|
||||
worked = DbManager.WarehouseQueries.updateOak(warehouse, newAmount);
|
||||
break;
|
||||
case 1334770447:
|
||||
worked = DbManager.WarehouseQueries.updateBronzewood(warehouse, newAmount);
|
||||
break;
|
||||
case 1191391799:
|
||||
worked = DbManager.WarehouseQueries.updateMandrake(warehouse, newAmount);
|
||||
break;
|
||||
case 2559427:
|
||||
worked = DbManager.WarehouseQueries.updateCoal(warehouse, newAmount);
|
||||
break;
|
||||
case 75173057:
|
||||
worked = DbManager.WarehouseQueries.updateAgate(warehouse, newAmount);
|
||||
break;
|
||||
case -1730704107:
|
||||
worked = DbManager.WarehouseQueries.updateDiamond(warehouse, newAmount);
|
||||
break;
|
||||
case 2977263:
|
||||
worked = DbManager.WarehouseQueries.updateOnyx(warehouse, newAmount);
|
||||
break;
|
||||
case 78329697:
|
||||
worked = DbManager.WarehouseQueries.updateAzoth(warehouse, newAmount);
|
||||
break;
|
||||
case -2036290524:
|
||||
worked = DbManager.WarehouseQueries.updateOrichalk(warehouse, newAmount);
|
||||
break;
|
||||
case 452320058:
|
||||
worked = DbManager.WarehouseQueries.updateAntimony(warehouse, newAmount);
|
||||
break;
|
||||
case -1586349421:
|
||||
worked = DbManager.WarehouseQueries.updateSulfur(warehouse, newAmount);
|
||||
break;
|
||||
case -472884509:
|
||||
worked = DbManager.WarehouseQueries.updateQuicksilver(warehouse, newAmount);
|
||||
break;
|
||||
case -1596311545:
|
||||
worked = DbManager.WarehouseQueries.updateGalvor(warehouse, newAmount);
|
||||
break;
|
||||
case 1532478436:
|
||||
worked = DbManager.WarehouseQueries.updateWormwood(warehouse, newAmount);
|
||||
break;
|
||||
case -697973233:
|
||||
worked = DbManager.WarehouseQueries.updateObsidian(warehouse, newAmount);
|
||||
break;
|
||||
case -1569826353:
|
||||
worked = DbManager.WarehouseQueries.updateBloodstone(warehouse, newAmount);
|
||||
break;
|
||||
case -1761257186:
|
||||
worked = DbManager.WarehouseQueries.updateMithril(warehouse, newAmount);
|
||||
break;
|
||||
}
|
||||
return worked;
|
||||
}
|
||||
|
||||
public static synchronized boolean withdraw(Warehouse warehouse, NPC npc, ItemBase ib, int amount, boolean transaction) {
|
||||
|
||||
int oldAmount = warehouse.resources.get(ib);
|
||||
|
||||
int newAmount = oldAmount - amount;
|
||||
|
||||
if (!WithdrawApproved(ib,amount, warehouse))
|
||||
return false;
|
||||
|
||||
warehouse.resources.put(ib, newAmount);
|
||||
Resource resourceType;
|
||||
|
||||
if (ib.getUUID() == 7)
|
||||
resourceType = Resource.GOLD;
|
||||
else
|
||||
resourceType = Resource.valueOf(ib.getName().toUpperCase());
|
||||
|
||||
if (transaction)
|
||||
AddTransactionToWarehouse(warehouse, npc.getObjectType(), npc.getObjectUUID(), Enum.TransactionType.WITHDRAWL, resourceType, amount);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static synchronized void transferResources(Warehouse warehouse, PlayerCharacter taxer, TaxResourcesMsg msg, ArrayList<Integer> realmResources, float taxPercent) {
|
||||
|
||||
for (int ibID : realmResources) {
|
||||
|
||||
ItemBase ib = ItemBase.getItemBase(ibID);
|
||||
|
||||
if (ib == null)
|
||||
return;
|
||||
|
||||
if (warehouse.resources.get(ib) == null)
|
||||
return;
|
||||
|
||||
int amount = (int) (warehouse.resources.get(ib) * taxPercent);
|
||||
|
||||
if (amount <= 0) {
|
||||
msg.getResources().put(ib.getHashID(), 0);
|
||||
continue;
|
||||
}
|
||||
|
||||
int oldAmount = warehouse.resources.get(ib);
|
||||
|
||||
if (oldAmount < amount)
|
||||
amount = oldAmount;
|
||||
|
||||
int newAmount = oldAmount - amount;
|
||||
|
||||
if (newAmount < amount)
|
||||
continue;
|
||||
|
||||
if (!WithdrawApproved(ib,amount,warehouse)) {
|
||||
msg.getResources().put(ib.getHashID(), 0);
|
||||
continue;
|
||||
}
|
||||
|
||||
msg.getResources().put(ib.getHashID(), amount);
|
||||
|
||||
warehouse.resources.put(ib, newAmount);
|
||||
depositRealmTaxes(taxer, ib, amount, warehouse);
|
||||
Resource resourceType;
|
||||
|
||||
if (ib.getUUID() == 7)
|
||||
resourceType = Resource.GOLD;
|
||||
else
|
||||
resourceType = Resource.valueOf(ib.getName().toUpperCase());
|
||||
|
||||
AddTransactionToWarehouse(warehouse, taxer.getObjectType(), taxer.getObjectUUID(), Enum.TransactionType.TAXRESOURCE, resourceType, amount);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized boolean withdraw(Warehouse warehouse, PlayerCharacter pc, ItemBase ib, int amount, boolean addToInventory, boolean transaction) {
|
||||
|
||||
if (pc == null)
|
||||
return false;
|
||||
|
||||
if (ib == null)
|
||||
return false;
|
||||
|
||||
if (warehouse.resources.get(ib) == null)
|
||||
return false;
|
||||
|
||||
if (amount <= 0)
|
||||
return false;
|
||||
|
||||
CharacterItemManager itemMan = pc.getCharItemManager();
|
||||
|
||||
if (itemMan == null)
|
||||
return false;
|
||||
|
||||
if (addToInventory)
|
||||
if (!itemMan.hasRoomInventory(ib.getWeight())) {
|
||||
ChatManager.chatSystemInfo(pc, "You can not carry any more of that item.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (addToInventory && ib.getUUID() == ItemBase.GOLD_BASE_ID) {
|
||||
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);
|
||||
|
||||
if (oldAmount < amount)
|
||||
return false;
|
||||
|
||||
int newAmount = oldAmount - amount;
|
||||
|
||||
|
||||
if (!WithdrawApproved(ib,amount,warehouse))
|
||||
return false;
|
||||
|
||||
warehouse.resources.put(ib, newAmount);
|
||||
|
||||
if (addToInventory) {
|
||||
if (ib.getUUID() == 7) {
|
||||
|
||||
itemMan.addGoldToInventory(amount, false);
|
||||
UpdateGoldMsg ugm = new UpdateGoldMsg(pc);
|
||||
ugm.configure();
|
||||
Dispatch dispatch = Dispatch.borrow(pc, ugm);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
|
||||
itemMan.updateInventory();
|
||||
} else {
|
||||
boolean itemWorked = false;
|
||||
Item item = new Item(ib, pc.getObjectUUID(), Enum.OwnerType.PlayerCharacter, (byte) 0, (byte) 0,
|
||||
(short) 1, (short) 1, true, false, Enum.ItemContainerType.INVENTORY, (byte) 0,
|
||||
new ArrayList<>(), "");
|
||||
item.setNumOfItems(amount);
|
||||
item.containerType = Enum.ItemContainerType.INVENTORY;
|
||||
|
||||
try {
|
||||
item = DbManager.ItemQueries.ADD_ITEM(item);
|
||||
itemWorked = true;
|
||||
} catch (Exception e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
if (itemWorked) {
|
||||
itemMan.addItemToInventory(item);
|
||||
itemMan.updateInventory();
|
||||
}
|
||||
}
|
||||
}
|
||||
Resource resourceType;
|
||||
|
||||
if (ib.getUUID() == 7)
|
||||
resourceType = Resource.GOLD;
|
||||
else
|
||||
resourceType = Resource.valueOf(ib.getName().toUpperCase());
|
||||
|
||||
if (transaction)
|
||||
AddTransactionToWarehouse(warehouse, pc.getObjectType(), pc.getObjectUUID(), Enum.TransactionType.WITHDRAWL, resourceType, amount);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static synchronized boolean loot(Warehouse warehouse, PlayerCharacter pc, ItemBase ib, int amount, boolean addToInventory) {
|
||||
|
||||
if (pc == null)
|
||||
return false;
|
||||
|
||||
if (ib == null)
|
||||
return false;
|
||||
|
||||
if (warehouse.resources.get(ib) == null)
|
||||
return false;
|
||||
|
||||
if (amount <= 0)
|
||||
return false;
|
||||
|
||||
CharacterItemManager itemMan = pc.getCharItemManager();
|
||||
|
||||
if (itemMan == null)
|
||||
return false;
|
||||
|
||||
if (!itemMan.hasRoomInventory(ib.getWeight())) {
|
||||
ChatManager.chatSystemInfo(pc, "You can not carry any more of that item.");
|
||||
return false;
|
||||
}
|
||||
|
||||
int oldAmount = warehouse.resources.get(ib);
|
||||
|
||||
if (oldAmount < amount)
|
||||
return false;
|
||||
|
||||
int newAmount = oldAmount - amount;
|
||||
|
||||
warehouse.resources.put(ib, newAmount);
|
||||
|
||||
if (addToInventory) {
|
||||
if (ib.getUUID() == 7) {
|
||||
|
||||
itemMan.addGoldToInventory(amount, false);
|
||||
UpdateGoldMsg ugm = new UpdateGoldMsg(pc);
|
||||
ugm.configure();
|
||||
Dispatch dispatch = Dispatch.borrow(pc, ugm);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
|
||||
itemMan.updateInventory();
|
||||
} else {
|
||||
boolean itemWorked = false;
|
||||
Item item = new Item(ib, pc.getObjectUUID(), Enum.OwnerType.PlayerCharacter, (byte) 0, (byte) 0,
|
||||
(short) 1, (short) 1, true, false, Enum.ItemContainerType.INVENTORY, (byte) 0,
|
||||
new ArrayList<>(), "");
|
||||
item.setNumOfItems(amount);
|
||||
item.containerType = Enum.ItemContainerType.INVENTORY;
|
||||
|
||||
try {
|
||||
item = DbManager.ItemQueries.ADD_ITEM(item);
|
||||
itemWorked = true;
|
||||
} catch (Exception e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
if (itemWorked) {
|
||||
itemMan.addItemToInventory(item);
|
||||
itemMan.updateInventory();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isEmpty(Warehouse warehouse) {
|
||||
int amount = 0;
|
||||
for (ItemBase ib : ItemBase.getResourceList()) {
|
||||
if (amount > 0)
|
||||
return false;
|
||||
amount += warehouse.resources.get(ib);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void loadAllTransactions(Warehouse warehouse) {
|
||||
warehouse.transactions = DbManager.WarehouseQueries.GET_TRANSACTIONS_FOR_WAREHOUSE(warehouse.buildingUID);
|
||||
}
|
||||
|
||||
public static void AddTransactionToWarehouse(Warehouse warehouse, Enum.GameObjectType targetType, int targetUUID, Enum.TransactionType transactionType, Resource resource, int amount) {
|
||||
|
||||
|
||||
if (!DbManager.WarehouseQueries.CREATE_TRANSACTION(warehouse.buildingUID, targetType, targetUUID, transactionType, resource, amount, DateTime.now()))
|
||||
return;
|
||||
|
||||
Transaction transaction = new Transaction(warehouse.buildingUID, targetType, targetUUID, transactionType, resource, amount, DateTime.now());
|
||||
warehouse.transactions.add(transaction);
|
||||
}
|
||||
|
||||
public static boolean isAboveCap(Warehouse warehouse, ItemBase ib, int deposit) {
|
||||
int newAmount = warehouse.resources.get(ib) + deposit;
|
||||
return newAmount > getMaxResources().get(ib.getUUID());
|
||||
|
||||
}
|
||||
|
||||
public static boolean isResourceLocked(Warehouse warehouse, ItemBase itemBase) {
|
||||
|
||||
Enum.ResourceType resourceType;
|
||||
|
||||
resourceType = Enum.ResourceType.resourceLookup.get(itemBase.getUUID());
|
||||
|
||||
return resourceType.elementOf(warehouse.lockedResourceTypes);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -96,7 +910,7 @@ public class Warehouse extends AbstractWorldObject {
|
||||
return;
|
||||
}
|
||||
|
||||
WarehouseManager.warehouseByBuildingUUID.put(this.buildingUID, this);
|
||||
warehouseByBuildingUUID.put(this.buildingUID, this);
|
||||
city.setWarehouseBuildingID(this.buildingUID);
|
||||
} catch (Exception E) {
|
||||
Logger.info(this.getObjectUUID() + " failed");
|
||||
|
||||
Reference in New Issue
Block a user