This commit is contained in:
@@ -0,0 +1,222 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
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.Utils;
|
||||
|
||||
namespace PkmnLib.Plugin.Gen7.Tests.Scripts.MoveVolatile;
|
||||
|
||||
/// <summary>
|
||||
/// Tests for the <see cref="FireWaterPledgeMove"/> volatile script, which implements the combined move of
|
||||
/// Fire Pledge and Water Pledge, and the <see cref="RainbowEffect"/> it creates.
|
||||
/// Bulbapedia (Fire Pledge): "If Fire Pledge and Water Pledge are used in the same turn, the ally moving
|
||||
/// second will use Water Pledge with a power of 150, and create a rainbow on the user's side of the field
|
||||
/// for four turns."
|
||||
/// </summary>
|
||||
public class FireWaterPledgeMoveTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a fully mocked test setup. The user's battle side gets a real <see cref="ScriptSet"/> as its
|
||||
/// volatile script set, so the rainbow created by the combined move can be inspected and driven.
|
||||
/// </summary>
|
||||
private static (FireWaterPledgeMove script, IExecutingMove move, IPokemon user, IBattleSide side, IScriptSet
|
||||
sideVolatile) CreateTestSetup()
|
||||
{
|
||||
var script = new FireWaterPledgeMove();
|
||||
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 user = Substitute.For<IPokemon>();
|
||||
user.BattleData.Returns(battleData);
|
||||
move.User.Returns(user);
|
||||
|
||||
return (script, move, user, side, sideVolatile);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Bulbapedia: "the ally moving second will use Water Pledge" when Fire Pledge and Water Pledge are
|
||||
/// combined. The marked choice's move is replaced with Water Pledge.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task ChangeMove_CombinedMove_ExecutesWaterPledge()
|
||||
{
|
||||
// Arrange
|
||||
var (script, _, _, _, _) = CreateTestSetup();
|
||||
var choice = Substitute.For<IMoveChoice>();
|
||||
StringKey moveName = "fire_pledge";
|
||||
|
||||
// Act
|
||||
script.ChangeMove(choice, ref moveName);
|
||||
|
||||
// Assert
|
||||
await Assert.That(moveName).IsEqualTo(new StringKey("water_pledge"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Bulbapedia: "the ally moving second will use Water Pledge with a power of 150".
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task ChangeBasePower_CombinedMove_PowerIs150()
|
||||
{
|
||||
// Arrange
|
||||
var (script, move, _, _, _) = CreateTestSetup();
|
||||
var target = Substitute.For<IPokemon>();
|
||||
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 rainbow on the user's side of the field for four turns."
|
||||
/// The <see cref="RainbowEffect"/> is added to the user's side.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task OnSecondaryEffect_CombinedMoveHits_AddsRainbowToUsersSide()
|
||||
{
|
||||
// Arrange
|
||||
var (script, move, _, _, sideVolatile) = CreateTestSetup();
|
||||
var target = Substitute.For<IPokemon>();
|
||||
|
||||
// Act
|
||||
script.OnSecondaryEffect(move, target, 0);
|
||||
|
||||
// Assert
|
||||
await Assert.That(sideVolatile.Get<RainbowEffect>()).IsNotNull();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Technical test: if the user has no <see cref="IPokemon.BattleData"/>, no rainbow is created and the
|
||||
/// script does not throw.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task OnSecondaryEffect_UserHasNoBattleData_DoesNothing()
|
||||
{
|
||||
// Arrange
|
||||
var (script, move, user, _, sideVolatile) = CreateTestSetup();
|
||||
user.BattleData.Returns((IPokemonBattleData?)null);
|
||||
var target = Substitute.For<IPokemon>();
|
||||
|
||||
// Act
|
||||
script.OnSecondaryEffect(move, target, 0);
|
||||
|
||||
// Assert
|
||||
await Assert.That(sideVolatile.Count).IsEqualTo(0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Bulbapedia: "The rainbow doubles the probability of additional effects taking place for moves used
|
||||
/// by that side of the field".
|
||||
/// </summary>
|
||||
[Test, Arguments(10f, 20f), Arguments(30f, 60f), Arguments(50f, 100f)]
|
||||
public async Task RainbowEffect_ChangeEffectChance_DoublesTheChance(float chance, float expected)
|
||||
{
|
||||
// Arrange
|
||||
var (script, move, _, _, sideVolatile) = CreateTestSetup();
|
||||
var target = Substitute.For<IPokemon>();
|
||||
script.OnSecondaryEffect(move, target, 0);
|
||||
var rainbow = sideVolatile.Get<RainbowEffect>()!;
|
||||
|
||||
// Act
|
||||
rainbow.ChangeEffectChance(move, target, 0, ref chance);
|
||||
|
||||
// Assert
|
||||
await Assert.That(chance).IsEqualTo(expected);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Bulbapedia: the rainbow is created "on the user's side of the field for four turns." After the
|
||||
/// fourth end-of-turn since its creation the rainbow must be gone.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task RainbowEffect_AfterFourEndOfTurns_RainbowHasFaded()
|
||||
{
|
||||
// Arrange
|
||||
var (script, move, _, side, sideVolatile) = CreateTestSetup();
|
||||
var target = Substitute.For<IPokemon>();
|
||||
script.OnSecondaryEffect(move, target, 0);
|
||||
var rainbow = sideVolatile.Get<RainbowEffect>()!;
|
||||
var battle = Substitute.For<IBattle>();
|
||||
|
||||
// Act - four end-of-turn ticks, counting the turn the rainbow was created
|
||||
for (var i = 0; i < 4; i++)
|
||||
rainbow.OnEndTurn(side, battle);
|
||||
|
||||
// Assert
|
||||
await Assert.That(sideVolatile.Contains("rainbow_effect")).IsFalse();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Technical test: the rainbow does not stay around forever; it removes itself from the side once its
|
||||
/// counter runs out (currently after the fifth end-of-turn).
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task RainbowEffect_AfterFiveEndOfTurns_HasRemovedItself()
|
||||
{
|
||||
// Arrange
|
||||
var (script, move, _, side, sideVolatile) = CreateTestSetup();
|
||||
var target = Substitute.For<IPokemon>();
|
||||
script.OnSecondaryEffect(move, target, 0);
|
||||
var rainbow = sideVolatile.Get<RainbowEffect>()!;
|
||||
var battle = Substitute.For<IBattle>();
|
||||
|
||||
// Act
|
||||
for (var i = 0; i < 5; i++)
|
||||
rainbow.OnEndTurn(side, battle);
|
||||
|
||||
// Assert
|
||||
await Assert.That(sideVolatile.Contains("rainbow_effect")).IsFalse();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user