This commit is contained in:
82
PkmnLib.Tests/Dynamic/PokemonTemporaryMoveTests.cs
Normal file
82
PkmnLib.Tests/Dynamic/PokemonTemporaryMoveTests.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using PkmnLib.Dynamic.Models;
|
||||
using PkmnLib.Static;
|
||||
using PkmnLib.Static.Species;
|
||||
using PkmnLib.Tests.Integration;
|
||||
|
||||
namespace PkmnLib.Tests.Dynamic;
|
||||
|
||||
/// <summary>
|
||||
/// Tests for the temporary move overlay (<see cref="IPokemon.LearnTemporaryMove"/>), used by effects such as
|
||||
/// Mimic. The permanently learned moves must never be mutated by a temporary move, and the overlay must be
|
||||
/// discarded by the engine itself when the Pokemon leaves the battlefield.
|
||||
/// </summary>
|
||||
public class PokemonTemporaryMoveTests
|
||||
{
|
||||
private static IPokemon CreatePokemon()
|
||||
{
|
||||
var library = LibraryHelpers.LoadLibrary();
|
||||
if (!library.StaticLibrary.Species.TryGet("bulbasaur", out var species))
|
||||
throw new InvalidOperationException("Failed to load bulbasaur species.");
|
||||
var pokemon = new PokemonImpl(library, species, species.GetDefaultForm(), new AbilityIndex
|
||||
{
|
||||
Index = 0,
|
||||
IsHidden = false,
|
||||
}, 50, 0, Gender.Male, 0, "hardy");
|
||||
pokemon.LearnMove("tackle", MoveLearnMethod.LevelUp, 0);
|
||||
return pokemon;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task LearnTemporaryMove_ReplacesMoveInMovesButNotInBaseMoves()
|
||||
{
|
||||
var pokemon = CreatePokemon();
|
||||
|
||||
pokemon.LearnTemporaryMove("swords_dance", MoveLearnMethod.Mimic, 0);
|
||||
|
||||
await Assert.That(pokemon.Moves[0]!.MoveData.Name.ToString()).IsEqualTo("swords_dance");
|
||||
await Assert.That(pokemon.Moves[0]!.LearnMethod).IsEqualTo(MoveLearnMethod.Mimic);
|
||||
await Assert.That(pokemon.BaseMoves[0]!.MoveData.Name.ToString()).IsEqualTo("tackle");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SetOnBattlefield_LeavingField_RestoresOriginalMoveWithItsPP()
|
||||
{
|
||||
var pokemon = CreatePokemon();
|
||||
pokemon.SetBattleData(Substitute.For<IBattle>(), 0);
|
||||
pokemon.SetOnBattlefield(true);
|
||||
|
||||
// Use the original move once, so we can verify its PP survives the temporary replacement untouched.
|
||||
var originalMove = pokemon.Moves[0]!;
|
||||
originalMove.TryUse();
|
||||
var expectedPp = originalMove.CurrentPp;
|
||||
|
||||
pokemon.LearnTemporaryMove("swords_dance", MoveLearnMethod.Mimic, 0);
|
||||
pokemon.SetOnBattlefield(false);
|
||||
|
||||
await Assert.That(ReferenceEquals(pokemon.Moves[0], originalMove)).IsTrue();
|
||||
await Assert.That(pokemon.Moves[0]!.CurrentPp).IsEqualTo(expectedPp);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ClearBattleData_RestoresOriginalMove()
|
||||
{
|
||||
var pokemon = CreatePokemon();
|
||||
pokemon.SetBattleData(Substitute.For<IBattle>(), 0);
|
||||
pokemon.LearnTemporaryMove("swords_dance", MoveLearnMethod.Mimic, 0);
|
||||
|
||||
pokemon.ClearBattleData();
|
||||
|
||||
await Assert.That(pokemon.Moves[0]!.MoveData.Name.ToString()).IsEqualTo("tackle");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Serialize_WithActiveTemporaryMove_WritesOriginalMove()
|
||||
{
|
||||
var pokemon = CreatePokemon();
|
||||
pokemon.LearnTemporaryMove("swords_dance", MoveLearnMethod.Mimic, 0);
|
||||
|
||||
var serialized = pokemon.Serialize();
|
||||
|
||||
await Assert.That(serialized.Moves[0]!.MoveName.ToString()).IsEqualTo("tackle");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user