Added event handlers for each of the level up events

This commit is contained in:
ClxS 2016-03-04 20:40:46 +00:00
parent 4712da9f2d
commit b8a9f8fc88
4 changed files with 72 additions and 2 deletions

View File

@ -108,6 +108,26 @@ namespace StardewModdingAPI.Events
public List<ItemStackChange> 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)

View File

@ -12,6 +12,7 @@ namespace StardewModdingAPI.Events
{
public static event EventHandler<EventArgsFarmerChanged> FarmerChanged = delegate { };
public static event EventHandler<EventArgsInventoryChanged> InventoryChanged = delegate { };
public static event EventHandler<EventArgsLevelUp> 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));
}
}
}

View File

@ -50,7 +50,7 @@ namespace StardewModdingAPI
{
return Boolean.Parse(o.ToString());
}
public static int GetHash(this IEnumerable enumerable)
{
string s = string.Empty;

View File

@ -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<Item, int> 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<ItemStackChange> changedItems;
if (player != null && HasInventoryChanged(player.items, out changedItems))
{