Initial commit
This commit is contained in:
58
PkmnLib.Static/Species/LearnableMoves.cs
Normal file
58
PkmnLib.Static/Species/LearnableMoves.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using PkmnLib.Static.Utils;
|
||||
|
||||
namespace PkmnLib.Static.Species;
|
||||
|
||||
/// <summary>
|
||||
/// The storage of the moves a Pokemon can learn.
|
||||
/// </summary>
|
||||
public interface ILearnableMoves
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds a new level move the Pokemon can learn.
|
||||
/// </summary>
|
||||
/// <param name="level">The level the Pokemon learns the move at.</param>
|
||||
/// <param name="move">The move the Pokemon learns.</param>
|
||||
/// <returns>Whether the move was added successfully.</returns>
|
||||
void AddLevelMove(LevelInt level, StringKey move);
|
||||
|
||||
/// <summary>
|
||||
/// Gets all moves a Pokemon can learn when leveling up to a specific level.
|
||||
/// </summary>
|
||||
/// <param name="level">The level the Pokemon is learning moves at.</param>
|
||||
/// <returns>The moves the Pokemon learns at that level.</returns>
|
||||
IReadOnlyList<StringKey> GetLearnedByLevel(LevelInt level);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the distinct moves a Pokemon can learn through leveling up.
|
||||
/// </summary>
|
||||
/// <returns>The moves the Pokemon can learn through leveling up.</returns>
|
||||
IReadOnlyList<StringKey> GetDistinctLevelMoves();
|
||||
}
|
||||
|
||||
public class LearnableMovesImpl : ILearnableMoves
|
||||
{
|
||||
private readonly Dictionary<LevelInt, List<StringKey>> _learnedByLevel = new();
|
||||
private readonly HashSet<StringKey> _distinctLevelMoves = new();
|
||||
|
||||
|
||||
public void AddLevelMove(LevelInt level, StringKey move)
|
||||
{
|
||||
if (!_learnedByLevel.TryGetValue(level, out var value))
|
||||
_learnedByLevel[level] = [move];
|
||||
else
|
||||
value.Add(move);
|
||||
_distinctLevelMoves.Add(move);
|
||||
}
|
||||
|
||||
public IReadOnlyList<StringKey> GetLearnedByLevel(LevelInt level)
|
||||
{
|
||||
if (!_learnedByLevel.TryGetValue(level, out var value))
|
||||
return Array.Empty<StringKey>();
|
||||
return value;
|
||||
}
|
||||
|
||||
public IReadOnlyList<StringKey> GetDistinctLevelMoves()
|
||||
{
|
||||
return _distinctLevelMoves.ToList();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user