diff --git a/PkmnLib.Dynamic/ScriptHandling/ItemScript.cs b/PkmnLib.Dynamic/ScriptHandling/ItemScript.cs index 7cde65f..5b2786f 100644 --- a/PkmnLib.Dynamic/ScriptHandling/ItemScript.cs +++ b/PkmnLib.Dynamic/ScriptHandling/ItemScript.cs @@ -41,7 +41,7 @@ public abstract class ItemScript : IDeepCloneable /// /// Returns whether the item is usable on the given target. /// - public virtual bool IsTargetValid(IBattlePokemon target) => false; + public virtual bool IsTargetValid(IPokemon target) => false; /// /// Returns whether the item can be held by a Pokémon. @@ -51,7 +51,7 @@ public abstract class ItemScript : IDeepCloneable /// /// Returns whether the item can be held by the given target. /// - public virtual bool CanTargetHold(IBattlePokemon pokemon) => true; + public virtual bool CanTargetHold(IPokemon pokemon) => true; /// /// Handles the use of the item. @@ -63,7 +63,7 @@ public abstract class ItemScript : IDeepCloneable /// /// Handles the use of the item on the given target. /// - public virtual void OnUseWithTarget(IBattlePokemon target, EventHook eventHook) + public virtual void OnUseWithTarget(IPokemon target, EventHook eventHook) { } } \ No newline at end of file diff --git a/PkmnLib.Dynamic/ScriptHandling/PokeballScript.cs b/PkmnLib.Dynamic/ScriptHandling/PokeballScript.cs index 8cc9a45..7ed9b6a 100644 --- a/PkmnLib.Dynamic/ScriptHandling/PokeballScript.cs +++ b/PkmnLib.Dynamic/ScriptHandling/PokeballScript.cs @@ -32,15 +32,17 @@ public abstract class PokeballScript : ItemScript public override ItemTargetType TargetType => ItemTargetType.FoePokemon; /// - public override bool IsTargetValid(IBattlePokemon target) => target.Battle.IsWildBattle; + public override bool IsTargetValid(IPokemon target) => target is IBattlePokemon { Battle: { IsWildBattle: true } }; /// - public override void OnUseWithTarget(IBattlePokemon target, EventHook eventHook) + public override void OnUseWithTarget(IPokemon target, EventHook eventHook) { - var result = target.Battle.AttempCapture(target.SideIndex, target.Position, Item); + if (target is not IBattlePokemon battlePokemon) + return; + var result = battlePokemon.Battle.AttempCapture(battlePokemon.SideIndex, battlePokemon.Position, Item); if (result.IsCaught) { - OnAfterSuccessfulCapture(target); + OnAfterSuccessfulCapture(battlePokemon); } } } \ No newline at end of file diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Items/EvolutionItem.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Items/EvolutionItem.cs index a3e1d21..e5d98ae 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Items/EvolutionItem.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Items/EvolutionItem.cs @@ -17,7 +17,7 @@ public class EvolutionItem : ItemScript public override ItemTargetType TargetType => ItemTargetType.OwnPokemon; /// - public override bool IsTargetValid(IBattlePokemon target) + public override bool IsTargetValid(IPokemon target) { foreach (var x in target.Species.EvolutionData) { @@ -33,7 +33,7 @@ public class EvolutionItem : ItemScript } /// - public override void OnUseWithTarget(IBattlePokemon target, EventHook eventHook) + public override void OnUseWithTarget(IPokemon target, EventHook eventHook) { var evolutionData = target.Species.EvolutionData.FirstOrDefault(x => { diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Items/HealingItem.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Items/HealingItem.cs index 91eb61a..f37add2 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Items/HealingItem.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Items/HealingItem.cs @@ -29,11 +29,11 @@ public class HealingItem : ItemScript } /// - public override bool IsTargetValid(IBattlePokemon target) => + public override bool IsTargetValid(IPokemon target) => !target.IsFainted && target.CurrentHealth < target.MaxHealth; /// - public override void OnUseWithTarget(IBattlePokemon target, EventHook eventHook) + public override void OnUseWithTarget(IPokemon target, EventHook eventHook) { target.Heal(_healAmount, customEventHook: eventHook); }