From 06ce7fd38dfb9f1ff9756ff02eac6a4abb57f7c2 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sun, 22 Dec 2024 11:27:03 +0100 Subject: [PATCH] When a move is changed through the ChangeMove hook, update the script --- PkmnLib.Dynamic/Models/BattleFlow/MoveTurnExecutor.cs | 11 ++++++++++- PkmnLib.Dynamic/ScriptHandling/ScriptContainer.cs | 5 +---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/PkmnLib.Dynamic/Models/BattleFlow/MoveTurnExecutor.cs b/PkmnLib.Dynamic/Models/BattleFlow/MoveTurnExecutor.cs index 483aa4c..00e2d2c 100644 --- a/PkmnLib.Dynamic/Models/BattleFlow/MoveTurnExecutor.cs +++ b/PkmnLib.Dynamic/Models/BattleFlow/MoveTurnExecutor.cs @@ -22,7 +22,16 @@ internal static class MoveTurnExecutor throw new InvalidOperationException( $"The move was changed to '{moveDataName}' by a script, but this move does not exist."); } - // FIXME: Change the script on the move when it is changed. + var secondaryEffect = moveData.SecondaryEffect; + if (secondaryEffect != null) + { + if (moveChoice.User.Library.ScriptResolver.TryResolve(ScriptCategory.Move, secondaryEffect.Name, out var script)) + { + moveChoice.Script.Set(script); + script.OnInitialize(moveChoice.User.Library, secondaryEffect.Parameters); + } + } + } var targetType = moveData.Target; diff --git a/PkmnLib.Dynamic/ScriptHandling/ScriptContainer.cs b/PkmnLib.Dynamic/ScriptHandling/ScriptContainer.cs index 37e576c..be79029 100644 --- a/PkmnLib.Dynamic/ScriptHandling/ScriptContainer.cs +++ b/PkmnLib.Dynamic/ScriptHandling/ScriptContainer.cs @@ -49,10 +49,7 @@ public class ScriptContainer : IEnumerable /// public void Set(Script script) { - if (Script is not null) - { - Script.OnRemove(); - } + Script?.OnRemove(); Script = script; }