Browse Source

Refactored out duplicate resource type.

combat-2
MagicBot 8 months ago
parent
commit
4646d03bdd
  1. 3
      src/engine/db/handlers/dbMineHandler.java
  2. 8
      src/engine/db/handlers/dbWarehouseHandler.java
  3. 10
      src/engine/gameManager/MaintenanceManager.java
  4. 4
      src/engine/net/client/handlers/ArcMineChangeProductionMsgHandler.java
  5. 29
      src/engine/objects/Mine.java
  6. 66
      src/engine/objects/MineProduction.java
  7. 10
      src/engine/objects/Realm.java
  8. 70
      src/engine/objects/Resource.java
  9. 9
      src/engine/objects/Transaction.java
  10. 44
      src/engine/objects/Warehouse.java

3
src/engine/db/handlers/dbMineHandler.java

@ -12,7 +12,6 @@ import engine.Enum; @@ -12,7 +12,6 @@ import engine.Enum;
import engine.gameManager.DbManager;
import engine.objects.Mine;
import engine.objects.MineProduction;
import engine.objects.Resource;
import org.pmw.tinylog.Logger;
import java.sql.Connection;
@ -84,7 +83,7 @@ public class dbMineHandler extends dbHandlerBase { @@ -84,7 +83,7 @@ public class dbMineHandler extends dbHandlerBase {
return false;
}
public boolean CHANGE_RESOURCE(Mine mine, Resource resource) {
public boolean CHANGE_RESOURCE(Mine mine, Enum.ResourceType resource) {
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_mine` SET `mine_resource`=? WHERE `UID`=?")) {

8
src/engine/db/handlers/dbWarehouseHandler.java

@ -9,12 +9,16 @@ @@ -9,12 +9,16 @@
package engine.db.handlers;
import engine.Enum;
import engine.Enum.GameObjectType;
import engine.Enum.ProtectionState;
import engine.Enum.TransactionType;
import engine.gameManager.DbManager;
import engine.math.Vector3fImmutable;
import engine.objects.*;
import engine.objects.AbstractGameObject;
import engine.objects.Building;
import engine.objects.Transaction;
import engine.objects.Warehouse;
import engine.server.MBServerStatics;
import org.joda.time.DateTime;
import org.pmw.tinylog.Logger;
@ -487,7 +491,7 @@ public class dbWarehouseHandler extends dbHandlerBase { @@ -487,7 +491,7 @@ public class dbWarehouseHandler extends dbHandlerBase {
return false;
}
public boolean CREATE_TRANSACTION(int warehouseBuildingID, GameObjectType targetType, int targetUUID, TransactionType transactionType, Resource resource, int amount, DateTime date) {
public boolean CREATE_TRANSACTION(int warehouseBuildingID, GameObjectType targetType, int targetUUID, TransactionType transactionType, Enum.ResourceType resource, int amount, DateTime date) {
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_warehouse_transactions` (`warehouseUID`, `targetType`,`targetUID`, `type`,`resource`,`amount`,`date` ) VALUES (?,?,?,?,?,?,?)")) {

10
src/engine/gameManager/MaintenanceManager.java

@ -251,7 +251,7 @@ public enum MaintenanceManager { @@ -251,7 +251,7 @@ public enum MaintenanceManager {
if (DbManager.WarehouseQueries.updateGold(warehouse, resourceValue - overDraft) == true) {
warehouse.resources.put(ItemBase.getItemBase(7), resourceValue - overDraft);
Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, building.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Resource.GOLD, overDraft);
Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, building.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Enum.ResourceType.GOLD, overDraft);
} else {
Logger.error("gold update failed for warehouse of UUID:" + warehouse.getObjectUUID());
return true;
@ -271,7 +271,7 @@ public enum MaintenanceManager { @@ -271,7 +271,7 @@ public enum MaintenanceManager {
if (DbManager.WarehouseQueries.updateStone(warehouse, resourceValue - 1500) == true) {
warehouse.resources.put(ItemBase.getItemBase(1580000), resourceValue - 1500);
Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, building.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Resource.STONE, 1500);
Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, building.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Enum.ResourceType.STONE, 1500);
} else {
Logger.error("stone update failed for warehouse of UUID:" + warehouse.getObjectUUID());
return true;
@ -283,7 +283,7 @@ public enum MaintenanceManager { @@ -283,7 +283,7 @@ public enum MaintenanceManager {
if (DbManager.WarehouseQueries.updateLumber(warehouse, resourceValue - 1500) == true) {
warehouse.resources.put(ItemBase.getItemBase(1580004), resourceValue - 1500);
Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, building.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Resource.LUMBER, 1500);
Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, building.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Enum.ResourceType.LUMBER, 1500);
} else {
Logger.error("lumber update failed for warehouse of UUID:" + warehouse.getObjectUUID());
return true;
@ -295,7 +295,7 @@ public enum MaintenanceManager { @@ -295,7 +295,7 @@ public enum MaintenanceManager {
if (DbManager.WarehouseQueries.updateGalvor(warehouse, resourceValue - 5) == true) {
warehouse.resources.put(ItemBase.getItemBase(1580017), resourceValue - 5);
Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, building.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Resource.GALVOR, 5);
Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, building.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Enum.ResourceType.GALVOR, 5);
} else {
Logger.error("galvor update failed for warehouse of UUID:" + warehouse.getObjectUUID());
return true;
@ -305,7 +305,7 @@ public enum MaintenanceManager { @@ -305,7 +305,7 @@ public enum MaintenanceManager {
if (DbManager.WarehouseQueries.updateWormwood(warehouse, resourceValue - 5) == true) {
warehouse.resources.put(ItemBase.getItemBase(1580018), resourceValue - 5);
Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, building.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Resource.WORMWOOD, 5);
Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, building.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Enum.ResourceType.WORMWOOD, 5);
} else {
Logger.error("wyrmwood update failed for warehouse of UUID:" + warehouse.getObjectUUID());
}

4
src/engine/net/client/handlers/ArcMineChangeProductionMsgHandler.java

@ -1,5 +1,6 @@ @@ -1,5 +1,6 @@
package engine.net.client.handlers;
import engine.Enum;
import engine.Enum.DispatchChannel;
import engine.exception.MsgSendException;
import engine.net.Dispatch;
@ -10,7 +11,6 @@ import engine.net.client.msg.ClientNetMsg; @@ -10,7 +11,6 @@ import engine.net.client.msg.ClientNetMsg;
import engine.objects.GuildStatusController;
import engine.objects.Mine;
import engine.objects.PlayerCharacter;
import engine.objects.Resource;
/*
* @Author:
@ -51,7 +51,7 @@ public class ArcMineChangeProductionMsgHandler extends AbstractClientMsgHandler @@ -51,7 +51,7 @@ public class ArcMineChangeProductionMsgHandler extends AbstractClientMsgHandler
//make sure valid resource
Resource resource = Resource.resourceByHash.get(changeProductionMsg.getResourceHash());
Enum.ResourceType resource = Enum.ResourceType.hashLookup.get(changeProductionMsg.getResourceHash());
if (resource == null)
return true;

29
src/engine/objects/Mine.java

@ -11,7 +11,10 @@ package engine.objects; @@ -11,7 +11,10 @@ package engine.objects;
import engine.Enum;
import engine.InterestManagement.WorldGrid;
import engine.gameManager.*;
import engine.gameManager.BuildingManager;
import engine.gameManager.ChatManager;
import engine.gameManager.DbManager;
import engine.gameManager.ZoneManager;
import engine.net.ByteBufferWriter;
import engine.net.client.msg.ErrorPopupMsg;
import engine.server.MBServerStatics;
@ -42,7 +45,7 @@ public class Mine extends AbstractGameObject { @@ -42,7 +45,7 @@ public class Mine extends AbstractGameObject {
public GuildTag guildTag;
public String nationName;
public GuildTag nationTag;
private Resource production;
private Enum.ResourceType production;
private Guild owningGuild;
private int flags;
private int buildingID;
@ -85,7 +88,7 @@ public class Mine extends AbstractGameObject { @@ -85,7 +88,7 @@ public class Mine extends AbstractGameObject {
this.nationTag = GuildTag.ERRANT;
}
this.production = Resource.valueOf(rs.getString("mine_resource"));
this.production = Enum.ResourceType.valueOf(rs.getString("mine_resource"));
this.lastClaimer = null;
}
@ -164,7 +167,7 @@ public class Mine extends AbstractGameObject { @@ -164,7 +167,7 @@ public class Mine extends AbstractGameObject {
writer.putString(mine.mineType.name);
writer.putString(mine.zoneName);
writer.putInt(mine.production.hash);
writer.putInt(mine.production.baseProduction);
writer.putInt(mine.production.mine_production);
writer.putInt(mine.getModifiedProductionAmount()); //TODO calculate range penalty here
writer.putInt(3600); //window in seconds
@ -307,7 +310,7 @@ public class Mine extends AbstractGameObject { @@ -307,7 +310,7 @@ public class Mine extends AbstractGameObject {
return mineCnt <= tolRank;
}
public boolean changeProductionType(Resource resource) {
public boolean changeProductionType(Enum.ResourceType resource) {
if (!this.validForMine(resource))
return false;
//update resource in database;
@ -330,7 +333,7 @@ public class Mine extends AbstractGameObject { @@ -330,7 +333,7 @@ public class Mine extends AbstractGameObject {
return this.zoneName;
}
public Resource getProduction() {
public Enum.ResourceType getProduction() {
return this.production;
}
@ -377,7 +380,7 @@ public class Mine extends AbstractGameObject { @@ -377,7 +380,7 @@ public class Mine extends AbstractGameObject {
building.isDeranking.compareAndSet(true, false);
}
public boolean validForMine(Resource r) {
public boolean validForMine(Enum.ResourceType r) {
if (this.mineType == null)
return false;
return this.mineType.validForMine(r, this.isExpansion());
@ -391,7 +394,7 @@ public class Mine extends AbstractGameObject { @@ -391,7 +394,7 @@ public class Mine extends AbstractGameObject {
writer.putString(this.mineType.name);
writer.putString(this.zoneName);
writer.putInt(this.production.hash);
writer.putInt(this.production.baseProduction);
writer.putInt(this.production.mine_production);
writer.putInt(this.getModifiedProductionAmount()); //TODO calculate range penalty here
writer.putInt(3600); //window in seconds
writer.putInt(this.isExpansion() ? this.mineType.xpacHash : this.mineType.hash);
@ -479,7 +482,7 @@ public class Mine extends AbstractGameObject { @@ -479,7 +482,7 @@ public class Mine extends AbstractGameObject {
if (this.owningGuild.getOwnedCity().getWarehouse() == null)
return false;
ItemBase resourceIB = ItemBase.getItemBase(this.production.UUID);
ItemBase resourceIB = ItemBase.getItemBase(this.production.templateID);
return Warehouse.depositFromMine(this, resourceIB, this.getModifiedProductionAmount(),this.owningGuild.getOwnedCity().getWarehouse());
}
@ -538,15 +541,15 @@ public class Mine extends AbstractGameObject { @@ -538,15 +541,15 @@ public class Mine extends AbstractGameObject {
//TODO Calculate Distance modifications.
//calculate base values.
int baseProduction = this.production.baseProduction;
float baseModValue = this.production.baseProduction * .1f;
float rankModValue = this.production.baseProduction * .0143f;
int baseProduction = this.production.mine_production;
float baseModValue = this.production.mine_production * .1f;
float rankModValue = this.production.mine_production * .0143f;
float totalModded = 0;
//get Mine Building.
Building mineBuilding = BuildingManager.getBuilding(this.buildingID);
if (mineBuilding == null)
return this.production.baseProduction;
return this.production.mine_production;
for (AbstractCharacter harvester : mineBuilding.getHirelings().keySet()) {
totalModded += baseModValue;
totalModded += rankModValue * harvester.getRank();

66
src/engine/objects/MineProduction.java

@ -9,22 +9,24 @@ @@ -9,22 +9,24 @@
package engine.objects;
import engine.Enum;
import java.util.HashMap;
public enum MineProduction {
LUMBER("Lumber Camp", new HashMap<>(), Resource.WORMWOOD, 1618637196, 1663491950),
ORE("Ore Mine", new HashMap<>(), Resource.OBSIDIAN, 518103023, -788976428),
GOLD("Gold Mine", new HashMap<>(), Resource.GALVOR, -662193002, -1227205358),
MAGIC("Magic Mine", new HashMap<>(), Resource.BLOODSTONE, 504746863, -1753567069);
LUMBER("Lumber Camp", new HashMap<>(), Enum.ResourceType.WORMWOOD, 1618637196, 1663491950),
ORE("Ore Mine", new HashMap<>(), Enum.ResourceType.OBSIDIAN, 518103023, -788976428),
GOLD("Gold Mine", new HashMap<>(), Enum.ResourceType.GALVOR, -662193002, -1227205358),
MAGIC("Magic Mine", new HashMap<>(), Enum.ResourceType.BLOODSTONE, 504746863, -1753567069);
public final String name;
public final HashMap<Integer, Resource> resources;
public final Resource xpac;
public final HashMap<Integer, Enum.ResourceType> resources;
public final Enum.ResourceType xpac;
public final int hash;
public final int xpacHash;
MineProduction(String name, HashMap<Integer, Resource> resources, Resource xpac, int hash, int xpacHash) {
MineProduction(String name, HashMap<Integer, Enum.ResourceType> resources, Enum.ResourceType xpac, int hash, int xpacHash) {
this.name = name;
this.resources = resources;
this.xpac = xpac;
@ -34,34 +36,34 @@ public enum MineProduction { @@ -34,34 +36,34 @@ public enum MineProduction {
public static void addResources() {
if (MineProduction.LUMBER.resources.size() == 0) {
MineProduction.LUMBER.resources.put(7, Resource.GOLD);
MineProduction.LUMBER.resources.put(1580004, Resource.LUMBER);
MineProduction.LUMBER.resources.put(1580005, Resource.OAK);
MineProduction.LUMBER.resources.put(1580006, Resource.BRONZEWOOD);
MineProduction.LUMBER.resources.put(1580007, Resource.MANDRAKE);
MineProduction.LUMBER.resources.put(7, Enum.ResourceType.GOLD);
MineProduction.LUMBER.resources.put(1580004, Enum.ResourceType.LUMBER);
MineProduction.LUMBER.resources.put(1580005, Enum.ResourceType.OAK);
MineProduction.LUMBER.resources.put(1580006, Enum.ResourceType.BRONZEWOOD);
MineProduction.LUMBER.resources.put(1580007, Enum.ResourceType.MANDRAKE);
}
if (MineProduction.ORE.resources.size() == 0) {
MineProduction.ORE.resources.put(7, Resource.GOLD);
MineProduction.ORE.resources.put(1580000, Resource.STONE);
MineProduction.ORE.resources.put(1580001, Resource.TRUESTEEL);
MineProduction.ORE.resources.put(1580002, Resource.IRON);
MineProduction.ORE.resources.put(1580003, Resource.ADAMANT);
MineProduction.ORE.resources.put(7, Enum.ResourceType.GOLD);
MineProduction.ORE.resources.put(1580000, Enum.ResourceType.STONE);
MineProduction.ORE.resources.put(1580001, Enum.ResourceType.TRUESTEEL);
MineProduction.ORE.resources.put(1580002, Enum.ResourceType.IRON);
MineProduction.ORE.resources.put(1580003, Enum.ResourceType.ADAMANT);
}
if (MineProduction.GOLD.resources.size() == 0) {
MineProduction.GOLD.resources.put(7, Resource.GOLD);
MineProduction.GOLD.resources.put(1580000, Resource.STONE);
MineProduction.GOLD.resources.put(1580008, Resource.COAL);
MineProduction.GOLD.resources.put(1580009, Resource.AGATE);
MineProduction.GOLD.resources.put(1580010, Resource.DIAMOND);
MineProduction.GOLD.resources.put(1580011, Resource.ONYX);
MineProduction.GOLD.resources.put(7, Enum.ResourceType.GOLD);
MineProduction.GOLD.resources.put(1580000, Enum.ResourceType.STONE);
MineProduction.GOLD.resources.put(1580008, Enum.ResourceType.COAL);
MineProduction.GOLD.resources.put(1580009, Enum.ResourceType.AGATE);
MineProduction.GOLD.resources.put(1580010, Enum.ResourceType.DIAMOND);
MineProduction.GOLD.resources.put(1580011, Enum.ResourceType.ONYX);
}
if (MineProduction.MAGIC.resources.size() == 0) {
MineProduction.MAGIC.resources.put(7, Resource.GOLD);
MineProduction.MAGIC.resources.put(1580012, Resource.AZOTH);
MineProduction.MAGIC.resources.put(1580013, Resource.ORICHALK);
MineProduction.MAGIC.resources.put(1580014, Resource.ANTIMONY);
MineProduction.MAGIC.resources.put(1580015, Resource.SULFUR);
MineProduction.MAGIC.resources.put(1580016, Resource.QUICKSILVER);
MineProduction.MAGIC.resources.put(7, Enum.ResourceType.GOLD);
MineProduction.MAGIC.resources.put(1580012, Enum.ResourceType.AZOTH);
MineProduction.MAGIC.resources.put(1580013, Enum.ResourceType.ORICHALK);
MineProduction.MAGIC.resources.put(1580014, Enum.ResourceType.ANTIMONY);
MineProduction.MAGIC.resources.put(1580015, Enum.ResourceType.SULFUR);
MineProduction.MAGIC.resources.put(1580016, Enum.ResourceType.QUICKSILVER);
}
}
@ -76,13 +78,13 @@ public enum MineProduction { @@ -76,13 +78,13 @@ public enum MineProduction {
return MineProduction.MAGIC;
}
public boolean validForMine(Resource r, boolean isXpac) {
public boolean validForMine(Enum.ResourceType r, boolean isXpac) {
if (r == null)
return false;
if (this.resources.containsKey(r.UUID))
if (this.resources.containsKey(r.templateID))
return true;
else
return isXpac && r.UUID == this.xpac.UUID;
return isXpac && r.templateID == this.xpac.templateID;
}

10
src/engine/objects/Realm.java

@ -270,7 +270,7 @@ public class Realm { @@ -270,7 +270,7 @@ public class Realm {
if (DbManager.WarehouseQueries.updateGold(warehouse, resourceValue - 5000000) == true) {
warehouse.resources.put(ItemBase.getItemBase(7), resourceValue - 5000000);
Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Resource.GOLD, 5000000);
Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Enum.ResourceType.GOLD, 5000000);
} else {
Logger.error("gold update failed for warehouse of UUID:" + warehouse.getObjectUUID());
return false;
@ -280,7 +280,7 @@ public class Realm { @@ -280,7 +280,7 @@ public class Realm {
if (DbManager.WarehouseQueries.updateStone(warehouse, resourceValue - 8000) == true) {
warehouse.resources.put(ItemBase.getItemBase(1580000), resourceValue - 8000);
Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Resource.STONE, 8000);
Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Enum.ResourceType.STONE, 8000);
} else {
Logger.error("stone update failed for warehouse of UUID:" + warehouse.getObjectUUID());
return false;
@ -290,7 +290,7 @@ public class Realm { @@ -290,7 +290,7 @@ public class Realm {
if (DbManager.WarehouseQueries.updateLumber(warehouse, resourceValue - 8000) == true) {
warehouse.resources.put(ItemBase.getItemBase(1580004), resourceValue - 8000);
Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Resource.LUMBER, 8000);
Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Enum.ResourceType.LUMBER, 8000);
} else {
Logger.error("lumber update failed for warehouse of UUID:" + warehouse.getObjectUUID());
return false;
@ -300,7 +300,7 @@ public class Realm { @@ -300,7 +300,7 @@ public class Realm {
if (DbManager.WarehouseQueries.updateGalvor(warehouse, resourceValue - 15) == true) {
warehouse.resources.put(ItemBase.getItemBase(1580017), resourceValue - 15);
Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Resource.GALVOR, 15);
Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Enum.ResourceType.GALVOR, 15);
} else {
Logger.error("galvor update failed for warehouse of UUID:" + warehouse.getObjectUUID());
return false;
@ -310,7 +310,7 @@ public class Realm { @@ -310,7 +310,7 @@ public class Realm {
if (DbManager.WarehouseQueries.updateWormwood(warehouse, resourceValue - 15) == true) {
warehouse.resources.put(ItemBase.getItemBase(1580018), resourceValue - 15);
Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Resource.WORMWOOD, 15);
Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Enum.ResourceType.WORMWOOD, 15);
} else {
Logger.error("wormwood update failed for warehouse of UUID:" + warehouse.getObjectUUID());
return false;

70
src/engine/objects/Resource.java

@ -1,70 +0,0 @@ @@ -1,70 +0,0 @@
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
package engine.objects;
import engine.server.MBServerStatics;
import java.util.concurrent.ConcurrentHashMap;
public enum Resource {
ADAMANT("DefaultAdamant", 1557001525, 10, 1580003),
AGATE("DefaultAgate", -1096157543, 20, 1580009),
ANTIMONY("DefaultAntimony", 1256147265, 10, 1580014),
AZOTH("DefaultAzoth", -1205326951, 20, 1580012),
BLOODSTONE("DefaultBloodstone", -1912381716, 5, 1580020),
BRONZEWOOD("DefaultBronzewood", -519681813, 30, 1580006),
COAL("DefaultCoal", -1672872311, 30, 1580008),
DIAMOND("DefaultDiamond", 1540225085, 20, 1580010),
GALVOR("DefaultGalvor", -1683992404, 5, 1580017),
IRON("DefaultIron", -1673518119, 20, 1580002),
LUMBER("DefaultLumber", -1628412684, 100, 1580004),
MANDRAKE("DefaultMandrake", -1519910613, 10, 1580007),
MITHRIL("DefaultMithril", 626743397, 5, 1580021),
OAK("DefaultOak", -1653034775, 30, 1580005),
OBSIDIAN("DefaultObsidian", 778019055, 5, 1580019),
ONYX("DefaultOnyx", -1675952151, 10, 1580011),
ORICHALK("DefaultOrichalk", -1468730955, 30, 1580013),
QUICKSILVER("DefaultQuicksilver", -2081208434, 10, 1580016),
STONE("DefaultStone", -1094703863, 100, 1580000),
SULFUR("DefaultSulfur", -1763687412, 10, 1580015),
TRUESTEEL("DefaultTruesteel", -169012482, 20, 1580001),
WORMWOOD("DefaultWormwood", 1204785075, 5, 1580018),
GOLD("DefaultGold", -1670881623, 50000, 7);
public static ConcurrentHashMap<Integer, Resource> resourceByHash;
//load lookups via hashes
static {
resourceByHash = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW);
for (Resource r : Resource.values())
resourceByHash.put(r.hash, r);
}
public final String name;
public final int hash;
public final int baseProduction;
public final int UUID;
Resource(String name, int hash, int baseProduction, int uuid) {
this.name = name;
this.hash = hash;
this.baseProduction = baseProduction;
this.UUID = uuid;
}
public static Resource GetResourceByHash(int hash) {
for (Resource resource : Resource.values()) {
if (hash == resource.hash)
return resource;
}
return Resource.MITHRIL;
}
}

9
src/engine/objects/Transaction.java

@ -9,6 +9,7 @@ @@ -9,6 +9,7 @@
package engine.objects;
import engine.Enum;
import engine.Enum.GameObjectType;
import engine.Enum.TransactionType;
import org.joda.time.DateTime;
@ -22,7 +23,7 @@ public class Transaction implements Comparable<Transaction> { @@ -22,7 +23,7 @@ public class Transaction implements Comparable<Transaction> {
private final int warehouseUUID;
private final int targetUUID;
private final Resource resource;
private final Enum.ResourceType resource;
private final DateTime date;
private final int amount;
private final TransactionType transactionType;
@ -34,7 +35,7 @@ public class Transaction implements Comparable<Transaction> { @@ -34,7 +35,7 @@ public class Transaction implements Comparable<Transaction> {
this.targetUUID = rs.getInt("targetUID");
this.targetType = GameObjectType.valueOf(rs.getString("targetType"));
this.transactionType = TransactionType.valueOf(rs.getString("type").toUpperCase());
this.resource = Resource.valueOf(rs.getString("resource").toUpperCase());
this.resource = Enum.ResourceType.valueOf(rs.getString("resource").toUpperCase());
this.amount = rs.getInt("amount");
Date sqlDateTime = rs.getTimestamp("date");
@ -47,7 +48,7 @@ public class Transaction implements Comparable<Transaction> { @@ -47,7 +48,7 @@ public class Transaction implements Comparable<Transaction> {
}
public Transaction(int warehouseUUID, GameObjectType targetType, int targetUUID, TransactionType transactionType, Resource resource, int amount,
public Transaction(int warehouseUUID, GameObjectType targetType, int targetUUID, TransactionType transactionType, Enum.ResourceType resource, int amount,
DateTime date) {
this.warehouseUUID = warehouseUUID;
this.targetUUID = targetUUID;
@ -69,7 +70,7 @@ public class Transaction implements Comparable<Transaction> { @@ -69,7 +70,7 @@ public class Transaction implements Comparable<Transaction> {
}
public Resource getResource() {
public Enum.ResourceType getResource() {
return resource;
}

44
src/engine/objects/Warehouse.java

@ -302,12 +302,12 @@ public class Warehouse extends AbstractWorldObject { @@ -302,12 +302,12 @@ public class Warehouse extends AbstractWorldObject {
warehouse.resources.put(ib, newAmount);
Resource resourceType;
Enum.ResourceType resourceType;
if (resource.template.item_type.equals(Enum.ItemType.GOLD))
resourceType = Resource.GOLD;
resourceType = Enum.ResourceType.GOLD;
else
resourceType = Resource.valueOf(ItemTemplate.itemTemplates.get(resource.getTemplsteID()).item_base_name.toUpperCase());
resourceType = Enum.ResourceType.valueOf(ItemTemplate.itemTemplates.get(resource.getTemplsteID()).item_base_name.toUpperCase());
if (transaction)
AddTransactionToWarehouse(warehouse, pc.getObjectType(), pc.getObjectUUID(), Enum.TransactionType.DEPOSIT, resourceType, amount);
@ -327,14 +327,14 @@ public class Warehouse extends AbstractWorldObject { @@ -327,14 +327,14 @@ public class Warehouse extends AbstractWorldObject {
return false;
warehouse.resources.put(resource, newAmount);
Resource resourceType;
Enum.ResourceType resourceType;
ItemTemplate template = ItemTemplate.itemTemplates.get(resource.getUUID());
if (resource.getUUID() == 7)
resourceType = Resource.GOLD;
resourceType = Enum.ResourceType.GOLD;
else
resourceType = Resource.valueOf(template.item_base_name.toUpperCase());
resourceType = Enum.ResourceType.valueOf(template.item_base_name.toUpperCase());
if (mine != null)
AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, mine.getBuildingID(), Enum.TransactionType.MINE, resourceType, amount);
@ -440,14 +440,14 @@ public class Warehouse extends AbstractWorldObject { @@ -440,14 +440,14 @@ public class Warehouse extends AbstractWorldObject {
int oldAmount = warehouse.resources.get(ib);
int newAmount = oldAmount + amount;
warehouse.resources.put(ib, newAmount);
Resource resourceType;
Enum.ResourceType resourceType;
ItemTemplate template = ItemTemplate.itemTemplates.get(ib.getUUID());
if (ib.getUUID() == 7)
resourceType = Resource.GOLD;
resourceType = Enum.ResourceType.GOLD;
else
resourceType = Resource.valueOf(template.item_base_name.toUpperCase());
resourceType = Enum.ResourceType.valueOf(template.item_base_name.toUpperCase());
AddTransactionToWarehouse(warehouse, taxer.getObjectType(), taxer.getObjectUUID(), Enum.TransactionType.TAXRESOURCEDEPOSIT, resourceType, amount);
@ -473,12 +473,12 @@ public class Warehouse extends AbstractWorldObject { @@ -473,12 +473,12 @@ public class Warehouse extends AbstractWorldObject {
return;
warehouse.resources.put(ib, newAmount);
Resource resourceType;
Enum.ResourceType resourceType;
if (ib.getUUID() == 7)
resourceType = Resource.GOLD;
resourceType = Enum.ResourceType.GOLD;
else
resourceType = Resource.valueOf(template.item_base_name.toUpperCase());
resourceType = Enum.ResourceType.valueOf(template.item_base_name.toUpperCase());
if (building != null)
AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, building.getObjectUUID(), Enum.TransactionType.DEPOSIT, resourceType, amount);
@ -592,12 +592,12 @@ public class Warehouse extends AbstractWorldObject { @@ -592,12 +592,12 @@ public class Warehouse extends AbstractWorldObject {
ItemTemplate template = ItemTemplate.itemTemplates.get(ib.getUUID());
warehouse.resources.put(ib, newAmount);
Resource resourceType;
Enum.ResourceType resourceType;
if (ib.getUUID() == 7)
resourceType = Resource.GOLD;
resourceType = Enum.ResourceType.GOLD;
else
resourceType = Resource.valueOf(template.item_base_name.toUpperCase());
resourceType = Enum.ResourceType.valueOf(template.item_base_name.toUpperCase());
if (transaction)
AddTransactionToWarehouse(warehouse, npc.getObjectType(), npc.getObjectUUID(), Enum.TransactionType.WITHDRAWL, resourceType, amount);
@ -648,12 +648,12 @@ public class Warehouse extends AbstractWorldObject { @@ -648,12 +648,12 @@ public class Warehouse extends AbstractWorldObject {
warehouse.resources.put(ib, newAmount);
depositRealmTaxes(taxer, ib, amount, warehouse);
Resource resource;
Enum.ResourceType resource;
if (resourceType.equals(Enum.ResourceType.GOLD))
resource = Resource.GOLD;
resource = Enum.ResourceType.GOLD;
else
resource = Resource.valueOf(template.item_base_name.toUpperCase());
resource = Enum.ResourceType.valueOf(template.item_base_name.toUpperCase());
AddTransactionToWarehouse(warehouse, taxer.getObjectType(), taxer.getObjectUUID(), Enum.TransactionType.TAXRESOURCE, resource, amount);
@ -739,12 +739,12 @@ public class Warehouse extends AbstractWorldObject { @@ -739,12 +739,12 @@ public class Warehouse extends AbstractWorldObject {
}
}
}
Resource resourceType;
Enum.ResourceType resourceType;
if (ib.getUUID() == 7)
resourceType = Resource.GOLD;
resourceType = Enum.ResourceType.GOLD;
else
resourceType = Resource.valueOf(template.item_base_name.toUpperCase());
resourceType = Enum.ResourceType.valueOf(template.item_base_name.toUpperCase());
if (transaction)
AddTransactionToWarehouse(warehouse, pc.getObjectType(), pc.getObjectUUID(), Enum.TransactionType.WITHDRAWL, resourceType, amount);
@ -835,7 +835,7 @@ public class Warehouse extends AbstractWorldObject { @@ -835,7 +835,7 @@ public class Warehouse extends AbstractWorldObject {
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) {
public static void AddTransactionToWarehouse(Warehouse warehouse, Enum.GameObjectType targetType, int targetUUID, Enum.TransactionType transactionType, Enum.ResourceType resource, int amount) {
if (!DbManager.WarehouseQueries.CREATE_TRANSACTION(warehouse.buildingUID, targetType, targetUUID, transactionType, resource, amount, DateTime.now()))

Loading…
Cancel
Save