예제 #1
0
        /// <summary>
        /// Set inventory item health
        /// </summary>
        /// <param name="inventoryItemSlotIndex">Inventory item slot index</param>
        /// <param name="health">Health</param>
        /// <returns>"true" if successful, otherwise "false"</returns>
        public bool SetInventoryItemHealth(uint inventoryItemSlotIndex, uint health)
        {
            bool ret = false;

            if ((items != null) && (inventoryItemSlotIndex < items.Count))
            {
                InventoryItemData inventory_item = items[(int)inventoryItemSlotIndex];
                items[(int)inventoryItemSlotIndex] = new InventoryItemData(inventory_item.Item, health, inventory_item.Quantity);
                ret = true;
            }
            return(ret);
        }
예제 #2
0
 /// <summary>
 /// Add items
 /// </summary>
 /// <param name="item">Item</param>
 /// <param name="health">Health</param>
 /// <param name="quantity">Quantity</param>
 public void AddItems(IItemObject item, uint health, uint quantity)
 {
     if (item == null)
     {
         throw new ArgumentNullException(nameof(item));
     }
     if (quantity > 0U)
     {
         uint remaining = quantity;
         if (items == null)
         {
             items = new List <InventoryItemData>();
         }
         for (int index = 0; index < items.Count; index++)
         {
             InventoryItemData item_data = items[index];
             if ((item_data.Item == item) && (item_data.Health == health))
             {
                 if (item.MaximalStackSize > 0U)
                 {
                     long capacity = (long)(item.MaximalStackSize) - item_data.Quantity;
                     if (capacity > 0L)
                     {
                         if (capacity < remaining)
                         {
                             items[index] = new InventoryItemData(item, health, item.MaximalStackSize);
                             remaining   -= (uint)capacity;
                         }
                         else
                         {
                             items[index] = new InventoryItemData(item, health, item_data.Quantity + remaining);
                             remaining    = 0U;
                             break;
                         }
                     }
                 }
                 else
                 {
                     items[index] = new InventoryItemData(item, health, item_data.Quantity + remaining);
                     remaining    = 0U;
                     break;
                 }
             }
         }
         while (remaining > 0U)
         {
             if (item.MaximalStackSize > 0U)
             {
                 if (remaining > item.MaximalStackSize)
                 {
                     items.Add(new InventoryItemData(item, health, item.MaximalStackSize));
                     remaining -= item.MaximalStackSize;
                 }
                 else
                 {
                     items.Add(new InventoryItemData(item, health, remaining));
                     remaining = 0U;
                 }
             }
             else
             {
                 items.Add(new InventoryItemData(item, health, remaining));
                 remaining = 0U;
             }
         }
     }
 }
예제 #3
0
        /// <summary>
        /// Add items with weight limit
        /// </summary>
        /// <param name="item">Item</param>
        /// <param name="health">Health</param>
        /// <param name="quantity">Quantity</param>
        /// <param name="weightLimit">Weight limit</param>
        /// <returns>Number of items added</returns>
        public uint AddItemsWithWeightLimit(IItemObject item, uint health, uint quantity, uint weightLimit)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }
            uint ret    = 0U;
            uint weight = Weight;

            if (weight < weightLimit)
            {
                uint remaining_capacity = weightLimit - weight;
                ret = remaining_capacity / item.Weight;
                ret = ((ret < quantity) ? ret : quantity);
                if (ret > 0U)
                {
                    uint remaining = ret;
                    for (int index = 0; index < items.Count; index++)
                    {
                        InventoryItemData item_data = items[index];
                        if ((item_data.Item == item) && (item_data.Health == health))
                        {
                            if (item.MaximalStackSize > 0U)
                            {
                                long capacity = (long)(item.MaximalStackSize) - item_data.Quantity;
                                if (capacity > 0L)
                                {
                                    if (capacity < remaining)
                                    {
                                        items[index] = new InventoryItemData(item, health, item.MaximalStackSize);
                                        remaining   -= (uint)capacity;
                                    }
                                    else
                                    {
                                        items[index] = new InventoryItemData(item, health, item_data.Quantity + remaining);
                                        remaining    = 0U;
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                items[index] = new InventoryItemData(item, health, item_data.Quantity + remaining);
                                remaining    = 0U;
                                break;
                            }
                        }
                    }
                    while (remaining > 0U)
                    {
                        if (item.MaximalStackSize > 0U)
                        {
                            if (remaining > item.MaximalStackSize)
                            {
                                items.Add(new InventoryItemData(item, health, item.MaximalStackSize));
                                remaining -= item.MaximalStackSize;
                            }
                            else
                            {
                                items.Add(new InventoryItemData(item, health, remaining));
                                remaining = 0U;
                            }
                        }
                        else
                        {
                            items.Add(new InventoryItemData(item, health, remaining));
                            remaining = 0U;
                        }
                    }
                }
            }
            return(ret);
        }