Browse Source

Resource.hash refactored

combat-2
MagicBot 8 months ago
parent
commit
0b68ae3960
  1. 63
      src/engine/Enum.java
  2. 6
      src/engine/net/client/msg/ViewResourcesMessage.java
  3. 13
      src/engine/objects/ItemBase.java
  4. 40
      src/engine/objects/Warehouse.java

63
src/engine/Enum.java

@ -2663,41 +2663,48 @@ public class Enum {
public enum ResourceType implements EnumBitSetHelper<ResourceType> { public enum ResourceType implements EnumBitSetHelper<ResourceType> {
STONE(1580000), STONE(1580000, 74856115),
TRUESTEEL(1580001), TRUESTEEL(1580001, -317484979),
IRON(1580002), IRON(1580002, 2504297),
ADAMANT(1580003), ADAMANT(1580003, -1741189964),
LUMBER(1580004), LUMBER(1580004, -1603256692),
OAK(1580005), OAK(1580005, 74767),
BRONZEWOOD(1580006), BRONZEWOOD(1580006, 1334770447),
MANDRAKE(1580007), MANDRAKE(1580007, 1191391799),
COAL(1580008), COAL(1580008, 2559427),
AGATE(1580009), AGATE(1580009, 75173057),
DIAMOND(1580010), DIAMOND(1580010, -1730704107),
ONYX(1580011), ONYX(1580011, 2977263),
AZOTH(1580012), AZOTH(1580012, 78329697),
ORICHALK(1580013), ORICHALK(1580013, -2036290524),
ANTIMONY(1580014), ANTIMONY(1580014, 452320058),
SULFUR(1580015), SULFUR(1580015, -1586349421),
QUICKSILVER(1580016), QUICKSILVER(1580016, -472884509),
GALVOR(1580017), GALVOR(1580017, -1596311545),
WORMWOOD(1580018), WORMWOOD(1580018, 1532478436),
OBSIDIAN(1580019), OBSIDIAN(1580019, -697973233),
BLOODSTONE(1580020), BLOODSTONE(1580020, -1569826353),
MITHRIL(1580021), MITHRIL(1580021, -1761257186),
GOLD(7); GOLD(7, 2308551);
public static HashMap<Integer, ResourceType> resourceLookup = new HashMap<>(); public static HashMap<Integer, ResourceType> resourceLookup = new HashMap<>();
public int itemID; public static HashMap<Integer, ResourceType> hashLookup = new HashMap<>();
public int templateID;
public int hash;
ResourceType(int itemID) { ResourceType(int templateID, int hash) {
this.itemID = itemID; this.templateID = templateID;
this.hash = hash;
} }
public static void InitializeResourceTypes() { public static void InitializeResourceTypes() {
for (ResourceType resourceType : ResourceType.values()) for (ResourceType resourceType : ResourceType.values()) {
resourceLookup.put(resourceType.itemID, resourceType); resourceLookup.put(resourceType.templateID, resourceType);
hashLookup.put(resourceType.hash, resourceType);
}
} }
} }

6
src/engine/net/client/msg/ViewResourcesMessage.java

@ -93,7 +93,8 @@ public class ViewResourcesMessage extends ClientNetMsg {
for (ItemBase ib : (warehouseObject.resources.keySet())) { for (ItemBase ib : (warehouseObject.resources.keySet())) {
writer.putInt(ib.getHashID()); Enum.ResourceType resourceType = Enum.ResourceType.resourceLookup.get(ib.getUUID());
writer.putInt(resourceType.hash);
writer.putInt((warehouseObject.resources.get(ib))); writer.putInt((warehouseObject.resources.get(ib)));
@ -106,7 +107,8 @@ public class ViewResourcesMessage extends ClientNetMsg {
writer.putInt(warehouseObject.resources.size()); writer.putInt(warehouseObject.resources.size());
for (ItemBase ib : warehouseObject.resources.keySet()) { for (ItemBase ib : warehouseObject.resources.keySet()) {
writer.putInt(ib.getHashID()); Enum.ResourceType resourceType = Enum.ResourceType.resourceLookup.get(ib.getUUID());
writer.putInt(resourceType.hash);
writer.putInt(0); //available? writer.putInt(0); //available?
writer.putInt(Warehouse.getMaxResources().get(ib.getUUID())); //max? writer.putInt(Warehouse.getMaxResources().get(ib.getUUID())); //max?
} }

13
src/engine/objects/ItemBase.java

@ -30,7 +30,6 @@ public class ItemBase {
public final int uuid; public final int uuid;
private final int modTable; private final int modTable;
private int hashID;
private final short percentRequired; private final short percentRequired;
private final short defense; private final short defense;
private final float dexPenalty; private final float dexPenalty;
@ -47,8 +46,6 @@ public class ItemBase {
this.uuid = rs.getInt("ID"); this.uuid = rs.getInt("ID");
this.modTable = rs.getInt("modTable"); this.modTable = rs.getInt("modTable");
this.hashID = rs.getInt("itemHashID");
this.isConsumable = false; this.isConsumable = false;
this.percentRequired = rs.getShort("percentRequired"); this.percentRequired = rs.getShort("percentRequired");
this.defense = rs.getShort("defense"); this.defense = rs.getShort("defense");
@ -82,7 +79,6 @@ public class ItemBase {
this.isConsumable = true; this.isConsumable = true;
break; break;
} }
initializeHashes();
} }
@ -149,19 +145,10 @@ public class ItemBase {
return ID > 7000099 && ID < 7000281; return ID > 7000099 && ID < 7000281;
} }
public final void initializeHashes() {
itemHashIDMap.put(this.hashID, uuid);
}
public int getModTable() { public int getModTable() {
return modTable; return modTable;
} }
public int getHashID() {
return hashID;
}
public final int getUUID() { public final int getUUID() {
return uuid; return uuid;
} }

40
src/engine/objects/Warehouse.java

@ -213,22 +213,18 @@ public class Warehouse extends AbstractWorldObject {
if (wh == null) if (wh == null)
return; return;
int itemBaseID = ItemBase.getItemHashIDMap().get(hashID); Enum.ResourceType resourceType = Enum.ResourceType.hashLookup.get(hashID);
ItemBase ib = ItemBase.getItemBase(itemBaseID);
if (ib == null)
return;
if (isResourceLocked(wh, ib)) { if (isResourceLocked(wh, ItemBase.getItemBase(resourceType.templateID))) {
boolean worked; boolean worked;
EnumBitSet<Enum.ResourceType> bitSet = EnumBitSet.asEnumBitSet(wh.lockedResourceTypes.toLong(), Enum.ResourceType.class); EnumBitSet<Enum.ResourceType> bitSet = EnumBitSet.asEnumBitSet(wh.lockedResourceTypes.toLong(), Enum.ResourceType.class);
bitSet.remove(Enum.ResourceType.resourceLookup.get(itemBaseID)); bitSet.remove(Enum.ResourceType.resourceLookup.get(ItemBase.getItemBase(resourceType.templateID)));
worked = DbManager.WarehouseQueries.updateLocks(wh, bitSet.toLong()); worked = DbManager.WarehouseQueries.updateLocks(wh, bitSet.toLong());
if (worked) { if (worked) {
wh.lockedResourceTypes.remove(Enum.ResourceType.resourceLookup.get(itemBaseID)); wh.lockedResourceTypes.remove(Enum.ResourceType.resourceLookup.get(ItemBase.getItemBase(resourceType.templateID)));
ViewResourcesMessage vrm = new ViewResourcesMessage(player); ViewResourcesMessage vrm = new ViewResourcesMessage(player);
vrm.setGuild(player.getGuild()); vrm.setGuild(player.getGuild());
vrm.setWarehouseBuilding(warehouse); vrm.setWarehouseBuilding(warehouse);
@ -241,12 +237,12 @@ public class Warehouse extends AbstractWorldObject {
EnumBitSet<Enum.ResourceType> bitSet = EnumBitSet.asEnumBitSet(wh.lockedResourceTypes.toLong(), Enum.ResourceType.class); EnumBitSet<Enum.ResourceType> bitSet = EnumBitSet.asEnumBitSet(wh.lockedResourceTypes.toLong(), Enum.ResourceType.class);
bitSet.add(Enum.ResourceType.resourceLookup.get(itemBaseID)); bitSet.add(Enum.ResourceType.resourceLookup.get(ItemBase.getItemBase(resourceType.templateID)));
if (!DbManager.WarehouseQueries.updateLocks(wh, bitSet.toLong())) if (!DbManager.WarehouseQueries.updateLocks(wh, bitSet.toLong()))
return; return;
wh.lockedResourceTypes.add(Enum.ResourceType.resourceLookup.get(itemBaseID)); wh.lockedResourceTypes.add(Enum.ResourceType.resourceLookup.get(ItemBase.getItemBase(resourceType.templateID)));
ViewResourcesMessage vrm = new ViewResourcesMessage(player); ViewResourcesMessage vrm = new ViewResourcesMessage(player);
vrm.setGuild(player.getGuild()); vrm.setGuild(player.getGuild());
vrm.setWarehouseBuilding(warehouse); vrm.setWarehouseBuilding(warehouse);
@ -538,7 +534,8 @@ public class Warehouse extends AbstractWorldObject {
if (oldAmount < amount) if (oldAmount < amount)
return false; return false;
int hashID = ib.getHashID(); Enum.ResourceType resourceType = Enum.ResourceType.resourceLookup.get(ib.getUUID());
int hashID = resourceType.hash;
int newAmount = oldAmount - amount; int newAmount = oldAmount - amount;
boolean worked = false; boolean worked = false;
@ -658,7 +655,8 @@ public class Warehouse extends AbstractWorldObject {
int amount = (int) (warehouse.resources.get(ib) * taxPercent); int amount = (int) (warehouse.resources.get(ib) * taxPercent);
if (amount <= 0) { if (amount <= 0) {
msg.getResources().put(ib.getHashID(), 0); Enum.ResourceType resourceType = Enum.ResourceType.resourceLookup.get(ib.getUUID());
msg.getResources().put(resourceType.hash, 0);
continue; continue;
} }
@ -672,23 +670,25 @@ public class Warehouse extends AbstractWorldObject {
if (newAmount < amount) if (newAmount < amount)
continue; continue;
if (!WithdrawApproved(ib,amount,warehouse)) { Enum.ResourceType resourceType = Enum.ResourceType.resourceLookup.get(ib.getUUID());
msg.getResources().put(ib.getHashID(), 0);
if (!WithdrawApproved(ib, amount, warehouse)) {
msg.getResources().put(resourceType.hash, 0);
continue; continue;
} }
msg.getResources().put(ib.getHashID(), amount); msg.getResources().put(resourceType.hash, amount);
warehouse.resources.put(ib, newAmount); warehouse.resources.put(ib, newAmount);
depositRealmTaxes(taxer, ib, amount, warehouse); depositRealmTaxes(taxer, ib, amount, warehouse);
Resource resourceType; Resource resource;
if (ib.getUUID() == 7) if (resourceType.equals(Enum.ResourceType.GOLD))
resourceType = Resource.GOLD; resource = Resource.GOLD;
else else
resourceType = Resource.valueOf(template.item_base_name.toUpperCase()); resource = Resource.valueOf(template.item_base_name.toUpperCase());
AddTransactionToWarehouse(warehouse, taxer.getObjectType(), taxer.getObjectUUID(), Enum.TransactionType.TAXRESOURCE, resourceType, amount); AddTransactionToWarehouse(warehouse, taxer.getObjectType(), taxer.getObjectUUID(), Enum.TransactionType.TAXRESOURCE, resource, amount);
} }
} }

Loading…
Cancel
Save