Browse Source

Refactor baked in stats

combat-2
MagicBot 8 months ago
parent
commit
6ee194924c
  1. 19
      src/engine/db/handlers/dbItemBaseHandler.java
  2. 24
      src/engine/objects/Item.java
  3. 5
      src/engine/objects/ItemBase.java

19
src/engine/db/handlers/dbItemBaseHandler.java

@ -26,25 +26,6 @@ public class dbItemBaseHandler extends dbHandlerBase {
} }
public void LOAD_BAKEDINSTATS(ItemBase itemBase) {
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_item_bakedinstat` WHERE `itemID` = ?")) {
preparedStatement.setInt(1, itemBase.getUUID());
ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) {
if (rs.getBoolean("fromUse"))
itemBase.getUsedStats().put(rs.getInt("token"), rs.getInt("numTrains"));
else
itemBase.getBakedInStats().put(rs.getInt("token"), rs.getInt("numTrains"));
}
} catch (SQLException e) {
Logger.error(e);
}
}
public void LOAD_ANIMATIONS(ItemBase itemBase) { public void LOAD_ANIMATIONS(ItemBase itemBase) {
ArrayList<Integer> tempList = new ArrayList<>(); ArrayList<Integer> tempList = new ArrayList<>();

24
src/engine/objects/Item.java

@ -76,7 +76,7 @@ public class Item extends AbstractWorldObject {
this.containerType = ItemContainerType.NONE; this.containerType = ItemContainerType.NONE;
this.numberOfItems = 1; this.numberOfItems = 1;
loadEnchantments(); loadEnchantments();
bakeInStats(); applyBakedInStats();
} }
/** /**
@ -1022,25 +1022,25 @@ public class Item extends AbstractWorldObject {
this.customName = name; this.customName = name;
} }
private void bakeInStats() { private void applyBakedInStats() {
EffectsBase effect; EffectsBase effect;
if (ConfigManager.serverType.equals(Enum.ServerType.LOGINSERVER)) if (ConfigManager.serverType.equals(Enum.ServerType.LOGINSERVER))
return; return;
if (this.getItemBase() != null)
for (Integer token : this.getItemBase().getBakedInStats().keySet()) { for (String effectID : this.template.item_user_power_action.keySet()) {
effect = PowersManager.getEffectByToken(token); effect = PowersManager.getEffectByIDString(effectID);
if (effect == null) { if (effect == null) {
Logger.error("missing effect of token " + token); Logger.error("missing effect of type: " + effectID);
continue; continue;
} }
AbstractPowerAction apa = PowersManager.getPowerActionByIDString(effect.getIDString());
apa.applyBakedInStatsForItem(this, this.getItemBase().getBakedInStats().get(token)); AbstractPowerAction apa = PowersManager.getPowerActionByIDString(effect.getIDString());
apa.applyBakedInStatsForItem(this, this.template.item_user_power_action.get(effectID)[0]);
} }
} }
@ -1123,7 +1123,7 @@ public class Item extends AbstractWorldObject {
@Override @Override
public void runAfterLoad() { public void runAfterLoad() {
loadEnchantments(); loadEnchantments();
bakeInStats(); applyBakedInStats();
} }

5
src/engine/objects/ItemBase.java

@ -99,7 +99,6 @@ public class ItemBase {
} catch (Exception e) { } catch (Exception e) {
Logger.error(e.getMessage()); Logger.error(e.getMessage());
} }
initBakedInStats();
initializeHashes(); initializeHashes();
} }
@ -152,10 +151,6 @@ public class ItemBase {
DbManager.ItemBaseQueries.LOAD_ALL_ITEMBASES(); DbManager.ItemBaseQueries.LOAD_ALL_ITEMBASES();
} }
private void initBakedInStats() {
DbManager.ItemBaseQueries.LOAD_BAKEDINSTATS(this);
}
public boolean isConsumable() { public boolean isConsumable() {
return this.isConsumable; return this.isConsumable;
} }

Loading…
Cancel
Save