Browse Source

Back filling item flags

combat-2
MagicBot 8 months ago
parent
commit
551361e10a
  1. 50
      src/engine/db/handlers/dbItemHandler.java
  2. 3
      src/engine/server/world/WorldServer.java

50
src/engine/db/handlers/dbItemHandler.java

@ -26,6 +26,7 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashSet; import java.util.HashSet;
@ -497,6 +498,34 @@ public class dbItemHandler extends dbHandlerBase {
} }
} }
public void UPDATE_ALL_FLAGS() {
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `obj_item`")) {
ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) {
int item_uuid = rs.getInt("UID");
int templateID = rs.getInt("item_itembaseID");
EnumSet<Enum.ItemFlags> item_flags = EnumSet.noneOf(Enum.ItemFlags.class);
item_flags.addAll(ItemTemplate.templates.get(templateID).item_flags);
int identified = rs.getInt("old_flags");
if (identified != 0)
item_flags.add(Enum.ItemFlags.Identified);
UPDATE_FLAGS(item_uuid, item_flags);
}
} catch (SQLException e) {
Logger.error(e);
}
}
public boolean UPDATE_FLAGS(Item item) { public boolean UPDATE_FLAGS(Item item) {
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
@ -518,6 +547,27 @@ public class dbItemHandler extends dbHandlerBase {
} }
} }
public boolean UPDATE_FLAGS(int itemUUID, EnumSet<Enum.ItemFlags> itemFlags) {
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_flags`=? WHERE `UID` = ?")) {
String flagString = "";
for (Enum.ItemFlags itemflag : itemFlags)
flagString += itemflag.toString() + ";";
preparedStatement.setString(1, flagString);
preparedStatement.setLong(2, itemUUID);
return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) {
Logger.error(e);
return false;
}
}
public boolean UPDATE_VALUE(Item item, int value) { public boolean UPDATE_VALUE(Item item, int value) {
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();

3
src/engine/server/world/WorldServer.java

@ -343,6 +343,9 @@ public class WorldServer {
Logger.info("Loading Item Templates"); Logger.info("Loading Item Templates");
DbManager.ItemQueries.LOAD_ITEM_TEMPLATES(); DbManager.ItemQueries.LOAD_ITEM_TEMPLATES();
Logger.info("Back filling item flags");
DbManager.ItemQueries.UPDATE_ALL_FLAGS();
Logger.info("Loading ItemBases"); Logger.info("Loading ItemBases");
ItemBase.loadAllItemBases(); ItemBase.loadAllItemBases();

Loading…
Cancel
Save