From 9d2c2de17ae2121a01c1ea98297a362b6cde1693 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Mon, 19 May 2025 15:30:57 +0200 Subject: [PATCH] Implements Paralysis --- PkmnLib.Dynamic/BattleFlow/MoveTurnExecutor.cs | 4 ++-- .../Scripts/Status/Burned.cs | 12 +++++++++++- .../Scripts/Status/Paralyzed.cs | 18 +++++++++++++++++- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/PkmnLib.Dynamic/BattleFlow/MoveTurnExecutor.cs b/PkmnLib.Dynamic/BattleFlow/MoveTurnExecutor.cs index 876a405..a3dc17d 100644 --- a/PkmnLib.Dynamic/BattleFlow/MoveTurnExecutor.cs +++ b/PkmnLib.Dynamic/BattleFlow/MoveTurnExecutor.cs @@ -69,6 +69,8 @@ public static class MoveTurnExecutor var executingMove = new ExecutingMoveImpl(targets, numberOfHits, chosenMove, useMove, moveChoice, battle); + battle.EventHook.Invoke(new MoveUseEvent(executingMove)); + var prevented = false; executingMove.RunScriptHook(x => x.PreventMove(executingMove, ref prevented)); if (prevented) @@ -79,8 +81,6 @@ public static class MoveTurnExecutor if (!executingMove.ChosenMove.TryUse(ppUsed)) return; - battle.EventHook.Invoke(new MoveUseEvent(executingMove)); - var failed = false; executingMove.RunScriptHook(x => x.FailMove(executingMove, ref failed)); if (failed) diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Status/Burned.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Status/Burned.cs index 82ab36a..d149c20 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Status/Burned.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Status/Burned.cs @@ -1,4 +1,5 @@ using PkmnLib.Static.Moves; +using PkmnLib.Static.Utils; namespace PkmnLib.Plugin.Gen7.Scripts.Status; @@ -30,6 +31,15 @@ public class Burned : Script if (_target == null) return; var damage = (uint)(_target.MaxHealth / 16f); - _target.Damage(damage, DamageSource.Status); + var eventBatch = new EventBatchId(); + battle.EventHook.Invoke(new DialogEvent("hurt_by_burn", new Dictionary + { + { "pokemon", _target }, + { "damage", damage }, + }) + { + BatchId = eventBatch, + }); + _target.Damage(damage, DamageSource.Status, eventBatch); } } \ No newline at end of file diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Status/Paralyzed.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Status/Paralyzed.cs index 4ec5ca3..24afc50 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Status/Paralyzed.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Status/Paralyzed.cs @@ -3,5 +3,21 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Status; [Script(ScriptCategory.Status, "paralyzed")] public class Paralyzed : Script { - // TODO: Implement the Paralyzed status effect. + /// + public override void ChangeSpeed(ITurnChoice choice, ref uint speed) + { + speed = (uint)(speed * 0.5f); + } + + /// + public override void PreventMove(IExecutingMove move, ref bool prevent) + { + if (move.Battle.Random.GetInt(0, 100) >= 25) + return; + prevent = true; + move.Battle.EventHook.Invoke(new DialogEvent("paralysis_prevent_move", new Dictionary + { + { "pokemon", move.User }, + })); + } } \ No newline at end of file