Files
PkmnLib.NET/Plugins/PkmnLib.Plugin.Gen7.Tests/Scripts/Moves/GeomancyTests.cs

142 lines
5.4 KiB
C#

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;
/// <summary>
/// Tests for the <see cref="Geomancy"/> 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."
/// </summary>
public class GeomancyTests
{
private static (Geomancy script, IExecutingMove move, IBattlePokemon user, ScriptSet userVolatile) CreateTestSetup()
{
var script = new Geomancy();
var move = Substitute.For<IExecutingMove>();
var user = Substitute.For<IBattlePokemon>();
// 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<IEnumerable<ScriptContainer>>()));
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<IEnumerable<ScriptContainer>>()));
var battle = Substitute.For<IBattle>();
battle.EventHook.Returns(new EventHook());
user.Battle.Returns(battle);
return (script, move, user, userVolatile);
}
/// <summary>
/// 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 <see cref="EventBatchId"/> parameter cannot be bound by
/// <c>Arg.Any</c>.
/// </summary>
private static object?[]? GetStatBoostArgs(IBattlePokemon pokemon, Statistic stat) =>
pokemon.ReceivedCalls().Where(c => c.GetMethodInfo().Name == "ChangeStatBoost").Select(c => c.GetArguments())
.FirstOrDefault(args => (Statistic)args[0]! == stat);
/// <summary>
/// Bulbapedia: "The user charges the move on the first turn." — on first use the move is prevented
/// from executing.
/// </summary>
[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();
}
/// <summary>
/// Bulbapedia: "The user charges the move on the first turn." — the charge turn attaches the
/// <see cref="RequireChargeEffect"/> volatile to the user so the move executes on the next turn.
/// </summary>
[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<RequireChargeEffect>())).IsTrue();
}
/// <summary>
/// Bulbapedia: "On the second turn" the move executes — when the charge volatile is already present,
/// the move is not prevented again.
/// </summary>
[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();
}
/// <summary>
/// Bulbapedia: on the second turn "the user's Special Attack, Special Defense, and Speed increase by
/// two stages." The boosts are self-inflicted.
/// </summary>
[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<IBattlePokemon>(), 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
}
/// <summary>
/// Bulbapedia: only "Special Attack, Special Defense, and Speed" are raised — Attack and Defense stay
/// untouched.
/// </summary>
[Test]
public async Task OnSecondaryEffect_Always_DoesNotRaiseAttackOrDefense()
{
// Arrange
var (script, move, user, _) = CreateTestSetup();
// Act
script.OnSecondaryEffect(move, Substitute.For<IBattlePokemon>(), 0);
// Assert
await Assert.That(GetStatBoostArgs(user, Statistic.Attack)).IsNull();
await Assert.That(GetStatBoostArgs(user, Statistic.Defense)).IsNull();
}
}