using System; using System.Collections.Generic; using System.Linq; using StardewValley; namespace StardewModdingAPI.Events { /// Event arguments for an event. public class InventoryChangedEventArgs : EventArgs { /********* ** Accessors *********/ /// The player whose inventory changed. public Farmer Player { get; } /// The added items. public IEnumerable Added { get; } /// The removed items. public IEnumerable Removed { get; } /// The items whose stack sizes changed, with the relative change. public IEnumerable QuantityChanged { get; } /********* ** Public methods *********/ /// Construct an instance. /// The player whose inventory changed. /// The inventory changes. internal InventoryChangedEventArgs(Farmer player, ItemStackChange[] changedItems) { this.Player = player; this.Added = changedItems .Where(n => n.ChangeType == ChangeType.Added) .Select(p => p.Item) .ToArray(); this.Removed = changedItems .Where(n => n.ChangeType == ChangeType.Removed) .Select(p => p.Item) .ToArray(); this.QuantityChanged = changedItems .Where(n => n.ChangeType == ChangeType.StackChange) .Select(change => new ItemStackSizeChange( item: change.Item, oldSize: change.Item.Stack - change.StackChange, newSize: change.Item.Stack )) .ToArray(); } } }