Browse Source

resource dupe

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

26
src/engine/objects/CharacterItemManager.java

@ -1254,13 +1254,37 @@ 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);
this.itemIDtoType.put(i.getObjectUUID(), i.getObjectType().ordinal()); this.itemIDtoType.put(i.getObjectUUID(), i.getObjectType().ordinal());
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