More work on Pokemon class wrapping.
This commit is contained in:
parent
c143235495
commit
4d74dcc263
|
@ -0,0 +1,7 @@
|
|||
namespace PkmnLibSharp.Battling
|
||||
{
|
||||
public enum DamageSource
|
||||
{
|
||||
AttackDamage = 0,
|
||||
}
|
||||
}
|
|
@ -13,8 +13,10 @@ namespace PkmnLibSharp.Battling
|
|||
{
|
||||
public Pokemon([NotNull] BattleLibrary library, [NotNull] Species species, [NotNull] Forme forme,
|
||||
byte level, uint experience, uint uid,
|
||||
Gender gender, byte coloring, [MaybeNull] Item heldItem, [MaybeNull] string nickname, bool hiddenAbility, byte abilityIndex,
|
||||
[NotNull] IReadOnlyCollection<LearnedMove> moves, StatisticSet<byte> ivs, StatisticSet<byte> evs, [NotNull] Nature nature)
|
||||
Gender gender, byte coloring, [MaybeNull] Item heldItem, [MaybeNull] string nickname, bool hiddenAbility,
|
||||
byte abilityIndex,
|
||||
[NotNull] IReadOnlyCollection<LearnedMove> moves, StatisticSet<byte> ivs, StatisticSet<byte> evs,
|
||||
[NotNull] Nature nature)
|
||||
: base(Pkmnlib.Generated.Pokemon.Construct(
|
||||
library.Ptr, species.Ptr, forme.Ptr, level, experience,
|
||||
uid, (Pkmnlib.Gender) gender, coloring, heldItem?.Ptr ?? IntPtr.Zero, nickname.ToPtr(),
|
||||
|
@ -24,8 +26,11 @@ namespace PkmnLibSharp.Battling
|
|||
ivs.HP, ivs.Attack, ivs.Defense, ivs.SpecialAttack,
|
||||
ivs.SpecialDefense, ivs.Speed, evs.HP, evs.Attack, evs.Defense,
|
||||
evs.SpecialAttack, evs.SpecialDefense, evs.Speed, nature.Ptr))
|
||||
{}
|
||||
{
|
||||
Library = library;
|
||||
}
|
||||
|
||||
public BattleLibrary Library { get; }
|
||||
public Species Species
|
||||
{
|
||||
get
|
||||
|
@ -55,6 +60,41 @@ namespace PkmnLibSharp.Battling
|
|||
public Gender Gender => (Gender) Creaturelibbattling.Generated.Creature.GetGender(Ptr);
|
||||
public byte Coloring => Creaturelibbattling.Generated.Creature.GetColoring(Ptr);
|
||||
public bool IsShiny => Coloring == 1;
|
||||
public uint CurrentHealth => Creaturelibbattling.Generated.Creature.GetCurrentHealth(Ptr);
|
||||
public uint MaxHealth => Creaturelibbattling.Generated.Creature.GetMaxHealth(Ptr);
|
||||
|
||||
public string ActiveAbility
|
||||
{
|
||||
get
|
||||
{
|
||||
var ptr = IntPtr.Zero;
|
||||
Creaturelibbattling.Generated.Creature.GetActiveTalent(Ptr, ref ptr).Assert();
|
||||
return ptr.PtrString();
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Change to wrapped
|
||||
public IntPtr Battle => Creaturelibbattling.Generated.Creature.GetBattle(Ptr);
|
||||
// TODO: Change to wrapped
|
||||
public IntPtr BattleSide => Creaturelibbattling.Generated.Creature.GetBattleSide(Ptr);
|
||||
public bool IsOnBattleField => Creaturelibbattling.Generated.Creature.IsOnBattleField(Ptr) == 1;
|
||||
|
||||
public Item HeldItem
|
||||
{
|
||||
get
|
||||
{
|
||||
var ptr = Creaturelibbattling.Generated.Creature.GetHeldItem(Ptr);
|
||||
if (ptr == IntPtr.Zero) return null;
|
||||
if (!TryResolvePointer(ptr, out Item item))
|
||||
{
|
||||
item = new Item(ptr);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
set =>
|
||||
Creaturelibbattling.Generated.Creature.SetHeldItemFromItem(Ptr,
|
||||
value?.Ptr ?? IntPtr.Zero);
|
||||
}
|
||||
|
||||
public string Nickname
|
||||
{
|
||||
|
@ -77,6 +117,79 @@ namespace PkmnLibSharp.Battling
|
|||
return Creaturelibbattling.Generated.Creature.HasHeldItem(Ptr, itemName.ToPtr()) == 1;
|
||||
}
|
||||
|
||||
public void SetHeldItem(string item)
|
||||
{
|
||||
if (string.IsNullOrEmpty(item))
|
||||
Creaturelibbattling.Generated.Creature.SetHeldItemFromItem(Ptr, IntPtr.Zero);
|
||||
else
|
||||
Creaturelibbattling.Generated.Creature.SetHeldItem(Ptr, item.ToPtr());
|
||||
}
|
||||
|
||||
public bool HasType(string type)
|
||||
{
|
||||
var typeByte = Library.StaticLibrary.TypeLibrary.GetTypeId(type);
|
||||
return Creaturelibbattling.Generated.Creature.HasType(Ptr, typeByte) == 1;
|
||||
}
|
||||
|
||||
public void ChangeLevelBy(sbyte amount)
|
||||
{
|
||||
Creaturelibbattling.Generated.Creature.ChangeLevelBy(Ptr, amount).Assert();
|
||||
}
|
||||
|
||||
public void AddExperience(uint experience)
|
||||
{
|
||||
Creaturelibbattling.Generated.Creature.AddExperience(Ptr, experience).Assert();
|
||||
}
|
||||
|
||||
public void Damage(uint damage, DamageSource source)
|
||||
{
|
||||
Creaturelibbattling.Generated.Creature.Damage(Ptr, damage, (Creaturelibbattling.DamageSource) source);
|
||||
}
|
||||
|
||||
public void Heal(uint damage, bool canRevive)
|
||||
{
|
||||
Creaturelibbattling.Generated.Creature.Heal(Ptr, damage, canRevive.ToNative());
|
||||
}
|
||||
|
||||
public void OverrideActiveAbility(string ability)
|
||||
{
|
||||
Creaturelibbattling.Generated.Creature.OverrideActiveTalent(Ptr, ability.ToPtr()).Assert();
|
||||
}
|
||||
|
||||
public void ClearVolatileScripts()
|
||||
{
|
||||
Creaturelibbattling.Generated.Creature.ClearVolatileScripts(Ptr).Assert();
|
||||
}
|
||||
|
||||
public void AddVolatileScript(string scriptName)
|
||||
{
|
||||
Creaturelibbattling.Generated.Creature.AddVolatileScriptByName(Ptr, scriptName.ToPtr()).Assert();
|
||||
}
|
||||
|
||||
//TODO: Change to wrapper
|
||||
public void AddVolatileScript(IntPtr script)
|
||||
{
|
||||
Creaturelibbattling.Generated.Creature.AddVolatileScript(Ptr, script).Assert();
|
||||
}
|
||||
|
||||
public void RemoveVolatileScript(string scriptName)
|
||||
{
|
||||
Creaturelibbattling.Generated.Creature.RemoveVolatileScriptByName(Ptr, scriptName.ToPtr()).Assert();
|
||||
}
|
||||
|
||||
//TODO: Change to wrapper
|
||||
public void RemoveVolatileScript(IntPtr script)
|
||||
{
|
||||
Creaturelibbattling.Generated.Creature.RemoveVolatileScript(Ptr, script).Assert();
|
||||
}
|
||||
|
||||
public bool HasVolatileScript(string scriptName)
|
||||
{
|
||||
return Creaturelibbattling.Generated.Creature.HasVolatileScript(Ptr, scriptName.ToPtr()) == 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private Species _species;
|
||||
|
|
|
@ -158,6 +158,12 @@ namespace Creaturelibbattling.Generated
|
|||
[DllImport("CreatureLibBattling", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_Creature_Heal")]
|
||||
internal static extern byte Heal(IntPtr p, uint health, byte canRevive);
|
||||
|
||||
/// <param name="p">const Creature *</param>
|
||||
/// <param name="out">const char * &</param>
|
||||
/// <returns>unsigned char</returns>
|
||||
[DllImport("CreatureLibBattling", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_Creature_GetActiveTalent")]
|
||||
internal static extern byte GetActiveTalent(IntPtr p, ref IntPtr @out);
|
||||
|
||||
/// <param name="p">Creature *</param>
|
||||
/// <param name="talent">const char *</param>
|
||||
/// <returns>unsigned char</returns>
|
||||
|
|
BIN
PkmnLibSharp/Native/libCreatureLibBattling.so (Stored with Git LFS)
BIN
PkmnLibSharp/Native/libCreatureLibBattling.so (Stored with Git LFS)
Binary file not shown.
BIN
PkmnLibSharp/Native/libpkmnLib.so (Stored with Git LFS)
BIN
PkmnLibSharp/Native/libpkmnLib.so (Stored with Git LFS)
Binary file not shown.
|
@ -45,6 +45,11 @@ namespace PkmnLibSharp.Utilities
|
|||
|
||||
public static bool TryResolvePointer<T>(IntPtr p, out T result) where T : PointerWrapper
|
||||
{
|
||||
if (p == IntPtr.Zero)
|
||||
{
|
||||
result = null;
|
||||
return true;
|
||||
}
|
||||
if (Cached.TryGetValue(p, out var val))
|
||||
{
|
||||
if (val.TryGetTarget(out var target))
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue