diff --git a/PkmnLib.Dynamic/BattleFlow/MoveTurnExecutor.cs b/PkmnLib.Dynamic/BattleFlow/MoveTurnExecutor.cs index 29826f2..303373a 100644 --- a/PkmnLib.Dynamic/BattleFlow/MoveTurnExecutor.cs +++ b/PkmnLib.Dynamic/BattleFlow/MoveTurnExecutor.cs @@ -123,6 +123,8 @@ public static class MoveTurnExecutor executingMove.RunScriptHookInterface(x => x.OnAfterMove(executingMove)); } + private static readonly ThreadLocal> TypeListCache = new(() => []); + private static void ExecuteMoveChoiceForTarget(IBattle battle, IExecutingMove executingMove, IPokemon target) { var failed = false; @@ -173,7 +175,11 @@ public static class MoveTurnExecutor hitData.Type = hitType; - var types = new List(target.Types); + // We re-use the TypeListCache to avoid allocating a new list every time. + var types = TypeListCache.Value; + types.Clear(); + types.AddRange(target.Types); + executingMove.RunScriptHook(x => x.ChangeTypesForMove(executingMove, target, hitIndex, types)); target.RunScriptHook(x => x.ChangeTypesForIncomingMove(executingMove, target, hitIndex, types));