PkmnLib.NET/PkmnLib.Static/Species/LearnableMoves.cs

98 lines
3.1 KiB
C#
Raw Normal View History

2024-07-20 11:51:52 +00:00
using PkmnLib.Static.Utils;
namespace PkmnLib.Static.Species;
/// <summary>
2024-07-20 14:12:39 +00:00
/// The storage of the moves a Pokémon can learn.
2024-07-20 11:51:52 +00:00
/// </summary>
public interface ILearnableMoves
{
/// <summary>
2024-07-20 14:12:39 +00:00
/// Adds a new level move the Pokémon can learn.
2024-07-20 11:51:52 +00:00
/// </summary>
2024-07-20 14:12:39 +00:00
/// <param name="level">The level the Pokémon learns the move at.</param>
/// <param name="move">The move the Pokémon learns.</param>
2024-07-20 11:51:52 +00:00
/// <returns>Whether the move was added successfully.</returns>
void AddLevelMove(LevelInt level, StringKey move);
2025-03-02 16:19:57 +00:00
2024-09-30 12:54:43 +00:00
/// <summary>
/// Adds a new egg move the Pokémon can learn.
/// </summary>
/// <param name="move"></param>
void AddEggMove(StringKey move);
2024-07-20 11:51:52 +00:00
/// <summary>
2024-07-20 14:12:39 +00:00
/// Gets all moves a Pokémon can learn when leveling up to a specific level.
2024-07-20 11:51:52 +00:00
/// </summary>
2024-07-20 14:12:39 +00:00
/// <param name="level">The level the Pokémon is learning moves at.</param>
/// <returns>The moves the Pokémon learns at that level.</returns>
2024-07-20 11:51:52 +00:00
IReadOnlyList<StringKey> GetLearnedByLevel(LevelInt level);
/// <summary>
2024-07-20 14:12:39 +00:00
/// Gets the distinct moves a Pokémon can learn through leveling up.
2024-07-20 11:51:52 +00:00
/// </summary>
2024-07-20 14:12:39 +00:00
/// <returns>The moves the Pokémon can learn through leveling up.</returns>
2024-07-20 11:51:52 +00:00
IReadOnlyList<StringKey> GetDistinctLevelMoves();
/// <summary>
/// Gets a list of all moves a Pokémon can learn up to a specific level.
/// </summary>
IReadOnlyList<StringKey> GetLearnableMovesUpToLevel(LevelInt level);
2025-03-02 16:19:57 +00:00
2024-09-30 12:54:43 +00:00
/// <summary>
/// Gets all moves a Pokémon can learn by breeding.
/// </summary>
IReadOnlyList<StringKey> GetEggMoves();
2024-07-20 11:51:52 +00:00
}
2024-07-20 14:12:39 +00:00
/// <inheritdoc />
2024-07-20 11:51:52 +00:00
public class LearnableMovesImpl : ILearnableMoves
{
private readonly Dictionary<LevelInt, List<StringKey>> _learnedByLevel = new();
private readonly HashSet<StringKey> _distinctLevelMoves = new();
2025-03-02 16:19:57 +00:00
private readonly List<StringKey> _eggMoves = new();
2024-07-20 11:51:52 +00:00
2024-07-20 14:12:39 +00:00
/// <inheritdoc />
2024-07-20 11:51:52 +00:00
public void AddLevelMove(LevelInt level, StringKey move)
{
if (!_learnedByLevel.TryGetValue(level, out var value))
_learnedByLevel[level] = [move];
else
value.Add(move);
_distinctLevelMoves.Add(move);
}
2024-09-30 12:54:43 +00:00
/// <inheritdoc />
public void AddEggMove(StringKey move)
{
if (_eggMoves.Contains(move))
return;
_eggMoves.Add(move);
}
2024-07-20 14:12:39 +00:00
/// <inheritdoc />
2024-07-20 11:51:52 +00:00
public IReadOnlyList<StringKey> GetLearnedByLevel(LevelInt level)
{
if (!_learnedByLevel.TryGetValue(level, out var value))
return Array.Empty<StringKey>();
return value;
}
2024-07-20 14:12:39 +00:00
/// <inheritdoc />
2025-03-02 16:19:57 +00:00
public IReadOnlyList<StringKey> GetDistinctLevelMoves() => _distinctLevelMoves.ToList();
2024-09-30 12:54:43 +00:00
/// <inheritdoc />
public IReadOnlyList<StringKey> GetLearnableMovesUpToLevel(LevelInt level)
{
var moves = new HashSet<StringKey>();
foreach (var kvp in _learnedByLevel.TakeWhile(kvp => kvp.Key <= level))
{
moves.UnionWith(kvp.Value);
}
return moves.ToList();
}
2024-09-30 12:54:43 +00:00
/// <inheritdoc />
public IReadOnlyList<StringKey> GetEggMoves() => _eggMoves;
2024-07-20 14:12:39 +00:00
}