|
|
|
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
|
|
|
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
|
|
|
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
|
|
|
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
|
|
|
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
|
|
|
// Magicbane Emulator Project © 2013 - 2022
|
|
|
|
// www.magicbane.com
|
|
|
|
|
|
|
|
|
|
|
|
package engine.objects;
|
|
|
|
|
|
|
|
import ch.claude_martin.enumbitset.EnumBitSet;
|
|
|
|
import engine.Enum;
|
|
|
|
import engine.gameManager.BuildingManager;
|
|
|
|
import engine.gameManager.WarehouseManager;
|
|
|
|
import org.pmw.tinylog.Logger;
|
|
|
|
import java.sql.ResultSet;
|
|
|
|
import java.sql.SQLException;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
|
|
|
public class Warehouse extends AbstractWorldObject {
|
|
|
|
|
|
|
|
|
|
|
|
public EnumBitSet<Enum.ResourceType> lockedResourceTypes;
|
|
|
|
public int UID;
|
|
|
|
public int buildingUID;
|
|
|
|
public ArrayList<Transaction> transactions = new ArrayList<>();
|
|
|
|
public ConcurrentHashMap<ItemBase, Integer> resources = new ConcurrentHashMap<>();
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ResultSet Constructor
|
|
|
|
*/
|
|
|
|
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.lockedResourceTypes = EnumBitSet.asEnumBitSet(rs.getLong("warehouse_locks"), Enum.ResourceType.class);
|
|
|
|
this.buildingUID = rs.getInt("parent");
|
|
|
|
WarehouseManager.warehouseByBuildingUUID.put(this.buildingUID, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void updateDatabase() {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void runAfterLoad() {
|
|
|
|
|
|
|
|
try {
|
|
|
|
Building warehouseBuilding = BuildingManager.getBuilding(this.buildingUID);
|
|
|
|
Logger.info("configuring warehouse " + UID + " for city " + warehouseBuilding.getCity().getCityName() + " structure UUID " + this.buildingUID);
|
|
|
|
|
|
|
|
//Building is gone, but Warehouse still in DB?? Should never happen, sanity check anyway.
|
|
|
|
if (warehouseBuilding == null) {
|
|
|
|
Logger.error("Failed to load Building for Warehouse");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Zone cityZone = warehouseBuilding.getParentZone();
|
|
|
|
|
|
|
|
if (cityZone == null) {
|
|
|
|
Logger.error("Failed to load Zone for Warehouse with UUID " + this.getObjectUUID());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
City city = City.getCity(cityZone.playerCityUUID);
|
|
|
|
|
|
|
|
if (city == null) {
|
|
|
|
Logger.error("Failed to load City for Warehouse with UUID " + this.getObjectUUID());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
WarehouseManager.warehouseByBuildingUUID.put(this.buildingUID, this);
|
|
|
|
city.setWarehouseBuildingID(this.buildingUID);
|
|
|
|
} catch (Exception E) {
|
|
|
|
Logger.info(this.getObjectUUID() + " failed");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|