Don't allow switching into a Pokemon that's already in the field
All checks were successful
Build / Build (push) Successful in 1m36s

This commit is contained in:
2025-10-19 11:04:08 +02:00
parent f061ba2455
commit 8fd7df5d80

View File

@@ -143,7 +143,7 @@ public interface IBattle : IScriptSource, IDeepCloneable, IDisposable
/// <summary> /// <summary>
/// Volatile scripts are scripts that are not permanent and can be removed by other scripts. /// Volatile scripts are scripts that are not permanent and can be removed by other scripts.
/// </summary> /// </summary>
public IScriptSet Volatile { get; } IScriptSet Volatile { get; }
/// <summary> /// <summary>
/// Gets the current weather of the battle. If no weather is present, this returns null. /// 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) if (preventMove)
return false; 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; return true;