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

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

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

102
src/engine/objects/Item.java

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

Loading…
Cancel
Save