using StardewValley; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Revitalize.Framework.Utilities { /// /// Handles dealing with objects. /// public class InventoryManager { /// /// How many items the inventory can hold. /// public int capacity; /// /// The hard uper limit in case of upgrading or resizing. /// private int maxCapacity; /// /// The hard uper limit for # of items to be held in case of upgrading or resizing. /// public int MaxCapacity { get { return maxCapacity; } } /// /// How many items are currently stored in the inventory. /// public int ItemCount { get { return this.items.Count; } } /// /// The actual contents of the inventory. /// public List items; /// /// Checks if the inventory is full or not. /// public bool IsFull { get { return this.ItemCount >= this.capacity; } } /// /// Checks to see if this core object actually has a valid inventory. /// public bool HasInventory { get { if (this.capacity <= 0) return false; return true; } } public InventoryManager() { this.capacity = 0; setMaxLimit(0); this.items = new List(); } /// /// Constructor. /// /// public InventoryManager(List items) { this.capacity = Int32.MaxValue; this.setMaxLimit(Int32.MaxValue); this.items = items; } /// /// Constructor. /// /// public InventoryManager(int capacity) { this.capacity = capacity; this.maxCapacity = Int32.MaxValue; this.items = new List(); } /// /// Constructor. /// /// /// public InventoryManager(int capacity, int MaxCapacity) { this.capacity = capacity; setMaxLimit(MaxCapacity); this.items = new List(); } /// /// Add the item to the inventory. /// /// /// public bool addItem(Item I) { if (IsFull) { return false; } else { foreach(Item self in this.items) { if (self == null) continue; if (self.canStackWith(I)) { self.addToStack(I.Stack); return true; } } this.items.Add(I); return true; } } /// /// Gets a reference to the object IF it exists in the inventory. /// /// /// public Item getItem(Item I) { foreach(Item i in this.items) { if (I == i) return I; } return null; } /// /// Get the item at the specific index. /// /// /// public Item getItemAtIndex(int Index) { return items[Index]; } /// /// Gets only one item from the stack. /// /// /// public Item getSingleItemFromStack(Item I) { if (I.Stack == 1) { return I; } else { I.Stack = I.Stack - 1; return I.getOne(); } } /// /// Empty the inventory. /// public void clear() { this.items.Clear(); } /// /// Empty the inventory. /// public void empty() { this.clear(); } /// /// Resize how many items can be held by this object. /// /// public void resizeCapacity(int Amount) { if (this.capacity + Amount < this.maxCapacity) { this.capacity += Amount; } } /// /// Sets the upper limity of the capacity size for the inventory. /// /// public void setMaxLimit(int amount) { this.maxCapacity = amount; } } }