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

@@ -21,8 +21,8 @@ public class LunarDanceTests
/// Creates a fully mocked test setup for the <see cref="LunarDance"/> move script, with the user at the
/// given position and the side's volatile scripts backed by a real <see cref="ScriptSet"/>.
/// </summary>
private static (LunarDance script, IExecutingMove move, IPokemon user, IScriptSet sideVolatile) CreateMoveSetup(
byte position = 1)
private static (LunarDance script, IExecutingMove move, IBattlePokemon user, IScriptSet sideVolatile)
CreateMoveSetup(byte position = 1)
{
var script = new LunarDance();
var move = Substitute.For<IExecutingMove>();
@@ -34,13 +34,10 @@ public class LunarDanceTests
IScriptSet sideVolatile = new ScriptSet(side);
side.VolatileScripts.Returns(sideVolatile);
var battleData = Substitute.For<IPokemonBattleData>();
battleData.BattleSide.Returns(side);
battleData.Position.Returns(position);
var user = Substitute.For<IPokemon>();
user.BattleData.Returns(battleData);
var user = Substitute.For<IBattlePokemon>();
move.User.Returns(user);
user.Position.Returns(position);
user.BattleSide.Returns(side);
return (script, move, user, sideVolatile);
}
@@ -49,9 +46,9 @@ public class LunarDanceTests
/// Creates a mocked replacement Pokémon with the given maximum HP for
/// <see cref="LunarDanceEffect"/> tests.
/// </summary>
private static IPokemon CreateReplacement(uint maxHp = 200)
private static IBattlePokemon CreateReplacement(uint maxHp = 200)
{
var pokemon = Substitute.For<IPokemon>();
var pokemon = Substitute.For<IBattlePokemon>();
pokemon.MaxHealth.Returns(maxHp);
return pokemon;
}
@@ -60,7 +57,7 @@ public class LunarDanceTests
/// Helper to extract the heal amount from a substitute's received Heal calls, or null when Heal was
/// never called.
/// </summary>
private static uint? GetHealAmount(IPokemon pokemon)
private static uint? GetHealAmount(IBattlePokemon pokemon)
{
var call = pokemon.ReceivedCalls().FirstOrDefault(c => c.GetMethodInfo().Name == "Heal");
return call != null ? (uint)call.GetArguments()[0]! : null;
@@ -78,7 +75,7 @@ public class LunarDanceTests
var (script, move, _, sideVolatile) = CreateMoveSetup();
// Act
script.OnSecondaryEffect(move, Substitute.For<IPokemon>(), 0);
script.OnSecondaryEffect(move, Substitute.For<IBattlePokemon>(), 0);
// Assert
await Assert.That(sideVolatile.Contains(ScriptUtils.ResolveName<LunarDanceEffect>())).IsTrue();
@@ -94,7 +91,7 @@ public class LunarDanceTests
var (script, move, user, _) = CreateMoveSetup();
// Act
script.OnSecondaryEffect(move, Substitute.For<IPokemon>(), 0);
script.OnSecondaryEffect(move, Substitute.For<IBattlePokemon>(), 0);
// Assert
await Assert.That(user.ReceivedCalls().Any(c => c.GetMethodInfo().Name == "Faint")).IsTrue();
@@ -109,7 +106,7 @@ public class LunarDanceTests
{
// Arrange
var (script, move, _, sideVolatile) = CreateMoveSetup(1);
script.OnSecondaryEffect(move, Substitute.For<IPokemon>(), 0);
script.OnSecondaryEffect(move, Substitute.For<IBattlePokemon>(), 0);
var effect = (LunarDanceEffect)sideVolatile.Get(new StringKey("lunar_dance"))!.Script!;
var replacement = CreateReplacement();
@@ -120,27 +117,6 @@ public class LunarDanceTests
await Assert.That(GetHealAmount(replacement)).IsNotNull();
}
/// <summary>
/// Technical test: outside of battle (no <see cref="IPokemon.BattleData"/>) the hook does nothing and
/// does not throw.
/// </summary>
[Test]
public async Task OnSecondaryEffect_NoBattleData_DoesNothing()
{
// Arrange
var script = new LunarDance();
var move = Substitute.For<IExecutingMove>();
var user = Substitute.For<IPokemon>();
user.BattleData.Returns((IPokemonBattleData?)null);
move.User.Returns(user);
// Act
script.OnSecondaryEffect(move, Substitute.For<IPokemon>(), 0);
// Assert
await Assert.That(user.ReceivedCalls().Any(c => c.GetMethodInfo().Name == "Faint")).IsFalse();
}
/// <summary>
/// Bulbapedia: "restores the HP ... of the Pokémon that is sent out to take its place" — the
/// replacement switching into the dancer's position is healed by its full maximum HP.