Tweaks and fixes for Pokemon capture
All checks were successful
Build / Build (push) Successful in 1m34s

This commit is contained in:
Deukhoofd 2025-08-03 12:00:20 +02:00
parent cccffc4954
commit a5675024a4
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
3 changed files with 27 additions and 2 deletions

View File

@ -1,5 +1,6 @@
using PkmnLib.Dynamic.Libraries;
using PkmnLib.Dynamic.Models;
using PkmnLib.Static;
namespace PkmnLib.Dynamic.Events;
@ -9,10 +10,11 @@ namespace PkmnLib.Dynamic.Events;
public class CaptureAttemptEvent : IEventData
{
/// <inheritdoc cref="CaptureAttemptEvent"/>
public CaptureAttemptEvent(IPokemon target, CaptureResult result)
public CaptureAttemptEvent(IPokemon target, CaptureResult result, IItem captureItem)
{
Target = target;
Result = result;
CaptureItem = captureItem;
}
/// <summary>
@ -25,6 +27,11 @@ public class CaptureAttemptEvent : IEventData
/// </summary>
public CaptureResult Result { get; init; }
/// <summary>
/// The item used to attempt the capture (e.g., a Poké Ball).
/// </summary>
public IItem CaptureItem { get; init; }
/// <inheritdoc />
public EventBatchId BatchId { get; init; }
}

View File

@ -533,7 +533,15 @@ public class BattleImpl : ScriptSource, IBattle
var side = Sides[target.BattleData!.SideIndex];
side.ForceClearPokemonFromField(target.BattleData.Position);
}
EventHook.Invoke(new CaptureAttemptEvent(target, attemptCapture));
EventHook.Invoke(new CaptureAttemptEvent(target, attemptCapture, item));
if (!CanSlotBeFilled(sideIndex, position))
{
Sides[sideIndex].MarkPositionAsUnfillable(position);
}
Sides[sideIndex].ForceClearPokemonFromField(position);
ValidateBattleState();
return attemptCapture;
}

View File

@ -25,6 +25,16 @@ public abstract class PokeballScript : ItemScript
// 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)
{