using PkmnLib.Dynamic.Models; using PkmnLib.Dynamic.Models.Choices; using PkmnLib.Dynamic.ScriptHandling; using PkmnLib.Dynamic.ScriptHandling.Registry; using PkmnLib.Plugin.Gen7.Scripts.Moves; using PkmnLib.Plugin.Gen7.Scripts.Pokemon; using PkmnLib.Static; using PkmnLib.Static.Utils; namespace PkmnLib.Plugin.Gen7.Tests.Scripts.Moves; /// /// Tests for the move script. /// Gen VII Bulbapedia behavior: "Mean Look prevents the target from switching out or fleeing (including via /// Teleport). [...] The effect only applies as long as the Pokémon that used it remains in battle." /// From Generation VI onward, Ghost-type Pokémon are immune to Mean Look. /// public class MeanLookTests { private static (MeanLook script, IExecutingMove move, IPokemon target, ScriptSet targetVolatile, ScriptSet userVolatile) CreateTestSetup() { var script = new MeanLook(); var move = Substitute.For(); // Use real script sets so the volatile scripts added by Mean Look can be inspected afterwards. var user = Substitute.For(); var userVolatile = new ScriptSet(user); user.Volatile.Returns(userVolatile); user.GetScripts().Returns(_ => new ScriptIterator(new List>())); move.User.Returns(user); var target = Substitute.For(); var targetVolatile = new ScriptSet(target); target.Volatile.Returns(targetVolatile); target.GetScripts().Returns(_ => new ScriptIterator(new List>())); move.GetHitData(target, 0).Returns(Substitute.For()); return (script, move, target, targetVolatile, userVolatile); } /// /// Bulbapedia: "Mean Look prevents the target from switching out or fleeing (including via Teleport)." /// Hitting the target attaches the volatile script to it. /// [Test] public async Task OnSecondaryEffect_Hit_AddsMeanLookEffectToTarget() { // Arrange var (script, move, target, targetVolatile, _) = CreateTestSetup(); // Act script.OnSecondaryEffect(move, target, 0); // Assert await Assert.That(targetVolatile.Contains(ScriptUtils.ResolveName())).IsTrue(); } /// /// Bulbapedia: "Mean Look prevents the target from switching out". /// The applied by the move prevents the target's switch choices /// through . /// [Test] public async Task OnSecondaryEffect_AppliedEffect_PreventsTargetFromSwitchingOut() { // Arrange var (script, move, target, targetVolatile, _) = CreateTestSetup(); script.OnSecondaryEffect(move, target, 0); await Assert.That(targetVolatile.TryGet(out var effect)).IsTrue(); // Act var prevent = false; effect!.PreventSelfSwitch(Substitute.For(), ref prevent); // Assert await Assert.That(prevent).IsTrue(); } /// /// Bulbapedia: "Mean Look prevents the target from [...] fleeing (including via Teleport)." /// The applied by the move prevents the target's flee choices /// through . /// [Test] public async Task OnSecondaryEffect_AppliedEffect_PreventsTargetFromFleeing() { // Arrange var (script, move, target, targetVolatile, _) = CreateTestSetup(); script.OnSecondaryEffect(move, target, 0); await Assert.That(targetVolatile.TryGet(out var effect)).IsTrue(); // Act var prevent = false; effect!.PreventSelfRunAway(Substitute.For(), ref prevent); // Assert await Assert.That(prevent).IsTrue(); } /// /// Bulbapedia: "The effect only applies as long as the Pokémon that used it remains in battle." /// The user is given a linked volatile that ties the trap to the /// user's presence in battle. /// [Test] public async Task OnSecondaryEffect_Hit_AddsLinkedEffectToUser() { // Arrange var (script, move, target, _, userVolatile) = CreateTestSetup(); // Act script.OnSecondaryEffect(move, target, 0); // Assert await Assert.That(userVolatile.Contains(ScriptUtils.ResolveName())).IsTrue(); } /// /// Bulbapedia: "The effect only applies as long as the Pokémon that used it remains in battle." /// When the user's linked volatile is removed (as happens when the user /// leaves the field), the target's trapping effect is removed as well. /// [Test] public async Task OnSecondaryEffect_UserEffectRemoved_TargetIsFreed() { // Arrange var (script, move, target, targetVolatile, userVolatile) = CreateTestSetup(); script.OnSecondaryEffect(move, target, 0); // Act - simulate the user leaving battle by removing its linked volatile userVolatile.Remove(ScriptUtils.ResolveName()); // Assert await Assert.That(targetVolatile.Contains(ScriptUtils.ResolveName())).IsFalse(); } /// /// Technical test: when the trapping volatile is blocked from being added to the target (the script /// set's returns null), the hit is marked as failed and no linked effect is /// added to the user. /// [Test] public async Task OnSecondaryEffect_EffectBlocked_HitFails() { // Arrange var script = new MeanLook(); var move = Substitute.For(); var user = Substitute.For(); var userVolatile = Substitute.For(); user.Volatile.Returns(userVolatile); move.User.Returns(user); var target = Substitute.For(); var targetVolatile = Substitute.For(); targetVolatile.Add(Arg.Any