From b8a9f8fc88706896c3191b80d17375a483183226 Mon Sep 17 00:00:00 2001 From: ClxS Date: Fri, 4 Mar 2016 20:40:46 +0000 Subject: [PATCH] Added event handlers for each of the level up events --- StardewModdingAPI/Events/EventArgs.cs | 20 +++++++++++ StardewModdingAPI/Events/Player.cs | 6 ++++ StardewModdingAPI/Extensions.cs | 2 +- StardewModdingAPI/Inheritance/SGame.cs | 46 +++++++++++++++++++++++++- 4 files changed, 72 insertions(+), 2 deletions(-) diff --git a/StardewModdingAPI/Events/EventArgs.cs b/StardewModdingAPI/Events/EventArgs.cs index 7f2e28c7..66d057a7 100644 --- a/StardewModdingAPI/Events/EventArgs.cs +++ b/StardewModdingAPI/Events/EventArgs.cs @@ -108,6 +108,26 @@ namespace StardewModdingAPI.Events public List QuantityChanged { get; private set; } } + public class EventArgsLevelUp : EventArgs + { + public enum LevelType + { + Combat, + Farming, + Fishing, + Foraging, + Mining, + Luck + } + public EventArgsLevelUp(LevelType type, Int32 newLevel) + { + Type = type; + NewLevel = newLevel; + } + public LevelType Type { get; private set; } + public Int32 NewLevel { get; private set; } + } + public class EventArgsIntChanged : EventArgs { public EventArgsIntChanged(Int32 priorInt, Int32 newInt) diff --git a/StardewModdingAPI/Events/Player.cs b/StardewModdingAPI/Events/Player.cs index 47d21f63..f0547f87 100644 --- a/StardewModdingAPI/Events/Player.cs +++ b/StardewModdingAPI/Events/Player.cs @@ -12,6 +12,7 @@ namespace StardewModdingAPI.Events { public static event EventHandler FarmerChanged = delegate { }; public static event EventHandler InventoryChanged = delegate { }; + public static event EventHandler LeveledUp = delegate { }; public static void InvokeFarmerChanged(Farmer priorFarmer, Farmer newFarmer) { @@ -22,5 +23,10 @@ namespace StardewModdingAPI.Events { InventoryChanged.Invoke(null, new EventArgsInventoryChanged(inventory, changedItems)); } + + public static void InvokeLeveledUp(EventArgsLevelUp.LevelType type, int newLevel) + { + LeveledUp.Invoke(null, new EventArgsLevelUp(type, newLevel)); + } } } diff --git a/StardewModdingAPI/Extensions.cs b/StardewModdingAPI/Extensions.cs index 1bd589db..7e849f12 100644 --- a/StardewModdingAPI/Extensions.cs +++ b/StardewModdingAPI/Extensions.cs @@ -50,7 +50,7 @@ namespace StardewModdingAPI { return Boolean.Parse(o.ToString()); } - + public static int GetHash(this IEnumerable enumerable) { string s = string.Empty; diff --git a/StardewModdingAPI/Inheritance/SGame.cs b/StardewModdingAPI/Inheritance/SGame.cs index 366f3045..36f905f7 100644 --- a/StardewModdingAPI/Inheritance/SGame.cs +++ b/StardewModdingAPI/Inheritance/SGame.cs @@ -12,6 +12,7 @@ using StardewValley.Menus; using StardewValley.Monsters; using StardewValley.Quests; using StardewValley.TerrainFeatures; +using StardewModdingAPI.Events; namespace StardewModdingAPI.Inheritance { @@ -48,6 +49,13 @@ namespace StardewModdingAPI.Inheritance public int PreviousItems_ { get; private set; } public Dictionary PreviousItems { get; private set; } + public int PreviousCombatLevel { get; private set; } + public int PreviousFarmingLevel { get; private set; } + public int PreviousFishingLevel { get; private set; } + public int PreviousForagingLevel { get; private set; } + public int PreviousMiningLevel { get; private set; } + public int PreviousLuckLevel { get; private set; } + public GameLocation PreviousGameLocation { get; private set; } public IClickableMenu PreviousActiveMenu { get; private set; } @@ -227,7 +235,7 @@ namespace StardewModdingAPI.Inheritance foreach (Keys k in FramePressedKeys) Events.ControlEvents.InvokeKeyPressed(k); - + if (KStateNow != KStatePrior) { Events.ControlEvents.InvokeKeyboardChanged(KStatePrior, KStateNow); @@ -264,6 +272,42 @@ namespace StardewModdingAPI.Inheritance PreviousFarmer = player; } + if (player != null && player.combatLevel != PreviousCombatLevel) + { + Events.PlayerEvents.InvokeLeveledUp(EventArgsLevelUp.LevelType.Combat, player.combatLevel); + PreviousCombatLevel = player.combatLevel; + } + + if (player != null && player.farmingLevel != PreviousFarmingLevel) + { + Events.PlayerEvents.InvokeLeveledUp(EventArgsLevelUp.LevelType.Farming, player.farmingLevel); + PreviousFarmingLevel = player.farmingLevel; + } + + if (player != null && player.fishingLevel != PreviousFishingLevel) + { + Events.PlayerEvents.InvokeLeveledUp(EventArgsLevelUp.LevelType.Fishing, player.fishingLevel); + PreviousFishingLevel = player.fishingLevel; + } + + if (player != null && player.foragingLevel != PreviousForagingLevel) + { + Events.PlayerEvents.InvokeLeveledUp(EventArgsLevelUp.LevelType.Foraging, player.foragingLevel); + PreviousForagingLevel = player.foragingLevel; + } + + if (player != null && player.miningLevel != PreviousMiningLevel) + { + Events.PlayerEvents.InvokeLeveledUp(EventArgsLevelUp.LevelType.Mining, player.miningLevel); + PreviousMiningLevel = player.miningLevel; + } + + if (player != null && player.luckLevel != PreviousLuckLevel) + { + Events.PlayerEvents.InvokeLeveledUp(EventArgsLevelUp.LevelType.Luck, player.luckLevel); + PreviousLuckLevel = player.luckLevel; + } + List changedItems; if (player != null && HasInventoryChanged(player.items, out changedItems)) {