public InventoryItem invItem()
        {
            InventoryItem inv = new InventoryItem();
            inv.setInvItem( item.id, item.quantity);

            return inv;
        }
Example #2
0
        public void createFromItem(InventoryItem keyItem, ItemLibrary items)
        {
            //this fills the "item" variable in this part
            item = new InventoryItem ();
            item.setInvItem (keyItem.id, keyItem.quantity);

            nodes = items.getItemAttachments (keyItem.id);
            baseStats = items.getItemStats (keyItem.id);

            currentPower = 0.0f;
            currentHealth = baseStats.stability;
            powerIn = 0.0f; //we will take this if needed
            powerOut = 0.0f; //we will put power here if we have extra
            type = items.getItemType (keyItem.id);

            Debug.Log ("LLLAAAMMAAASS");
        }
Example #3
0
 public int addItem(InventoryItem itemstack)
 {
     //this code makes the assumption that quantity is limited to a single stack
     int quantityleft = itemstack.quantity;
     int quantitymoved = 0;
     for (int i=0; i<size; i++) {
         //Debug.Log (itemstack.id.ToString());
         //Debug.Log (contents[i].id.ToString());
         if (itemstack.id == contents[i].id) {
             //Debug.Log ("Match Found");
             //Debug.Log (itemstack.id.ToString());
             //Debug.Log (itemstack.quantity.ToString());
             quantityleft = contents[i].Add(quantityleft);
         }
     }
     if (quantityleft > 0) {
         int firstempty = getEmptySlot ();
         while (firstempty > -1) {
             int temp = contents [firstempty].Add(quantityleft);
             if(temp != quantityleft) {
                 contents[firstempty].id = itemstack.id;
                 quantityleft = temp;
             }
             //if we placed it all, we can exit here
             if (quantityleft < 1)
                 return 0;
             else //otherwise, go after another empty slot
                 firstempty = getEmptySlot ();
         }
         Debug.Log ("Too much!");
         //Debug.Log (itemstack.id.ToString());
         //we could not find any more empty slots
         return quantityleft;
     }
     return 0;
 }
Example #4
0
 public InventoryItem swapSlot(int slot, InventoryItem swapItem)
 {
     InventoryItem thisStack = new InventoryItem ();
     if ((size > slot) && (slot > -1)) {
         thisStack = contents [slot];
         contents [slot] = swapItem;
     }
     return thisStack;
 }
Example #5
0
        public int pullItem(InventoryItem requestedItem)
        {
            //subtract a single item stack from this container, return amount we could not subtract
            int quantityneeded = requestedItem.quantity;
            int quantitymoved = 0;

            for (int i=0; i<size; i++) {
                if (requestedItem.id == contents [i].id) {
                    quantityneeded -= contents [i].Remove(quantityneeded);

                    //if we got all we needed, we can exit
                    if (quantityneeded < 1)
                        return 0;
                }
            }
            //we did not grab it all
            return quantityneeded;
        }
Example #6
0
        public InventoryItem getItem(int slot)
        {
            InventoryItem thisitem = new InventoryItem ();

            if (size > slot) {
                thisitem.id = contents [slot].id;
                thisitem.quantity = contents [slot].quantity;
            }
            return thisitem;
        }
Example #7
0
 public int addSlot(int slot, InventoryItem itemstack)
 {
     //limits pull to specified slot
     if (size > slot) {
         InventoryItem thisStack = contents [slot];
         if (thisStack.IsEmpty ()) thisStack.id = itemstack.id;
         if (thisStack.id == itemstack.id) {
             int amount = thisStack.Add(itemstack.quantity);
             return amount;
         }
         Debug.Log ("Error: mismatched id");
         return itemstack.quantity;
     }
     Debug.Log ("Error: slot out of range");
     return itemstack.quantity;
 }
Example #8
0
 public void reset(int newID, int newQuant)
 {
     destroyAtThisTime = Time.time + lifeTime;
     item = new InventoryItem();
     item.setInvItem (newID, newQuant);
 }