Deukhoofd a5675024a4
All checks were successful
Build / Build (push) Successful in 1m34s
Tweaks and fixes for Pokemon capture
2025-08-03 12:00:20 +02:00

49 lines
1.4 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(IPokemon target, ref byte catchRate);
public virtual void OnAfterSuccessfulCapture(IPokemon target)
{
// Default implementation does nothing.
// Override this method in derived classes to add custom behavior after a successful capture.
}
/// <inheritdoc />
public override bool IsItemUsable => true;
/// <inheritdoc />
public override bool RequiresTarget => true;
/// <inheritdoc />
public override bool IsTargetValid(IPokemon target) =>
target.BattleData is not null && target.BattleData.Battle.IsWildBattle;
/// <inheritdoc />
public override void OnUseWithTarget(IPokemon target, EventHook eventHook)
{
var battleData = target.BattleData;
var result = battleData?.Battle.AttempCapture(battleData.SideIndex, battleData.Position, Item);
if (result is { IsCaught: true })
{
OnAfterSuccessfulCapture(target);
}
}
}