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

@@ -26,9 +26,9 @@ public class HealBlockTests
/// Creates a mocked Pokémon whose <see cref="IPokemon.Volatile"/> is a real <see cref="ScriptSet"/>,
/// so scripts can be added and can remove themselves.
/// </summary>
private static (IPokemon pokemon, ScriptSet volatileSet) CreatePokemonWithRealVolatile()
private static (IBattlePokemon pokemon, ScriptSet volatileSet) CreatePokemonWithRealVolatile()
{
var pokemon = Substitute.For<IPokemon>();
var pokemon = Substitute.For<IBattlePokemon>();
var volatileSet = new ScriptSet(pokemon);
pokemon.Volatile.Returns(volatileSet);
pokemon.GetScripts().Returns(_ => new ScriptIterator(new List<IEnumerable<ScriptContainer>>()));
@@ -194,7 +194,7 @@ public class HealBlockTests
{
// Arrange
var effect = new HealBlockEffect();
var pokemon = Substitute.For<IPokemon>();
var pokemon = Substitute.For<IBattlePokemon>();
var prevented = false;
// Act
@@ -207,7 +207,7 @@ public class HealBlockTests
/// <summary>
/// Bulbapedia (Generation V onwards): "Heal Block will not prevent Pokémon with the Ability Regenerator
/// from having their HP restored upon switching out." Run through the real switch-out flow (the direct
/// <see cref="IBattleSide.SwapPokemon(byte, IPokemon?)"/> call moves such as U-turn make), a damaged
/// <see cref="IBattleSide.SwapPokemon(byte, IBattlePokemon?)"/> call moves such as U-turn make), a damaged
/// Pokémon with Regenerator under Heal Block still restores 1/3 of its max HP.
/// </summary>
[Test]
@@ -220,13 +220,13 @@ public class HealBlockTests
IPokemon CreateMienfoo(byte abilityIndex) => new PokemonImpl(library, species!, species!.GetDefaultForm(),
new AbilityIndex { IsHidden = false, Index = abilityIndex }, 50, 0, Gender.Male, 0, "hardy");
var regeneratorMon = CreateMienfoo(1);
await Assert.That(regeneratorMon.ActiveAbility!.Name).IsEqualTo(new StringKey("regenerator"));
var regeneratorMonPersistent = CreateMienfoo(1);
await Assert.That(regeneratorMonPersistent.Ability.Name).IsEqualTo(new StringKey("regenerator"));
var benchMon = CreateMienfoo(0);
var opponent = CreateMienfoo(0);
var party = new PokemonPartyImpl(6);
party.SwapInto(regeneratorMon, 0);
party.SwapInto(regeneratorMonPersistent, 0);
party.SwapInto(benchMon, 1);
var opponentParty = new PokemonPartyImpl(6);
opponentParty.SwapInto(opponent, 0);
@@ -234,8 +234,9 @@ public class HealBlockTests
new BattlePartyImpl(party, [new ResponsibleIndex(0, 0)]),
new BattlePartyImpl(opponentParty, [new ResponsibleIndex(1, 0)]),
], false, 2, 1, false, "grass", 10);
battle.Sides[0].SwapPokemon(0, regeneratorMon);
battle.Sides[1].SwapPokemon(0, opponent);
battle.Sides[0].SendOut(0, regeneratorMonPersistent);
battle.Sides[1].SendOut(0, opponent);
var regeneratorMon = battle.Parties[0].GetBattlePokemon(regeneratorMonPersistent)!;
regeneratorMon.Damage(60, DamageSource.MoveDamage, new EventBatchId());
regeneratorMon.Volatile.Add(new HealBlockEffect());
@@ -244,7 +245,7 @@ public class HealBlockTests
var healthBeforeSwitch = regeneratorMon.CurrentHealth;
// Act
battle.Sides[0].SwapPokemon(0, benchMon);
battle.Sides[0].SendOut(0, benchMon);
// Assert
await Assert.That(regeneratorMon.CurrentHealth).IsEqualTo(healthBeforeSwitch + regeneratorMon.MaxHealth / 3);