Support for PokemonParty.

This commit is contained in:
Deukhoofd committed 2020-07-25 15:23:01 +02:00
1 parent e4a515e11a
commit d01e6a8df7
10 files changed
+113 -8

No files matched your search

+1 -1
View File
@@ -77,7 +77,7 @@ namespace PkmnLibSharp.Battling
} }
} }
private BattleLibrary(IntPtr ptr) : base(ptr) internal BattleLibrary(IntPtr ptr) : base(ptr)
{ {
} }
+23 -1
View File
@@ -11,6 +11,13 @@ namespace PkmnLibSharp.Battling
{ {
public class Pokemon : PointerWrapper 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, public Pokemon([NotNull] BattleLibrary library, [NotNull] Species species, [NotNull] Forme forme,
byte level, uint experience, uint uid, byte level, uint experience, uint uid,
Gender gender, byte coloring, [MaybeNull] Item heldItem, [MaybeNull] string nickname, bool hiddenAbility, Gender gender, byte coloring, [MaybeNull] Item heldItem, [MaybeNull] string nickname, bool hiddenAbility,
@@ -30,7 +37,13 @@ namespace PkmnLibSharp.Battling
Library = library; 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 public Species Species
{ {
get get
@@ -305,5 +318,14 @@ namespace PkmnLibSharp.Battling
{ {
Pkmnlib.Generated.Pokemon.Destruct(Ptr); Pkmnlib.Generated.Pokemon.Destruct(Ptr);
} }
protected internal override void MarkAsDeleted()
{
base.MarkAsDeleted();
foreach (var move in Moves)
{
move.MarkAsDeleted();
}
}
} }
} }
+71
View File
@@ -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")] [DllImport("CreatureLibBattling", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_Creature_Destruct")]
internal static extern void Destruct(IntPtr p); 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> /// <param name="p">const Creature *</param>
/// <returns>const CreatureSpecies *</returns> /// <returns>const CreatureSpecies *</returns>
[DllImport("CreatureLibBattling", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_Creature_GetSpecies")] [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")] [DllImport("CreatureLibBattling", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_CreatureParty_Switch")]
internal static extern byte Switch(IntPtr p, ulong a, ulong b); 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> /// <param name="p">const CreatureParty *</param>
/// <returns>bool</returns> /// <returns>bool</returns>
[DllImport("CreatureLibBattling", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_CreatureParty_HasAvailableCreatures")] [DllImport("CreatureLibBattling", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_CreatureParty_HasAvailableCreatures")]
Binary file not shown.
Binary file not shown.
Binary file not shown.
+1 -1
View File
@@ -35,7 +35,7 @@ namespace PkmnLibSharp.Utilities
Initialize(ptr); Initialize(ptr);
} }
protected internal void Initialize(IntPtr ptr) protected internal virtual void Initialize(IntPtr ptr)
{ {
_ptr = ptr; _ptr = ptr;
var weakRef = new WeakReference<object>(this); var weakRef = new WeakReference<object>(this);
+1 -1
View File
@@ -1 +1 @@
{"enums":[{"byteSize":1,"filename":"CreatureLibLibrary","name":"AttackCategory","values":{"0":"Physical","1":"Magical","2":"Status"}},{"byteSize":1,"filename":"CreatureLibLibrary","name":"AttackTarget","values":{"0":"Adjacent","1":"AdjacentAlly","10":"RandomOpponent","11":"Self","2":"AdjacentAllySelf","3":"AdjacentOpponent","4":"All","5":"AllAdjacent","6":"AllAdjacentOpponent","7":"AllAlly","8":"AllOpponent","9":"Any"}},{"byteSize":1,"filename":"CreatureLibLibrary","name":"EffectParameterType","values":{"0":"None","1":"Bool","2":"Int","3":"Float","4":"String"}},{"byteSize":1,"filename":"CreatureLibLibrary","name":"Gender","values":{"0":"Male","1":"Female","2":"Genderless"}},{"byteSize":1,"filename":"CreatureLibLibrary","name":"ItemCategory","values":{"0":"MiscItem","1":"CaptureDevice","2":"Medicine","3":"Berry","4":"MoveLearner","5":"VariantChanger","6":"KeyItem","7":"Mail"}},{"byteSize":1,"filename":"CreatureLibLibrary","name":"BattleItemCategory","values":{"0":"None","1":"Healing","2":"StatusHealing","3":"CaptureDevice","4":"MiscBattleItem"}},{"byteSize":1,"filename":"CreatureLibLibrary","name":"Statistic","values":{"0":"Health","1":"PhysicalAttack","2":"PhysicalDefense","3":"MagicalAttack","4":"MagicalDefense","5":"Speed"}},{"byteSize":1,"filename":"CreatureLibBattling","name":"ScriptCategory","values":{"0":"Attack","1":"Talent","2":"Status","3":"Creature","4":"Battle","5":"Side"}},{"byteSize":1,"filename":"CreatureLibBattling","name":"Statistic","values":{"0":"Health","1":"PhysicalAttack","2":"PhysicalDefense","3":"MagicalAttack","4":"MagicalDefense","5":"Speed"}},{"byteSize":1,"filename":"CreatureLibBattling","name":"Gender","values":{"0":"Male","1":"Female","2":"Genderless"}},{"byteSize":1,"filename":"CreatureLibBattling","name":"ItemCategory","values":{"0":"MiscItem","1":"CaptureDevice","2":"Medicine","3":"Berry","4":"MoveLearner","5":"VariantChanger","6":"KeyItem","7":"Mail"}},{"byteSize":1,"filename":"CreatureLibBattling","name":"BattleItemCategory","values":{"0":"None","1":"Healing","2":"StatusHealing","3":"CaptureDevice","4":"MiscBattleItem"}},{"byteSize":1,"filename":"CreatureLibBattling","name":"DamageSource","values":{"0":"AttackDamage"}},{"byteSize":1,"filename":"CreatureLibBattling","name":"EventDataKind","values":{"0":"Damage","1":"Heal","2":"Faint","3":"DisplayText"}},{"byteSize":4,"filename":"CreatureLibBattling","name":"AttackLearnMethod","values":{"0":"Unknown","1":"Level"}},{"byteSize":1,"filename":"CreatureLibBattling","name":"TurnChoiceKind","values":{"0":"Pass","1":"Attack","2":"Item","3":"Switch","4":"Flee"}},{"byteSize":1,"filename":"CreatureLibBattling","name":"EffectParameterType","values":{"0":"None","1":"Bool","2":"Int","3":"Float","4":"String"}},{"byteSize":1,"filename":"CreatureLibBattling","name":"AttackCategory","values":{"0":"Physical","1":"Magical","2":"Status"}},{"byteSize":1,"filename":"CreatureLibBattling","name":"AttackTarget","values":{"0":"Adjacent","1":"AdjacentAlly","10":"RandomOpponent","11":"Self","2":"AdjacentAllySelf","3":"AdjacentOpponent","4":"All","5":"AllAdjacent","6":"AllAdjacentOpponent","7":"AllAlly","8":"AllOpponent","9":"Any"}}],"functions":[{"filename":"CreatureLibLibrary","name":"CreatureLib_C_GetLastException","parameters":[],"returns":"const char *"},{"filename":"CreatureLibLibrary","name":"CreatureLib_AttackData_Construct","parameters":[{"name":"out","type":"AttackData * &"},{"name":"name","type":"const char *"},{"name":"type","type":"unsigned char"},{"name":"category","type":"AttackCategory"},{"name":"power","type":"unsigned char"},{"name":"accuracy","type":"unsigned char"},{"name":"baseUsage","type":"unsigned char"},{"name":"target","type":"AttackTarget"},{"name":"priority","type":"signed char"},{"name":"effectChance","type":"float"},{"name":"effectName","type":"const char *"},{"name":"effectParameters","type":"EffectParameter * *"},{"name":"effectParameterCount","type":"long unsigned int"},{"name":"flags","type":"const char * *"},{"name":"flagsCount","type":"long unsigned int"}],"returns":"unsigned char"},{"filename":"CreatureLibLibrary","name":"CreatureLib_AttackData_Destruct","parameters":[{"name":"p","type":"const AttackData *"}],"returns":"void"},{"filename":"CreatureLibLibrary","name":"CreatureLib_AttackData_GetName","parameters":[{"name":"p","type":"const AttackData *"}],"returns":"const char *"},{"filename":"CreatureLibLibrary","name":"CreatureLib_AttackData_GetType","parameters":[{"name":"p","type":"const AttackData *"}],"returns":"unsigned char"},{"filename":"CreatureLibLibrary","name":"CreatureLib_AttackData_GetCategory","parameters":[{"name":"p","type":"const AttackData *"}],"returns":"AttackCategory"},{"filename":"CreatureLibLibrary","name":"CreatureLib_AttackData_GetBasePower","parameters":[{"name":"p","type":"const AttackData *"}],"returns":"unsigned char"},{"filename":"CreatureLibLibrary","name":"CreatureLib_AttackData_GetAccuracy","parameters":[{"name":"p","type":"const AttackData *"}],"returns":"unsigned char"},{"filename":"Line truncated {"enums":[{"byteSize":1,"filename":"CreatureLibLibrary","name":"AttackCategory","values":{"0":"Physical","1":"Magical","2":"Status"}},{"byteSize":1,"filename":"CreatureLibLibrary","name":"AttackTarget","values":{"0":"Adjacent","1":"AdjacentAlly","10":"RandomOpponent","11":"Self","2":"AdjacentAllySelf","3":"AdjacentOpponent","4":"All","5":"AllAdjacent","6":"AllAdjacentOpponent","7":"AllAlly","8":"AllOpponent","9":"Any"}},{"byteSize":1,"filename":"CreatureLibLibrary","name":"EffectParameterType","values":{"0":"None","1":"Bool","2":"Int","3":"Float","4":"String"}},{"byteSize":1,"filename":"CreatureLibLibrary","name":"Gender","values":{"0":"Male","1":"Female","2":"Genderless"}},{"byteSize":1,"filename":"CreatureLibLibrary","name":"ItemCategory","values":{"0":"MiscItem","1":"CaptureDevice","2":"Medicine","3":"Berry","4":"MoveLearner","5":"VariantChanger","6":"KeyItem","7":"Mail"}},{"byteSize":1,"filename":"CreatureLibLibrary","name":"BattleItemCategory","values":{"0":"None","1":"Healing","2":"StatusHealing","3":"CaptureDevice","4":"MiscBattleItem"}},{"byteSize":1,"filename":"CreatureLibLibrary","name":"Statistic","values":{"0":"Health","1":"PhysicalAttack","2":"PhysicalDefense","3":"MagicalAttack","4":"MagicalDefense","5":"Speed"}},{"byteSize":1,"filename":"CreatureLibBattling","name":"ScriptCategory","values":{"0":"Attack","1":"Talent","2":"Status","3":"Creature","4":"Battle","5":"Side"}},{"byteSize":1,"filename":"CreatureLibBattling","name":"Statistic","values":{"0":"Health","1":"PhysicalAttack","2":"PhysicalDefense","3":"MagicalAttack","4":"MagicalDefense","5":"Speed"}},{"byteSize":1,"filename":"CreatureLibBattling","name":"Gender","values":{"0":"Male","1":"Female","2":"Genderless"}},{"byteSize":1,"filename":"CreatureLibBattling","name":"ItemCategory","values":{"0":"MiscItem","1":"CaptureDevice","2":"Medicine","3":"Berry","4":"MoveLearner","5":"VariantChanger","6":"KeyItem","7":"Mail"}},{"byteSize":1,"filename":"CreatureLibBattling","name":"BattleItemCategory","values":{"0":"None","1":"Healing","2":"StatusHealing","3":"CaptureDevice","4":"MiscBattleItem"}},{"byteSize":1,"filename":"CreatureLibBattling","name":"DamageSource","values":{"0":"AttackDamage"}},{"byteSize":1,"filename":"CreatureLibBattling","name":"EventDataKind","values":{"0":"Damage","1":"Heal","2":"Faint","3":"DisplayText"}},{"byteSize":4,"filename":"CreatureLibBattling","name":"AttackLearnMethod","values":{"0":"Unknown","1":"Level"}},{"byteSize":1,"filename":"CreatureLibBattling","name":"TurnChoiceKind","values":{"0":"Pass","1":"Attack","2":"Item","3":"Switch","4":"Flee"}},{"byteSize":1,"filename":"CreatureLibBattling","name":"EffectParameterType","values":{"0":"None","1":"Bool","2":"Int","3":"Float","4":"String"}},{"byteSize":1,"filename":"CreatureLibBattling","name":"AttackCategory","values":{"0":"Physical","1":"Magical","2":"Status"}},{"byteSize":1,"filename":"CreatureLibBattling","name":"AttackTarget","values":{"0":"Adjacent","1":"AdjacentAlly","10":"RandomOpponent","11":"Self","2":"AdjacentAllySelf","3":"AdjacentOpponent","4":"All","5":"AllAdjacent","6":"AllAdjacentOpponent","7":"AllAlly","8":"AllOpponent","9":"Any"}}],"functions":[{"filename":"CreatureLibLibrary","name":"CreatureLib_C_GetLastException","parameters":[],"returns":"const char *"},{"filename":"CreatureLibLibrary","name":"CreatureLib_AttackData_Construct","parameters":[{"name":"out","type":"AttackData * &"},{"name":"name","type":"const char *"},{"name":"type","type":"unsigned char"},{"name":"category","type":"AttackCategory"},{"name":"power","type":"unsigned char"},{"name":"accuracy","type":"unsigned char"},{"name":"baseUsage","type":"unsigned char"},{"name":"target","type":"AttackTarget"},{"name":"priority","type":"signed char"},{"name":"effectChance","type":"float"},{"name":"effectName","type":"const char *"},{"name":"effectParameters","type":"EffectParameter * *"},{"name":"effectParameterCount","type":"long unsigned int"},{"name":"flags","type":"const char * *"},{"name":"flagsCount","type":"long unsigned int"}],"returns":"unsigned char"},{"filename":"CreatureLibLibrary","name":"CreatureLib_AttackData_Destruct","parameters":[{"name":"p","type":"const AttackData *"}],"returns":"void"},{"filename":"CreatureLibLibrary","name":"CreatureLib_AttackData_GetName","parameters":[{"name":"p","type":"const AttackData *"}],"returns":"const char *"},{"filename":"CreatureLibLibrary","name":"CreatureLib_AttackData_GetType","parameters":[{"name":"p","type":"const AttackData *"}],"returns":"unsigned char"},{"filename":"CreatureLibLibrary","name":"CreatureLib_AttackData_GetCategory","parameters":[{"name":"p","type":"const AttackData *"}],"returns":"AttackCategory"},{"filename":"CreatureLibLibrary","name":"CreatureLib_AttackData_GetBasePower","parameters":[{"name":"p","type":"const AttackData *"}],"returns":"unsigned char"},{"filename":"CreatureLibLibrary","name":"CreatureLib_AttackData_GetAccuracy","parameters":[{"name":"p","type":"const AttackData *"}],"returns":"unsigned char"},{"filename":"Line truncated