Move all battle state from IPokemon to an ephemeral IBattlePokemon wrapper

This commit is contained in:
2026-08-28 15:20:26 +02:00
parent 942be8eaeb
commit 8a2733a0a9
859 changed files with 4408 additions and 5331 deletions

View File

@@ -20,31 +20,29 @@ public class FairyLockTests
/// Creates a fully mocked test setup where the battle has a real <see cref="ScriptSet"/> as its volatile
/// script set.
/// </summary>
private static (FairyLock script, IExecutingMove move, IPokemon target, IBattle battle, IScriptSet battleVolatile)
CreateTestSetup()
private static (FairyLock script, IExecutingMove move, IBattlePokemon target, IBattle battle, IScriptSet
battleVolatile) CreateTestSetup()
{
var script = new FairyLock();
var move = Substitute.For<IExecutingMove>();
var target = Substitute.For<IPokemon>();
var target = Substitute.For<IBattlePokemon>();
var battle = Substitute.For<IBattle>();
battle.GetScripts().Returns(_ => new ScriptIterator(Array.Empty<IEnumerable<ScriptContainer>>()));
IScriptSet battleVolatile = new ScriptSet(battle);
battle.Volatile.Returns(battleVolatile);
var battleData = Substitute.For<IPokemonBattleData>();
battleData.Battle.Returns(battle);
target.BattleData.Returns(battleData);
target.Battle.Returns(battle);
return (script, move, target, battle, battleVolatile);
}
/// <summary>
/// Creates a mocked Pokémon with the given type names as its <see cref="IPokemon.Types"/>.
/// Creates a mocked Pokémon with the given type names as its <see cref="IBattlePokemon.Types"/>.
/// </summary>
private static IPokemon CreatePokemonWithTypes(params string[] types)
private static IBattlePokemon CreatePokemonWithTypes(params string[] types)
{
var pokemon = Substitute.For<IPokemon>();
var pokemon = Substitute.For<IBattlePokemon>();
pokemon.Types.Returns(types.Select((name, index) => new TypeIdentifier((byte)(index + 1), new StringKey(name)))
.ToList());
return pokemon;
@@ -68,23 +66,6 @@ public class FairyLockTests
await Assert.That(battleVolatile.Contains(ScriptUtils.ResolveName<FairyLockEffect>())).IsTrue();
}
/// <summary>
/// Technical test: without battle data on the target (outside of battle) the secondary effect does
/// nothing and does not throw.
/// </summary>
[Test]
public void OnSecondaryEffect_TargetHasNoBattleData_DoesNotThrow()
{
// Arrange
var script = new FairyLock();
var move = Substitute.For<IExecutingMove>();
var target = Substitute.For<IPokemon>();
target.BattleData.Returns((IPokemonBattleData?)null);
// Act & Assert - should not throw
script.OnSecondaryEffect(move, target, 0);
}
/// <summary>
/// Bulbapedia: "Fairy Lock prevents all Pokémon (except Ghost types) on the field from switching out".
/// A non-Ghost Pokémon is prevented from switching.