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

41 lines
1.0 KiB
C#

using PkmnLib.Static.Utils;
namespace PkmnLib.Plugin.Gen7.Scripts.Items;
[ItemScript("healing_item")]
public class HealingItem : ItemScript
{
private uint _healAmount;
/// <inheritdoc />
public HealingItem(IItem item) : base(item)
{
}
/// <inheritdoc />
public override bool IsItemUsable => true;
/// <inheritdoc />
public override bool RequiresTarget => true;
/// <inheritdoc />
public override void OnInitialize(IReadOnlyDictionary<StringKey, object?>? parameters)
{
if (parameters == null || !parameters.TryGetValue("heal_amount", out var healAmountObj) ||
healAmountObj is not int healAmount)
{
healAmount = 20;
}
_healAmount = (uint)healAmount;
}
/// <inheritdoc />
public override bool IsTargetValid(IPokemon target) => !target.IsFainted;
/// <inheritdoc />
public override void OnUseWithTarget(IPokemon target, EventHook eventHook)
{
target.Heal(_healAmount, customEventHook: eventHook);
}
}