Initial set up for item use
This commit is contained in:
40
Plugins/PkmnLib.Plugin.Gen7/Scripts/Items/HealingItem.cs
Normal file
40
Plugins/PkmnLib.Plugin.Gen7/Scripts/Items/HealingItem.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System.Collections.Generic;
|
||||
using PkmnLib.Dynamic.Models;
|
||||
using PkmnLib.Dynamic.ScriptHandling;
|
||||
using PkmnLib.Dynamic.ScriptHandling.Registry;
|
||||
using PkmnLib.Static.Utils;
|
||||
|
||||
namespace PkmnLib.Plugin.Gen7.Scripts.Items;
|
||||
|
||||
[ItemScript("healing_item")]
|
||||
public class HealingItem : ItemScript
|
||||
{
|
||||
private uint _healAmount;
|
||||
|
||||
/// <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)
|
||||
{
|
||||
target.Heal(_healAmount);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user