Browse Source

Schema update

combat-2
MagicBot 8 months ago
parent
commit
d57eb295e9
  1. 44
      src/engine/db/handlers/dbItemHandler.java
  2. 20
      src/engine/objects/Item.java

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

@ -26,7 +26,6 @@ import java.sql.PreparedStatement; @@ -26,7 +26,6 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashSet;
@ -161,7 +160,7 @@ public class dbItemHandler extends dbHandlerBase { @@ -161,7 +160,7 @@ public class dbItemHandler extends dbHandlerBase {
ArrayList<Item> itemList;
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_item`.*, `object`.`parent`, `object`.`type` FROM `object` INNER JOIN `obj_item` ON `object`.`UID` = `obj_item`.`UID` WHERE `object`.`parent`=? && `obj_item`.`item_container`='equip';")) {
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_item`.*, `object`.`parent`, `object`.`type` FROM `object` INNER JOIN `obj_item` ON `object`.`UID` = `obj_item`.`UID` WHERE `object`.`parent`=? && `obj_item`.`container`='equip';")) {
preparedStatement.setLong(1, targetId);
ResultSet rs = preparedStatement.executeQuery();
@ -277,7 +276,7 @@ public class dbItemHandler extends dbHandlerBase { @@ -277,7 +276,7 @@ public class dbItemHandler extends dbHandlerBase {
public boolean MOVE_GOLD(final Item from, final Item to, final int amt) {
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_numberOfItems` = CASE WHEN `UID`=? THEN ? WHEN `UID`=? THEN ? END WHERE `UID` IN (?, ?);")) {
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `numberOfItems` = CASE WHEN `UID`=? THEN ? WHEN `UID`=? THEN ? END WHERE `UID` IN (?, ?);")) {
int newFromAmt = from.getNumOfItems() - amt;
int newToAmt = to.getNumOfItems() + amt;
@ -307,7 +306,7 @@ public class dbItemHandler extends dbHandlerBase { @@ -307,7 +306,7 @@ public class dbItemHandler extends dbHandlerBase {
continue;
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` LEFT JOIN `object` ON `object`.`UID` = `obj_item`.`UID` SET `object`.`parent`=NULL, `obj_item`.`item_container`='none' WHERE `object`.`UID`=?;")) {
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` LEFT JOIN `object` ON `object`.`UID` = `obj_item`.`UID` SET `object`.`parent`=NULL, `obj_item`.`container`='none' WHERE `object`.`UID`=?;")) {
preparedStatement.setLong(1, item.getObjectUUID());
worked = (preparedStatement.executeUpdate() > 0);
@ -397,7 +396,7 @@ public class dbItemHandler extends dbHandlerBase { @@ -397,7 +396,7 @@ public class dbItemHandler extends dbHandlerBase {
public boolean SET_DURABILITY(final Item item, int value) {
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_durabilityCurrent`=? WHERE `UID`=? AND `item_durabilityCurrent`=?")) {
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `combat_health_current`=? WHERE `UID`=? AND `combat_health_current`=?")) {
preparedStatement.setInt(1, value);
preparedStatement.setLong(2, item.getObjectUUID());
@ -414,7 +413,7 @@ public class dbItemHandler extends dbHandlerBase { @@ -414,7 +413,7 @@ public class dbItemHandler extends dbHandlerBase {
public boolean UPDATE_FORGE_TO_INVENTORY(final Item item) {
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_container` = ? WHERE `UID` = ? AND `item_container` = 'forge';")) {
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `container` = ? WHERE `UID` = ? AND `container` = 'forge';")) {
preparedStatement.setString(1, "inventory");
preparedStatement.setLong(2, item.getObjectUUID());
@ -451,7 +450,7 @@ public class dbItemHandler extends dbHandlerBase { @@ -451,7 +450,7 @@ public class dbItemHandler extends dbHandlerBase {
return false;
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_numberOfItems`=? WHERE `UID`=?")) {
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `numberOfItems`=? WHERE `UID`=?")) {
preparedStatement.setInt(1, newValue);
preparedStatement.setLong(2, item.getObjectUUID());
@ -468,7 +467,7 @@ public class dbItemHandler extends dbHandlerBase { @@ -468,7 +467,7 @@ public class dbItemHandler extends dbHandlerBase {
public boolean UPDATE_REMAINING_CHARGES(final Item item) {
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_chargesRemaining` = ? WHERE `UID` = ?")) {
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `chargesRemaining` = ? WHERE `UID` = ?")) {
preparedStatement.setInt(1, (byte) item.chargesRemaining);
preparedStatement.setLong(2, item.getObjectUUID());
@ -488,7 +487,7 @@ public class dbItemHandler extends dbHandlerBase { @@ -488,7 +487,7 @@ public class dbItemHandler extends dbHandlerBase {
public boolean ZERO_ITEM_STACK(Item item) {
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_numberOfItems`=0 WHERE `UID` = ?")) {
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `numberOfItems`=0 WHERE `UID` = ?")) {
preparedStatement.setLong(1, item.getObjectUUID());
@ -503,7 +502,7 @@ public class dbItemHandler extends dbHandlerBase { @@ -503,7 +502,7 @@ public class dbItemHandler extends dbHandlerBase {
public boolean UPDATE_FLAGS(Item item) {
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_flags`=? WHERE `UID` = ?")) {
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `flags`=? WHERE `UID` = ?")) {
String flagString = "";
@ -523,29 +522,6 @@ public class dbItemHandler extends dbHandlerBase { @@ -523,29 +522,6 @@ 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() + ";";
flagString = flagString.replaceAll(";$", "");
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) {
// Write 0 if we will not modify the value from template
@ -554,7 +530,7 @@ public class dbItemHandler extends dbHandlerBase { @@ -554,7 +530,7 @@ public class dbItemHandler extends dbHandlerBase {
value = 0;
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_value`=? WHERE `UID` = ?")) {
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `value`=? WHERE `UID` = ?")) {
preparedStatement.setInt(1, value);
preparedStatement.setLong(2, item.getObjectUUID());

20
src/engine/objects/Item.java

@ -86,7 +86,7 @@ public class Item extends AbstractWorldObject { @@ -86,7 +86,7 @@ public class Item extends AbstractWorldObject {
public Item(ResultSet rs) throws SQLException {
super(rs);
this.templateID = rs.getInt("item_itemBaseID");
this.templateID = rs.getInt("templateID");
this.template = ItemTemplate.templates.get(this.templateID);
if (this.template == null)
@ -94,14 +94,14 @@ public class Item extends AbstractWorldObject { @@ -94,14 +94,14 @@ public class Item extends AbstractWorldObject {
// Name override in db.
this.name = rs.getString("item_name");
this.name = rs.getString("name");
if (this.name == null)
this.name = "";
// Set container enumeration
String container = rs.getString("item_container");
String container = rs.getString("container");
switch (container) {
case "inventory":
@ -126,9 +126,9 @@ public class Item extends AbstractWorldObject { @@ -126,9 +126,9 @@ public class Item extends AbstractWorldObject {
this.ownerID = rs.getInt("parent");
this.chargesRemaining = rs.getByte("item_chargesRemaining");
this.chargesRemaining = rs.getByte("chargesRemaining");
this.combat_health_current = rs.getShort("item_durabilityCurrent");
this.combat_health_current = rs.getShort("combat_health_current");
DbObjectType ownerType;
ownerType = DbManager.BuildingQueries.GET_UID_ENUM(this.ownerID);
@ -147,18 +147,18 @@ public class Item extends AbstractWorldObject { @@ -147,18 +147,18 @@ public class Item extends AbstractWorldObject {
this.canDestroy = true;
this.equipSlot = EquipSlotType.values()[rs.getByte("item_equipSlot")];
this.equipSlot = EquipSlotType.values()[rs.getByte("equipSlot")];
this.numberOfItems = rs.getInt("item_numberOfItems");
this.numberOfItems = rs.getInt("numberOfItems");
String flagString = rs.getString("item_flags");
String flagString = rs.getString("flags");
if (flagString.isEmpty() == false)
for (String itemFlag : flagString.split(";"))
this.flags.add(Enum.ItemFlags.valueOf(itemFlag));
this.dateToUpgrade = rs.getLong("item_dateToUpgrade");
this.value = rs.getInt("item_value");
this.dateToUpgrade = rs.getLong("dateToUpgrade");
this.value = rs.getInt("value");
if (this.value == 0)
this.value = this.template.item_value;

Loading…
Cancel
Save