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,23 +20,19 @@ public class InstructTests
/// Creates a fully mocked test setup for Instruct tests. When <paramref name="lastMoveName"/> is given,
/// the target has a repeatable last move choice of that name; otherwise it has not moved yet.
/// </summary>
private static (Instruct script, IExecutingMove move, IBattle battle, IPokemon target, IHitData hitData, IMoveChoice
? lastChoice) CreateTestSetup(string? lastMoveName)
private static (Instruct script, IExecutingMove move, IBattle battle, IBattlePokemon target, IHitData hitData,
IMoveChoice? lastChoice) CreateTestSetup(string? lastMoveName)
{
var script = new Instruct();
var move = Substitute.For<IExecutingMove>();
var user = Substitute.For<IPokemon>();
var user = Substitute.For<IBattlePokemon>();
move.User.Returns(user);
var battle = Substitute.For<IBattle>();
var userBattleData = Substitute.For<IPokemonBattleData>();
userBattleData.Battle.Returns(battle);
user.BattleData.Returns(userBattleData);
user.Battle.Returns(battle);
var target = Substitute.For<IPokemon>();
var target = Substitute.For<IBattlePokemon>();
target.IsUsable.Returns(true);
var targetBattleData = Substitute.For<IPokemonBattleData>();
target.BattleData.Returns(targetBattleData);
IMoveChoice? lastChoice = null;
if (lastMoveName != null)
@@ -44,14 +40,14 @@ public class InstructTests
lastChoice = Substitute.For<IMoveChoice>();
// The choice needs a real (empty) script iterator so the turn runner's hook pass works on it.
lastChoice.GetScripts().Returns(_ => new ScriptIterator(new List<IEnumerable<ScriptContainer>>()));
lastChoice.User.Returns(Substitute.For<IPokemon>());
lastChoice.User.Returns(Substitute.For<IBattlePokemon>());
var moveData = Substitute.For<IMoveData>();
moveData.Name.Returns(new StringKey(lastMoveName));
var learnedMove = Substitute.For<ILearnedMove>();
learnedMove.MoveData.Returns(moveData);
lastChoice.ChosenMove.Returns(learnedMove);
}
targetBattleData.LastMoveChoice.Returns(lastChoice);
target.LastMoveChoice.Returns(lastChoice);
var hitData = Substitute.For<IHitData>();
move.GetHitData(target, 0).Returns(hitData);
@@ -130,23 +126,6 @@ public class InstructTests
hitData.DidNotReceive().Fail();
}
/// <summary>
/// Technical test: if the user has no <see cref="IPokemon.BattleData"/>, the script does nothing.
/// </summary>
[Test]
public void OnSecondaryEffect_UserHasNoBattleData_DoesNothing()
{
// Arrange
var (script, move, _, target, hitData, _) = CreateTestSetup("tackle");
move.User.BattleData.Returns((IPokemonBattleData?)null);
// Act
script.OnSecondaryEffect(move, target, 0);
// Assert
hitData.DidNotReceive().Fail();
}
/// <summary>
/// Bulbapedia: "The move cannot force repetition of Instruct itself, Sketch, Transform, Mimic, King's
/// Shield, Struggle, moves requiring recharge (like Hyper Beam), moves with charging turns (like Dig),