|
|
@ -12,6 +12,7 @@ package engine.objects; |
|
|
|
import engine.Enum; |
|
|
|
import engine.Enum; |
|
|
|
import engine.Enum.GameObjectType; |
|
|
|
import engine.Enum.GameObjectType; |
|
|
|
import engine.Enum.ItemType; |
|
|
|
import engine.Enum.ItemType; |
|
|
|
|
|
|
|
import engine.devcmd.cmds.MakeItemCmd; |
|
|
|
import engine.gameManager.*; |
|
|
|
import engine.gameManager.*; |
|
|
|
import engine.math.Vector3fImmutable; |
|
|
|
import engine.math.Vector3fImmutable; |
|
|
|
import engine.net.Dispatch; |
|
|
|
import engine.net.Dispatch; |
|
|
@ -23,10 +24,7 @@ import engine.powers.poweractions.AbstractPowerAction; |
|
|
|
import engine.server.MBServerStatics; |
|
|
|
import engine.server.MBServerStatics; |
|
|
|
import org.pmw.tinylog.Logger; |
|
|
|
import org.pmw.tinylog.Logger; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.*; |
|
|
|
import java.util.Collection; |
|
|
|
|
|
|
|
import java.util.HashSet; |
|
|
|
|
|
|
|
import java.util.Iterator; |
|
|
|
|
|
|
|
import java.util.concurrent.ConcurrentHashMap; |
|
|
|
import java.util.concurrent.ConcurrentHashMap; |
|
|
|
import java.util.concurrent.ThreadLocalRandom; |
|
|
|
import java.util.concurrent.ThreadLocalRandom; |
|
|
|
|
|
|
|
|
|
|
@ -778,6 +776,8 @@ public class CharacterItemManager { |
|
|
|
this.commitTrade(); |
|
|
|
this.commitTrade(); |
|
|
|
this.closeTradeWindow(ctwm1, false); |
|
|
|
this.closeTradeWindow(ctwm1, false); |
|
|
|
other.getCharItemManager().closeTradeWindow(ctwm2, false); |
|
|
|
other.getCharItemManager().closeTradeWindow(ctwm2, false); |
|
|
|
|
|
|
|
other.getCharItemManager().StackResources(); |
|
|
|
|
|
|
|
this.StackResources(); |
|
|
|
} |
|
|
|
} |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
@ -1254,18 +1254,12 @@ 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()); |
|
|
|
|
|
|
|
if(i.getItemBase().getType().equals(ItemType.RESOURCE)){ |
|
|
|
|
|
|
|
this.StackResources(); |
|
|
|
|
|
|
|
} |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -2626,4 +2620,57 @@ public class CharacterItemManager { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void StackResources(){ |
|
|
|
|
|
|
|
if(this.getOwner().getObjectType().equals(GameObjectType.PlayerCharacter) == false) |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
//create hashmap of all resources in inventory sorted by type
|
|
|
|
|
|
|
|
HashMap<ItemBase,ArrayList<Item>> resources = new HashMap<>(); |
|
|
|
|
|
|
|
//populate resources hashmap with items currently in inventory
|
|
|
|
|
|
|
|
for(Item item : this.getInventory()){ |
|
|
|
|
|
|
|
if(Warehouse.getMaxResources().get(item.getItemBaseID()) != null && Warehouse.getMaxResources().get(item.getItemBaseID()) != 0){ |
|
|
|
|
|
|
|
if(resources.containsKey(item.getItemBaseID())){ |
|
|
|
|
|
|
|
resources.get(item.getItemBase()).add(item); |
|
|
|
|
|
|
|
} else{ |
|
|
|
|
|
|
|
resources.put(item.getItemBase(),new ArrayList<>()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//create a purge list to remove form inventory after we compile all the stacks together
|
|
|
|
|
|
|
|
ArrayList<Item> purgeList = new ArrayList<>(); |
|
|
|
|
|
|
|
ArrayList<Item> newStacks = new ArrayList<>(); |
|
|
|
|
|
|
|
//now we have all our resources sorted, lets combine them into one single stack for each type
|
|
|
|
|
|
|
|
for(ItemBase resourceBase : resources.keySet()){ |
|
|
|
|
|
|
|
int count = 0; |
|
|
|
|
|
|
|
for(Item resource : resources.get(resourceBase)){ |
|
|
|
|
|
|
|
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, |
|
|
|
|
|
|
|
new ArrayList<>(), ""); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
item.setNumOfItems(count); |
|
|
|
|
|
|
|
newStacks.add(item); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//create new stacks in database, add to inventory and update window
|
|
|
|
|
|
|
|
for(Item item : newStacks){ |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
item = DbManager.ItemQueries.ADD_ITEM(item); |
|
|
|
|
|
|
|
if(item != null){ |
|
|
|
|
|
|
|
this.addItemToInventory(item); |
|
|
|
|
|
|
|
this.updateInventory(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
ChatManager.chatSystemError((PlayerCharacter)this.getOwner(), "Resource Stack Error: Unable to create item. " + e.getMessage()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (Item purged : purgeList){ |
|
|
|
|
|
|
|
this.delete(purged); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.updateInventory(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|