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

62 lines
2.0 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);
/// <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();
}
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();
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-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 />
2024-07-20 11:51:52 +00:00
public IReadOnlyList<StringKey> GetDistinctLevelMoves()
{
return _distinctLevelMoves.ToList();
}
2024-07-20 14:12:39 +00:00
}