summaryrefslogtreecommitdiff
path: root/src/SMAPI/Events/PlayerEvents.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-10-07 23:20:36 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-10-07 23:20:36 -0400
commitd0dd2f7ba729de6be749d326a2fed78988ba9d7b (patch)
treea22127da6a8900e9f29bbb847bfd5d3347f6b952 /src/SMAPI/Events/PlayerEvents.cs
parent7889676ea24cafc945899bf25608784e3f5bc9e0 (diff)
parent5928f5f86c4493ddb6b89bce0b7d0fb73a884c09 (diff)
downloadSMAPI-d0dd2f7ba729de6be749d326a2fed78988ba9d7b.tar.gz
SMAPI-d0dd2f7ba729de6be749d326a2fed78988ba9d7b.tar.bz2
SMAPI-d0dd2f7ba729de6be749d326a2fed78988ba9d7b.zip
Merge branch 'add-mod-build-config' into develop
Diffstat (limited to 'src/SMAPI/Events/PlayerEvents.cs')
-rw-r--r--src/SMAPI/Events/PlayerEvents.cs43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/SMAPI/Events/PlayerEvents.cs b/src/SMAPI/Events/PlayerEvents.cs
new file mode 100644
index 00000000..5a9a9d5f
--- /dev/null
+++ b/src/SMAPI/Events/PlayerEvents.cs
@@ -0,0 +1,43 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using StardewModdingAPI.Framework;
+using StardewValley;
+
+namespace StardewModdingAPI.Events
+{
+ /// <summary>Events raised when the player data changes.</summary>
+ public static class PlayerEvents
+ {
+ /*********
+ ** Events
+ *********/
+ /// <summary>Raised after the player's inventory changes in any way (added or removed item, sorted, etc).</summary>
+ public static event EventHandler<EventArgsInventoryChanged> InventoryChanged;
+
+ /// <summary> Raised after the player levels up a skill. This happens as soon as they level up, not when the game notifies the player after their character goes to bed.</summary>
+ public static event EventHandler<EventArgsLevelUp> LeveledUp;
+
+
+ /*********
+ ** Internal methods
+ *********/
+ /// <summary>Raise an <see cref="InventoryChanged"/> event.</summary>
+ /// <param name="monitor">Encapsulates monitoring and logging.</param>
+ /// <param name="inventory">The player's inventory.</param>
+ /// <param name="changedItems">The inventory changes.</param>
+ internal static void InvokeInventoryChanged(IMonitor monitor, List<Item> inventory, IEnumerable<ItemStackChange> changedItems)
+ {
+ monitor.SafelyRaiseGenericEvent($"{nameof(PlayerEvents)}.{nameof(PlayerEvents.InventoryChanged)}", PlayerEvents.InventoryChanged?.GetInvocationList(), null, new EventArgsInventoryChanged(inventory, changedItems.ToList()));
+ }
+
+ /// <summary>Rase a <see cref="LeveledUp"/> event.</summary>
+ /// <param name="monitor">Encapsulates monitoring and logging.</param>
+ /// <param name="type">The player skill that leveled up.</param>
+ /// <param name="newLevel">The new skill level.</param>
+ internal static void InvokeLeveledUp(IMonitor monitor, EventArgsLevelUp.LevelType type, int newLevel)
+ {
+ monitor.SafelyRaiseGenericEvent($"{nameof(PlayerEvents)}.{nameof(PlayerEvents.LeveledUp)}", PlayerEvents.LeveledUp?.GetInvocationList(), null, new EventArgsLevelUp(type, newLevel));
+ }
+ }
+}