using PkmnLib.Dynamic.Events; using PkmnLib.Dynamic.Models; using PkmnLib.Dynamic.ScriptHandling; using PkmnLib.Dynamic.ScriptHandling.Registry; using PkmnLib.Plugin.Gen7.Scripts.Moves; using PkmnLib.Plugin.Gen7.Scripts.Pokemon; using PkmnLib.Static; namespace PkmnLib.Plugin.Gen7.Tests.Scripts.Moves; /// /// Tests for the move script. /// Gen VII Bulbapedia behavior: "The user charges the move on the first turn. On the second turn, the /// user's Special Attack, Special Defense, and Speed increase by two stages." /// public class GeomancyTests { private static (Geomancy script, IExecutingMove move, IPokemon user, ScriptSet userVolatile) CreateTestSetup() { var script = new Geomancy(); var move = Substitute.For(); var user = Substitute.For(); // Use a real script set so the charge volatile added by Geomancy can be inspected afterwards. var userVolatile = new ScriptSet(user); user.Volatile.Returns(userVolatile); user.GetScripts().Returns(_ => new ScriptIterator(new List>())); move.User.Returns(user); // BaseChargeMove.PreventMove runs the BypassChargeMove custom trigger hook on the executing move, // so the move itself also needs a script iterator. move.GetScripts().Returns(_ => new ScriptIterator(new List>())); var battle = Substitute.For(); battle.EventHook.Returns(new EventHook()); var battleData = Substitute.For(); battleData.Battle.Returns(battle); user.BattleData.Returns(battleData); return (script, move, user, userVolatile); } /// /// Helper to extract the arguments of the received ChangeStatBoost call for the given statistic, or /// null when that stat was not boosted. Received-call inspection is used instead of NSubstitute /// argument matchers because the trailing parameter cannot be bound by /// Arg.Any. /// private static object?[]? GetStatBoostArgs(IPokemon pokemon, Statistic stat) => pokemon.ReceivedCalls().Where(c => c.GetMethodInfo().Name == "ChangeStatBoost").Select(c => c.GetArguments()) .FirstOrDefault(args => (Statistic)args[0]! == stat); /// /// Bulbapedia: "The user charges the move on the first turn." — on first use the move is prevented /// from executing. /// [Test] public async Task PreventMove_FirstUse_PreventsMoveForChargeTurn() { // Arrange var (script, move, _, _) = CreateTestSetup(); var prevent = false; // Act script.PreventMove(move, ref prevent); // Assert await Assert.That(prevent).IsTrue(); } /// /// Bulbapedia: "The user charges the move on the first turn." — the charge turn attaches the /// volatile to the user so the move executes on the next turn. /// [Test] public async Task PreventMove_FirstUse_AddsChargeVolatileToUser() { // Arrange var (script, move, _, userVolatile) = CreateTestSetup(); var prevent = false; // Act script.PreventMove(move, ref prevent); // Assert await Assert.That(userVolatile.Contains(ScriptUtils.ResolveName())).IsTrue(); } /// /// Bulbapedia: "On the second turn" the move executes — when the charge volatile is already present, /// the move is not prevented again. /// [Test] public async Task PreventMove_SecondTurn_DoesNotPreventMove() { // Arrange var (script, move, user, userVolatile) = CreateTestSetup(); userVolatile.Add(script.CreateVolatile(user)); var prevent = false; // Act script.PreventMove(move, ref prevent); // Assert await Assert.That(prevent).IsFalse(); } /// /// Bulbapedia: on the second turn "the user's Special Attack, Special Defense, and Speed increase by /// two stages." The boosts are self-inflicted. /// [Test, Arguments(Statistic.SpecialAttack), Arguments(Statistic.SpecialDefense), Arguments(Statistic.Speed)] public async Task OnSecondaryEffect_Always_RaisesStatByTwoStages(Statistic stat) { // Arrange var (script, move, user, _) = CreateTestSetup(); // Act script.OnSecondaryEffect(move, Substitute.For(), 0); // Assert var args = GetStatBoostArgs(user, stat); await Assert.That(args).IsNotNull(); await Assert.That((sbyte)args![1]!).IsEqualTo((sbyte)2); await Assert.That((bool)args[2]!).IsTrue(); // self-inflicted await Assert.That((bool)args[3]!).IsFalse(); // not forced } /// /// Bulbapedia: only "Special Attack, Special Defense, and Speed" are raised — Attack and Defense stay /// untouched. /// [Test] public async Task OnSecondaryEffect_Always_DoesNotRaiseAttackOrDefense() { // Arrange var (script, move, user, _) = CreateTestSetup(); // Act script.OnSecondaryEffect(move, Substitute.For(), 0); // Assert await Assert.That(GetStatBoostArgs(user, Statistic.Attack)).IsNull(); await Assert.That(GetStatBoostArgs(user, Statistic.Defense)).IsNull(); } }