Implements more functionality.
This commit is contained in:
parent
e4f8e46102
commit
e08be5c013
|
@ -60,6 +60,7 @@ namespace PkmnLibSharp.Battling
|
|||
public byte WinningSide => Creaturelib.Generated.Battle.GetWinningSide(Ptr);
|
||||
public ulong SidesCount => Creaturelib.Generated.Battle.GetSidesCount(Ptr);
|
||||
public ulong PartiesCount => Creaturelib.Generated.Battle.GetPartiesCount(Ptr);
|
||||
public ulong MonsPerSide => Creaturelib.Generated.Battle.GetCreaturesPerSide(Ptr);
|
||||
|
||||
public ReadOnlyNativePtrArray<BattleSide> Sides
|
||||
{
|
||||
|
|
|
@ -6,6 +6,15 @@ namespace PkmnLibSharp.Battling
|
|||
public class BattleSide : PointerWrapper
|
||||
{
|
||||
internal BattleSide(IntPtr ptr) : base(ptr){}
|
||||
|
||||
public byte SideIndex => Creaturelib.Generated.BattleSide.GetSideIndex(Ptr);
|
||||
|
||||
public byte IndexOf(Pokemon pokemon)
|
||||
{
|
||||
byte b = 0;
|
||||
Creaturelib.Generated.BattleSide.GetCreatureIndex(ref b, Ptr, pokemon.Ptr).Assert();
|
||||
return b;
|
||||
}
|
||||
|
||||
protected override void DeletePtr()
|
||||
{
|
||||
|
|
|
@ -8,7 +8,7 @@ namespace PkmnLibSharp.Battling.Events
|
|||
{
|
||||
}
|
||||
|
||||
Pokemon Pokemon
|
||||
public Pokemon Pokemon
|
||||
{
|
||||
get
|
||||
{
|
||||
|
|
|
@ -57,6 +57,11 @@ namespace Creaturelib.Generated
|
|||
[DllImport("CreatureLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_Battle_GetCurrentTurn")]
|
||||
internal static extern uint GetCurrentTurn(IntPtr p);
|
||||
|
||||
/// <param name="p">Battle *</param>
|
||||
/// <returns>unsigned int</returns>
|
||||
[DllImport("CreatureLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_Battle_GetCreaturesPerSide")]
|
||||
internal static extern uint GetCreaturesPerSide(IntPtr p);
|
||||
|
||||
/// <param name="p">const Battle *</param>
|
||||
/// <returns>ChoiceQueue *</returns>
|
||||
[DllImport("CreatureLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_Battle_GetCurrentTurnQueue")]
|
||||
|
|
|
@ -30,11 +30,27 @@ namespace Creaturelib.Generated
|
|||
[DllImport("CreatureLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_LearnableAttacks_GetAttacksForLevel")]
|
||||
internal static extern IntPtr GetAttacksForLevel(IntPtr p, byte level);
|
||||
|
||||
/// <param name="p">LearnableAttacks *</param>
|
||||
/// <param name="level">unsigned char</param>
|
||||
/// <returns>bool</returns>
|
||||
[DllImport("CreatureLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_LearnableAttacks_HasAttacksForLevel")]
|
||||
internal static extern byte HasAttacksForLevel(IntPtr p, byte level);
|
||||
|
||||
/// <param name="p">LearnableAttacks *</param>
|
||||
/// <param name="level">unsigned char</param>
|
||||
/// <returns>long unsigned int</returns>
|
||||
[DllImport("CreatureLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_LearnableAttacks_GetAttacksForLevelCount")]
|
||||
internal static extern ulong GetAttacksForLevelCount(IntPtr p, byte level);
|
||||
|
||||
/// <param name="p">LearnableAttacks *</param>
|
||||
/// <returns>long unsigned int</returns>
|
||||
[DllImport("CreatureLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_LearnableAttacks_GetDistinctLevelAttacksCount")]
|
||||
internal static extern ulong GetDistinctLevelAttacksCount(IntPtr p);
|
||||
|
||||
/// <param name="p">LearnableAttacks *</param>
|
||||
/// <returns>const const AttackData * *</returns>
|
||||
[DllImport("CreatureLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_LearnableAttacks_GetDistinctLevelAttacks")]
|
||||
internal static extern IntPtr GetDistinctLevelAttacks(IntPtr p);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,5 +28,11 @@ namespace Pkmnlib.Generated
|
|||
[DllImport("pkmnLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "PkmnLib_PokemonLibrary_GetNatureLibrary")]
|
||||
internal static extern IntPtr GetNatureLibrary(IntPtr p);
|
||||
|
||||
/// <param name="p">const SpeciesLibrary *</param>
|
||||
/// <param name="species">const PokemonSpecies *</param>
|
||||
/// <returns>const PokemonSpecies *</returns>
|
||||
[DllImport("pkmnLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "PkmnLib_PokemonLibrary_FindPreEvolution")]
|
||||
internal static extern IntPtr FindPreEvolution(IntPtr p, IntPtr species);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,15 +14,59 @@ namespace PkmnLibSharp.Library
|
|||
public LearnableMoves(byte maxLevel)
|
||||
{
|
||||
var ptr = IntPtr.Zero;
|
||||
LearnableAttacks.Construct(ref ptr, maxLevel);
|
||||
Pkmnlib.Generated.LearnableMoves.Construct(ref ptr, maxLevel);
|
||||
Initialize(ptr);
|
||||
}
|
||||
|
||||
public ReadOnlyNativePtrArray<MoveData> DistinctLevelMoves
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_distinctLevelMoves != null) return _distinctLevelMoves;
|
||||
var count = LearnableAttacks.GetDistinctLevelAttacksCount(Ptr);
|
||||
var ptr = LearnableAttacks.GetDistinctLevelAttacks(Ptr);
|
||||
_distinctLevelMoves = new ReadOnlyNativePtrArray<MoveData>(ptr, (int) count);
|
||||
return _distinctLevelMoves;
|
||||
}
|
||||
}
|
||||
|
||||
public ReadOnlyNativePtrArray<MoveData> EggMoves
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_eggMoves != null) return _eggMoves;
|
||||
var count = Pkmnlib.Generated.LearnableMoves.GetEggMovesCount(Ptr);
|
||||
var ptr = Pkmnlib.Generated.LearnableMoves.GetEggMoves(Ptr);
|
||||
_eggMoves = new ReadOnlyNativePtrArray<MoveData>(ptr, (int) count);
|
||||
return _eggMoves;
|
||||
}
|
||||
}
|
||||
|
||||
public void AddLevelAttack(byte level, MoveData move)
|
||||
|
||||
public ReadOnlyNativePtrArray<MoveData> GetMovesForLevel(byte level)
|
||||
{
|
||||
if (LearnableAttacks.HasAttacksForLevel(Ptr, level) != 1)
|
||||
{
|
||||
return new ReadOnlyNativePtrArray<MoveData>();
|
||||
}
|
||||
var count = LearnableAttacks.GetAttacksForLevelCount(Ptr, level);
|
||||
var ptr = LearnableAttacks.GetAttacksForLevel(Ptr, level);
|
||||
return new ReadOnlyNativePtrArray<MoveData>(ptr, (int) count);
|
||||
}
|
||||
|
||||
public void AddLevelMove(byte level, MoveData move)
|
||||
{
|
||||
LearnableAttacks.AddLevelAttack(Ptr, level, move.Ptr);
|
||||
}
|
||||
public void AddEggMove(MoveData move)
|
||||
{
|
||||
Pkmnlib.Generated.LearnableMoves.AddEggMove(Ptr, move.Ptr);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private ReadOnlyNativePtrArray<MoveData>? _distinctLevelMoves;
|
||||
private ReadOnlyNativePtrArray<MoveData>? _eggMoves;
|
||||
protected override void DeletePtr()
|
||||
{
|
||||
LearnableAttacks.Destruct(Ptr);
|
||||
|
|
BIN
PkmnLibSharp/Native/libCreatureLib.so (Stored with Git LFS)
BIN
PkmnLibSharp/Native/libCreatureLib.so (Stored with Git LFS)
Binary file not shown.
BIN
PkmnLibSharp/Native/libpkmnLib.so (Stored with Git LFS)
BIN
PkmnLibSharp/Native/libpkmnLib.so (Stored with Git LFS)
Binary file not shown.
|
@ -11,6 +11,13 @@ namespace PkmnLibSharp.Utilities
|
|||
private T?[] _cache;
|
||||
private Type _type = typeof(T);
|
||||
|
||||
internal ReadOnlyNativePtrArray()
|
||||
{
|
||||
_ptr = IntPtr.Zero;
|
||||
Count = 0;
|
||||
_cache = new T[Count];
|
||||
}
|
||||
|
||||
internal ReadOnlyNativePtrArray(IntPtr ptr, int length)
|
||||
{
|
||||
_ptr = ptr;
|
||||
|
@ -68,6 +75,8 @@ namespace PkmnLibSharp.Utilities
|
|||
{
|
||||
unsafe
|
||||
{
|
||||
if (index >= Count)
|
||||
throw new IndexOutOfRangeException();
|
||||
// Where's your god now?
|
||||
// (We add the offset of the index to the pointer, then dereference the pointer pointer to get the actual pointer to the object we want.)
|
||||
var p = new IntPtr(*(void**)IntPtr.Add(_ptr, index * IntPtr.Size).ToPointer());
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,64 @@
|
|||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using PkmnLibSharp.Library;
|
||||
using PkmnLibSharp.Library.Moves;
|
||||
|
||||
namespace PkmnLibSharpTests.Library
|
||||
{
|
||||
public class LearnableMovesTests
|
||||
{
|
||||
private static MoveData CreateTestMove(string name)
|
||||
{
|
||||
return new MoveData(name, 0, MoveCategory.Physical, 100, 100, 5, MoveTarget.Any,
|
||||
0, 0, "", new EffectParameter[0], new string[0]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AddLevelMoves()
|
||||
{
|
||||
var moves = new LearnableMoves(100);
|
||||
moves.AddLevelMove(1, CreateTestMove("foo"));
|
||||
moves.AddLevelMove(5, CreateTestMove("bar"));
|
||||
moves.Dispose();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AddAndGetLevelMoves()
|
||||
{
|
||||
var moves = new LearnableMoves(100);
|
||||
var fooMove = CreateTestMove("foo");
|
||||
var barMove = CreateTestMove("bar");
|
||||
moves.AddLevelMove(1, fooMove);
|
||||
moves.AddLevelMove(1, barMove);
|
||||
moves.AddLevelMove(5, barMove);
|
||||
|
||||
|
||||
Assert.AreEqual(2, moves.GetMovesForLevel(1).Count);
|
||||
Assert.AreEqual("foo", moves.GetMovesForLevel(1)[0].Name);
|
||||
Assert.AreEqual("bar", moves.GetMovesForLevel(1)[1].Name);
|
||||
Assert.AreEqual(1, moves.GetMovesForLevel(5).Count);
|
||||
Assert.AreEqual(0, moves.GetMovesForLevel(2).Count);
|
||||
|
||||
moves.Dispose();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetDistinctLevelMoves()
|
||||
{
|
||||
var moves = new LearnableMoves(100);
|
||||
var fooMove = CreateTestMove("foo");
|
||||
var barMove = CreateTestMove("bar");
|
||||
moves.AddLevelMove(1, fooMove);
|
||||
moves.AddLevelMove(1, barMove);
|
||||
moves.AddLevelMove(5, barMove);
|
||||
|
||||
var distinctMoves = moves.DistinctLevelMoves;
|
||||
Assert.AreEqual(2, distinctMoves.Count);
|
||||
Assert.AreEqual("foo", distinctMoves[0].Name);
|
||||
Assert.AreEqual("bar", distinctMoves[1].Name);
|
||||
|
||||
moves.Dispose();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue