71 lines
2.2 KiB
C#
71 lines
2.2 KiB
C#
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();
|
|
}
|
|
}
|
|
}
|
|
} |