Deukhoofd defb1349ca
All checks were successful
Build / Build (push) Successful in 47s
Add EventHook parameter to item use scripts
Items can be used on Pokemon outside of battle, and we want the user of the library to be able to check for what changed. This allows for example a heal event to be sent back to the user of the library after using an item.
2025-06-15 11:59:17 +02:00

69 lines
1.8 KiB
C#

using PkmnLib.Dynamic.Events;
using PkmnLib.Dynamic.Models;
using PkmnLib.Static;
using PkmnLib.Static.Utils;
namespace PkmnLib.Dynamic.ScriptHandling;
/// <summary>
/// Base class for item scripts.
/// </summary>
public abstract class ItemScript : IDeepCloneable
{
/// <inheritdoc cref="ItemScript"/>
protected ItemScript(IItem item)
{
Item = item;
}
/// <summary>
/// The item associated with this script.
/// </summary>
protected IItem Item { get; private set; }
/// <summary>
/// Initializes the script with the given parameters for a specific item
/// </summary>
public virtual void OnInitialize(IReadOnlyDictionary<StringKey, object?>? parameters)
{
}
/// <summary>
/// Returns whether the item is usable in the current context.
/// </summary>
public virtual bool IsItemUsable => false;
/// <summary>
/// Returns whether the item requires a target to be used.
/// </summary>
public virtual bool RequiresTarget => false;
/// <summary>
/// Returns whether the item is usable on the given target.
/// </summary>
public virtual bool IsTargetValid(IPokemon target) => false;
/// <summary>
/// Returns whether the item can be held by a Pokémon.
/// </summary>
public virtual bool IsHoldable => false;
/// <summary>
/// Returns whether the item can be held by the given target.
/// </summary>
public virtual bool CanTargetHold(IPokemon pokemon) => false;
/// <summary>
/// Handles the use of the item.
/// </summary>
public virtual void OnUse(EventHook eventHook)
{
}
/// <summary>
/// Handles the use of the item on the given target.
/// </summary>
public virtual void OnUseWithTarget(IPokemon target, EventHook eventHook)
{
}
}