159 lines
5.9 KiB
C#
159 lines
5.9 KiB
C#
using PkmnLib.Dynamic.Models;
|
|
using PkmnLib.Dynamic.ScriptHandling;
|
|
using PkmnLib.Dynamic.ScriptHandling.Registry;
|
|
using PkmnLib.Plugin.Gen7.Scripts.Battle;
|
|
using PkmnLib.Plugin.Gen7.Scripts.Moves;
|
|
using PkmnLib.Static;
|
|
|
|
namespace PkmnLib.Plugin.Gen7.Tests.Scripts.Moves;
|
|
|
|
/// <summary>
|
|
/// Tests for the <see cref="IonDeluge"/> move script and its <see cref="IonDelugeEffect"/> battle volatile.
|
|
/// Gen VII Bulbapedia behavior (Generation VI base text): "For the remainder of the current turn, Ion Deluge
|
|
/// causes all Normal-type moves to become Electric-type instead, including status moves." (The Gen VII
|
|
/// section only describes a version 1.0 glitch of Ultra Sun/Ultra Moon, which is not intended behavior.)
|
|
/// </summary>
|
|
public class IonDelugeTests
|
|
{
|
|
/// <summary>
|
|
/// Bulbapedia: "Ion Deluge causes all Normal-type moves to become Electric-type" — the effect applies to
|
|
/// the whole field, so using the move adds the <see cref="IonDelugeEffect"/> to the battle's volatile
|
|
/// scripts.
|
|
/// </summary>
|
|
[Test]
|
|
public async Task OnSecondaryEffect_Used_AddsIonDelugeEffectToBattle()
|
|
{
|
|
// Arrange
|
|
var script = new IonDeluge();
|
|
var move = Substitute.For<IExecutingMove>();
|
|
var user = Substitute.For<IPokemon>();
|
|
move.User.Returns(user);
|
|
var battle = Substitute.For<IBattle>();
|
|
battle.GetScripts().Returns(_ => new ScriptIterator(new List<IEnumerable<ScriptContainer>>()));
|
|
var battleVolatile = new ScriptSet(battle);
|
|
battle.Volatile.Returns(battleVolatile);
|
|
var battleData = Substitute.For<IPokemonBattleData>();
|
|
battleData.Battle.Returns(battle);
|
|
user.BattleData.Returns(battleData);
|
|
var target = Substitute.For<IPokemon>();
|
|
|
|
// Act
|
|
script.OnSecondaryEffect(move, target, 0);
|
|
|
|
// Assert
|
|
await Assert.That(battleVolatile.Get<IonDelugeEffect>()).IsNotNull();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Technical test: if the user has no <see cref="IPokemon.BattleData"/>, the script does nothing and
|
|
/// does not throw.
|
|
/// </summary>
|
|
[Test]
|
|
public async Task OnSecondaryEffect_UserHasNoBattleData_DoesNothing()
|
|
{
|
|
// Arrange
|
|
var script = new IonDeluge();
|
|
var move = Substitute.For<IExecutingMove>();
|
|
var user = Substitute.For<IPokemon>();
|
|
user.BattleData.Returns((IPokemonBattleData?)null);
|
|
move.User.Returns(user);
|
|
|
|
// Act
|
|
script.OnSecondaryEffect(move, Substitute.For<IPokemon>(), 0);
|
|
|
|
// Assert - nothing thrown, nothing to observe
|
|
await Assert.That(user.BattleData).IsNull();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Bulbapedia: "Ion Deluge causes all Normal-type moves to become Electric-type instead, including
|
|
/// status moves."
|
|
/// </summary>
|
|
[Test]
|
|
public async Task ChangeMoveType_NormalTypeMove_BecomesElectric()
|
|
{
|
|
// Arrange
|
|
var effect = new IonDelugeEffect();
|
|
var move = Substitute.For<IExecutingMove>();
|
|
var target = Substitute.For<IPokemon>();
|
|
var library = LibraryHelpers.LoadLibrary();
|
|
target.Library.Returns(library);
|
|
var types = library.StaticLibrary.Types;
|
|
await Assert.That(types.TryGetTypeIdentifier("normal", out var normal)).IsTrue();
|
|
await Assert.That(types.TryGetTypeIdentifier("electric", out var electric)).IsTrue();
|
|
TypeIdentifier? moveType = normal;
|
|
|
|
// Act
|
|
effect.ChangeMoveType(move, target, 0, ref moveType);
|
|
|
|
// Assert
|
|
await Assert.That(moveType.HasValue).IsTrue();
|
|
await Assert.That(moveType!.Value).IsEqualTo(electric);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Bulbapedia: only "Normal-type moves" are converted; a move of any other type keeps its type.
|
|
/// </summary>
|
|
[Test]
|
|
public async Task ChangeMoveType_NonNormalTypeMove_TypeUnchanged()
|
|
{
|
|
// Arrange
|
|
var effect = new IonDelugeEffect();
|
|
var move = Substitute.For<IExecutingMove>();
|
|
var target = Substitute.For<IPokemon>();
|
|
var library = LibraryHelpers.LoadLibrary();
|
|
target.Library.Returns(library);
|
|
var types = library.StaticLibrary.Types;
|
|
await Assert.That(types.TryGetTypeIdentifier("water", out var water)).IsTrue();
|
|
TypeIdentifier? moveType = water;
|
|
|
|
// Act
|
|
effect.ChangeMoveType(move, target, 0, ref moveType);
|
|
|
|
// Assert
|
|
await Assert.That(moveType.HasValue).IsTrue();
|
|
await Assert.That(moveType!.Value).IsEqualTo(water);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Technical test: a move without a resolved type is left alone.
|
|
/// </summary>
|
|
[Test]
|
|
public async Task ChangeMoveType_NullMoveType_TypeUnchanged()
|
|
{
|
|
// Arrange
|
|
var effect = new IonDelugeEffect();
|
|
var move = Substitute.For<IExecutingMove>();
|
|
var target = Substitute.For<IPokemon>();
|
|
TypeIdentifier? moveType = null;
|
|
|
|
// Act
|
|
effect.ChangeMoveType(move, target, 0, ref moveType);
|
|
|
|
// Assert
|
|
await Assert.That(moveType).IsNull();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Bulbapedia: the type conversion lasts "for the remainder of the current turn" — at the end of the
|
|
/// turn the effect must remove itself from the battle.
|
|
/// </summary>
|
|
[Test]
|
|
public async Task OnEndTurn_TurnEnds_EffectRemovesItself()
|
|
{
|
|
// Arrange
|
|
var effect = new IonDelugeEffect();
|
|
var battle = Substitute.For<IBattle>();
|
|
battle.GetScripts().Returns(_ => new ScriptIterator(new List<IEnumerable<ScriptContainer>>()));
|
|
var battleVolatile = new ScriptSet(battle);
|
|
battle.Volatile.Returns(battleVolatile);
|
|
battleVolatile.Add(effect);
|
|
|
|
// Act - run the end-of-turn hook, if the effect has one at all
|
|
if (effect is IScriptOnEndTurn onEndTurn)
|
|
onEndTurn.OnEndTurn(battle, battle);
|
|
|
|
// Assert
|
|
await Assert.That(battleVolatile.Contains(ScriptUtils.ResolveName<IonDelugeEffect>())).IsFalse();
|
|
}
|
|
} |