summaryrefslogtreecommitdiff
path: root/src/SMAPI/Events/InventoryChangedEventArgs.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2018-11-19 13:48:19 -0500
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2018-11-19 13:48:19 -0500
commit593723b7940ba72a786fc4c7366c56f9813d977b (patch)
tree4d23fbef5bc5a20115f10ca04ae3379df78cc8e1 /src/SMAPI/Events/InventoryChangedEventArgs.cs
parent4f28ea33bd7cc65485402c5e85259083e86b49e1 (diff)
parent3dc27a5681dcfc4ae30e95570d9966f2e14a4dd7 (diff)
downloadSMAPI-593723b7940ba72a786fc4c7366c56f9813d977b.tar.gz
SMAPI-593723b7940ba72a786fc4c7366c56f9813d977b.tar.bz2
SMAPI-593723b7940ba72a786fc4c7366c56f9813d977b.zip
Merge branch 'develop' into stable
Diffstat (limited to 'src/SMAPI/Events/InventoryChangedEventArgs.cs')
-rw-r--r--src/SMAPI/Events/InventoryChangedEventArgs.cs56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/SMAPI/Events/InventoryChangedEventArgs.cs b/src/SMAPI/Events/InventoryChangedEventArgs.cs
new file mode 100644
index 00000000..a081611b
--- /dev/null
+++ b/src/SMAPI/Events/InventoryChangedEventArgs.cs
@@ -0,0 +1,56 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using StardewValley;
+
+namespace StardewModdingAPI.Events
+{
+ /// <summary>Event arguments for an <see cref="IPlayerEvents.InventoryChanged"/> event.</summary>
+ public class InventoryChangedEventArgs : EventArgs
+ {
+ /*********
+ ** Accessors
+ *********/
+ /// <summary>The player whose inventory changed.</summary>
+ public Farmer Player { get; }
+
+ /// <summary>The added items.</summary>
+ public IEnumerable<Item> Added { get; }
+
+ /// <summary>The removed items.</summary>
+ public IEnumerable<Item> Removed { get; }
+
+ /// <summary>The items whose stack sizes changed, with the relative change.</summary>
+ public IEnumerable<ItemStackSizeChange> QuantityChanged { get; }
+
+
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ /// <param name="player">The player whose inventory changed.</param>
+ /// <param name="changedItems">The inventory changes.</param>
+ public 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();
+ }
+ }
+}