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,11 +22,12 @@ public class FireSpinTests
/// <see cref="ScriptSet"/> as its volatile set, so the applied effect can be inspected.
/// The battle random is stubbed to return 5, the maximum of Fire Spin's four-to-five turn duration.
/// </summary>
private static (FireSpin script, IExecutingMove move, IPokemon target, IScriptSet targetVolatile) CreateTestSetup()
private static (FireSpin script, IExecutingMove move, IBattlePokemon target, IScriptSet targetVolatile)
CreateTestSetup()
{
var script = new FireSpin();
var move = Substitute.For<IExecutingMove>();
var target = Substitute.For<IPokemon>();
var target = Substitute.For<IBattlePokemon>();
target.GetScripts().Returns(_ => new ScriptIterator(new List<IEnumerable<ScriptContainer>>()));
var targetVolatile = new ScriptSet(target);
target.Volatile.Returns(targetVolatile);
@@ -35,9 +36,7 @@ public class FireSpinTests
random.GetInt(Arg.Any<int>(), Arg.Any<int>()).Returns(5);
var battle = Substitute.For<IBattle>();
battle.Random.Returns(random);
var battleData = Substitute.For<IPokemonBattleData>();
battleData.Battle.Returns(battle);
target.BattleData.Returns(battleData);
target.Battle.Returns(battle);
return (script, move, target, targetVolatile);
}
@@ -84,19 +83,20 @@ public class FireSpinTests
/// Creates a trapped Pokémon substitute with the given maximum HP, together with the
/// <see cref="FireSpinEffect"/> that traps it.
/// </summary>
private static (FireSpinEffect effect, IPokemon owner) CreateTrappedPokemon(uint maxHealth, IPokemon? user = null)
private static (FireSpinEffect effect, IBattlePokemon owner) CreateTrappedPokemon(uint maxHealth,
IBattlePokemon? user = null)
{
var owner = Substitute.For<IPokemon>();
var owner = Substitute.For<IBattlePokemon>();
owner.BoostedStats.Returns(new StatisticSet<uint>(maxHealth, 1, 1, 1, 1, 1));
owner.MaxHealth.Returns(maxHealth);
owner.Types.Returns(new List<TypeIdentifier> { new(10, "fire") });
return (new FireSpinEffect(owner, 5, user ?? Substitute.For<IPokemon>()), owner);
return (new FireSpinEffect(owner, 5, user ?? Substitute.For<IBattlePokemon>()), owner);
}
/// <summary>
/// Helper to extract the damage amount from a Pokémon's received Damage calls.
/// </summary>
private static uint? GetDamageAmount(IPokemon pokemon)
private static uint? GetDamageAmount(IBattlePokemon pokemon)
{
var call = pokemon.ReceivedCalls().FirstOrDefault(c => c.GetMethodInfo().Name == "Damage");
return call != null ? (uint)call.GetArguments()[0]! : null;
@@ -206,7 +206,7 @@ public class FireSpinTests
{
// Arrange
var (script, move, target, targetVolatile) = CreateTestSetup();
var user = Substitute.For<IPokemon>();
var user = Substitute.For<IBattlePokemon>();
user.HasHeldItem("binding_band").Returns(true);
move.User.Returns(user);
target.BoostedStats.Returns(new StatisticSet<uint>(120, 1, 1, 1, 1, 1));