Browse Source

More item refactor work.

combat-2
MagicBot 9 months ago
parent
commit
5736f0a7a3
  1. 2
      src/engine/db/handlers/dbItemHandler.java
  2. 37
      src/engine/devcmd/cmds/MakeItemCmd.java
  3. 102
      src/engine/objects/Item.java

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

@ -60,7 +60,7 @@ public class dbItemHandler extends dbHandlerBase {
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("CALL `item_CREATE`(?, ?, ?, ?, ?, ?, ?, ?, ?,?);")) { PreparedStatement preparedStatement = connection.prepareStatement("CALL `item_CREATE`(?, ?, ?, ?, ?, ?, ?, ?, ?,?);")) {
preparedStatement.setInt(1, toAdd.getOwnerID()); preparedStatement.setInt(1, toAdd.ownerID);
preparedStatement.setInt(2, toAdd.getTemplsteID()); preparedStatement.setInt(2, toAdd.getTemplsteID());
preparedStatement.setInt(3, (byte) toAdd.chargesRemaining); preparedStatement.setInt(3, (byte) toAdd.chargesRemaining);
preparedStatement.setInt(4, (short) toAdd.durabilityCurrent); preparedStatement.setInt(4, (short) toAdd.durabilityCurrent);

37
src/engine/devcmd/cmds/MakeItemCmd.java

@ -17,8 +17,6 @@ import engine.gameManager.DbManager;
import engine.objects.*; import engine.objects.*;
import engine.powers.EffectsBase; import engine.powers.EffectsBase;
import java.util.ArrayList;
/** /**
* @author Eighty * @author Eighty
*/ */
@ -175,57 +173,54 @@ public class MakeItemCmd extends AbstractDevCmd {
return; return;
} }
} }
ItemBase ib = ItemBase.getItemBase(itembaseID); ItemTemplate template = ItemTemplate.itemTemplates.get(itembaseID);
if (ib == null) {
if (template == null) {
throwbackError(pc, "Unable to find itembase of ID " + itembaseID); throwbackError(pc, "Unable to find itembase of ID " + itembaseID);
return; return;
} }
if ((numItems > 1) if ((numItems > 1)
&& (ib.getType().equals(ItemType.RESOURCE) == false) && (template.item_type.equals(ItemType.RESOURCE) == false)
&& (ib.getType().equals(ItemType.OFFERING)) == false) && (template.item_type.equals(ItemType.OFFERING)) == false)
numItems = 1; numItems = 1;
CharacterItemManager cim = pc.getCharItemManager(); CharacterItemManager cim = pc.getCharItemManager();
if (cim == null) { if (cim == null) {
throwbackError(pc, "Unable to find the character item manager for player " + pc.getFirstName() + '.'); throwbackError(pc, "Unable to find the character item manager for player " + pc.getFirstName() + '.');
return; return;
} }
byte charges = (byte) ib.getNumCharges();
short dur = (short) ib.getDurability();
String result = ""; String result = "";
for (int i = 0; i < quantity; i++) { for (int i = 0; i < quantity; i++) {
short weight = ib.getWeight();
int weight = template.item_wt;
if (!cim.hasRoomInventory(weight)) { if (!cim.hasRoomInventory(weight)) {
throwbackError(pc, "Not enough room in inventory for any more of this item. " + i + " produced."); throwbackError(pc, "Not enough room in inventory for any more of this item. " + i + " produced.");
if (i > 0) if (i > 0)
cim.updateInventory(); cim.updateInventory();
return; return;
} }
boolean worked = false; Item item = new Item(itembaseID);
Item item = new Item(ib, pc.getObjectUUID(), item.ownerID = pc.getObjectUUID();
OwnerType.PlayerCharacter, charges, charges, dur, dur, item.ownerType = OwnerType.PlayerCharacter;
true, false, ItemContainerType.INVENTORY, (byte) 0,
new ArrayList<>(), "");
if (numItems > 1) if (numItems > 1)
item.setNumOfItems(numItems); item.setNumOfItems(numItems);
try { try {
item = DbManager.ItemQueries.PERSIST(item); item = DbManager.ItemQueries.PERSIST(item);
worked = true;
} catch (Exception e) { } catch (Exception e) {
throwbackError(pc, "DB error 1: Unable to create item. " + e.getMessage()); throwbackError(pc, "DB error 1: Unable to create item. " + e.getMessage());
return; return;
} }
if (item == null || !worked) {
throwbackError(pc, "DB error 2: Unable to create item.");
return;
}
//create prefix //create prefix
if (!prefix.isEmpty()) if (!prefix.isEmpty())
item.addPermanentEnchantmentForDev(prefix, 0); item.addPermanentEnchantmentForDev(prefix, 0);

102
src/engine/objects/Item.java

@ -57,7 +57,6 @@ public class Item extends AbstractWorldObject {
public OwnerType ownerType; public OwnerType ownerType;
public int templsteID; public int templsteID;
private AbstractWorldObject lastOwner; private AbstractWorldObject lastOwner;
private ArrayList<EnchantmentBase> enchants = new ArrayList<>();
private long dateToUpgrade; private long dateToUpgrade;
private String customName = ""; private String customName = "";
private int magicValue; private int magicValue;
@ -73,7 +72,7 @@ public class Item extends AbstractWorldObject {
this.template = ItemTemplate.itemTemplates.get(templateID); this.template = ItemTemplate.itemTemplates.get(templateID);
this.chargesRemaining = this.template.item_initial_charges; this.chargesRemaining = this.template.item_initial_charges;
this.durabilityCurrent = this.template.combat_health_full; this.durabilityCurrent = this.template.combat_health_full;
this.equipSlot = 0;
loadEnchantments(); loadEnchantments();
bakeInStats(); bakeInStats();
} }
@ -82,7 +81,7 @@ public class Item extends AbstractWorldObject {
OwnerType ownerType, byte chargesMax, byte chargesRemaining, OwnerType ownerType, byte chargesMax, byte chargesRemaining,
short durabilityCurrent, short durabilityMax, boolean canDestroy, short durabilityCurrent, short durabilityMax, boolean canDestroy,
boolean rentable, Enum.ItemContainerType containerType, byte equipSlot, boolean rentable, Enum.ItemContainerType containerType, byte equipSlot,
ArrayList<EnchantmentBase> enchants, String name) { String name) {
super(); super();
this.templsteID = itemBase.getUUID(); this.templsteID = itemBase.getUUID();
this.ownerID = ownerID; this.ownerID = ownerID;
@ -101,7 +100,6 @@ public class Item extends AbstractWorldObject {
this.containerType = containerType; this.containerType = containerType;
this.canDestroy = canDestroy; this.canDestroy = canDestroy;
this.equipSlot = equipSlot; this.equipSlot = equipSlot;
this.enchants = enchants;
this.flags = 1; this.flags = 1;
this.value = this.magicValue; this.value = this.magicValue;
this.customName = name; this.customName = name;
@ -133,7 +131,6 @@ public class Item extends AbstractWorldObject {
this.durabilityCurrent = (short) itemBase.getDurability(); this.durabilityCurrent = (short) itemBase.getDurability();
this.canDestroy = canDestroy; this.canDestroy = canDestroy;
this.equipSlot = equipSlot; this.equipSlot = equipSlot;
this.enchants = enchants;
this.flags = 1; this.flags = 1;
this.value = this.magicValue; this.value = this.magicValue;
@ -420,14 +417,12 @@ public class Item extends AbstractWorldObject {
boolean itemWorked = false; boolean itemWorked = false;
Item item = new Item(toCreate, reciever.getObjectUUID(), OwnerType.PlayerCharacter, (byte) 0, (byte) 0, Item item = new Item(toCreate.getUUID());
(short) 1, (short) 1, true, false, Enum.ItemContainerType.INVENTORY, (byte) 0,
new ArrayList<>(), "");
synchronized (item) { item.ownerID = reciever.getObjectUUID();
item.numberOfItems = amount; item.ownerType = OwnerType.PlayerCharacter;
}
item.containerType = Enum.ItemContainerType.INVENTORY; item.containerType = Enum.ItemContainerType.INVENTORY;
item.numberOfItems = amount;
try { try {
item = DbManager.ItemQueries.PERSIST(item); item = DbManager.ItemQueries.PERSIST(item);
@ -589,57 +584,13 @@ public class Item extends AbstractWorldObject {
} }
public static Item createItemForPlayer(PlayerCharacter pc, ItemBase ib) { public static Item createItemForPlayer(PlayerCharacter pc, ItemBase ib) {
Item item = null;
byte charges = 0;
charges = (byte) ib.getNumCharges();
short durability = (short) ib.getDurability();
Item temp = new Item(ib, pc.getObjectUUID(),
OwnerType.PlayerCharacter, charges, charges, durability, durability,
true, false, Enum.ItemContainerType.INVENTORY, (byte) 0,
new ArrayList<>(), "");
try {
item = DbManager.ItemQueries.PERSIST(temp);
} catch (Exception e) {
Logger.error(e);
}
return item;
}
public static Item createItemForPlayerBank(PlayerCharacter pc, ItemBase ib) {
Item item = null;
byte charges = 0;
charges = (byte) ib.getNumCharges();
short durability = (short) ib.getDurability(); Item item = new Item(ib.getUUID());
item.ownerID = pc.getObjectUUID();
item.ownerType = OwnerType.PlayerCharacter;
Item temp = new Item(ib, pc.getObjectUUID(),
OwnerType.PlayerCharacter, charges, charges, durability, durability,
true, false, Enum.ItemContainerType.BANK, (byte) 0,
new ArrayList<>(), "");
try { try {
item = DbManager.ItemQueries.PERSIST(temp); item = DbManager.ItemQueries.PERSIST(item);
} catch (Exception e) {
}
return item;
}
public static Item createItemForMob(Mob mob, ItemBase ib) {
Item item = null;
byte charges = 0;
charges = (byte) ib.getNumCharges();
short durability = (short) ib.getDurability();
Item temp = new Item(ib, mob.getObjectUUID(),
OwnerType.Mob, charges, charges, durability, durability,
true, false, Enum.ItemContainerType.INVENTORY, (byte) 0,
new ArrayList<>(), "");
try {
item = DbManager.ItemQueries.PERSIST(temp);
} catch (Exception e) { } catch (Exception e) {
Logger.error(e); Logger.error(e);
} }
@ -667,23 +618,16 @@ public class Item extends AbstractWorldObject {
ownerID = accountID; ownerID = accountID;
ownerType = OwnerType.Account; ownerType = OwnerType.Account;
Item newGold = new Item(ib.getUUID());
Item newGold = new Item(ib, ownerID, ownerType, newGold.ownerID = ownerID;
(byte) 0, (byte) 0, (short) 0, (short) 0, true, false, containerType, (byte) 0, newGold.ownerType = ownerType;
new ArrayList<>(), ""); newGold.containerType = containerType;
synchronized (newGold) {
newGold.numberOfItems = 0; newGold.numberOfItems = 0;
}
if (persist) { if (persist) {
try { try {
newGold = DbManager.ItemQueries.PERSIST(newGold); newGold = DbManager.ItemQueries.PERSIST(newGold);
if (newGold != null) {
synchronized (newGold) {
newGold.numberOfItems = 0;
}
}
} catch (Exception e) { } catch (Exception e) {
Logger.error(e); Logger.error(e);
} }
@ -729,28 +673,20 @@ public class Item extends AbstractWorldObject {
} }
} }
Item newGold = new Item(ib, ownerID, ownerType, Item newGold = new Item(ib.getUUID());
(byte) 0, (byte) 0, (short) 0, (short) 0, true, false, containerType, (byte) 0, newGold.ownerID = ownerID;
new ArrayList<>(), ""); newGold.ownerType = ownerType;
newGold.containerType = containerType;
synchronized (newGold) {
newGold.numberOfItems = 0; newGold.numberOfItems = 0;
}
if (persist) { if (persist) {
try { try {
newGold = DbManager.ItemQueries.PERSIST(newGold); newGold = DbManager.ItemQueries.PERSIST(newGold);
if (newGold != null) {
synchronized (newGold) {
newGold.numberOfItems = 0;
}
}
} catch (Exception e) { } catch (Exception e) {
Logger.error(e); Logger.error(e);
} }
DbManager.ItemQueries.ZERO_ITEM_STACK(newGold); DbManager.ItemQueries.ZERO_ITEM_STACK(newGold);
} }
newGold.containerType = containerType;
return newGold; return newGold;
} }

Loading…
Cancel
Save