diff --git a/PkmnLib.Dynamic/BattleFlow/TurnRunner.cs b/PkmnLib.Dynamic/BattleFlow/TurnRunner.cs index aed909b..4f3e07b 100644 --- a/PkmnLib.Dynamic/BattleFlow/TurnRunner.cs +++ b/PkmnLib.Dynamic/BattleFlow/TurnRunner.cs @@ -1,3 +1,4 @@ +using PkmnLib.Dynamic.Events; using PkmnLib.Dynamic.Models; using PkmnLib.Dynamic.Models.Choices; using PkmnLib.Dynamic.ScriptHandling; @@ -180,6 +181,7 @@ public static class TurnRunner var side = battle.Sides[itemChoice.TargetSide.Value]; target = side.Pokemon[itemChoice.TargetPosition.Value]; } + battle.EventHook.Invoke(new ItemUseEvent(user, itemChoice.Item)); itemChoice.Item.RunItemScript(battle.Library.ScriptResolver, target ?? user, battle.EventHook); } } \ No newline at end of file diff --git a/PkmnLib.Dynamic/Events/ItemUseEvent.cs b/PkmnLib.Dynamic/Events/ItemUseEvent.cs new file mode 100644 index 0000000..811816e --- /dev/null +++ b/PkmnLib.Dynamic/Events/ItemUseEvent.cs @@ -0,0 +1,19 @@ +using PkmnLib.Dynamic.Models; +using PkmnLib.Static; + +namespace PkmnLib.Dynamic.Events; + +public record ItemUseEvent : IEventData +{ + public ItemUseEvent(IPokemon pokemon, IItem itemUsed) + { + Pokemon = pokemon; + ItemUsed = itemUsed; + } + + public IPokemon Pokemon { get; set; } + public IItem ItemUsed { get; set; } + + /// + 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 f90d13e..469e394 100644 --- a/PkmnLib.Dynamic/Models/Battle.cs +++ b/PkmnLib.Dynamic/Models/Battle.cs @@ -535,13 +535,16 @@ public class BattleImpl : ScriptSource, IBattle } EventHook.Invoke(new CaptureAttemptEvent(target, attemptCapture, item)); - if (!CanSlotBeFilled(sideIndex, position)) + if (attemptCapture.IsCaught) { - Sides[sideIndex].MarkPositionAsUnfillable(position); - } - Sides[sideIndex].ForceClearPokemonFromField(position); + if (!CanSlotBeFilled(sideIndex, position)) + { + Sides[sideIndex].MarkPositionAsUnfillable(position); + } + Sides[sideIndex].ForceClearPokemonFromField(position); - ValidateBattleState(); + ValidateBattleState(); + } return attemptCapture; } diff --git a/Plugins/PkmnLib.Plugin.Gen7/Libraries/Battling/Gen7CaptureLibrary.cs b/Plugins/PkmnLib.Plugin.Gen7/Libraries/Battling/Gen7CaptureLibrary.cs index ba60cf8..aadf6d0 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Libraries/Battling/Gen7CaptureLibrary.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Libraries/Battling/Gen7CaptureLibrary.cs @@ -70,7 +70,7 @@ public class Gen7CaptureLibrary : ICaptureLibrary } } } - var success = shakes >= 3; + var success = shakes >= 4; return new CaptureResult(success, shakes, false); } } \ No newline at end of file