2020-05-02 17:54:07 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Immutable;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
using Creatureliblibrary.Generated;
|
2020-05-02 20:58:08 +00:00
|
|
|
using PkmnLibSharp.Utilities;
|
2020-07-18 14:49:11 +00:00
|
|
|
using Random = PkmnLibSharp.Utilities.Random;
|
2020-05-02 17:54:07 +00:00
|
|
|
|
|
|
|
namespace PkmnLibSharp.Library
|
|
|
|
{
|
|
|
|
public class Forme : PointerWrapper
|
|
|
|
{
|
2020-05-02 20:58:08 +00:00
|
|
|
private ImmutableArray<string> _abilities;
|
|
|
|
private ImmutableArray<string> _hiddenAbilities;
|
|
|
|
private LearnableMoves _moves;
|
2020-07-18 14:49:11 +00:00
|
|
|
private string _name;
|
|
|
|
private ImmutableArray<byte> _types;
|
|
|
|
|
|
|
|
internal Forme(IntPtr parent) : base(parent)
|
|
|
|
{
|
|
|
|
}
|
2020-05-02 17:54:07 +00:00
|
|
|
|
2020-05-02 20:58:08 +00:00
|
|
|
public string Name => _name ??= SpeciesVariant.GetName(Ptr).PtrString();
|
2020-05-02 17:54:07 +00:00
|
|
|
public float Height => SpeciesVariant.GetHeight(Ptr);
|
|
|
|
public float Weight => SpeciesVariant.GetWeight(Ptr);
|
|
|
|
public float BaseExperience => SpeciesVariant.GetBaseExperience(Ptr);
|
|
|
|
|
|
|
|
public ImmutableArray<byte> Types
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
if (_types != null)
|
|
|
|
return _types;
|
|
|
|
|
|
|
|
var typesCount = SpeciesVariant.GetTypeCount(Ptr);
|
|
|
|
var types = new byte[typesCount];
|
2020-07-18 14:49:11 +00:00
|
|
|
for (ulong i = 0; i < typesCount; i++) types[i] = SpeciesVariant.GetType(Ptr, i);
|
2020-05-02 17:54:07 +00:00
|
|
|
|
|
|
|
_types = types.ToImmutableArray();
|
|
|
|
return _types;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-06 12:40:29 +00:00
|
|
|
public uint BaseHealth => SpeciesVariant.GetStatistic(Ptr, (byte) Statistic.Health);
|
|
|
|
public uint BaseAttack => SpeciesVariant.GetStatistic(Ptr, (Creatureliblibrary.Statistic) Statistic.Attack);
|
|
|
|
public uint BaseDefense => SpeciesVariant.GetStatistic(Ptr, (Creatureliblibrary.Statistic) Statistic.Defense);
|
|
|
|
|
|
|
|
public uint BaseSpecialAttack =>
|
|
|
|
SpeciesVariant.GetStatistic(Ptr, (Creatureliblibrary.Statistic) Statistic.SpecialAttack);
|
|
|
|
|
|
|
|
public uint BaseSpecialDefense =>
|
|
|
|
SpeciesVariant.GetStatistic(Ptr, (Creatureliblibrary.Statistic) Statistic.SpecialDefense);
|
|
|
|
|
|
|
|
public uint BaseSpeed => SpeciesVariant.GetStatistic(Ptr, (Creatureliblibrary.Statistic) Statistic.Speed);
|
2020-05-02 17:54:07 +00:00
|
|
|
|
2020-05-02 20:58:08 +00:00
|
|
|
public ImmutableArray<string> Abilities
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
if (_abilities != null)
|
|
|
|
return _abilities;
|
|
|
|
|
|
|
|
var abilityCount = SpeciesVariant.GetTalentCount(Ptr);
|
|
|
|
var abilities = new string[abilityCount];
|
|
|
|
for (byte i = 0; i < abilityCount; i++)
|
|
|
|
{
|
2020-07-18 14:49:11 +00:00
|
|
|
var s = IntPtr.Zero;
|
2020-05-03 09:38:49 +00:00
|
|
|
SpeciesVariant.GetTalent(Ptr, MarshalHelper.False, i, ref s).Assert();
|
2020-05-02 20:58:08 +00:00
|
|
|
abilities[i] = s.PtrString();
|
|
|
|
}
|
|
|
|
|
|
|
|
_abilities = abilities.ToImmutableArray();
|
|
|
|
return _abilities;
|
|
|
|
}
|
|
|
|
}
|
2020-05-06 12:40:29 +00:00
|
|
|
|
2020-05-02 20:58:08 +00:00
|
|
|
public ImmutableArray<string> HiddenAbilities
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
if (_hiddenAbilities != null)
|
|
|
|
return _hiddenAbilities;
|
|
|
|
|
|
|
|
var abilityCount = SpeciesVariant.GetSecretTalentCount(Ptr);
|
|
|
|
var abilities = new string[abilityCount];
|
|
|
|
for (byte i = 0; i < abilityCount; i++)
|
|
|
|
{
|
2020-07-18 14:49:11 +00:00
|
|
|
var s = IntPtr.Zero;
|
2020-05-03 09:38:49 +00:00
|
|
|
SpeciesVariant.GetTalent(Ptr, MarshalHelper.True, i, ref s).Assert();
|
2020-05-02 20:58:08 +00:00
|
|
|
abilities[i] = s.PtrString();
|
|
|
|
}
|
|
|
|
|
|
|
|
_hiddenAbilities = abilities.ToImmutableArray();
|
|
|
|
return _hiddenAbilities;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-03 15:14:07 +00:00
|
|
|
public LearnableMoves Moves
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
if (_moves != null) return _moves;
|
|
|
|
var movesPtr = SpeciesVariant.GetLearnableAttacks(Ptr);
|
2020-07-18 14:49:11 +00:00
|
|
|
if (!TryResolvePointer(movesPtr, out _moves)) _moves = new LearnableMoves(movesPtr);
|
2020-05-06 12:40:29 +00:00
|
|
|
|
2020-05-03 15:14:07 +00:00
|
|
|
return _moves;
|
|
|
|
}
|
|
|
|
}
|
2020-05-02 17:54:07 +00:00
|
|
|
|
|
|
|
public int GetPkmnType(int index)
|
|
|
|
{
|
|
|
|
return Types[index];
|
|
|
|
}
|
|
|
|
|
2020-07-18 14:49:11 +00:00
|
|
|
public static Forme Create(string name, float height, float weight, uint baseExperience, byte[] types,
|
2020-05-02 17:54:07 +00:00
|
|
|
ushort baseHealth, ushort baseAttack, ushort baseDefense, ushort baseSpecialAttack,
|
2020-05-02 20:58:08 +00:00
|
|
|
ushort baseSpecialDefense, ushort baseSpeed, string[] abilities, string[] hiddenAbilities,
|
|
|
|
LearnableMoves moves)
|
2020-05-02 17:54:07 +00:00
|
|
|
{
|
2020-05-02 20:58:08 +00:00
|
|
|
var abilitiesConverted = abilities.Select(x => x.ToPtr()).ToArray();
|
|
|
|
var hiddenAbilitiesConverted = hiddenAbilities.Select(x => x.ToPtr()).ToArray();
|
2020-07-18 14:49:11 +00:00
|
|
|
var ab = abilitiesConverted.ArrayPtr();
|
|
|
|
var hab = abilitiesConverted.ArrayPtr();
|
|
|
|
var ptr = SpeciesVariant.Construct(name.ToPtr(), height, weight, baseExperience, types.ArrayPtr(),
|
|
|
|
(ulong) types.Length, baseHealth, baseAttack, baseDefense, baseSpecialAttack,
|
|
|
|
baseSpecialDefense, baseSpeed, (IntPtr) ab, (ulong) abilities.Length, (IntPtr) hab,
|
|
|
|
(ulong) hiddenAbilities.Length, moves.Ptr);
|
|
|
|
var f = new Forme(ptr);
|
|
|
|
foreach (var intPtr in abilitiesConverted)
|
|
|
|
Marshal.FreeHGlobal(intPtr);
|
|
|
|
foreach (var intPtr in hiddenAbilitiesConverted)
|
|
|
|
Marshal.FreeHGlobal(intPtr);
|
|
|
|
return f;
|
2020-05-02 17:54:07 +00:00
|
|
|
}
|
|
|
|
|
2020-07-18 14:49:11 +00:00
|
|
|
public byte GetRandomAbility(Random rand)
|
2020-05-02 17:54:07 +00:00
|
|
|
{
|
2020-07-18 14:49:11 +00:00
|
|
|
return SpeciesVariant.GetRandomTalent(Ptr, rand.Ptr);
|
2020-05-02 17:54:07 +00:00
|
|
|
}
|
|
|
|
|
2020-05-20 12:47:17 +00:00
|
|
|
protected internal override void MarkAsDeleted()
|
|
|
|
{
|
|
|
|
base.MarkAsDeleted();
|
|
|
|
_moves?.MarkAsDeleted();
|
|
|
|
}
|
|
|
|
|
2020-05-03 15:14:07 +00:00
|
|
|
protected override void DeletePtr()
|
2020-05-02 17:54:07 +00:00
|
|
|
{
|
|
|
|
SpeciesVariant.Destruct(Ptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|