/// <summary>
    /// Adds a number of empty slots to the end of this inventory.
    /// </summary>
    /// <param name="addSize">Number of slots to add.</param>
    public void expandInventory(int addSize)
    {
        InventoryContents newContents = new InventoryContents(this._size + addSize);

        for (int i = 0; i < this._size; i++)
        {
            newContents.contentsArray[i] = this.contents.contentsArray[i];
        }
        this._size += addSize;
    }
Пример #2
0
            public void Add(InventoryContents additionalContents)
            {
                if (additionalContents != null)
                {
                    Currency += additionalContents.Currency;
                    Abilities.AddRange(additionalContents.Abilities);

                    additionalContents.Clear();
                }
            }
Пример #3
0
 /// <summary>
 /// Adds the given item to the inventory.
 /// </summary>
 /// <param name="item"></param>
 public void AddItem(Item item)
 {
     if (InventoryContents.TryAdd(item.ItemName, item))
     {
         InventoryCounts.Add(item.ItemName, 1);
     }
     else
     {
         InventoryCounts[item.ItemName]++;
     }
 }
Пример #4
0
        public void Initialise(BaseCharacterController owner, InventoryContents initialContents, bool dropped = false)
        {
            Contents.Add(initialContents);
            Owner    = owner;
            OnGround = dropped;

            Debug.Assert(Contents != null);

            if (!OnGround)
            {
                Owner.Health.OnDied += OnDie;
            }
        }
    /// <summary>
    /// Expands this inventory by the size of, and adds all the items of another inventory.
    /// </summary>
    /// <param name="consumedInventory">The inventory that will be added onto this one.</param>
    public void mergeInventory(Inventory consumedInventory)
    {
        int newSize = this._size + consumedInventory._size;
        InventoryContents newContents = new InventoryContents(newSize);

        for (int i = 0; i < this._size; i++)
        {
            newContents.contentsArray[i] = this.contents.contentsArray[i];
        }
        for (int i = 0; i < consumedInventory._size; i++)
        {
            newContents.contentsArray[i + this._size] = consumedInventory.contents.contentsArray[i];
        }
        this.contents = newContents;
    }
Пример #6
0
 /// <summary>
 /// Removes an item from the inventory and returns it to the caller.
 /// </summary>
 /// <param name="item">Item to remove</param>
 public void RemoveItem(string itemName)
 {
     if (InventoryCounts[itemName] > 1)
     {
         InventoryCounts[itemName]--;
     }
     else if (InventoryCounts[itemName] == 1)
     {
         InventoryContents.Remove(itemName);
         InventoryCounts.Remove(itemName);
     }
     else
     {
         throw new ArgumentOutOfRangeException("An inventory cannot have a negative number of items.");
     }
 }
Пример #7
0
        public void Add(InventoryContents additionalContents)
        {
            int currencyChange = (int)additionalContents.Currency;

            Contents.Add(additionalContents);

            OnGetCurrency.InvokeSafe(currencyChange);

            if (Owner != null)
            {
                App.WorldState.SetState(new Narrative.WorldProperty(Owner.ID, Narrative.EProperty.MoneyEqual, Contents.Currency));
                foreach (Ability ability in Contents.Abilities)
                {
                    Owner.UnlockAbility(ability);
                }
            }
        }
    /// <summary>
    /// Splits the specified number of slots from the end of this inventory into a separate inventory.
    /// </summary>
    /// <param name="truncateBy">The number of slots to snip off this end of the inventory.</param>
    /// <returns>A new inventory that contains the slots and items removed from this inventory.</returns>
    public Inventory truncateInventory(int truncateBy)
    {
        Inventory         returnInventory = new Inventory(truncateBy);
        InventoryContents newContents     = new InventoryContents(this._size - truncateBy);

        // Create the return inventory
        for (int i = this._size - truncateBy; i < this._size; i++)
        {
            returnInventory.contents.contentsArray[i - (this._size - truncateBy)] = this.contents.contentsArray[i];
        }
        // Create the new contents array for this inventory
        for (int i = 0; i < this._size - truncateBy; i++)
        {
            newContents.contentsArray[i] = this.contents.contentsArray[i];
        }
        this.contents = newContents;
        this._size   -= truncateBy;
        return(returnInventory);
    }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="sizeParam">Number of slots the inventory will have.</param>
 public Inventory(int size = 1)
 {
     _size    = size;
     contents = new InventoryContents(size);
 }
Пример #10
0
 public InventoryContents(InventoryContents other)
 {
     Currency  = other.Currency;
     Abilities = new List <Ability>(other.Abilities);
 }