Lots of work
This commit is contained in:
63
PkmnLibSharp/Library/EffectParameter.cs
Normal file
63
PkmnLibSharp/Library/EffectParameter.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using Pkmnlib;
|
||||
using PkmnLibSharp.Utilities;
|
||||
|
||||
namespace PkmnLibSharp.Library
|
||||
{
|
||||
public class EffectParameter : PointerWrapper
|
||||
{
|
||||
public EffectParameter(string s) : base(Creatureliblibrary.Generated.EffectParameter.FromString(s.ToPtr()))
|
||||
{
|
||||
}
|
||||
|
||||
public EffectParameter(bool b) : base(Creatureliblibrary.Generated.EffectParameter.FromBool(b))
|
||||
{
|
||||
}
|
||||
|
||||
public EffectParameter(long l) : base(Creatureliblibrary.Generated.EffectParameter.FromInt(l))
|
||||
{
|
||||
}
|
||||
|
||||
public EffectParameter(float f) : base(Creatureliblibrary.Generated.EffectParameter.FromFloat(f))
|
||||
{
|
||||
}
|
||||
|
||||
public EffectParameterType ParameterType =>
|
||||
(EffectParameterType) Creatureliblibrary.Generated.EffectParameter.GetType(Ptr);
|
||||
|
||||
public bool AsBool()
|
||||
{
|
||||
bool b = false;
|
||||
Creatureliblibrary.Generated.EffectParameter.AsBool(Ptr, ref b).Assert();
|
||||
return b;
|
||||
}
|
||||
|
||||
public long AsInt()
|
||||
{
|
||||
long i = 0;
|
||||
Creatureliblibrary.Generated.EffectParameter.AsInt(Ptr, ref i).Assert();
|
||||
return i;
|
||||
}
|
||||
|
||||
public float AsFloat()
|
||||
{
|
||||
float f = 0;
|
||||
Creatureliblibrary.Generated.EffectParameter.AsFloat(Ptr, ref f).Assert();
|
||||
return f;
|
||||
}
|
||||
|
||||
public string AsString()
|
||||
{
|
||||
IntPtr p = IntPtr.Zero;
|
||||
Creatureliblibrary.Generated.EffectParameter.AsString(Ptr, ref p).Assert();
|
||||
return p.PtrString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
internal override void DeletePtr()
|
||||
{
|
||||
Creatureliblibrary.Generated.EffectParameter.Destruct(Ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using Creatureliblibrary;
|
||||
using Creatureliblibrary.Generated;
|
||||
using PkmnLibSharp.Utilities;
|
||||
|
||||
namespace PkmnLibSharp.Library
|
||||
{
|
||||
@@ -11,8 +12,11 @@ namespace PkmnLibSharp.Library
|
||||
{
|
||||
private string _name;
|
||||
private ImmutableArray<byte> _types;
|
||||
private ImmutableArray<string> _abilities;
|
||||
private ImmutableArray<string> _hiddenAbilities;
|
||||
private LearnableMoves _moves;
|
||||
|
||||
public string Name => _name ??= SpeciesVariant.GetName(Ptr);
|
||||
public string Name => _name ??= SpeciesVariant.GetName(Ptr).PtrString();
|
||||
public float Height => SpeciesVariant.GetHeight(Ptr);
|
||||
public float Weight => SpeciesVariant.GetWeight(Ptr);
|
||||
public float BaseExperience => SpeciesVariant.GetBaseExperience(Ptr);
|
||||
@@ -43,6 +47,48 @@ namespace PkmnLibSharp.Library
|
||||
public uint BaseSpecialDefense => SpeciesVariant.GetStatistic(Ptr, Statistic.MagicalDefense);
|
||||
public uint BaseSpeed => SpeciesVariant.GetStatistic(Ptr, Statistic.Speed);
|
||||
|
||||
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++)
|
||||
{
|
||||
IntPtr s = IntPtr.Zero;
|
||||
SpeciesVariant.GetTalent(Ptr, false, i, ref s).Assert();
|
||||
abilities[i] = s.PtrString();
|
||||
}
|
||||
|
||||
_abilities = abilities.ToImmutableArray();
|
||||
return _abilities;
|
||||
}
|
||||
}
|
||||
|
||||
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++)
|
||||
{
|
||||
IntPtr s = IntPtr.Zero;
|
||||
SpeciesVariant.GetTalent(Ptr, true, i, ref s).Assert();
|
||||
abilities[i] = s.PtrString();
|
||||
}
|
||||
|
||||
_hiddenAbilities = abilities.ToImmutableArray();
|
||||
return _hiddenAbilities;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int GetPkmnType(int index)
|
||||
{
|
||||
@@ -52,28 +98,25 @@ namespace PkmnLibSharp.Library
|
||||
|
||||
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)
|
||||
ushort baseSpecialDefense, ushort baseSpeed, string[] abilities, string[] hiddenAbilities,
|
||||
LearnableMoves moves)
|
||||
{
|
||||
var abilitiesConverted = abilities.Select(Marshal.StringToHGlobalUni).ToArray();
|
||||
var hiddenAbilitiesConverted = hiddenAbilities.Select(Marshal.StringToHGlobalUni).ToArray();
|
||||
fixed (byte* t = types)
|
||||
var abilitiesConverted = abilities.Select(x => x.ToPtr()).ToArray();
|
||||
var hiddenAbilitiesConverted = hiddenAbilities.Select(x => x.ToPtr()).ToArray();
|
||||
fixed (IntPtr* ab = abilitiesConverted)
|
||||
{
|
||||
fixed (IntPtr* ab = abilitiesConverted)
|
||||
fixed (IntPtr* hab = hiddenAbilitiesConverted)
|
||||
{
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
29
PkmnLibSharp/Library/LearnableMoves.cs
Normal file
29
PkmnLibSharp/Library/LearnableMoves.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using Creatureliblibrary.Generated;
|
||||
|
||||
namespace PkmnLibSharp.Library
|
||||
{
|
||||
public class LearnableMoves : PointerWrapper
|
||||
{
|
||||
private LearnableMoves(IntPtr ptr) : base(ptr)
|
||||
{
|
||||
}
|
||||
|
||||
public static LearnableMoves Create(byte maxLevel)
|
||||
{
|
||||
var ptr = IntPtr.Zero;
|
||||
LearnableAttacks.Construct(ref ptr, maxLevel);
|
||||
return new LearnableMoves(ptr);
|
||||
}
|
||||
|
||||
public void AddLevelAttack(byte level, MoveData move)
|
||||
{
|
||||
LearnableAttacks.AddLevelAttack(Ptr, level, move.Ptr);
|
||||
}
|
||||
|
||||
internal override void DeletePtr()
|
||||
{
|
||||
LearnableAttacks.Destruct(Ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
58
PkmnLibSharp/Library/MoveData.cs
Normal file
58
PkmnLibSharp/Library/MoveData.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using Creatureliblibrary.Generated;
|
||||
using Pkmnlib;
|
||||
using PkmnLibSharp.Utilities;
|
||||
using AttackCategory = Creatureliblibrary.AttackCategory;
|
||||
|
||||
namespace PkmnLibSharp.Library
|
||||
{
|
||||
public class MoveData : PointerWrapper
|
||||
{
|
||||
private string _name;
|
||||
private string _secondaryEffectName;
|
||||
|
||||
public string Name => _name ??= AttackData.GetName(Ptr).PtrString();
|
||||
public byte Type => AttackData.GetType(Ptr);
|
||||
public MoveCategory Category => (MoveCategory) AttackData.GetCategory(Ptr);
|
||||
public byte BasePower => AttackData.GetBasePower(Ptr);
|
||||
public byte Accuracy => AttackData.GetAccuracy(Ptr);
|
||||
public byte BaseUsages => AttackData.GetBaseUsages(Ptr);
|
||||
public AttackTarget Target => AttackData.GetTarget(Ptr);
|
||||
public sbyte Priority => AttackData.GetPriority(Ptr);
|
||||
public bool HasSecondaryEffect => AttackData.HasSecondaryEffect(Ptr);
|
||||
public float SecondaryEffectChance => AttackData.GetSecondaryEffectChance(Ptr);
|
||||
|
||||
public string SecondaryEffectName =>
|
||||
_secondaryEffectName ??= AttackData.GetSecondaryEffectName(Ptr).PtrString();
|
||||
|
||||
public bool HasFlag(string s)
|
||||
{
|
||||
return AttackData.HasFlag(Ptr, s.ToPtr());
|
||||
}
|
||||
|
||||
public static MoveData Create(string name, byte type, MoveCategory category, byte power, byte accuracy,
|
||||
byte baseUsage, AttackTarget target, sbyte priority, float effectChance, string effectName,
|
||||
EffectParameter[] parameters, string[] flags)
|
||||
{
|
||||
var ptr = IntPtr.Zero;
|
||||
var pars = parameters.Select(x => x.Ptr).ToArray().ArrayPtr();
|
||||
var f = flags.Select(x => x.ToPtr()).ToArray().ArrayPtr();
|
||||
|
||||
AttackData.Construct(ref ptr, name.ToPtr(), type, (AttackCategory) category, power, accuracy, baseUsage,
|
||||
(Creatureliblibrary.AttackTarget) target, priority, effectChance, effectName.ToPtr(), pars,
|
||||
(ulong) parameters.Length, f, (ulong) flags.Length).Assert();
|
||||
return new MoveData(ptr);
|
||||
}
|
||||
|
||||
private MoveData(IntPtr ptr) : base(ptr)
|
||||
{
|
||||
}
|
||||
|
||||
internal override void DeletePtr()
|
||||
{
|
||||
AttackData.Destruct(Ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,17 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using Pkmnlib.Generated;
|
||||
using PkmnLibSharp.Utilities;
|
||||
|
||||
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))
|
||||
public Species(ushort id, string name, Forme defaultForme, float genderRatio, string growthRate,
|
||||
byte captureRate,
|
||||
byte baseHappiness) : base(PokemonSpecies.Construct(id, name.ToPtr(), defaultForme.Ptr, genderRatio,
|
||||
growthRate.ToPtr(), captureRate, baseHappiness))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user