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

@@ -167,10 +167,18 @@ public interface IPokemon : IScriptSource, IDeepCloneable
/// <summary>
/// The moves the Pokemon has learned. This is of a set length of <see cref="Const.MovesCount"/>. Empty move slots
/// are null.
/// are null. If a move slot is temporarily replaced (see <see cref="LearnTemporaryMove"/>), this shows the
/// replacement move.
/// </summary>
IReadOnlyList<ILearnedMove?> Moves { get; }
/// <summary>
/// The permanently learned moves of the Pokemon, ignoring any temporary replacements made through
/// <see cref="LearnTemporaryMove"/>. This is of a set length of <see cref="Const.MovesCount"/>. Empty move
/// slots are null.
/// </summary>
IReadOnlyList<ILearnedMove?> BaseMoves { get; }
/// <summary>
/// Checks whether the Pokemon has a specific move in its current moveset.
/// </summary>
@@ -181,6 +189,14 @@ public interface IPokemon : IScriptSource, IDeepCloneable
/// </summary>
void SwapMoves(byte index1, byte index2);
/// <summary>
/// Temporarily replaces the move in the given slot until the Pokemon leaves the battlefield. The permanently
/// learned move in the slot is left untouched and becomes visible again automatically. Used by effects such as
/// Mimic.
/// </summary>
/// <exception cref="KeyNotFoundException">Thrown when the move is not found in the move library.</exception>
void LearnTemporaryMove(StringKey moveName, MoveLearnMethod method, byte index);
/// <summary>
/// Whether or not the Pokemon is allowed to gain experience.
/// </summary>
@@ -772,8 +788,19 @@ public class PokemonImpl : ScriptSource, IPokemon
private readonly ILearnedMove?[] _learnedMoves = new ILearnedMove[Const.MovesCount];
/// <summary>
/// Battle-only per-slot overrides of <see cref="_learnedMoves"/>. The permanent moveset is never mutated by
/// temporary moves; discarding this array is all that is needed to restore the original moves.
/// </summary>
private ILearnedMove?[]? _temporaryMoves;
/// <inheritdoc />
public IReadOnlyList<ILearnedMove?> Moves => _learnedMoves;
public IReadOnlyList<ILearnedMove?> Moves => _temporaryMoves == null
? _learnedMoves
: _temporaryMoves.Select((move, index) => move ?? _learnedMoves[index]).ToArray();
/// <inheritdoc />
public IReadOnlyList<ILearnedMove?> BaseMoves => _learnedMoves;
/// <inheritdoc />
public bool HasMove(StringKey moveName) => Moves.Any(move => move?.MoveData.Name == moveName);
@@ -783,10 +810,9 @@ public class PokemonImpl : ScriptSource, IPokemon
{
if (index1 >= Const.MovesCount || index2 >= Const.MovesCount)
return;
var move1 = _learnedMoves[index1];
var move2 = _learnedMoves[index2];
_learnedMoves[index1] = move2;
_learnedMoves[index2] = move1;
(_learnedMoves[index1], _learnedMoves[index2]) = (_learnedMoves[index2], _learnedMoves[index1]);
if (_temporaryMoves != null)
(_temporaryMoves[index1], _temporaryMoves[index2]) = (_temporaryMoves[index2], _temporaryMoves[index1]);
}
/// <inheritdoc />
@@ -1286,6 +1312,18 @@ public class PokemonImpl : ScriptSource, IPokemon
_learnedMoves[index] = new LearnedMoveImpl(move, method);
}
/// <inheritdoc />
public void LearnTemporaryMove(StringKey moveName, MoveLearnMethod method, byte index)
{
if (index >= Const.MovesCount)
throw new ArgumentOutOfRangeException(nameof(index), $"Move slot {index} is out of range.");
if (!Library.StaticLibrary.Moves.TryGet(moveName, out var move))
throw new KeyNotFoundException($"Move {moveName} not found.");
_temporaryMoves ??= new ILearnedMove?[Const.MovesCount];
_temporaryMoves[index] = new LearnedMoveImpl(move, method);
}
/// <inheritdoc />
public bool HasStatus(StringKey status) => StatusScript.Script?.Name == status;
@@ -1367,6 +1405,7 @@ public class PokemonImpl : ScriptSource, IPokemon
if (!onBattleField)
{
Volatile.Clear();
_temporaryMoves = null;
HeightInMeters = Form.Height;
Types = Form.Types;
OverrideAbility = null;
@@ -1388,6 +1427,7 @@ public class PokemonImpl : ScriptSource, IPokemon
var battleData = BattleData;
BattleData = null;
Volatile.Clear();
_temporaryMoves = null;
HeightInMeters = Form.Height;
Types = Form.Types;
OverrideAbility = null;