This commit is contained in:
188
Plugins/PkmnLib.Plugin.Gen7.Tests/Scripts/Moves/MeanLookTests.cs
Normal file
188
Plugins/PkmnLib.Plugin.Gen7.Tests/Scripts/Moves/MeanLookTests.cs
Normal file
@@ -0,0 +1,188 @@
|
||||
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;
|
||||
|
||||
/// <summary>
|
||||
/// Tests for the <see cref="MeanLook"/> 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.
|
||||
/// </summary>
|
||||
public class MeanLookTests
|
||||
{
|
||||
private static (MeanLook script, IExecutingMove move, IPokemon target, ScriptSet targetVolatile, ScriptSet
|
||||
userVolatile) CreateTestSetup()
|
||||
{
|
||||
var script = new MeanLook();
|
||||
var move = Substitute.For<IExecutingMove>();
|
||||
|
||||
// Use real script sets so the volatile scripts added by Mean Look can be inspected afterwards.
|
||||
var user = Substitute.For<IPokemon>();
|
||||
var userVolatile = new ScriptSet(user);
|
||||
user.Volatile.Returns(userVolatile);
|
||||
user.GetScripts().Returns(_ => new ScriptIterator(new List<IEnumerable<ScriptContainer>>()));
|
||||
move.User.Returns(user);
|
||||
|
||||
var target = Substitute.For<IPokemon>();
|
||||
var targetVolatile = new ScriptSet(target);
|
||||
target.Volatile.Returns(targetVolatile);
|
||||
target.GetScripts().Returns(_ => new ScriptIterator(new List<IEnumerable<ScriptContainer>>()));
|
||||
move.GetHitData(target, 0).Returns(Substitute.For<IHitData>());
|
||||
|
||||
return (script, move, target, targetVolatile, userVolatile);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Bulbapedia: "Mean Look prevents the target from switching out or fleeing (including via Teleport)."
|
||||
/// Hitting the target attaches the <see cref="MeanLookEffectTarget"/> volatile script to it.
|
||||
/// </summary>
|
||||
[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<MeanLookEffectTarget>())).IsTrue();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Bulbapedia: "Mean Look prevents the target from switching out".
|
||||
/// The <see cref="MeanLookEffectTarget"/> applied by the move prevents the target's switch choices
|
||||
/// through <see cref="MeanLookEffectTarget.PreventSelfSwitch"/>.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task OnSecondaryEffect_AppliedEffect_PreventsTargetFromSwitchingOut()
|
||||
{
|
||||
// Arrange
|
||||
var (script, move, target, targetVolatile, _) = CreateTestSetup();
|
||||
script.OnSecondaryEffect(move, target, 0);
|
||||
await Assert.That(targetVolatile.TryGet<MeanLookEffectTarget>(out var effect)).IsTrue();
|
||||
|
||||
// Act
|
||||
var prevent = false;
|
||||
effect!.PreventSelfSwitch(Substitute.For<ISwitchChoice>(), ref prevent);
|
||||
|
||||
// Assert
|
||||
await Assert.That(prevent).IsTrue();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Bulbapedia: "Mean Look prevents the target from [...] fleeing (including via Teleport)."
|
||||
/// The <see cref="MeanLookEffectTarget"/> applied by the move prevents the target's flee choices
|
||||
/// through <see cref="MeanLookEffectTarget.PreventSelfRunAway"/>.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task OnSecondaryEffect_AppliedEffect_PreventsTargetFromFleeing()
|
||||
{
|
||||
// Arrange
|
||||
var (script, move, target, targetVolatile, _) = CreateTestSetup();
|
||||
script.OnSecondaryEffect(move, target, 0);
|
||||
await Assert.That(targetVolatile.TryGet<MeanLookEffectTarget>(out var effect)).IsTrue();
|
||||
|
||||
// Act
|
||||
var prevent = false;
|
||||
effect!.PreventSelfRunAway(Substitute.For<IFleeChoice>(), ref prevent);
|
||||
|
||||
// Assert
|
||||
await Assert.That(prevent).IsTrue();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Bulbapedia: "The effect only applies as long as the Pokémon that used it remains in battle."
|
||||
/// The user is given a linked <see cref="MeanLookEffectUser"/> volatile that ties the trap to the
|
||||
/// user's presence in battle.
|
||||
/// </summary>
|
||||
[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<MeanLookEffectUser>())).IsTrue();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Bulbapedia: "The effect only applies as long as the Pokémon that used it remains in battle."
|
||||
/// When the user's linked <see cref="MeanLookEffectUser"/> volatile is removed (as happens when the user
|
||||
/// leaves the field), the target's trapping effect is removed as well.
|
||||
/// </summary>
|
||||
[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<MeanLookEffectUser>());
|
||||
|
||||
// Assert
|
||||
await Assert.That(targetVolatile.Contains(ScriptUtils.ResolveName<MeanLookEffectTarget>())).IsFalse();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Technical test: when the trapping volatile is blocked from being added to the target (the script
|
||||
/// set's <see cref="IScriptSet.Add"/> returns null), the hit is marked as failed and no linked effect is
|
||||
/// added to the user.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task OnSecondaryEffect_EffectBlocked_HitFails()
|
||||
{
|
||||
// Arrange
|
||||
var script = new MeanLook();
|
||||
var move = Substitute.For<IExecutingMove>();
|
||||
var user = Substitute.For<IPokemon>();
|
||||
var userVolatile = Substitute.For<IScriptSet>();
|
||||
user.Volatile.Returns(userVolatile);
|
||||
move.User.Returns(user);
|
||||
|
||||
var target = Substitute.For<IPokemon>();
|
||||
var targetVolatile = Substitute.For<IScriptSet>();
|
||||
targetVolatile.Add(Arg.Any<Script>(), Arg.Any<bool>()).Returns((ScriptContainer?)null);
|
||||
target.Volatile.Returns(targetVolatile);
|
||||
|
||||
var hitData = Substitute.For<IHitData>();
|
||||
move.GetHitData(target, 0).Returns(hitData);
|
||||
|
||||
// Act
|
||||
script.OnSecondaryEffect(move, target, 0);
|
||||
|
||||
// Assert
|
||||
hitData.Received(1).Fail();
|
||||
await Assert.That(userVolatile.ReceivedCalls().Any(c => c.GetMethodInfo().Name == "Add")).IsFalse();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Bulbapedia (Generation VI onward): "Ghost-type Pokémon become immune to Mean Look."
|
||||
/// Using Mean Look on a Ghost-type target should not trap it, so no <see cref="MeanLookEffectTarget"/>
|
||||
/// may be added.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task OnSecondaryEffect_GhostTypeTarget_DoesNotTrapTarget()
|
||||
{
|
||||
// Arrange
|
||||
var (script, move, target, targetVolatile, _) = CreateTestSetup();
|
||||
target.Types.Returns([new TypeIdentifier(8, new StringKey("ghost"))]);
|
||||
|
||||
// Act
|
||||
script.OnSecondaryEffect(move, target, 0);
|
||||
|
||||
// Assert
|
||||
await Assert.That(targetVolatile.Contains(ScriptUtils.ResolveName<MeanLookEffectTarget>())).IsFalse();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user