using System.Diagnostics.CodeAnalysis;
using PkmnLib.Static.Utils;
namespace PkmnLib.Static.Libraries;
///
/// The library for all growth rates in the game.
///
public interface IReadOnlyGrowthRateLibrary
{
///
/// Tries to get a growth rate from the library. Returns false if the growth rate is not found.
///
bool TryGet(StringKey key, [MaybeNullWhen(false)] out IGrowthRate value);
///
/// Gets a random growth rate from the library.
///
IGrowthRate GetRandom(IRandom random);
///
/// Gets the amount of growth rates in the library.
///
int Count { get; }
///
/// Whether the library is empty.
///
bool IsEmpty { get; }
///
/// Calculates the experience for a given growth key name and a certain level.
///
uint CalculateExperience(StringKey key, LevelInt level);
///
/// Calculates the level for a given growth key name and a certain experience.
///
LevelInt CalculateLevel(StringKey key, uint experience);
}
///
public class GrowthRateLibrary : DataLibrary, IReadOnlyGrowthRateLibrary
{
///
public uint CalculateExperience(StringKey key, LevelInt level)
{
if (!TryGet(key, out var growthRate))
{
throw new KeyNotFoundException($"Growth rate {key} not found.");
}
return growthRate.CalculateExperience(level);
}
///
public LevelInt CalculateLevel(StringKey key, uint experience)
{
if (!TryGet(key, out var growthRate))
{
throw new KeyNotFoundException($"Growth rate {key} not found.");
}
return growthRate.CalculateLevel(experience);
}
}