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

@@ -36,26 +36,22 @@ public class DisableTests
/// Creates a fully mocked test setup where the target's volatile scripts are a real
/// <see cref="ScriptSet"/> and its last used move is the given one (or none).
/// </summary>
private static (Disable script, IExecutingMove move, IPokemon target, ScriptSet targetVolatile, IHitData hitData)
CreateTestSetup(string? lastUsedMove, bool lastMoveIsStruggle = false)
private static (Disable script, IExecutingMove move, IBattlePokemon target, ScriptSet targetVolatile, IHitData
hitData) CreateTestSetup(string? lastUsedMove, bool lastMoveIsStruggle = false)
{
var script = new Disable();
var move = Substitute.For<IExecutingMove>();
var user = Substitute.For<IPokemon>();
var userBattleData = Substitute.For<IPokemonBattleData>();
user.BattleData.Returns(userBattleData);
var user = Substitute.For<IBattlePokemon>();
move.User.Returns(user);
var target = Substitute.For<IPokemon>();
var target = Substitute.For<IBattlePokemon>();
var targetVolatile = new ScriptSet(target);
target.Volatile.Returns(targetVolatile);
target.GetScripts().Returns(_ => new ScriptIterator(new List<IEnumerable<ScriptContainer>>()));
var targetBattleData = Substitute.For<IPokemonBattleData>();
// Create the choice before the Returns call; configuring substitutes inside Returns is not allowed.
var lastMoveChoice = lastUsedMove == null ? null : CreateMoveChoice(lastUsedMove);
targetBattleData.LastMoveChoice.Returns(lastMoveChoice);
target.BattleData.Returns(targetBattleData);
target.LastMoveChoice.Returns(lastMoveChoice);
// Struggle is recognized through the misc library's replacement choice check, not by name.
var miscLibrary = Substitute.For<IMiscLibrary>();
@@ -144,24 +140,6 @@ public class DisableTests
await Assert.That(targetVolatile.Contains(ScriptUtils.ResolveName<DisableEffect>())).IsFalse();
}
/// <summary>
/// Technical test: without battle data on the user (outside of battle) the effect does nothing and
/// does not throw.
/// </summary>
[Test]
public async Task OnSecondaryEffect_UserHasNoBattleData_DoesNothing()
{
// Arrange
var (script, move, target, targetVolatile, _) = CreateTestSetup("tackle");
move.User.BattleData.Returns((IPokemonBattleData?)null);
// Act
script.OnSecondaryEffect(move, target, 0);
// Assert
await Assert.That(targetVolatile.Contains(ScriptUtils.ResolveName<DisableEffect>())).IsFalse();
}
/// <summary>
/// Bulbapedia: "Disable temporarily prevents the target from using a specific move." Selecting the
/// disabled move is prevented by the <see cref="DisableEffect"/>.
@@ -207,7 +185,7 @@ public class DisableTests
public async Task OnEndTurn_ThreeTurnsPassed_EffectStillActive()
{
// Arrange
var target = Substitute.For<IPokemon>();
var target = Substitute.For<IBattlePokemon>();
var targetVolatile = new ScriptSet(target);
target.GetScripts().Returns(_ => new ScriptIterator(new List<IEnumerable<ScriptContainer>>()));
var effect = new DisableEffect(new StringKey("tackle"));
@@ -230,7 +208,7 @@ public class DisableTests
public async Task OnEndTurn_FourTurnsPassed_EffectRemovesItself()
{
// Arrange
var target = Substitute.For<IPokemon>();
var target = Substitute.For<IBattlePokemon>();
var targetVolatile = new ScriptSet(target);
target.GetScripts().Returns(_ => new ScriptIterator(new List<IEnumerable<ScriptContainer>>()));
var effect = new DisableEffect(new StringKey("tackle"));