diff --git a/PkmnLib.Dynamic/Events/CaptureAttemptEvent.cs b/PkmnLib.Dynamic/Events/CaptureAttemptEvent.cs
index 6ef8d64..d8bb3db 100644
--- a/PkmnLib.Dynamic/Events/CaptureAttemptEvent.cs
+++ b/PkmnLib.Dynamic/Events/CaptureAttemptEvent.cs
@@ -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
{
///
- public CaptureAttemptEvent(IPokemon target, CaptureResult result)
+ public CaptureAttemptEvent(IPokemon target, CaptureResult result, IItem captureItem)
{
Target = target;
Result = result;
+ CaptureItem = captureItem;
}
///
@@ -25,6 +27,11 @@ public class CaptureAttemptEvent : IEventData
///
public CaptureResult Result { get; init; }
+ ///
+ /// The item used to attempt the capture (e.g., a Poké Ball).
+ ///
+ public IItem CaptureItem { get; init; }
+
///
public EventBatchId BatchId { get; init; }
}
\ No newline at end of file
diff --git a/PkmnLib.Dynamic/Models/Battle.cs b/PkmnLib.Dynamic/Models/Battle.cs
index 2052abf..f90d13e 100644
--- a/PkmnLib.Dynamic/Models/Battle.cs
+++ b/PkmnLib.Dynamic/Models/Battle.cs
@@ -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;
}
diff --git a/PkmnLib.Dynamic/ScriptHandling/PokeballScript.cs b/PkmnLib.Dynamic/ScriptHandling/PokeballScript.cs
index 5cdb289..bb81689 100644
--- a/PkmnLib.Dynamic/ScriptHandling/PokeballScript.cs
+++ b/PkmnLib.Dynamic/ScriptHandling/PokeballScript.cs
@@ -25,6 +25,16 @@ public abstract class PokeballScript : ItemScript
// Override this method in derived classes to add custom behavior after a successful capture.
}
+ ///
+ public override bool IsItemUsable => true;
+
+ ///
+ public override bool RequiresTarget => true;
+
+ ///
+ public override bool IsTargetValid(IPokemon target) =>
+ target.BattleData is not null && target.BattleData.Battle.IsWildBattle;
+
///
public override void OnUseWithTarget(IPokemon target, EventHook eventHook)
{