using System;
using System.Collections.Generic;
using System.Linq;
using StardewModdingAPI.Framework;
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.
/// Encapsulates monitoring and logging.
/// Whether the save has been loaded. This is always true.
internal static void InvokeLoadedGame(IMonitor monitor, EventArgsLoadedGameChanged loaded)
{
monitor.SafelyRaiseGenericEvent($"{nameof(PlayerEvents)}.{nameof(PlayerEvents.LoadedGame)}", PlayerEvents.LoadedGame?.GetInvocationList(), null, loaded);
}
/// Raise a event.
/// Encapsulates monitoring and logging.
/// The previous player character.
/// The new player character.
internal static void InvokeFarmerChanged(IMonitor monitor, Farmer priorFarmer, Farmer newFarmer)
{
monitor.SafelyRaiseGenericEvent($"{nameof(PlayerEvents)}.{nameof(PlayerEvents.FarmerChanged)}", PlayerEvents.FarmerChanged?.GetInvocationList(), null, new EventArgsFarmerChanged(priorFarmer, newFarmer));
}
/// Raise an event.
/// Encapsulates monitoring and logging.
/// The player's inventory.
/// The inventory changes.
internal static void InvokeInventoryChanged(IMonitor monitor, List- inventory, IEnumerable changedItems)
{
monitor.SafelyRaiseGenericEvent($"{nameof(PlayerEvents)}.{nameof(PlayerEvents.InventoryChanged)}", PlayerEvents.InventoryChanged?.GetInvocationList(), null, new EventArgsInventoryChanged(inventory, changedItems.ToList()));
}
/// Rase a event.
/// Encapsulates monitoring and logging.
/// The player skill that leveled up.
/// The new skill level.
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));
}
}
}