Implements growth rates

This commit is contained in:
2022-09-20 17:31:20 +02:00
parent 52852af781
commit d2069fc938
5 changed files with 122 additions and 2 deletions

View File

@@ -0,0 +1,22 @@
using System;
using System.Runtime.InteropServices;
using LevelInt = System.Byte;
namespace PkmnLibSharp.FFI.StaticData
{
internal static class GrowthRate
{
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
internal static extern IntPtr growth_rate_lookup_new(IntPtr array, ulong length);
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
internal static extern void growth_rate_lookup_drop(IntPtr p);
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
internal static extern LevelInt growth_rate_calculate_level(IntPtr p, uint experience);
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
internal static extern uint growth_rate_calculate_experience(IntPtr p, LevelInt level);
}
}

View File

@@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using PkmnLibSharp.Utils;
using Interface = PkmnLibSharp.FFI.StaticData.GrowthRate;
using LevelInt = System.Byte;
namespace PkmnLibSharp.StaticData
{
public abstract class GrowthRate : ExternPointer<object>
{
protected internal GrowthRate()
{
}
protected internal GrowthRate(IntPtr ptr, bool isOwner) : base(ptr, isOwner)
{
}
public LevelInt CalculateLevel(uint experience)
{
return Interface.growth_rate_calculate_level(Ptr, experience);
}
public uint CalculateExperience(LevelInt level)
{
return Interface.growth_rate_calculate_experience(Ptr, level);
}
protected override void Destructor()
{
Interface.growth_rate_lookup_drop(Ptr);
}
}
public class LookupGrowthRate : GrowthRate
{
public LookupGrowthRate(uint[] experienceArray)
{
var arrayPtr = experienceArray.ArrayPtr();
var ptr = Interface.growth_rate_lookup_new(arrayPtr, (ulong)experienceArray.Length);
InitializePointer(ptr, true);
}
protected override object CreateCache()
{
return new object();
}
}
}

BIN
PkmnLibRSharp/libpkmn_lib.so (Stored with Git LFS)

Binary file not shown.