Adds mimic
All checks were successful
Build / Build (push) Successful in 2m3s

This commit is contained in:
2026-08-27 17:33:37 +02:00
parent d2a82b5fe3
commit 3a58f55bbf
6 changed files with 201 additions and 21 deletions

View 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");
}
}