2020-07-25 13:23:01 +00:00
|
|
|
using System;
|
|
|
|
using PkmnLibSharp.Utilities;
|
|
|
|
|
|
|
|
namespace PkmnLibSharp.Battling
|
|
|
|
{
|
|
|
|
public class PokemonParty : PointerWrapper
|
|
|
|
{
|
|
|
|
private ReadOnlyNativePtrArray<Pokemon> _party;
|
|
|
|
|
2020-07-31 12:19:21 +00:00
|
|
|
internal PokemonParty(IntPtr ptr) : base(ptr){}
|
|
|
|
|
|
|
|
public PokemonParty(byte size = 6) : base(Creaturelib.Generated.CreatureParty.ConstructWithSize(size))
|
2020-07-25 13:23:01 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
public PokemonParty(Pokemon[] pokemon) : base(
|
2020-07-31 12:19:21 +00:00
|
|
|
Creaturelib.Generated.CreatureParty.ConstructFromArray(pokemon.ArrayPtr(), (ulong) pokemon.Length))
|
2020-07-25 13:23:01 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
public Pokemon GetAtIndex(ulong index)
|
|
|
|
{
|
|
|
|
var ptr = IntPtr.Zero;
|
2020-07-31 12:19:21 +00:00
|
|
|
Creaturelib.Generated.CreatureParty.GetAtIndex(ref ptr, Ptr, index).Assert();
|
2020-07-25 13:23:01 +00:00
|
|
|
return TryResolvePointer(ptr, out Pokemon pkmn) ? pkmn : new Pokemon(ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Switch(ulong indexA, ulong indexB)
|
|
|
|
{
|
2020-07-31 12:19:21 +00:00
|
|
|
Creaturelib.Generated.CreatureParty.Switch(Ptr, indexA, indexB);
|
2020-07-25 13:23:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public Pokemon SwapInto(ulong indexA, Pokemon pokemon)
|
|
|
|
{
|
2020-07-31 12:19:21 +00:00
|
|
|
var ptr = Creaturelib.Generated.CreatureParty.SwapInto(Ptr, indexA, pokemon.Ptr);
|
2020-07-25 13:23:01 +00:00
|
|
|
if (TryResolvePointer(ptr, out Pokemon newPokemon))
|
|
|
|
{
|
|
|
|
return newPokemon;
|
|
|
|
}
|
|
|
|
return new Pokemon(ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool HasAvailablePokemon()
|
|
|
|
{
|
2020-07-31 12:19:21 +00:00
|
|
|
return Creaturelib.Generated.CreatureParty.HasAvailableCreatures(Ptr) == 1;
|
2020-07-25 13:23:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public ReadOnlyNativePtrArray<Pokemon> Party
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
if (_party != null) return _party;
|
2020-07-31 12:19:21 +00:00
|
|
|
var ptr = Creaturelib.Generated.CreatureParty.GetParty(Ptr);
|
2020-07-25 13:23:01 +00:00
|
|
|
_party = new ReadOnlyNativePtrArray<Pokemon>(ptr, (int) Length);
|
|
|
|
return _party;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-31 12:19:21 +00:00
|
|
|
public ulong Length => Creaturelib.Generated.CreatureParty.GetLength(Ptr);
|
2020-07-25 13:23:01 +00:00
|
|
|
|
|
|
|
protected override void DeletePtr()
|
|
|
|
{
|
2020-07-31 12:19:21 +00:00
|
|
|
Creaturelib.Generated.CreatureParty.Destruct(Ptr);
|
2020-07-25 13:23:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected internal override void MarkAsDeleted()
|
|
|
|
{
|
|
|
|
base.MarkAsDeleted();
|
|
|
|
foreach (var pokemon in Party)
|
|
|
|
{
|
|
|
|
pokemon.MarkAsDeleted();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|