Browse Source

resource stacking bug

lakebane-master
FatBoy-DOTC 10 months ago
parent
commit
dd548acfe1
  1. 16
      src/engine/objects/CharacterItemManager.java

16
src/engine/objects/CharacterItemManager.java

@ -1260,12 +1260,15 @@ public class CharacterItemManager {
} }
if (i.getItemBase().getType().equals(ItemType.RESOURCE) && this.getOwner().getObjectType().equals(GameObjectType.PlayerCharacter)) { if (i.getItemBase().getType().equals(ItemType.RESOURCE) && this.getOwner().getObjectType().equals(GameObjectType.PlayerCharacter)) {
boolean added = false; boolean added = false;
for(Item item : this.getInventory()){ ArrayList<Item> purge = new ArrayList<>();
int count = i.getNumOfItems();
for(Item item : this.inventory){
if(item.getItemBaseID() == i.getItemBaseID()){ if(item.getItemBaseID() == i.getItemBaseID()){
if(item.getNumOfItems() + i.getNumOfItems() <= Warehouse.getMaxResources().get(item.getItemBaseID())) { purge.add(item);
item.setNumOfItems(item.getNumOfItems() + i.getNumOfItems()); if(count + item.getNumOfItems() <= Warehouse.maxResources.get(i.getItemBaseID())) {
updateInventory(); count += item.getNumOfItems();
added = true; added = true;
purge.add(item);
} }
} }
} }
@ -1276,7 +1279,12 @@ public class CharacterItemManager {
ItemBase ib = i.getItemBase(); ItemBase ib = i.getItemBase();
if (ib != null) if (ib != null)
this.inventoryWeight += ib.getWeight(); this.inventoryWeight += ib.getWeight();
} else{
this.inventory.removeAll(purge);
i.setNumOfItems(count);
this.inventory.add(i);
} }
this.updateInventory();
}else { }else {
this.inventory.add(i); this.inventory.add(i);
this.itemIDtoType.put(i.getObjectUUID(), i.getObjectType().ordinal()); this.itemIDtoType.put(i.getObjectUUID(), i.getObjectType().ordinal());

Loading…
Cancel
Save