Initial commit, implements Forme
This commit is contained in:
91
PkmnLibSharp/Library/Forme.cs
Normal file
91
PkmnLibSharp/Library/Forme.cs
Normal file
@@ -0,0 +1,91 @@
|
||||
using System;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using Creatureliblibrary;
|
||||
using Creatureliblibrary.Generated;
|
||||
|
||||
namespace PkmnLibSharp.Library
|
||||
{
|
||||
public class Forme : PointerWrapper
|
||||
{
|
||||
private string _name;
|
||||
private ImmutableArray<byte> _types;
|
||||
|
||||
public string Name => _name ??= SpeciesVariant.GetName(Ptr);
|
||||
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];
|
||||
for (ulong i = 0; i < typesCount; i++)
|
||||
{
|
||||
types[i] = SpeciesVariant.GetType(Ptr, i);
|
||||
}
|
||||
|
||||
_types = types.ToImmutableArray();
|
||||
return _types;
|
||||
}
|
||||
}
|
||||
|
||||
public uint BaseHealth => SpeciesVariant.GetStatistic(Ptr, Statistic.Health);
|
||||
public uint BaseAttack => SpeciesVariant.GetStatistic(Ptr, Statistic.PhysicalAttack);
|
||||
public uint BaseDefense => SpeciesVariant.GetStatistic(Ptr, Statistic.PhysicalDefense);
|
||||
public uint BaseSpecialAttack => SpeciesVariant.GetStatistic(Ptr, Statistic.MagicalAttack);
|
||||
public uint BaseSpecialDefense => SpeciesVariant.GetStatistic(Ptr, Statistic.MagicalDefense);
|
||||
public uint BaseSpeed => SpeciesVariant.GetStatistic(Ptr, Statistic.Speed);
|
||||
|
||||
|
||||
public int GetPkmnType(int index)
|
||||
{
|
||||
return Types[index];
|
||||
}
|
||||
|
||||
|
||||
public static unsafe Forme Create(string name, float height, float weight, uint baseExperience, byte[] types,
|
||||
ushort baseHealth, ushort baseAttack, ushort baseDefense, ushort baseSpecialAttack,
|
||||
ushort baseSpecialDefense, ushort baseSpeed, string[] abilities, string[] hiddenAbilities)
|
||||
{
|
||||
var abilitiesConverted = abilities.Select(Marshal.StringToHGlobalUni).ToArray();
|
||||
var hiddenAbilitiesConverted = hiddenAbilities.Select(Marshal.StringToHGlobalUni).ToArray();
|
||||
fixed (byte* t = types)
|
||||
{
|
||||
fixed (IntPtr* ab = abilitiesConverted)
|
||||
{
|
||||
fixed (IntPtr* hab = hiddenAbilitiesConverted)
|
||||
{
|
||||
var ptr = SpeciesVariant.Construct(name, height, weight, baseExperience, (IntPtr)t,
|
||||
(ulong) types.Length,
|
||||
baseHealth, baseAttack, baseDefense, baseSpecialAttack, baseSpecialDefense,
|
||||
baseSpeed, (IntPtr)ab, (ulong) abilities.Length, (IntPtr)hab,
|
||||
(ulong) hiddenAbilities.Length, IntPtr.Zero);
|
||||
var f = new Forme(ptr);
|
||||
foreach (var intPtr in abilitiesConverted)
|
||||
Marshal.FreeHGlobal(intPtr);
|
||||
foreach (var intPtr in hiddenAbilitiesConverted)
|
||||
Marshal.FreeHGlobal(intPtr);
|
||||
return f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Forme(IntPtr parent)
|
||||
: base(parent)
|
||||
{
|
||||
}
|
||||
|
||||
internal override void DeletePtr()
|
||||
{
|
||||
SpeciesVariant.Destruct(Ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
19
PkmnLibSharp/Library/Species.cs
Normal file
19
PkmnLibSharp/Library/Species.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using Pkmnlib.Generated;
|
||||
|
||||
namespace PkmnLibSharp.Library
|
||||
{
|
||||
public class Species : PointerWrapper
|
||||
{
|
||||
// ReSharper disable once SuggestBaseTypeForParameter
|
||||
public Species(ushort id, string name, Forme defaultForme, float genderRatio, string growthRate, byte captureRate,
|
||||
byte baseHappiness) : base(PokemonSpecies.Construct(id, name, defaultForme.Ptr, genderRatio, growthRate, captureRate, baseHappiness))
|
||||
{
|
||||
}
|
||||
|
||||
internal override void DeletePtr()
|
||||
{
|
||||
Pokemon.Destruct(Ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user