Support for PokemonParty.
This commit is contained in:
parent
e4a515e11a
commit
d01e6a8df7
|
@ -77,7 +77,7 @@ namespace PkmnLibSharp.Battling
|
|||
}
|
||||
}
|
||||
|
||||
private BattleLibrary(IntPtr ptr) : base(ptr)
|
||||
internal BattleLibrary(IntPtr ptr) : base(ptr)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,13 @@ namespace PkmnLibSharp.Battling
|
|||
{
|
||||
public class Pokemon : PointerWrapper
|
||||
{
|
||||
public Pokemon(){}
|
||||
|
||||
internal Pokemon(IntPtr ptr) : base(ptr)
|
||||
{
|
||||
Initialize(ptr);
|
||||
}
|
||||
|
||||
public Pokemon([NotNull] BattleLibrary library, [NotNull] Species species, [NotNull] Forme forme,
|
||||
byte level, uint experience, uint uid,
|
||||
Gender gender, byte coloring, [MaybeNull] Item heldItem, [MaybeNull] string nickname, bool hiddenAbility,
|
||||
|
@ -30,7 +37,13 @@ namespace PkmnLibSharp.Battling
|
|||
Library = library;
|
||||
}
|
||||
|
||||
public BattleLibrary Library { get; }
|
||||
protected internal override void Initialize(IntPtr ptr)
|
||||
{
|
||||
base.Initialize(ptr);
|
||||
Library = new BattleLibrary(Creaturelibbattling.Generated.Creature.GetLibrary(Ptr));
|
||||
}
|
||||
|
||||
public BattleLibrary Library { get; private set; }
|
||||
public Species Species
|
||||
{
|
||||
get
|
||||
|
@ -305,5 +318,14 @@ namespace PkmnLibSharp.Battling
|
|||
{
|
||||
Pkmnlib.Generated.Pokemon.Destruct(Ptr);
|
||||
}
|
||||
|
||||
protected internal override void MarkAsDeleted()
|
||||
{
|
||||
base.MarkAsDeleted();
|
||||
foreach (var move in Moves)
|
||||
{
|
||||
move.MarkAsDeleted();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
using System;
|
||||
using PkmnLibSharp.Utilities;
|
||||
|
||||
namespace PkmnLibSharp.Battling
|
||||
{
|
||||
public class PokemonParty : PointerWrapper
|
||||
{
|
||||
private ReadOnlyNativePtrArray<Pokemon> _party;
|
||||
|
||||
public PokemonParty(ulong size) : base(Creaturelibbattling.Generated.CreatureParty.ConstructWithSize(size))
|
||||
{}
|
||||
|
||||
public PokemonParty(Pokemon[] pokemon) : base(
|
||||
Creaturelibbattling.Generated.CreatureParty.ConstructFromArray(pokemon.ArrayPtr(), (ulong) pokemon.Length))
|
||||
{}
|
||||
|
||||
public Pokemon GetAtIndex(ulong index)
|
||||
{
|
||||
var ptr = IntPtr.Zero;
|
||||
Creaturelibbattling.Generated.CreatureParty.GetAtIndex(ref ptr, Ptr, index);
|
||||
return TryResolvePointer(ptr, out Pokemon pkmn) ? pkmn : new Pokemon(ptr);
|
||||
}
|
||||
|
||||
public void Switch(ulong indexA, ulong indexB)
|
||||
{
|
||||
Creaturelibbattling.Generated.CreatureParty.Switch(Ptr, indexA, indexB);
|
||||
}
|
||||
|
||||
public Pokemon SwapInto(ulong indexA, Pokemon pokemon)
|
||||
{
|
||||
var ptr = Creaturelibbattling.Generated.CreatureParty.SwapInto(Ptr, indexA, pokemon.Ptr);
|
||||
if (TryResolvePointer(ptr, out Pokemon newPokemon))
|
||||
{
|
||||
return newPokemon;
|
||||
}
|
||||
return new Pokemon(ptr);
|
||||
}
|
||||
|
||||
public bool HasAvailablePokemon()
|
||||
{
|
||||
return Creaturelibbattling.Generated.CreatureParty.HasAvailableCreatures(Ptr) == 1;
|
||||
}
|
||||
|
||||
public ReadOnlyNativePtrArray<Pokemon> Party
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_party != null) return _party;
|
||||
var ptr = Creaturelibbattling.Generated.CreatureParty.GetParty(Ptr);
|
||||
_party = new ReadOnlyNativePtrArray<Pokemon>(ptr, (int) Length);
|
||||
return _party;
|
||||
}
|
||||
}
|
||||
|
||||
public ulong Length => Creaturelibbattling.Generated.CreatureParty.GetLength(Ptr);
|
||||
|
||||
protected override void DeletePtr()
|
||||
{
|
||||
Creaturelibbattling.Generated.CreatureParty.Destruct(Ptr);
|
||||
}
|
||||
|
||||
protected internal override void MarkAsDeleted()
|
||||
{
|
||||
base.MarkAsDeleted();
|
||||
foreach (var pokemon in Party)
|
||||
{
|
||||
pokemon.MarkAsDeleted();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -31,6 +31,11 @@ namespace Creaturelibbattling.Generated
|
|||
[DllImport("CreatureLibBattling", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_Creature_Destruct")]
|
||||
internal static extern void Destruct(IntPtr p);
|
||||
|
||||
/// <param name="p">const Creature *</param>
|
||||
/// <returns>const BattleLibrary *</returns>
|
||||
[DllImport("CreatureLibBattling", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_Creature_GetLibrary")]
|
||||
internal static extern IntPtr GetLibrary(IntPtr p);
|
||||
|
||||
/// <param name="p">const Creature *</param>
|
||||
/// <returns>const CreatureSpecies *</returns>
|
||||
[DllImport("CreatureLibBattling", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_Creature_GetSpecies")]
|
||||
|
|
|
@ -36,6 +36,13 @@ namespace Creaturelibbattling.Generated
|
|||
[DllImport("CreatureLibBattling", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_CreatureParty_Switch")]
|
||||
internal static extern byte Switch(IntPtr p, ulong a, ulong b);
|
||||
|
||||
/// <param name="p">CreatureParty *</param>
|
||||
/// <param name="index">long unsigned int</param>
|
||||
/// <param name="creature">Creature *</param>
|
||||
/// <returns>Creature *</returns>
|
||||
[DllImport("CreatureLibBattling", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_CreatureParty_SwapInto")]
|
||||
internal static extern IntPtr SwapInto(IntPtr p, ulong index, IntPtr creature);
|
||||
|
||||
/// <param name="p">const CreatureParty *</param>
|
||||
/// <returns>bool</returns>
|
||||
[DllImport("CreatureLibBattling", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_CreatureParty_HasAvailableCreatures")]
|
||||
|
|
BIN
PkmnLibSharp/Native/libCreatureLibBattling.so (Stored with Git LFS)
BIN
PkmnLibSharp/Native/libCreatureLibBattling.so (Stored with Git LFS)
Binary file not shown.
BIN
PkmnLibSharp/Native/libCreatureLibLibrary.so (Stored with Git LFS)
BIN
PkmnLibSharp/Native/libCreatureLibLibrary.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.
|
@ -35,7 +35,7 @@ namespace PkmnLibSharp.Utilities
|
|||
Initialize(ptr);
|
||||
}
|
||||
|
||||
protected internal void Initialize(IntPtr ptr)
|
||||
protected internal virtual void Initialize(IntPtr ptr)
|
||||
{
|
||||
_ptr = ptr;
|
||||
var weakRef = new WeakReference<object>(this);
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue