Implements growth rates
This commit is contained in:
parent
52852af781
commit
d2069fc938
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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)
BIN
PkmnLibRSharp/libpkmn_lib.so (Stored with Git LFS)
Binary file not shown.
|
@ -0,0 +1,38 @@
|
|||
using NUnit.Framework;
|
||||
using PkmnLibSharp.StaticData;
|
||||
|
||||
namespace PkmnLibRSharpTests.StaticData
|
||||
{
|
||||
public class GrowthRateTests
|
||||
{
|
||||
[Test]
|
||||
public void CreateAndDropLookupGrowthRate()
|
||||
{
|
||||
var growthRate = new LookupGrowthRate(new uint[] { 0, 1, 5, 10, 20, 100, 200, 500 });
|
||||
growthRate.Dispose();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void LookupGrowthRateCalculateLevel()
|
||||
{
|
||||
var growthRate = new LookupGrowthRate(new uint[] { 0, 1, 5, 10, 20, 100, 200, 500 });
|
||||
Assert.AreEqual(1, growthRate.CalculateLevel(0));
|
||||
Assert.AreEqual(2, growthRate.CalculateLevel(1));
|
||||
Assert.AreEqual(2, growthRate.CalculateLevel(2));
|
||||
Assert.AreEqual(3, growthRate.CalculateLevel(5));
|
||||
growthRate.Dispose();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void LookupGrowthRateCalculateExperience()
|
||||
{
|
||||
var growthRate = new LookupGrowthRate(new uint[] { 0, 1, 5, 10, 20, 100, 200, 500 });
|
||||
Assert.AreEqual(0, growthRate.CalculateExperience(1));
|
||||
Assert.AreEqual(1, growthRate.CalculateExperience(2));
|
||||
Assert.AreEqual(5, growthRate.CalculateExperience(3));
|
||||
Assert.AreEqual(10, growthRate.CalculateExperience(4));
|
||||
growthRate.Dispose();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -20,5 +20,16 @@ namespace PkmnLibRSharpTests.StaticData
|
|||
Assert.AreEqual(-3, move.Priority);
|
||||
Assert.AreEqual(null, move.SecondaryEffect);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestMoveWithSecondaryEffect()
|
||||
{
|
||||
using var effect = new SecondaryEffect(0.25f, "foobar", Array.Empty<EffectParameter>());
|
||||
using var move = new MoveData("foobar", new TypeIdentifier(), MoveCategory.Physical, 68, 23, 56,
|
||||
MoveTarget.Any, -3, effect, Array.Empty<string>());
|
||||
Assert.That(move.SecondaryEffect != null);
|
||||
Assert.AreEqual("foobar", move.SecondaryEffect!.Name);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue