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; /// /// Tests for the volatile script, which implements the combined move of /// Fire Pledge and Grass Pledge, and the 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." /// public class FireGrassPledgeMoveTests { /// /// Creates a fully mocked test setup. The target's battle side gets a real as /// its volatile script set, so the sea of fire created by the combined move can be inspected and driven. /// private static (FireGrassPledgeMove script, IExecutingMove move, IBattlePokemon target, IBattleSide side, IScriptSet sideVolatile) CreateTestSetup() { var script = new FireGrassPledgeMove(); var move = Substitute.For(); var side = Substitute.For(); side.GetScripts().Returns(_ => new ScriptIterator(new List>())); var sideVolatile = new ScriptSet(side); side.VolatileScripts.Returns(sideVolatile); var target = Substitute.For(); target.BattleSide.Returns(side); return (script, move, target, side, sideVolatile); } /// /// 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. /// private static IBattlePokemon CreateSidePokemon(string typeName, uint maxHealth) { var pokemon = Substitute.For(); pokemon.Types.Returns(new List { new(1, typeName) }); pokemon.MaxHealth.Returns(maxHealth); return pokemon; } /// /// Helper to count the Damage calls a Pokémon received. /// private static int CountDamageCalls(IBattlePokemon pokemon) => pokemon.ReceivedCalls().Count(c => c.GetMethodInfo().Name == "Damage"); /// /// 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. /// [Test] public async Task ChangeMove_CombinedMove_ExecutesFirePledge() { // Arrange var (script, _, _, _, _) = CreateTestSetup(); var choice = Substitute.For(); StringKey moveName = "grass_pledge"; // Act script.ChangeMove(choice, ref moveName); // Assert await Assert.That(moveName).IsEqualTo(new StringKey("fire_pledge")); } /// /// Bulbapedia: "the ally moving second will use Fire Pledge with a power of 150". /// [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); } /// /// Bulbapedia: the combined move will "create a sea of fire on the target's side of the field for four /// turns." The is added to the target's side. /// [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()).IsNotNull(); } /// /// 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." /// [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 { waterPokemon }); script.OnSecondaryEffect(move, target, 0); var seaOfFire = sideVolatile.Get()!; // Act seaOfFire.OnEndTurn(side, Substitute.For()); // 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); } /// /// 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. /// [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 { firePokemon }); script.OnSecondaryEffect(move, target, 0); var seaOfFire = sideVolatile.Get()!; // Act seaOfFire.OnEndTurn(side, Substitute.For()); // Assert await Assert.That(CountDamageCalls(firePokemon)).IsEqualTo(0); } /// /// 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. /// [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 { waterPokemon }); script.OnSecondaryEffect(move, target, 0); var seaOfFire = sideVolatile.Get()!; var battle = Substitute.For(); // 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); } /// /// Technical test: once its duration has run out, the sea of fire removes itself from the side's /// volatile scripts. /// [Test] public async Task SeaOfFireEffect_AfterExpiry_HasRemovedItselfFromSide() { // Arrange var (script, move, target, side, sideVolatile) = CreateTestSetup(); side.Pokemon.Returns(new List()); script.OnSecondaryEffect(move, target, 0); var seaOfFire = sideVolatile.Get()!; var battle = Substitute.For(); // Act for (var i = 0; i < 5; i++) seaOfFire.OnEndTurn(side, battle); // Assert await Assert.That(sideVolatile.Contains("sea_of_fire_effect")).IsFalse(); } }