using PkmnLib.Dynamic.Models; using PkmnLib.Dynamic.ScriptHandling; using PkmnLib.Dynamic.ScriptHandling.Registry; using PkmnLib.Plugin.Gen7.Scripts.Moves; using PkmnLib.Plugin.Gen7.Scripts.Side; using PkmnLib.Static.Moves; namespace PkmnLib.Plugin.Gen7.Tests.Scripts.Moves; /// /// Tests for the move script and the it applies. /// Gen VII Bulbapedia behavior: "Mat Block protects all Pokémon on the user's side of the field from any /// physical or special moves for that turn." /// public class MatBlockTests { private static (MatBlock script, IExecutingMove move, IPokemon target, IHitData hitData, IScriptSet sideVolatile) CreateTestSetup(uint switchInTurn, uint currentTurn) { var script = new MatBlock(); var side = Substitute.For(); // Use a real script set so the side script added by Mat Block can be inspected afterwards. var sideVolatile = new ScriptSet(side); side.VolatileScripts.Returns(sideVolatile); side.GetScripts().Returns(_ => new ScriptIterator(new List>())); var battle = Substitute.For(); battle.CurrentTurnNumber.Returns(currentTurn); var battleData = Substitute.For(); battleData.Battle.Returns(battle); battleData.BattleSide.Returns(side); battleData.SwitchInTurn.Returns(switchInTurn); var user = Substitute.For(); user.BattleData.Returns(battleData); var move = Substitute.For(); move.User.Returns(user); var target = Substitute.For(); var hitData = Substitute.For(); move.GetHitData(target, 0).Returns(hitData); return (script, move, target, hitData, sideVolatile); } private static IExecutingMove CreateExecutingMoveOfCategory(MoveCategory category) { var useMove = Substitute.For(); useMove.Category.Returns(category); var move = Substitute.For(); move.UseMove.Returns(useMove); return move; } /// /// Bulbapedia: "Mat Block protects all Pokémon on the user's side of the field" — using the move on /// the user's first turn on the field attaches the to the user's side. /// [Test] public async Task OnSecondaryEffect_UsedOnSwitchInTurn_AddsMatBlockEffectToUsersSide() { // Arrange var (script, move, target, _, sideVolatile) = CreateTestSetup(1, 1); // Act script.OnSecondaryEffect(move, target, 0); // Assert await Assert.That(sideVolatile.Contains(ScriptUtils.ResolveName())).IsTrue(); } /// /// Bulbapedia: Mat Block only fails "if not used on the first turn after the Pokémon enters the /// field" — on the user's first turn on the field the hit is not marked as failed. /// [Test] public async Task OnSecondaryEffect_UsedOnSwitchInTurn_HitDoesNotFail() { // Arrange var (script, move, target, hitData, _) = CreateTestSetup(1, 1); // Act script.OnSecondaryEffect(move, target, 0); // Assert await Assert.That(hitData.ReceivedCalls().Any(c => c.GetMethodInfo().Name == "Fail")).IsFalse(); } /// /// Bulbapedia: "Mat Block will fail if not used on the first turn after the Pokémon enters the field; /// the Pokémon must be switched out and back in to be able to use Mat Block again." /// [Test] public async Task OnSecondaryEffect_NotFirstTurnOnField_HitFails() { // Arrange var (script, move, target, hitData, _) = CreateTestSetup(1, 2); // Act script.OnSecondaryEffect(move, target, 0); // Assert await Assert.That(hitData.ReceivedCalls().Any(c => c.GetMethodInfo().Name == "Fail")).IsTrue(); } /// /// Bulbapedia: "Mat Block will fail if not used on the first turn after the Pokémon enters the field" /// — when it fails, no protection is set up on the user's side. /// [Test] public async Task OnSecondaryEffect_NotFirstTurnOnField_NoEffectAdded() { // Arrange var (script, move, target, _, sideVolatile) = CreateTestSetup(1, 2); // Act script.OnSecondaryEffect(move, target, 0); // Assert await Assert.That(sideVolatile.Contains(ScriptUtils.ResolveName())).IsFalse(); } /// /// Bulbapedia: the protection covers "any physical or special moves" — the /// blocks an incoming damaging hit of either category. /// [Test, Arguments(MoveCategory.Physical), Arguments(MoveCategory.Special)] public async Task MatBlockEffect_DamagingMove_IsBlocked(MoveCategory category) { // Arrange var effect = new MatBlockEffect(); var incomingMove = CreateExecutingMoveOfCategory(category); var block = false; // Act effect.BlockIncomingHit(incomingMove, Substitute.For(), 0, ref block); // Assert await Assert.That(block).IsTrue(); } /// /// Bulbapedia: Mat Block protects "from any physical or special moves" — unlike Protect it does not /// stop status moves, so an incoming status move is not blocked. /// [Test] public async Task MatBlockEffect_StatusMove_IsNotBlocked() { // Arrange var effect = new MatBlockEffect(); var incomingMove = CreateExecutingMoveOfCategory(MoveCategory.Status); var block = false; // Act effect.BlockIncomingHit(incomingMove, Substitute.For(), 0, ref block); // Assert await Assert.That(block).IsFalse(); } /// /// Bulbapedia: the protection lasts "for that turn" — at the end of the turn the /// removes itself from the side. /// [Test] public async Task MatBlockEffect_OnEndTurn_EffectExpires() { // Arrange var effect = new MatBlockEffect(); var side = Substitute.For(); side.GetScripts().Returns(_ => new ScriptIterator(new List>())); IScriptSet sideVolatile = new ScriptSet(side); sideVolatile.Add(effect); // Act effect.OnEndTurn(side, Substitute.For()); // Assert await Assert.That(sideVolatile.Contains(ScriptUtils.ResolveName())).IsFalse(); } /// /// Technical test: outside of battle (no battle data) no protection can be raised and nothing /// happens. /// [Test] public async Task OnSecondaryEffect_NullBattleData_DoesNothing() { // Arrange var (script, move, target, hitData, sideVolatile) = CreateTestSetup(1, 1); move.User.BattleData.Returns((IPokemonBattleData?)null); // Act script.OnSecondaryEffect(move, target, 0); // Assert - no effect is added and the hit is not failed await Assert.That(sideVolatile.Contains(ScriptUtils.ResolveName())).IsFalse(); await Assert.That(hitData.ReceivedCalls().Any(c => c.GetMethodInfo().Name == "Fail")).IsFalse(); } }