Files
PkmnLib.NET/PkmnLib.Dynamic/ScriptHandling/PokeballScript.cs
T
2026-11-03 15:45:54 +01:00

53 lines
1.7 KiB
C#

using PkmnLib.Dynamic.Events;
using PkmnLib.Dynamic.Models;
using PkmnLib.Static;
namespace PkmnLib.Dynamic.ScriptHandling;
/// <summary>
/// Base class for Pokéball scripts.
/// </summary>
public abstract class PokeballScript : ItemScript
{
/// <inheritdoc />
protected PokeballScript(IItem item) : base(item)
{
}
/// <summary>
/// Returns the catch rate of the Pokéball against the given target Pokémon.
/// </summary>
public abstract void ChangeCatchRate(IBattlePokemon target, ref byte catchRate);
public virtual void OnAfterSuccessfulCapture(IBattlePokemon target)
{
// Default implementation does nothing.
// Override this method in derived classes to add custom behavior after a successful capture.
}
/// <summary>
/// Whether the pokeball has a perfect capture rate, for example the master ball.
/// </summary>
public virtual bool IsAlwaysSuccessful(IBattlePokemon target) => false;
/// <inheritdoc />
public override bool IsItemUsable => true;
/// <inheritdoc />
public override ItemTargetType TargetType => ItemTargetType.FoePokemon;
/// <inheritdoc />
public override bool IsTargetValid(IPokemon target) => target is IBattlePokemon { Battle: { IsWildBattle: true } };
/// <inheritdoc />
public override void OnUseWithTarget(IPokemon target, EventHook eventHook)
{
if (target is not IBattlePokemon battlePokemon)
return;
var result = battlePokemon.Battle.AttempCapture(battlePokemon.SideIndex, battlePokemon.Position, Item);
if (result.IsCaught)
{
OnAfterSuccessfulCapture(battlePokemon);
}
}
}