222 lines
8.4 KiB
C#
222 lines
8.4 KiB
C#
using PkmnLib.Dynamic.Models;
|
|
using PkmnLib.Dynamic.Models.Choices;
|
|
using PkmnLib.Dynamic.ScriptHandling;
|
|
using PkmnLib.Plugin.Gen7.Scripts.MoveVolatile;
|
|
using PkmnLib.Plugin.Gen7.Scripts.Side;
|
|
using PkmnLib.Static;
|
|
using PkmnLib.Static.Utils;
|
|
|
|
namespace PkmnLib.Plugin.Gen7.Tests.Scripts.MoveVolatile;
|
|
|
|
/// <summary>
|
|
/// Tests for the <see cref="FireGrassPledgeMove"/> volatile script, which implements the combined move of
|
|
/// Fire Pledge and Grass Pledge, and the <see cref="SeaOfFireEffect"/> it creates.
|
|
/// Bulbapedia (Fire Pledge): "If Fire Pledge and Grass Pledge are used in the same turn, the ally moving
|
|
/// second will use Fire Pledge with a power of 150, and create a sea of fire on the target's side of the
|
|
/// field for four turns. The sea of fire damages all non-Fire Pokémon on that side of the field for 1/8 of
|
|
/// their maximum HP at the end of each turn."
|
|
/// </summary>
|
|
public class FireGrassPledgeMoveTests
|
|
{
|
|
/// <summary>
|
|
/// Creates a fully mocked test setup. The target's battle side gets a real <see cref="ScriptSet"/> as
|
|
/// its volatile script set, so the sea of fire created by the combined move can be inspected and driven.
|
|
/// </summary>
|
|
private static (FireGrassPledgeMove script, IExecutingMove move, IPokemon target, IBattleSide side, IScriptSet
|
|
sideVolatile) CreateTestSetup()
|
|
{
|
|
var script = new FireGrassPledgeMove();
|
|
var move = Substitute.For<IExecutingMove>();
|
|
|
|
var side = Substitute.For<IBattleSide>();
|
|
side.GetScripts().Returns(_ => new ScriptIterator(new List<IEnumerable<ScriptContainer>>()));
|
|
var sideVolatile = new ScriptSet(side);
|
|
side.VolatileScripts.Returns(sideVolatile);
|
|
|
|
var battleData = Substitute.For<IPokemonBattleData>();
|
|
battleData.BattleSide.Returns(side);
|
|
var target = Substitute.For<IPokemon>();
|
|
target.BattleData.Returns(battleData);
|
|
|
|
return (script, move, target, side, sideVolatile);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Creates a Pokémon substitute of the given type with the given maximum HP, for placing on the side
|
|
/// covered by the sea of fire.
|
|
/// </summary>
|
|
private static IPokemon CreateSidePokemon(string typeName, uint maxHealth)
|
|
{
|
|
var pokemon = Substitute.For<IPokemon>();
|
|
pokemon.Types.Returns(new List<TypeIdentifier> { new(1, typeName) });
|
|
pokemon.MaxHealth.Returns(maxHealth);
|
|
return pokemon;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Helper to count the Damage calls a Pokémon received.
|
|
/// </summary>
|
|
private static int CountDamageCalls(IPokemon pokemon) =>
|
|
pokemon.ReceivedCalls().Count(c => c.GetMethodInfo().Name == "Damage");
|
|
|
|
/// <summary>
|
|
/// Bulbapedia: "the ally moving second will use Fire Pledge" when Fire Pledge and Grass Pledge are
|
|
/// combined. The marked choice's move is replaced with Fire Pledge.
|
|
/// </summary>
|
|
[Test]
|
|
public async Task ChangeMove_CombinedMove_ExecutesFirePledge()
|
|
{
|
|
// Arrange
|
|
var (script, _, _, _, _) = CreateTestSetup();
|
|
var choice = Substitute.For<IMoveChoice>();
|
|
StringKey moveName = "grass_pledge";
|
|
|
|
// Act
|
|
script.ChangeMove(choice, ref moveName);
|
|
|
|
// Assert
|
|
await Assert.That(moveName).IsEqualTo(new StringKey("fire_pledge"));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Bulbapedia: "the ally moving second will use Fire Pledge with a power of 150".
|
|
/// </summary>
|
|
[Test]
|
|
public async Task ChangeBasePower_CombinedMove_PowerIs150()
|
|
{
|
|
// Arrange
|
|
var (script, move, target, _, _) = CreateTestSetup();
|
|
ushort basePower = 80;
|
|
|
|
// Act
|
|
script.ChangeBasePower(move, target, 0, ref basePower);
|
|
|
|
// Assert
|
|
await Assert.That(basePower).IsEqualTo((ushort)150);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Bulbapedia: the combined move will "create a sea of fire on the target's side of the field for four
|
|
/// turns." The <see cref="SeaOfFireEffect"/> is added to the target's side.
|
|
/// </summary>
|
|
[Test]
|
|
public async Task OnSecondaryEffect_CombinedMoveHits_AddsSeaOfFireToTargetsSide()
|
|
{
|
|
// Arrange
|
|
var (script, move, target, _, sideVolatile) = CreateTestSetup();
|
|
|
|
// Act
|
|
script.OnSecondaryEffect(move, target, 0);
|
|
|
|
// Assert
|
|
await Assert.That(sideVolatile.Get<SeaOfFireEffect>()).IsNotNull();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Technical test: if the target has no <see cref="IPokemon.BattleData"/>, no sea of fire is created
|
|
/// and the script does not throw.
|
|
/// </summary>
|
|
[Test]
|
|
public async Task OnSecondaryEffect_TargetHasNoBattleData_DoesNothing()
|
|
{
|
|
// Arrange
|
|
var (script, move, target, _, sideVolatile) = CreateTestSetup();
|
|
target.BattleData.Returns((IPokemonBattleData?)null);
|
|
|
|
// Act
|
|
script.OnSecondaryEffect(move, target, 0);
|
|
|
|
// Assert
|
|
await Assert.That(sideVolatile.Count).IsEqualTo(0);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Bulbapedia: "The sea of fire damages all non-Fire Pokémon on that side of the field for 1/8 of
|
|
/// their maximum HP at the end of each turn."
|
|
/// </summary>
|
|
[Test, Arguments(96u, 12u), Arguments(100u, 12u), Arguments(120u, 15u)]
|
|
public async Task SeaOfFireEffect_OnEndTurn_DamagesNonFirePokemonForOneEighthOfMaxHp(uint maxHealth,
|
|
uint expectedDamage)
|
|
{
|
|
// Arrange
|
|
var (script, move, target, side, sideVolatile) = CreateTestSetup();
|
|
var waterPokemon = CreateSidePokemon("water", maxHealth);
|
|
side.Pokemon.Returns(new List<IPokemon?> { waterPokemon });
|
|
script.OnSecondaryEffect(move, target, 0);
|
|
var seaOfFire = sideVolatile.Get<SeaOfFireEffect>()!;
|
|
|
|
// Act
|
|
seaOfFire.OnEndTurn(side, Substitute.For<IBattle>());
|
|
|
|
// Assert
|
|
var call = waterPokemon.ReceivedCalls().First(c => c.GetMethodInfo().Name == "Damage");
|
|
await Assert.That((uint)call.GetArguments()[0]!).IsEqualTo(expectedDamage);
|
|
await Assert.That((DamageSource)call.GetArguments()[1]!).IsEqualTo(DamageSource.Misc);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Bulbapedia: the sea of fire damages "all non-Fire Pokémon on that side of the field" — Fire-type
|
|
/// Pokémon are not hurt by it.
|
|
/// </summary>
|
|
[Test]
|
|
public async Task SeaOfFireEffect_OnEndTurn_DoesNotDamageFirePokemon()
|
|
{
|
|
// Arrange
|
|
var (script, move, target, side, sideVolatile) = CreateTestSetup();
|
|
var firePokemon = CreateSidePokemon("fire", 100);
|
|
side.Pokemon.Returns(new List<IPokemon?> { firePokemon });
|
|
script.OnSecondaryEffect(move, target, 0);
|
|
var seaOfFire = sideVolatile.Get<SeaOfFireEffect>()!;
|
|
|
|
// Act
|
|
seaOfFire.OnEndTurn(side, Substitute.For<IBattle>());
|
|
|
|
// Assert
|
|
await Assert.That(CountDamageCalls(firePokemon)).IsEqualTo(0);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Bulbapedia: the sea of fire lasts "for four turns", damaging "at the end of each turn." Over any
|
|
/// number of end-of-turns, a non-Fire Pokémon on the covered side is damaged exactly four times.
|
|
/// </summary>
|
|
[Test]
|
|
public async Task SeaOfFireEffect_LastsFourTurns_DamagesExactlyFourTimes()
|
|
{
|
|
// Arrange
|
|
var (script, move, target, side, sideVolatile) = CreateTestSetup();
|
|
var waterPokemon = CreateSidePokemon("water", 96);
|
|
side.Pokemon.Returns(new List<IPokemon?> { waterPokemon });
|
|
script.OnSecondaryEffect(move, target, 0);
|
|
var seaOfFire = sideVolatile.Get<SeaOfFireEffect>()!;
|
|
var battle = Substitute.For<IBattle>();
|
|
|
|
// Act - more end-of-turns than the sea of fire lasts
|
|
for (var i = 0; i < 6; i++)
|
|
seaOfFire.OnEndTurn(side, battle);
|
|
|
|
// Assert
|
|
await Assert.That(CountDamageCalls(waterPokemon)).IsEqualTo(4);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Technical test: once its duration has run out, the sea of fire removes itself from the side's
|
|
/// volatile scripts.
|
|
/// </summary>
|
|
[Test]
|
|
public async Task SeaOfFireEffect_AfterExpiry_HasRemovedItselfFromSide()
|
|
{
|
|
// Arrange
|
|
var (script, move, target, side, sideVolatile) = CreateTestSetup();
|
|
side.Pokemon.Returns(new List<IPokemon?>());
|
|
script.OnSecondaryEffect(move, target, 0);
|
|
var seaOfFire = sideVolatile.Get<SeaOfFireEffect>()!;
|
|
var battle = Substitute.For<IBattle>();
|
|
|
|
// Act
|
|
for (var i = 0; i < 5; i++)
|
|
seaOfFire.OnEndTurn(side, battle);
|
|
|
|
// Assert
|
|
await Assert.That(sideVolatile.Contains("sea_of_fire_effect")).IsFalse();
|
|
}
|
|
} |