From 8fd7df5d80140786552d746f800344be4ce9facd Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sun, 19 Oct 2025 11:04:08 +0200 Subject: [PATCH] Don't allow switching into a Pokemon that's already in the field --- PkmnLib.Dynamic/Models/Battle.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/PkmnLib.Dynamic/Models/Battle.cs b/PkmnLib.Dynamic/Models/Battle.cs index 469e394..7c260af 100644 --- a/PkmnLib.Dynamic/Models/Battle.cs +++ b/PkmnLib.Dynamic/Models/Battle.cs @@ -143,7 +143,7 @@ public interface IBattle : IScriptSource, IDeepCloneable, IDisposable /// /// Volatile scripts are scripts that are not permanent and can be removed by other scripts. /// - public IScriptSet Volatile { get; } + IScriptSet Volatile { get; } /// /// Gets the current weather of the battle. If no weather is present, this returns null. @@ -341,6 +341,16 @@ public class BattleImpl : ScriptSource, IBattle if (preventMove) return false; } + else if (choice is ISwitchChoice switchChoice) + { + if (!switchChoice.SwitchTo.IsUsable) + return false; + // Can't switch to a Pokémon already on the field + if (switchChoice.SwitchTo.BattleData is { IsOnBattlefield: true }) + return false; + if (switchChoice.SwitchTo == switchChoice.User) + return false; + } return true;