|
|
@ -2274,7 +2274,6 @@ public class CharacterItemManager { |
|
|
|
|
|
|
|
|
|
|
|
if (this.absCharacter.getObjectType().equals(GameObjectType.PlayerCharacter) == false) |
|
|
|
if (this.absCharacter.getObjectType().equals(GameObjectType.PlayerCharacter) == false) |
|
|
|
return; |
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
PlayerCharacter pc = (PlayerCharacter) this.absCharacter; |
|
|
|
PlayerCharacter pc = (PlayerCharacter) this.absCharacter; |
|
|
|
|
|
|
|
|
|
|
|
UpdateInventoryMsg updateInventoryMsg = new UpdateInventoryMsg(inventory, this.getBank(), this.getGoldInventory(), add); |
|
|
|
UpdateInventoryMsg updateInventoryMsg = new UpdateInventoryMsg(inventory, this.getBank(), this.getGoldInventory(), add); |
|
|
@ -2312,7 +2311,6 @@ public class CharacterItemManager { |
|
|
|
* Update the player's inventory window by resending the entire contents. |
|
|
|
* Update the player's inventory window by resending the entire contents. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void updateInventory() { |
|
|
|
public void updateInventory() { |
|
|
|
this.StackResources(); |
|
|
|
|
|
|
|
this.updateInventory(this.getInventory(), true); |
|
|
|
this.updateInventory(this.getInventory(), true); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -2617,55 +2615,42 @@ public class CharacterItemManager { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void StackResources(){ |
|
|
|
public void StackResources(){ |
|
|
|
if(this.getOwner().getObjectType().equals(GameObjectType.PlayerCharacter) == false) |
|
|
|
if(!this.getOwner().getObjectType().equals(GameObjectType.PlayerCharacter)) |
|
|
|
return; |
|
|
|
return; |
|
|
|
//create hashmap of all resources in inventory sorted by type
|
|
|
|
ArrayList<Item> resources = new ArrayList<>(); |
|
|
|
HashMap<ItemBase,ArrayList<Item>> resources = new HashMap<>(); |
|
|
|
HashMap<Integer,Integer> newStacks = new HashMap<>(); |
|
|
|
//populate resources hashmap with items currently in inventory
|
|
|
|
|
|
|
|
for(Item item : this.getInventory()){ |
|
|
|
for(Item item : this.getInventory()){ |
|
|
|
if(Warehouse.getMaxResources().get(item.getItemBaseID()) != null && Warehouse.getMaxResources().get(item.getItemBaseID()) != 0){ |
|
|
|
if(item.getItemBase().getType().equals(ItemType.RESOURCE)){ |
|
|
|
if(resources.containsKey(item.getItemBase())){ |
|
|
|
resources.add(item); |
|
|
|
resources.get(item.getItemBase()).add(item); |
|
|
|
if(newStacks.containsKey(item.getItemBaseID())){ |
|
|
|
} else{ |
|
|
|
newStacks.put(item.getItemBaseID(),newStacks.get(item.getItemBaseID()) + item.getNumOfItems()); |
|
|
|
resources.put(item.getItemBase(),new ArrayList<>()); |
|
|
|
}else{ |
|
|
|
} |
|
|
|
newStacks.put(item.getItemBaseID(),item.getNumOfItems()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
//create a purge list to remove form inventory after we compile all the stacks together
|
|
|
|
} |
|
|
|
ArrayList<Item> purgeList = new ArrayList<>(); |
|
|
|
//do stacking here
|
|
|
|
ArrayList<Item> newStacks = new ArrayList<>(); |
|
|
|
PlayerCharacter pc = PlayerCharacter.getFromCache(this.getOwner().getObjectUUID()); |
|
|
|
//now we have all our resources sorted, lets combine them into one single stack for each type
|
|
|
|
for(Integer id : newStacks.keySet()){ |
|
|
|
for(ItemBase resourceBase : resources.keySet()){ |
|
|
|
ItemBase ib = ItemBase.getItemBase(id); |
|
|
|
int count = 0; |
|
|
|
Item item = new Item(ib, pc.getObjectUUID(), |
|
|
|
for(Item resource : resources.get(resourceBase)){ |
|
|
|
Enum.OwnerType.PlayerCharacter, (byte) 0, (byte) 0, (short) ib.getDurability(), (short) ib.getDurability(), |
|
|
|
count += resource.getNumOfItems(); |
|
|
|
|
|
|
|
purgeList.add(resource); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Item item = new Item(resourceBase, this.getOwner().getObjectUUID(), |
|
|
|
|
|
|
|
Enum.OwnerType.PlayerCharacter, (byte) 0, (byte) 0, (short) resourceBase.getDurability(), (short) resourceBase.getDurability(), |
|
|
|
|
|
|
|
true, false, Enum.ItemContainerType.INVENTORY, (byte) 0, |
|
|
|
true, false, Enum.ItemContainerType.INVENTORY, (byte) 0, |
|
|
|
new ArrayList<>(), ""); |
|
|
|
new ArrayList<>(), ""); |
|
|
|
|
|
|
|
|
|
|
|
item.setNumOfItems(count); |
|
|
|
item.setNumOfItems(newStacks.get(id)); |
|
|
|
newStacks.add(item); |
|
|
|
try{ |
|
|
|
} |
|
|
|
|
|
|
|
//create new stacks in database, add to inventory and update window
|
|
|
|
|
|
|
|
for(Item item : newStacks){ |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
item = DbManager.ItemQueries.ADD_ITEM(item); |
|
|
|
item = DbManager.ItemQueries.ADD_ITEM(item); |
|
|
|
if(item != null){ |
|
|
|
|
|
|
|
this.addItemToInventory(item); |
|
|
|
this.addItemToInventory(item); |
|
|
|
} |
|
|
|
}catch(Exception e){ |
|
|
|
} catch (Exception e) { |
|
|
|
ChatManager.chatSystemError(pc, "Failed To Stack Resources"); |
|
|
|
ChatManager.chatSystemError((PlayerCharacter)this.getOwner(), "Resource Stack Error: Unable to create item. " + e.getMessage()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for (Item purged : purgeList){ |
|
|
|
|
|
|
|
this.delete(purged); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
for(Item item : resources) |
|
|
|
|
|
|
|
this.delete(item); |
|
|
|
|
|
|
|
|
|
|
|
//this.updateInventory();
|
|
|
|
this.updateInventory(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|