PkmnLibRSharp/PkmnLibRSharp/StaticData/Libraries/GrowthRateLibrary.cs

59 lines
2.2 KiB
C#

using System;
using System.Collections.Generic;
using JetBrains.Annotations;
using PkmnLibSharp.Utils;
using Interface = PkmnLibSharp.FFI.StaticData.Libraries.GrowthRateLibrary;
namespace PkmnLibSharp.StaticData.Libraries
{
/// <summary>
/// A library to store all growth rates.
/// </summary>
public class GrowthRateLibrary : HandleType
{
// ReSharper disable once CollectionNeverQueried.Local
private Dictionary<string, GrowthRate> _growthRates = new();
/// <inheritdoc cref="GrowthRateLibrary"/>
protected GrowthRateLibrary(FFIHandle handle) : base(handle)
{
}
/// <summary>
/// Instantiates a new growth rate library with a capacity.
/// </summary>
public static GrowthRateLibrary Create(ulong capacity)
{
var handle = Interface.growth_rate_library_new(capacity);
var lib = Resolver.Instance.ResolveGrowthRateLibrary(handle.Resolve());
if (capacity > 0)
lib._growthRates = new Dictionary<string, GrowthRate>((int)capacity, StringComparer.InvariantCultureIgnoreCase);
return lib;
}
/// <summary>
/// Calculates the level for a given growth key name and a certain experience.
/// </summary>
[MustUseReturnValue]
public LevelInt CalculateLevel(string name, uint experience) =>
Interface.growth_rate_library_calculate_level(Handle, name.ToPtr(), experience).Result();
/// <summary>
/// Calculates the experience for a given growth key name and a certain level.
/// </summary>
[MustUseReturnValue]
public uint CalculateExperience(string name, LevelInt level)
{
return Interface.growth_rate_library_calculate_experience(Handle, name.ToPtr(), level).Result();
}
/// <summary>
/// Adds a new growth rate with a name and value.
/// </summary>
public void AddGrowthRate(string name, GrowthRate growthRate)
{
Interface.growth_rate_library_add_growth_rate(Handle, name.ToPtr(), growthRate.Handle);
_growthRates.Add(name, growthRate);
}
}
}