diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/CustomTriggers.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/CustomTriggers.cs index 242b2b0..f602bda 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/CustomTriggers.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/CustomTriggers.cs @@ -40,7 +40,7 @@ public static class CustomTriggers public static readonly StringKey BypassSleep = "bypass_sleep"; - public record BypassSleepArgs(IExecutingMove Move, bool Bypass) : ICustomTriggerArgs + public record BypassSleepArgs(IMoveChoice Choice, bool Bypass) : ICustomTriggerArgs { public bool Bypass { get; set; } = Bypass; } diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Status/Sleep.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Status/Sleep.cs index 174d169..36b4e4b 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Status/Sleep.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Status/Sleep.cs @@ -1,7 +1,7 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Status; [Script(ScriptCategory.Status, "sleep")] -public class Sleep : Script, IScriptPreventMove, IAIInfoScriptNumberTurnsLeft +public class Sleep : Script, IScriptChangeNumberOfHits, IAIInfoScriptNumberTurnsLeft { private IPokemon? _pokemon; public int Turns { get; set; } @@ -27,23 +27,27 @@ public class Sleep : Script, IScriptPreventMove, IAIInfoScriptNumberTurnsLeft } /// - public void PreventMove(IExecutingMove move, ref bool prevent) + /// + /// This is slightly hacky, but setting number of hits to 0 stops the move *before* the MoveUseEvent is triggered, + /// so this is cleaner for UI. + /// + public void ChangeNumberOfHits(IMoveChoice choice, ref byte numberOfHits) { Turns--; - if (Turns <= 0) + if (Turns < 0) { - move.User.ClearStatus(); + choice.User.ClearStatus(); return; } - if (move.UseMove.HasFlag(MoveFlags.UsableWhileAsleep)) + if (choice.ChosenMove.MoveData.HasFlag(MoveFlags.UsableWhileAsleep)) return; - var args = new CustomTriggers.BypassSleepArgs(move, false); - move.RunScriptHook(x => x.CustomTrigger(CustomTriggers.BypassSleep, args)); + var args = new CustomTriggers.BypassSleepArgs(choice, false); + choice.RunScriptHook(x => x.CustomTrigger(CustomTriggers.BypassSleep, args)); if (args.Bypass) return; - prevent = true; + numberOfHits = 0; } ///