forked from MagicBane/Server
item_wt refactored to template
This commit is contained in:
@@ -90,21 +90,29 @@ public class CharacterItemManager {
|
||||
}
|
||||
|
||||
public static void takeFromNPC(NPC npc, PlayerCharacter pc, Item take, ClientMessagePump clientMessagePump) {
|
||||
|
||||
ItemBase ib = take.getItemBase();
|
||||
if (ib == null)
|
||||
ItemTemplate template = take.template;
|
||||
|
||||
if (template == null)
|
||||
return;
|
||||
|
||||
CharacterItemManager itemMan = pc.getCharItemManager();
|
||||
|
||||
if (itemMan == null)
|
||||
return;
|
||||
|
||||
CharacterItemManager npcCim = npc.getCharItemManager();
|
||||
|
||||
if (npcCim == null)
|
||||
return;
|
||||
if (!npcCim.inventoryContains(take)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!itemMan.hasRoomInventory(ib.getWeight()))
|
||||
if (!npcCim.inventoryContains(take))
|
||||
return;
|
||||
|
||||
if (!itemMan.hasRoomInventory(template.item_wt))
|
||||
return;
|
||||
|
||||
if (take != null) {
|
||||
itemMan.buyFromNPC(take, npc);
|
||||
itemMan.updateInventory();
|
||||
@@ -621,7 +629,7 @@ public class CharacterItemManager {
|
||||
if (!i.validForInventory(source.getClientConnection(), source, this))
|
||||
return false;
|
||||
|
||||
if (!tradingWith.hasRoomTrade(i.getItemBase().getWeight())) {
|
||||
if (!tradingWith.hasRoomTrade(i.template.item_wt)) {
|
||||
dispatch = Dispatch.borrow(source, msg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY);
|
||||
return false;
|
||||
@@ -1251,9 +1259,10 @@ public class CharacterItemManager {
|
||||
this.inventory.add(i);
|
||||
this.itemIDtoType.put(i.getObjectUUID(), i.getObjectType().ordinal());
|
||||
|
||||
ItemBase ib = i.getItemBase();
|
||||
if (ib != null)
|
||||
this.inventoryWeight += ib.getWeight();
|
||||
|
||||
if (i.template != null)
|
||||
this.inventoryWeight += i.template.item_wt;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1503,18 +1512,19 @@ public class CharacterItemManager {
|
||||
|
||||
synchronized (this) {
|
||||
synchronized (itemMan) {
|
||||
itemBase = purchasedItem.getItemBase();
|
||||
ItemTemplate template = purchasedItem.template;
|
||||
|
||||
if (itemBase == null)
|
||||
if (template == null)
|
||||
return false;
|
||||
|
||||
//test inventory is not full
|
||||
|
||||
if (!hasRoomInventory(itemBase.getWeight()))
|
||||
if (!hasRoomInventory(template.item_wt))
|
||||
return false;
|
||||
|
||||
if (!itemMan.inventory.contains(purchasedItem))
|
||||
return false;
|
||||
|
||||
// attempt to transfer item in db
|
||||
|
||||
if (purchasedItem.getObjectType() == GameObjectType.MobLoot) {
|
||||
@@ -1625,10 +1635,11 @@ public class CharacterItemManager {
|
||||
return null;
|
||||
|
||||
// get weight of item
|
||||
ItemBase ib = lootItem.getItemBase();
|
||||
if (ib == null)
|
||||
|
||||
if (lootItem.template == null)
|
||||
return null;
|
||||
short weight = ib.getWeight();
|
||||
|
||||
int weight = lootItem.template.item_wt;
|
||||
|
||||
// make sure lootingPlayer has room for item
|
||||
if (!lootItem.getItemBase().getType().equals(ItemType.GOLD) && !looterItems.hasRoomInventory(weight))
|
||||
@@ -2106,7 +2117,7 @@ public class CharacterItemManager {
|
||||
return true; // npc's need checked
|
||||
}
|
||||
|
||||
public boolean hasRoomTrade(short itemWeight) {
|
||||
public boolean hasRoomTrade(int itemWeight) {
|
||||
|
||||
PlayerCharacter playerCharacter;
|
||||
PlayerCharacter tradeCharacter;
|
||||
@@ -2134,13 +2145,15 @@ public class CharacterItemManager {
|
||||
return tradeWeight <= (int) playerCharacter.statStrBase * 3;
|
||||
}
|
||||
|
||||
public boolean hasRoomBank(short weight) {
|
||||
public boolean hasRoomBank(int weight) {
|
||||
|
||||
if (this.absCharacter == null)
|
||||
return false;
|
||||
|
||||
return weight <= this.absCharacter.getBankCapacityRemaining();
|
||||
}
|
||||
|
||||
public boolean hasRoomVault(short weight) {
|
||||
public boolean hasRoomVault(int weight) {
|
||||
if (this.absCharacter == null)
|
||||
return false;
|
||||
return weight <= this.absCharacter.getVaultCapacityRemaining();
|
||||
@@ -2181,8 +2194,7 @@ public class CharacterItemManager {
|
||||
if (item == null)
|
||||
continue;
|
||||
|
||||
ItemBase ib = item.getItemBase();
|
||||
weight += ib.getWeight();
|
||||
weight += item.template.item_wt;
|
||||
}
|
||||
return weight;
|
||||
}
|
||||
@@ -2200,10 +2212,9 @@ public class CharacterItemManager {
|
||||
|
||||
public void calculateBankWeight() {
|
||||
this.bankWeight = 0;
|
||||
for (Item i : this.bank) {
|
||||
ItemBase ib = i.getItemBase();
|
||||
if (ib != null)
|
||||
this.bankWeight += ib.getWeight();
|
||||
for (Item item : this.bank) {
|
||||
if (item.template != null)
|
||||
this.bankWeight += item.template.item_value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2212,28 +2223,25 @@ public class CharacterItemManager {
|
||||
Collection<Item> c = this.equipped.values();
|
||||
Iterator<Item> it = c.iterator();
|
||||
while (it.hasNext()) {
|
||||
Item i = it.next();
|
||||
ItemBase ib = i.getItemBase();
|
||||
if (ib != null)
|
||||
this.equipWeight += ib.getWeight();
|
||||
Item item = it.next();
|
||||
if (item.template != null)
|
||||
this.equipWeight += item.template.item_wt;
|
||||
}
|
||||
}
|
||||
|
||||
public void calculateInventoryWeight() {
|
||||
this.inventoryWeight = 0;
|
||||
for (Item i : this.inventory) {
|
||||
ItemBase ib = i.getItemBase();
|
||||
if (ib != null)
|
||||
this.inventoryWeight += ib.getWeight();
|
||||
for (Item item : this.inventory) {
|
||||
if (item.template != null)
|
||||
this.inventoryWeight += item.template.item_wt;
|
||||
}
|
||||
}
|
||||
|
||||
public void calculateVaultWeight() {
|
||||
this.vaultWeight = 0;
|
||||
for (Item i : this.vault) {
|
||||
ItemBase ib = i.getItemBase();
|
||||
if (ib != null)
|
||||
this.vaultWeight += ib.getWeight();
|
||||
for (Item item : this.vault) {
|
||||
if (item.template != null)
|
||||
this.vaultWeight += item.template.item_wt;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user