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

@@ -22,7 +22,7 @@ public class FireGrassPledgeMoveTests
/// Creates a fully mocked test setup. The target's battle side gets a real <see cref="ScriptSet"/> as
/// its volatile script set, so the sea of fire created by the combined move can be inspected and driven.
/// </summary>
private static (FireGrassPledgeMove script, IExecutingMove move, IPokemon target, IBattleSide side, IScriptSet
private static (FireGrassPledgeMove script, IExecutingMove move, IBattlePokemon target, IBattleSide side, IScriptSet
sideVolatile) CreateTestSetup()
{
var script = new FireGrassPledgeMove();
@@ -33,11 +33,9 @@ public class FireGrassPledgeMoveTests
var sideVolatile = new ScriptSet(side);
side.VolatileScripts.Returns(sideVolatile);
var battleData = Substitute.For<IPokemonBattleData>();
battleData.BattleSide.Returns(side);
var target = Substitute.For<IPokemon>();
target.BattleData.Returns(battleData);
var target = Substitute.For<IBattlePokemon>();
target.BattleSide.Returns(side);
return (script, move, target, side, sideVolatile);
}
@@ -45,9 +43,9 @@ public class FireGrassPledgeMoveTests
/// Creates a Pokémon substitute of the given type with the given maximum HP, for placing on the side
/// covered by the sea of fire.
/// </summary>
private static IPokemon CreateSidePokemon(string typeName, uint maxHealth)
private static IBattlePokemon CreateSidePokemon(string typeName, uint maxHealth)
{
var pokemon = Substitute.For<IPokemon>();
var pokemon = Substitute.For<IBattlePokemon>();
pokemon.Types.Returns(new List<TypeIdentifier> { new(1, typeName) });
pokemon.MaxHealth.Returns(maxHealth);
return pokemon;
@@ -56,7 +54,7 @@ public class FireGrassPledgeMoveTests
/// <summary>
/// Helper to count the Damage calls a Pokémon received.
/// </summary>
private static int CountDamageCalls(IPokemon pokemon) =>
private static int CountDamageCalls(IBattlePokemon pokemon) =>
pokemon.ReceivedCalls().Count(c => c.GetMethodInfo().Name == "Damage");
/// <summary>
@@ -112,24 +110,6 @@ public class FireGrassPledgeMoveTests
await Assert.That(sideVolatile.Get<SeaOfFireEffect>()).IsNotNull();
}
/// <summary>
/// Technical test: if the target has no <see cref="IPokemon.BattleData"/>, no sea of fire is created
/// and the script does not throw.
/// </summary>
[Test]
public async Task OnSecondaryEffect_TargetHasNoBattleData_DoesNothing()
{
// Arrange
var (script, move, target, _, sideVolatile) = CreateTestSetup();
target.BattleData.Returns((IPokemonBattleData?)null);
// Act
script.OnSecondaryEffect(move, target, 0);
// Assert
await Assert.That(sideVolatile.Count).IsEqualTo(0);
}
/// <summary>
/// Bulbapedia: "The sea of fire damages all non-Fire Pokémon on that side of the field for 1/8 of
/// their maximum HP at the end of each turn."
@@ -141,7 +121,7 @@ public class FireGrassPledgeMoveTests
// Arrange
var (script, move, target, side, sideVolatile) = CreateTestSetup();
var waterPokemon = CreateSidePokemon("water", maxHealth);
side.Pokemon.Returns(new List<IPokemon?> { waterPokemon });
side.Pokemon.Returns(new List<IBattlePokemon?> { waterPokemon });
script.OnSecondaryEffect(move, target, 0);
var seaOfFire = sideVolatile.Get<SeaOfFireEffect>()!;
@@ -164,7 +144,7 @@ public class FireGrassPledgeMoveTests
// Arrange
var (script, move, target, side, sideVolatile) = CreateTestSetup();
var firePokemon = CreateSidePokemon("fire", 100);
side.Pokemon.Returns(new List<IPokemon?> { firePokemon });
side.Pokemon.Returns(new List<IBattlePokemon?> { firePokemon });
script.OnSecondaryEffect(move, target, 0);
var seaOfFire = sideVolatile.Get<SeaOfFireEffect>()!;
@@ -185,7 +165,7 @@ public class FireGrassPledgeMoveTests
// Arrange
var (script, move, target, side, sideVolatile) = CreateTestSetup();
var waterPokemon = CreateSidePokemon("water", 96);
side.Pokemon.Returns(new List<IPokemon?> { waterPokemon });
side.Pokemon.Returns(new List<IBattlePokemon?> { waterPokemon });
script.OnSecondaryEffect(move, target, 0);
var seaOfFire = sideVolatile.Get<SeaOfFireEffect>()!;
var battle = Substitute.For<IBattle>();
@@ -207,7 +187,7 @@ public class FireGrassPledgeMoveTests
{
// Arrange
var (script, move, target, side, sideVolatile) = CreateTestSetup();
side.Pokemon.Returns(new List<IPokemon?>());
side.Pokemon.Returns(new List<IBattlePokemon?>());
script.OnSecondaryEffect(move, target, 0);
var seaOfFire = sideVolatile.Get<SeaOfFireEffect>()!;
var battle = Substitute.For<IBattle>();