Browse Source

resource dupe

lakebane-master
FatBoy-DOTC 10 months ago
parent
commit
77e9a4d9bf
  1. 24
      src/engine/objects/CharacterItemManager.java

24
src/engine/objects/CharacterItemManager.java

@ -1254,6 +1254,14 @@ public class CharacterItemManager {
} }
return false; return false;
} }
} else if (i.getItemBase().getType().equals(ItemType.RESOURCE)) {
if(this.inventoryContainsResource(i)){
Item resource = getResource(i);
if(resource != null){
resource.setNumOfItems(resource.getNumOfItems() + i.getNumOfItems());
return true;
}
}
} }
this.inventory.add(i); this.inventory.add(i);
@ -1261,6 +1269,22 @@ public class CharacterItemManager {
return true; return true;
} }
private boolean inventoryContainsResource(Item resource) {
for(Item i : this.inventory){
if(i.getItemBaseID() == resource.getItemBaseID())
return true;
}
return false;
}
private Item getResource(Item resource) {
for(Item i : this.inventory){
if(i.getItemBaseID() == resource.getItemBaseID())
return i;
}
return null;
}
//called for adding gold of a specified amount //called for adding gold of a specified amount
public synchronized boolean addItemToInventory(Item i, int amount) { public synchronized boolean addItemToInventory(Item i, int amount) {
if (i.getItemBase().getType().equals(ItemType.GOLD)) if (i.getItemBase().getType().equals(ItemType.GOLD))

Loading…
Cancel
Save