Fixes for sleep
All checks were successful
Build / Build (push) Successful in 1m4s

This commit is contained in:
2026-05-23 11:33:15 +02:00
parent 391edd98f1
commit e18b193f7d
2 changed files with 13 additions and 9 deletions

View File

@@ -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
}
/// <inheritdoc />
public void PreventMove(IExecutingMove move, ref bool prevent)
/// <remarks>
/// 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.
/// </remarks>
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<IScriptCustomTrigger>(x => x.CustomTrigger(CustomTriggers.BypassSleep, args));
var args = new CustomTriggers.BypassSleepArgs(choice, false);
choice.RunScriptHook<IScriptCustomTrigger>(x => x.CustomTrigger(CustomTriggers.BypassSleep, args));
if (args.Bypass)
return;
prevent = true;
numberOfHits = 0;
}
/// <inheritdoc />