using System;
using System.Collections.Generic;
using System.Linq;
using StardewModdingAPI.Inheritance;
using StardewValley;
namespace StardewModdingAPI.Events
{
/// Events raised when the player data changes.
public static class PlayerEvents
{
/*********
** Events
*********/
/// Raised after the player loads a saved game.
public static event EventHandler LoadedGame;
/// Raised after the game assigns a new player character. This happens just before ; it's unclear how this would happen any other time.
public static event EventHandler FarmerChanged;
/// Raised after the player's inventory changes in any way (added or removed item, sorted, etc).
public static event EventHandler InventoryChanged;
/// 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.
public static event EventHandler LeveledUp;
/*********
** Internal methods
*********/
/// Raise a event.
/// Whether the save has been loaded. This is always true.
internal static void InvokeLoadedGame(EventArgsLoadedGameChanged loaded)
{
PlayerEvents.LoadedGame?.Invoke(null, loaded);
}
/// Raise a event.
/// The previous player character.
/// The new player character.
internal static void InvokeFarmerChanged(Farmer priorFarmer, Farmer newFarmer)
{
PlayerEvents.FarmerChanged?.Invoke(null, new EventArgsFarmerChanged(priorFarmer, newFarmer));
}
/// Raise an event.
/// The player's inventory.
/// The inventory changes.
internal static void InvokeInventoryChanged(List- inventory, IEnumerable changedItems)
{
PlayerEvents.InventoryChanged?.Invoke(null, new EventArgsInventoryChanged(inventory, changedItems.ToList()));
}
/// Rase a event.
/// The player skill that leveled up.
/// The new skill level.
internal static void InvokeLeveledUp(EventArgsLevelUp.LevelType type, int newLevel)
{
PlayerEvents.LeveledUp?.Invoke(null, new EventArgsLevelUp(type, newLevel));
}
}
}