This commit is contained in:
@@ -0,0 +1,210 @@
|
||||
using PkmnLib.Dynamic.Models;
|
||||
using PkmnLib.Dynamic.Models.Choices;
|
||||
using PkmnLib.Dynamic.ScriptHandling;
|
||||
using PkmnLib.Dynamic.ScriptHandling.Registry;
|
||||
using PkmnLib.Plugin.Gen7.Scripts.Battle;
|
||||
using PkmnLib.Plugin.Gen7.Scripts.Moves;
|
||||
using PkmnLib.Static;
|
||||
using PkmnLib.Static.Utils;
|
||||
|
||||
namespace PkmnLib.Plugin.Gen7.Tests.Scripts.Moves;
|
||||
|
||||
/// <summary>
|
||||
/// Tests for the <see cref="FairyLock"/> move script and its attached <see cref="FairyLockEffect"/>.
|
||||
/// Gen VII Bulbapedia behavior: "Fairy Lock prevents all Pokémon (except Ghost types) on the field from
|
||||
/// switching out or fleeing during their next turn."
|
||||
/// </summary>
|
||||
public class FairyLockTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a fully mocked test setup where the battle has a real <see cref="ScriptSet"/> as its volatile
|
||||
/// script set.
|
||||
/// </summary>
|
||||
private static (FairyLock script, IExecutingMove move, IPokemon target, IBattle battle, IScriptSet battleVolatile)
|
||||
CreateTestSetup()
|
||||
{
|
||||
var script = new FairyLock();
|
||||
var move = Substitute.For<IExecutingMove>();
|
||||
var target = Substitute.For<IPokemon>();
|
||||
|
||||
var battle = Substitute.For<IBattle>();
|
||||
battle.GetScripts().Returns(_ => new ScriptIterator(Array.Empty<IEnumerable<ScriptContainer>>()));
|
||||
IScriptSet battleVolatile = new ScriptSet(battle);
|
||||
battle.Volatile.Returns(battleVolatile);
|
||||
|
||||
var battleData = Substitute.For<IPokemonBattleData>();
|
||||
battleData.Battle.Returns(battle);
|
||||
target.BattleData.Returns(battleData);
|
||||
|
||||
return (script, move, target, battle, battleVolatile);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a mocked Pokémon with the given type names as its <see cref="IPokemon.Types"/>.
|
||||
/// </summary>
|
||||
private static IPokemon CreatePokemonWithTypes(params string[] types)
|
||||
{
|
||||
var pokemon = Substitute.For<IPokemon>();
|
||||
pokemon.Types.Returns(types.Select((name, index) => new TypeIdentifier((byte)(index + 1), new StringKey(name)))
|
||||
.ToList());
|
||||
return pokemon;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Bulbapedia: "Fairy Lock prevents all Pokémon (except Ghost types) on the field from switching out or
|
||||
/// fleeing during their next turn." Using the move puts the <see cref="FairyLockEffect"/> on the battle's
|
||||
/// volatile scripts so it affects the whole field.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task OnSecondaryEffect_AddsFairyLockEffectToBattleVolatile()
|
||||
{
|
||||
// Arrange
|
||||
var (script, move, target, _, battleVolatile) = CreateTestSetup();
|
||||
|
||||
// Act
|
||||
script.OnSecondaryEffect(move, target, 0);
|
||||
|
||||
// Assert
|
||||
await Assert.That(battleVolatile.Contains(ScriptUtils.ResolveName<FairyLockEffect>())).IsTrue();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Technical test: without battle data on the target (outside of battle) the secondary effect does
|
||||
/// nothing and does not throw.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void OnSecondaryEffect_TargetHasNoBattleData_DoesNotThrow()
|
||||
{
|
||||
// Arrange
|
||||
var script = new FairyLock();
|
||||
var move = Substitute.For<IExecutingMove>();
|
||||
var target = Substitute.For<IPokemon>();
|
||||
target.BattleData.Returns((IPokemonBattleData?)null);
|
||||
|
||||
// Act & Assert - should not throw
|
||||
script.OnSecondaryEffect(move, target, 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Bulbapedia: "Fairy Lock prevents all Pokémon (except Ghost types) on the field from switching out".
|
||||
/// A non-Ghost Pokémon is prevented from switching.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task PreventSelfSwitch_NonGhostPokemon_SwitchPrevented()
|
||||
{
|
||||
// Arrange
|
||||
var effect = new FairyLockEffect();
|
||||
var user = CreatePokemonWithTypes("normal");
|
||||
var choice = Substitute.For<ISwitchChoice>();
|
||||
choice.User.Returns(user);
|
||||
var prevent = false;
|
||||
|
||||
// Act
|
||||
effect.PreventSelfSwitch(choice, ref prevent);
|
||||
|
||||
// Assert
|
||||
await Assert.That(prevent).IsTrue();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Bulbapedia: Fairy Lock prevents all Pokémon "(except Ghost types)" from switching out — a Ghost-type
|
||||
/// Pokémon can still switch out.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task PreventSelfSwitch_GhostTypePokemon_SwitchNotPrevented()
|
||||
{
|
||||
// Arrange
|
||||
var effect = new FairyLockEffect();
|
||||
var user = CreatePokemonWithTypes("ghost");
|
||||
var choice = Substitute.For<ISwitchChoice>();
|
||||
choice.User.Returns(user);
|
||||
var prevent = false;
|
||||
|
||||
// Act
|
||||
effect.PreventSelfSwitch(choice, ref prevent);
|
||||
|
||||
// Assert
|
||||
await Assert.That(prevent).IsFalse();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Bulbapedia: "Fairy Lock prevents all Pokémon (except Ghost types) on the field from switching out or
|
||||
/// fleeing during their next turn." A non-Ghost Pokémon is prevented from fleeing.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task PreventSelfRunAway_NonGhostPokemon_FleeingPrevented()
|
||||
{
|
||||
// Arrange
|
||||
var effect = new FairyLockEffect();
|
||||
var user = CreatePokemonWithTypes("normal");
|
||||
var choice = Substitute.For<IFleeChoice>();
|
||||
choice.User.Returns(user);
|
||||
var prevent = false;
|
||||
|
||||
// Act
|
||||
effect.PreventSelfRunAway(choice, ref prevent);
|
||||
|
||||
// Assert
|
||||
await Assert.That(prevent).IsTrue();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Bulbapedia: Fairy Lock prevents all Pokémon "(except Ghost types)" from fleeing — a Ghost-type
|
||||
/// Pokémon can still flee.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task PreventSelfRunAway_GhostTypePokemon_FleeingNotPrevented()
|
||||
{
|
||||
// Arrange
|
||||
var effect = new FairyLockEffect();
|
||||
var user = CreatePokemonWithTypes("ghost");
|
||||
var choice = Substitute.For<IFleeChoice>();
|
||||
choice.User.Returns(user);
|
||||
var prevent = false;
|
||||
|
||||
// Act
|
||||
effect.PreventSelfRunAway(choice, ref prevent);
|
||||
|
||||
// Assert
|
||||
await Assert.That(prevent).IsFalse();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Bulbapedia: the lock applies "during their next turn" — at the end of the turn Fairy Lock was used,
|
||||
/// the <see cref="FairyLockEffect"/> stays on the battle so the following turn is still locked.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task OnEndTurn_FirstEndOfTurn_EffectRemains()
|
||||
{
|
||||
// Arrange
|
||||
var (script, move, target, battle, battleVolatile) = CreateTestSetup();
|
||||
script.OnSecondaryEffect(move, target, 0);
|
||||
var effect = battleVolatile.Get<FairyLockEffect>()!;
|
||||
|
||||
// Act - end of the turn Fairy Lock was used
|
||||
effect.OnEndTurn(battle, battle);
|
||||
|
||||
// Assert
|
||||
await Assert.That(battleVolatile.Contains(ScriptUtils.ResolveName<FairyLockEffect>())).IsTrue();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Bulbapedia: the lock only lasts "during their next turn" — at the end of the turn after Fairy Lock
|
||||
/// was used, the <see cref="FairyLockEffect"/> removes itself.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task OnEndTurn_SecondEndOfTurn_EffectRemovesItself()
|
||||
{
|
||||
// Arrange
|
||||
var (script, move, target, battle, battleVolatile) = CreateTestSetup();
|
||||
script.OnSecondaryEffect(move, target, 0);
|
||||
var effect = battleVolatile.Get<FairyLockEffect>()!;
|
||||
|
||||
// Act - end of the turn Fairy Lock was used, then end of the locked turn
|
||||
effect.OnEndTurn(battle, battle);
|
||||
effect.OnEndTurn(battle, battle);
|
||||
|
||||
// Assert
|
||||
await Assert.That(battleVolatile.Contains(ScriptUtils.ResolveName<FairyLockEffect>())).IsFalse();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user