forked from MagicBane/Server
Refactor item_type
This commit is contained in:
@@ -191,19 +191,19 @@ public class CharacterItemManager {
|
||||
}
|
||||
break;
|
||||
case BANK:
|
||||
if (i.getItemBase().getType().equals(ItemType.GOLD))
|
||||
if (i.template.item_type.equals(ItemType.GOLD))
|
||||
this.goldBank = i;
|
||||
else if (this.bank.contains(i) == false)
|
||||
this.bank.add(i);
|
||||
break;
|
||||
case INVENTORY:
|
||||
if (i.getItemBase().getType().equals(ItemType.GOLD))
|
||||
if (i.template.item_type.equals(ItemType.GOLD))
|
||||
this.goldInventory = i;
|
||||
else if (this.inventory.contains(i) == false)
|
||||
this.inventory.add(i);
|
||||
break;
|
||||
case VAULT:
|
||||
if (i.getItemBase().getType().equals(ItemType.GOLD))
|
||||
if (i.template.item_type.equals(ItemType.GOLD))
|
||||
this.goldVault = i;
|
||||
else if (this.vault.contains(i) == false)
|
||||
this.vault.add(i);
|
||||
@@ -238,13 +238,13 @@ public class CharacterItemManager {
|
||||
this.equipped.put(i.equipSlot, i);
|
||||
break;
|
||||
case BANK:
|
||||
if (i.getItemBase().getType().equals(ItemType.GOLD))
|
||||
if (i.template.item_type.equals(ItemType.GOLD))
|
||||
this.goldBank = i;
|
||||
else if (this.bank.contains(i) == false)
|
||||
this.bank.add(i);
|
||||
break;
|
||||
case INVENTORY:
|
||||
if (i.getItemBase().getType().equals(ItemType.GOLD))
|
||||
if (i.template.item_type.equals(ItemType.GOLD))
|
||||
this.goldInventory = i;
|
||||
else if (this.inventory.contains(i) == false)
|
||||
this.inventory.add(i);
|
||||
@@ -915,7 +915,7 @@ public class CharacterItemManager {
|
||||
if (i == null)
|
||||
return false;
|
||||
|
||||
if (i.getItemBase().getType().equals(ItemType.GOLD)) {
|
||||
if (i.template.item_type.equals(ItemType.GOLD)) {
|
||||
if (this.getGoldInventory() != null) {
|
||||
if (i.getObjectUUID() == this.getGoldInventory().getObjectUUID())
|
||||
this.goldInventory = null;
|
||||
@@ -945,7 +945,7 @@ public class CharacterItemManager {
|
||||
}
|
||||
|
||||
private synchronized boolean junk(Item i, boolean updateInventory) {
|
||||
if (i.getItemBase().getType().equals(ItemType.GOLD)) {
|
||||
if (i.template.item_type.equals(ItemType.GOLD)) {
|
||||
if (this.getGoldInventory().getObjectUUID() == i.getObjectUUID())
|
||||
if (DbManager.ItemQueries.UPDATE_GOLD(i, 0)) {
|
||||
this.getGoldInventory().setNumOfItems(0);
|
||||
@@ -1000,8 +1000,7 @@ public class CharacterItemManager {
|
||||
|
||||
if (equippedContains(item)) {
|
||||
fromEquip = true;
|
||||
ItemBase ib = item.getItemBase();
|
||||
if (ib != null && ib.getType().equals(ItemType.GOLD))
|
||||
if (item.template.item_type.equals(ItemType.GOLD))
|
||||
this.absCharacter.cancelOnUnEquip();
|
||||
}
|
||||
|
||||
@@ -1211,7 +1210,7 @@ public class CharacterItemManager {
|
||||
|
||||
// This removes ingame item from inventory for loot.
|
||||
private synchronized boolean removeItemFromInventory(Item i) {
|
||||
if (i.getItemBase().getType().equals(ItemType.GOLD)) {
|
||||
if (i.template.item_type.equals(ItemType.GOLD)) {
|
||||
if (i.getObjectUUID() != this.getGoldInventory().getObjectUUID())
|
||||
return false;
|
||||
if (!DbManager.ItemQueries.UPDATE_GOLD(this.goldInventory, 0)) {
|
||||
@@ -1234,7 +1233,7 @@ public class CharacterItemManager {
|
||||
|
||||
// This adds item to inventory for loot. Validity checks already handled
|
||||
public synchronized boolean addItemToInventory(Item i) {
|
||||
if (i.getItemBase().getType().equals(ItemType.GOLD))
|
||||
if (i.template.item_type.equals(ItemType.GOLD))
|
||||
if (this.absCharacter.getObjectType() == GameObjectType.Mob) {
|
||||
if (this.goldInventory == null)
|
||||
loadGoldItems();
|
||||
@@ -1261,7 +1260,7 @@ public class CharacterItemManager {
|
||||
|
||||
//called for adding gold of a specified amount
|
||||
public synchronized boolean addItemToInventory(Item i, int amount) {
|
||||
if (i.getItemBase().getType().equals(ItemType.GOLD))
|
||||
if (i.template.item_type.equals(ItemType.GOLD))
|
||||
return DbManager.ItemQueries.UPDATE_GOLD(this.getGoldInventory(), this.goldInventory.getNumOfItems() + amount);
|
||||
return false;
|
||||
}
|
||||
@@ -1623,9 +1622,9 @@ public class CharacterItemManager {
|
||||
synchronized (lockFirst) {
|
||||
synchronized (lockSecond) {
|
||||
// make sure current player has item in inventory
|
||||
if (lootItem.getItemBase().getType().equals(ItemType.GOLD) && lootItem.getObjectUUID() != this.getGoldInventory().getObjectUUID() && !(this.absCharacter.getObjectType().equals(GameObjectType.Mob)))
|
||||
if (lootItem.template.item_type.equals(ItemType.GOLD) && lootItem.getObjectUUID() != this.getGoldInventory().getObjectUUID() && !(this.absCharacter.getObjectType().equals(GameObjectType.Mob)))
|
||||
return null;
|
||||
else if (!this.inventory.contains(lootItem) && !this.getEquippedList().contains(lootItem) && !lootItem.getItemBase().getType().equals(ItemType.GOLD))
|
||||
else if (!this.inventory.contains(lootItem) && !this.getEquippedList().contains(lootItem) && !lootItem.template.item_type.equals(ItemType.GOLD))
|
||||
return null;
|
||||
|
||||
// get weight of item
|
||||
@@ -1636,10 +1635,10 @@ public class CharacterItemManager {
|
||||
int weight = lootItem.template.item_wt;
|
||||
|
||||
// make sure lootingPlayer has room for item
|
||||
if (!lootItem.getItemBase().getType().equals(ItemType.GOLD) && !looterItems.hasRoomInventory(weight))
|
||||
if (!lootItem.template.item_type.equals(ItemType.GOLD) && !looterItems.hasRoomInventory(weight))
|
||||
return null;
|
||||
|
||||
if (lootItem.getItemBase().getType().equals(ItemType.GOLD))
|
||||
if (lootItem.template.item_type.equals(ItemType.GOLD))
|
||||
if (amount != -1) { //from steal
|
||||
int total = lootItem.getNumOfItems();
|
||||
amount = (amount > total) ? total : amount;
|
||||
@@ -1702,25 +1701,25 @@ public class CharacterItemManager {
|
||||
* Delegates
|
||||
*/
|
||||
public synchronized boolean bankContains(Item i) {
|
||||
if (i.getItemBase().getType().equals(ItemType.GOLD))
|
||||
if (i.template.item_type.equals(ItemType.GOLD))
|
||||
return (this.getGoldBank() != null && this.goldBank.getObjectUUID() == i.getObjectUUID());
|
||||
return bank.contains(i);
|
||||
}
|
||||
|
||||
public synchronized boolean inventoryContains(Item i) {
|
||||
if (i.getItemBase().getType().equals(ItemType.GOLD))
|
||||
if (i.template.item_type.equals(ItemType.GOLD))
|
||||
return (this.getGoldInventory() != null && this.goldInventory.getObjectUUID() == i.getObjectUUID());
|
||||
return inventory.contains(i);
|
||||
}
|
||||
|
||||
public synchronized boolean forgeContains(Item i, NPC vendor) {
|
||||
if (i.getItemBase().getType().equals(ItemType.GOLD))
|
||||
if (i.template.item_type.equals(ItemType.GOLD))
|
||||
return (this.getGoldInventory() != null && this.goldInventory.getObjectUUID() == i.getObjectUUID());
|
||||
return vendor.getRolling().contains(i);
|
||||
}
|
||||
|
||||
public synchronized boolean vaultContains(Item i) {
|
||||
if (i.getItemBase().getType().equals(ItemType.GOLD))
|
||||
if (i.template.item_type.equals(ItemType.GOLD))
|
||||
return (this.getGoldVault() != null && this.goldVault.getObjectUUID() == i.getObjectUUID());
|
||||
return this.account.getVault().contains(i);
|
||||
}
|
||||
@@ -2004,13 +2003,13 @@ public class CharacterItemManager {
|
||||
item.zeroItem();
|
||||
item.containerType = Enum.ItemContainerType.INVENTORY;
|
||||
|
||||
if (item.getItemBase().getType().equals(ItemType.GOLD))
|
||||
if (item.template.item_type.equals(ItemType.GOLD))
|
||||
//only add gold item once
|
||||
if (!corpse.hasGold())
|
||||
corpse.setHasGold(true);
|
||||
newInventory.add(item);
|
||||
} else //item
|
||||
if (item.getItemBase().getType().equals(ItemType.GOLD)) {
|
||||
if (item.template.item_type.equals(ItemType.GOLD)) {
|
||||
int amt = item.getNumOfItems();
|
||||
item.setNumOfItems(0);
|
||||
MobLoot ml = new MobLoot(this.absCharacter, amt);
|
||||
|
||||
@@ -280,7 +280,7 @@ public class Item extends AbstractWorldObject {
|
||||
writer.put((byte) 0);
|
||||
|
||||
|
||||
if (item.getItemBase().getType().getValue() != 20) {
|
||||
if (item.template.item_type.equals(ItemType.EMPLOYMENTCONTRACT) == false) {
|
||||
writer.putShort((short) 0);
|
||||
return;
|
||||
}
|
||||
@@ -459,7 +459,7 @@ public class Item extends AbstractWorldObject {
|
||||
int serialized = 0;
|
||||
for (Item item : list) {
|
||||
|
||||
if (item.getItemBase().getType().equals(ItemType.GOLD))
|
||||
if (item.template.item_type.equals(ItemType.GOLD))
|
||||
if (item.numberOfItems == 0)
|
||||
continue;
|
||||
try {
|
||||
@@ -493,7 +493,7 @@ public class Item extends AbstractWorldObject {
|
||||
int serialized = 0;
|
||||
for (Item item : list) {
|
||||
|
||||
if (item.getItemBase().getType().equals(ItemType.GOLD))
|
||||
if (item.template.item_type.equals(ItemType.GOLD))
|
||||
if (item.numberOfItems == 0)
|
||||
continue;
|
||||
try {
|
||||
|
||||
@@ -30,8 +30,6 @@ public class ItemBase {
|
||||
private static final ArrayList<ItemBase> _resourceList = new ArrayList<>();
|
||||
public final int uuid;
|
||||
|
||||
//requirements/restrictions
|
||||
private final ItemType type;
|
||||
private final int modTable;
|
||||
private final int useID;
|
||||
private int hashID;
|
||||
@@ -61,8 +59,6 @@ public class ItemBase {
|
||||
public ItemBase(ResultSet rs) throws SQLException {
|
||||
|
||||
this.uuid = rs.getInt("ID");
|
||||
|
||||
this.type = ItemType.valueOf(rs.getString("Type"));
|
||||
this.useID = rs.getInt("useID");
|
||||
this.useAmount = rs.getByte("useAmount");
|
||||
this.modTable = rs.getInt("modTable");
|
||||
@@ -84,18 +80,17 @@ public class ItemBase {
|
||||
|
||||
this.twoHanded = (rs.getInt("twoHanded") == 1);
|
||||
|
||||
switch (this.type) {
|
||||
switch (ItemTemplate.itemTemplates.get(this.getUUID()).item_type) {
|
||||
case RUNE:
|
||||
case SCROLL:
|
||||
case COMMANDROD:
|
||||
case WAND:
|
||||
case POTION:
|
||||
case TEARS:
|
||||
case GUILDCHARTER:
|
||||
case CHARTER:
|
||||
case DEED:
|
||||
case CONTRACT:
|
||||
case WATERBUCKET:
|
||||
case EMPLOYMENTCONTRACT:
|
||||
case BUCKET:
|
||||
case REALMCHARTER:
|
||||
case GIFT:
|
||||
case TREASURE:
|
||||
this.isConsumable = true;
|
||||
break;
|
||||
case OFFERING:
|
||||
@@ -118,7 +113,7 @@ public class ItemBase {
|
||||
|
||||
_itemBaseByUUID.put(itemBase.uuid, itemBase);
|
||||
|
||||
if (itemBase.type.equals(ItemType.RESOURCE))
|
||||
if (ItemTemplate.itemTemplates.get(itemBase.uuid).item_type.equals(ItemType.RESOURCE))
|
||||
_resourceList.add(itemBase);
|
||||
|
||||
ItemTemplate template = ItemTemplate.itemTemplates.get(itemBase.uuid);
|
||||
@@ -225,10 +220,6 @@ public class ItemBase {
|
||||
|
||||
}
|
||||
|
||||
public ItemType getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public int getUseID() {
|
||||
return this.useID;
|
||||
}
|
||||
|
||||
@@ -220,7 +220,7 @@ public class ItemFactory {
|
||||
int suffixCost = 0;
|
||||
|
||||
|
||||
if (ib.getType() == ItemType.WEAPON && ib.getPercentRequired() == 110) {
|
||||
if (template.item_type.equals(ItemType.WEAPON) && ib.getPercentRequired() == 110) {
|
||||
switch (ib.getSkillRequired()) {
|
||||
case "Bow":
|
||||
case "Crossbow":
|
||||
@@ -814,7 +814,7 @@ public class ItemFactory {
|
||||
int galvorAmount = 0;
|
||||
int wormwoodAmount = 0;
|
||||
|
||||
if (ib.getType() == ItemType.WEAPON && ib.getPercentRequired() == 110) {
|
||||
if (template.item_type.equals(ItemType.WEAPON) && ib.getPercentRequired() == 110) {
|
||||
switch (ib.getSkillRequired()) {
|
||||
case "Bow":
|
||||
case "Crossbow":
|
||||
|
||||
@@ -1295,7 +1295,7 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed {
|
||||
if (ib == null)
|
||||
return 0;
|
||||
|
||||
if (!ib.getType().equals(ItemType.ARMOR))
|
||||
if (!armor.template.item_type.equals(ItemType.ARMOR))
|
||||
return 0;
|
||||
|
||||
if (ib.getSkillRequired().isEmpty())
|
||||
@@ -1334,7 +1334,7 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed {
|
||||
|
||||
if (ib == null)
|
||||
noWeapon = true;
|
||||
else if (ib.getType().equals(ItemType.WEAPON) == false) {
|
||||
else if (weapon.template.item_type.equals(ItemType.WEAPON) == false) {
|
||||
defaultAtrAndDamage(mainHand);
|
||||
return;
|
||||
} else
|
||||
|
||||
@@ -69,7 +69,7 @@ public final class MobLoot extends Item {
|
||||
this.ownerID = mob.getObjectUUID();
|
||||
this.objectUUID = generateId();
|
||||
|
||||
if (quantity == 0 && ib.getType() == ItemType.RESOURCE)
|
||||
if (quantity == 0 && ItemTemplate.itemTemplates.get(ib.getUUID()).item_type == ItemType.RESOURCE)
|
||||
quantity = 1;
|
||||
|
||||
if (quantity > 0)
|
||||
@@ -129,10 +129,9 @@ public final class MobLoot extends Item {
|
||||
if (isDeleted)
|
||||
return null;
|
||||
|
||||
if (this.getItemBase().getType().equals(ItemType.GOLD))
|
||||
if (this.template.item_type.equals(ItemType.GOLD))
|
||||
return null;
|
||||
|
||||
|
||||
Item item = (Item) this;
|
||||
|
||||
item.setOwner(looter);
|
||||
|
||||
@@ -1070,7 +1070,7 @@ public class NPC extends AbstractCharacter {
|
||||
ItemBase itemBase;
|
||||
for (Integer itemID : fullItemList) {
|
||||
itemBase = ItemBase.getItemBase(itemID);
|
||||
boolean exclude = itemBase.getPercentRequired() == 0 && itemBase.getType() == ItemType.WEAPON;
|
||||
boolean exclude = itemBase.getPercentRequired() == 0 && ItemTemplate.itemTemplates.get(itemID).item_type == ItemType.WEAPON;
|
||||
if (itemBase.getPercentRequired() <= maxSkill && !exclude)
|
||||
filteredItemList.add(itemID);
|
||||
}
|
||||
@@ -1095,7 +1095,7 @@ public class NPC extends AbstractCharacter {
|
||||
if (ib == null)
|
||||
return 0;
|
||||
|
||||
if (ib.getType() == ItemType.SCROLL)
|
||||
if (ItemTemplate.itemTemplates.get(itemID).item_type == ItemType.SCROLL)
|
||||
return this.getRank() * 60 * 60 * 3;
|
||||
|
||||
float time;
|
||||
|
||||
@@ -2840,11 +2840,11 @@ public class PlayerCharacter extends AbstractCharacter {
|
||||
ItemBase ib = item.getItemBase();
|
||||
if (ib != null) {
|
||||
|
||||
if ((ib.getType().equals(ItemType.WEAPON))
|
||||
if ((item.template.item_type.equals(ItemType.WEAPON))
|
||||
&& (ib.getSkillRequired().equals(type) || ib.getMastery().equals(type)))
|
||||
return true;
|
||||
|
||||
return (ib.getType().equals(ItemType.ARMOR))
|
||||
return (item.template.item_type.equals(ItemType.ARMOR))
|
||||
&& (ib.getSkillRequired().equals(type));
|
||||
}
|
||||
|
||||
@@ -3865,7 +3865,7 @@ public class PlayerCharacter extends AbstractCharacter {
|
||||
ItemBase ib = weapon.getItemBase();
|
||||
if (ib == null)
|
||||
noWeapon = true;
|
||||
else if (!ib.getType().equals(ItemType.WEAPON)) {
|
||||
else if (!weapon.template.item_type.equals(ItemType.WEAPON)) {
|
||||
defaultAtrAndDamage(mainHand);
|
||||
return;
|
||||
} else
|
||||
@@ -3884,7 +3884,7 @@ public class PlayerCharacter extends AbstractCharacter {
|
||||
if (noWeapon) {
|
||||
if (mainHand) {
|
||||
Item off = this.charItemManager.getEquipped().get(EquipSlotType.LHELD);
|
||||
if (off != null && off.getItemBase() != null && off.getItemBase().getType().equals(ItemType.WEAPON))
|
||||
if (off != null && off.getItemBase() != null && off.template.item_type.equals(ItemType.WEAPON))
|
||||
this.rangeHandOne = 10 * (1 + (this.statStrBase / 600)); // Set
|
||||
// to
|
||||
// no
|
||||
@@ -4026,7 +4026,7 @@ public class PlayerCharacter extends AbstractCharacter {
|
||||
//if duel wielding, cut damage by 30%
|
||||
if (otherHand != null) {
|
||||
ItemBase ibo = otherHand.getItemBase();
|
||||
if (ibo != null && ibo.getType().equals(ItemType.WEAPON)) {
|
||||
if (ibo != null && otherHand.template.equals(ItemType.WEAPON)) {
|
||||
min *= 0.7f;
|
||||
max *= 0.7f;
|
||||
}
|
||||
@@ -4171,10 +4171,12 @@ public class PlayerCharacter extends AbstractCharacter {
|
||||
if (ib == null)
|
||||
return 0;
|
||||
|
||||
if (!ib.getType().equals(ItemType.ARMOR))
|
||||
if (!armor.template.item_type.equals(ItemType.ARMOR))
|
||||
return 0;
|
||||
|
||||
if (ib.getSkillRequired().isEmpty())
|
||||
return ib.getDefense();
|
||||
|
||||
CharacterSkill armorSkill = this.skills.get(ib.getSkillRequired());
|
||||
if (armorSkill == null) {
|
||||
Logger.error("Player " + this.getObjectUUID()
|
||||
|
||||
@@ -341,7 +341,7 @@ public class Warehouse extends AbstractWorldObject {
|
||||
|
||||
Resource resourceType;
|
||||
|
||||
if (resource.getItemBase().getType().equals(Enum.ItemType.GOLD))
|
||||
if (resource.template.item_type.equals(Enum.ItemType.GOLD))
|
||||
resourceType = Resource.GOLD;
|
||||
else
|
||||
resourceType = Resource.valueOf(ItemTemplate.itemTemplates.get(resource.getTemplsteID()).item_base_name.toUpperCase());
|
||||
|
||||
Reference in New Issue
Block a user