2020-07-25 13:23:01 +00:00
|
|
|
using System;
|
2020-08-10 17:13:17 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
2020-07-25 13:23:01 +00:00
|
|
|
using PkmnLibSharp.Utilities;
|
|
|
|
|
|
|
|
namespace PkmnLibSharp.Battling
|
|
|
|
{
|
2020-08-10 17:13:17 +00:00
|
|
|
public class PokemonParty : PointerWrapper, IEnumerable<Pokemon>
|
2020-07-25 13:23:01 +00:00
|
|
|
{
|
2020-08-10 17:13:17 +00:00
|
|
|
private ReadOnlyNativePtrArray<Pokemon?>? _party;
|
2020-07-25 13:23:01 +00:00
|
|
|
|
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
|
|
|
{}
|
2020-08-10 17:13:17 +00:00
|
|
|
|
|
|
|
public virtual Pokemon this[int i] => GetAtIndex((ulong) i);
|
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-08-08 12:32:27 +00:00
|
|
|
return TryResolvePointer(ptr, out Pokemon? pkmn) ? pkmn! : new Pokemon(ptr);
|
2020-07-25 13:23:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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-08-22 13:45:50 +00:00
|
|
|
var ptr = IntPtr.Zero;
|
|
|
|
Creaturelib.Generated.CreatureParty.SwapInto(ref ptr, Ptr, indexA, pokemon.Ptr).Assert();
|
2020-08-08 12:32:27 +00:00
|
|
|
if (TryResolvePointer(ptr, out Pokemon? newPokemon))
|
|
|
|
return newPokemon!;
|
2020-07-25 13:23:01 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-08-10 17:13:17 +00:00
|
|
|
public ReadOnlyNativePtrArray<Pokemon?> Party
|
2020-07-25 13:23:01 +00:00
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
if (_party != null) return _party;
|
2020-07-31 12:19:21 +00:00
|
|
|
var ptr = Creaturelib.Generated.CreatureParty.GetParty(Ptr);
|
2020-08-10 17:13:17 +00:00
|
|
|
_party = new ReadOnlyNativePtrArray<Pokemon?>(ptr, (int) Length);
|
2020-07-25 13:23:01 +00:00
|
|
|
return _party;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-31 12:19:21 +00:00
|
|
|
public ulong Length => Creaturelib.Generated.CreatureParty.GetLength(Ptr);
|
2020-08-10 17:13:17 +00:00
|
|
|
|
|
|
|
public void PackParty()
|
|
|
|
{
|
|
|
|
Creaturelib.Generated.CreatureParty.PackParty(Ptr);
|
|
|
|
}
|
2020-07-25 13:23:01 +00:00
|
|
|
|
2020-08-10 17:13:17 +00:00
|
|
|
public IEnumerator<Pokemon?> GetEnumerator()
|
|
|
|
{
|
|
|
|
return Party.GetEnumerator();
|
|
|
|
}
|
|
|
|
|
|
|
|
IEnumerator IEnumerable.GetEnumerator()
|
|
|
|
{
|
|
|
|
return GetEnumerator();
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2020-08-10 17:13:17 +00:00
|
|
|
pokemon?.MarkAsDeleted();
|
2020-07-25 13:23:01 +00:00
|
|
|
}
|
|
|
|
}
|
2020-08-10 17:13:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2020-07-25 13:23:01 +00:00
|
|
|
}
|
|
|
|
}
|