Browse Source

Refactor baked in stats

combat-2
MagicBot 8 months ago
parent
commit
6ee194924c
  1. 19
      src/engine/db/handlers/dbItemBaseHandler.java
  2. 16
      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 { @@ -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) {
ArrayList<Integer> tempList = new ArrayList<>();

16
src/engine/objects/Item.java

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

5
src/engine/objects/ItemBase.java

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

Loading…
Cancel
Save