Adds support for new evolution helper functions

master
Deukhoofd 2021-07-09 15:59:42 +02:00
parent 3b25f8b415
commit dc79ed6e46
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
21 changed files with 164 additions and 38 deletions

View File

@ -0,0 +1,30 @@
using System;
using PkmnLibSharp.Library.Evolution;
using PkmnLibSharp.Utilities;
namespace PkmnLibSharp.Battling
{
public class EvolutionScript : PointerWrapper
{
internal EvolutionScript(IntPtr script) : base(script)
{
}
public bool DoesEvolveFromLevelUp(EvolutionData data, Pokemon pokemon)
{
unsafe
{
byte b = 0;
var bPtr = new IntPtr(&b);
Pkmnlib.Generated.EvolutionScript.DoesEvolveFromLevelUp(Ptr, data.Ptr, pokemon.Ptr, bPtr).Assert();
return b == 1;
}
}
protected override void DeletePtr()
{
throw new System.NotImplementedException();
}
}
}

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Pkmnlib;
using PkmnLibSharp.Library.Items;
using PkmnLibSharp.Utilities;
@ -8,9 +9,13 @@ namespace PkmnLibSharp.Battling
{
public class AngelScriptResolver : ScriptResolver
{
private readonly Dictionary<string, EvolutionScript?> _evolutionScriptCache =
new Dictionary<string, EvolutionScript?>();
public AngelScriptResolver() : base(Pkmnlib.Generated.AngelScriptResolver.Construct())
{
}
internal AngelScriptResolver(IntPtr ptr) : base(ptr)
{
}
@ -19,11 +24,36 @@ namespace PkmnLibSharp.Battling
{
Pkmnlib.Generated.AngelScriptResolver.Initialize(Ptr, library.Ptr).Assert();
}
public void CreateScript(string name, string script)
{
Pkmnlib.Generated.AngelScriptResolver.CreateScript(Ptr, name.ToPtr(), script.ToPtr()).Assert();
}
public Script LoadScript(ScriptCategory category, string name)
{
var ptr = IntPtr.Zero;
Pkmnlib.Generated.AngelScriptResolver
.LoadScript(ref ptr, Ptr, (Pkmnlib.ScriptCategory) category, name.ToPtr()).Assert();
return new AngelscriptScript(ptr);
}
public EvolutionScript? LoadEvolutionScript(string name)
{
if (_evolutionScriptCache.TryGetValue(name, out var s))
{
return s;
}
var ptr = IntPtr.Zero;
Pkmnlib.Generated.AngelScriptResolver.LoadEvolutionScript(ref ptr, Ptr, name.ToPtr()).Assert();
if (ptr == IntPtr.Zero)
{
_evolutionScriptCache.Add(name, null);
return null;
}
s = new EvolutionScript(ptr);
_evolutionScriptCache.Add(name, s);
return s;
}
public void LoadByteCodeFromMemory(byte[] data)
{
@ -34,6 +64,7 @@ namespace PkmnLibSharp.Battling
}
public unsafe delegate void* GlobalMethod(void* parameter);
public void RegisterGlobalMethod(string methodName, GlobalMethod method)
{
var methodPtr = Marshal.GetFunctionPointerForDelegate(method);

View File

@ -1,6 +1,9 @@
using System;
using System.Runtime.InteropServices;
using Creaturelib.Generated;
using PkmnLibSharp.Battling.ChoiceTurn;
using PkmnLibSharp.Library;
using PkmnLibSharp.Library.Evolution;
using PkmnLibSharp.Utilities;
using BaseTurnChoice = PkmnLibSharp.Battling.ChoiceTurn.BaseTurnChoice;
@ -8,11 +11,20 @@ namespace PkmnLibSharp.Battling
{
public class MiscLibrary : PointerWrapper
{
private delegate TimeOfDay GetTimeDelegate();
internal MiscLibrary(IntPtr ptr) : base(ptr)
{
}
public MiscLibrary() : base(Pkmnlib.Generated.MiscLibrary.Construct())
public MiscLibrary()
{
GetTimeDelegate getTime = GetTime;
Initialize(Pkmnlib.Generated.MiscLibrary.Construct(Marshal.GetFunctionPointerForDelegate(getTime)));
}
public virtual TimeOfDay GetTime()
{
return TimeOfDay.Morning;
}
public bool IsCritical(IntPtr move, Pokemon target, byte hitNumber)
@ -41,6 +53,12 @@ namespace PkmnLibSharp.Battling
return new MoveTurnChoice(b);
}
public bool CanEvolveFromLevelUp(EvolutionData evolutionData, Pokemon pokemon)
{
byte b = 0;
Pkmnlib.Generated.MiscLibrary.CanEvolveFromLevelUp(ref b, Ptr, evolutionData.Ptr, pokemon.Ptr).Assert();
return b == 1;
}
protected override void DeletePtr()
{

View File

@ -21,9 +21,9 @@ namespace PkmnLibSharp.Battling
public Pokemon(BattleLibrary library, Species species, Forme forme, byte level, uint experience, uint uid,
Gender gender, byte coloring, Item? heldItem, string? nickname, bool hiddenAbility, byte abilityIndex,
IReadOnlyCollection<LearnedMove> moves, StatisticSet<byte> ivs, StatisticSet<byte> evs, Nature nature,
bool allowedExperienceGain = true, bool isEgg = false) :
base(CreatePtr(library, species, forme, level, experience, uid, gender, coloring, heldItem, nickname,
hiddenAbility, abilityIndex, moves, ivs, evs, nature, allowedExperienceGain, isEgg))
bool allowedExperienceGain = true, bool isEgg = false) : base(CreatePtr(library, species, forme, level,
experience, uid, gender, coloring, heldItem, nickname, hiddenAbility, abilityIndex, moves, ivs, evs, nature,
allowedExperienceGain, isEgg))
{
Library = library;
Initialize();
@ -346,7 +346,7 @@ namespace PkmnLibSharp.Battling
}
}
public string? StatusName => Pkmnlib.Generated.Pokemon.GetStatusName(Ptr).PtrString();
public string? StatusName => Creaturelib.Generated.Creature.GetStatusName(Ptr).PtrString();
public void Initialize()
{
@ -490,12 +490,12 @@ namespace PkmnLibSharp.Battling
public void SetStatus(string name)
{
Pkmnlib.Generated.Pokemon.SetStatus(Ptr, name.ToPtr());
Creaturelib.Generated.Creature.SetStatus(Ptr, name.ToPtr());
}
public void ClearStatus()
{
Pkmnlib.Generated.Pokemon.ClearStatus(Ptr);
Creaturelib.Generated.Creature.ClearStatus(Ptr);
}
public void ChangeFriendship(sbyte amount)

View File

@ -0,0 +1,13 @@
namespace PkmnLibSharp.Battling
{
public enum ScriptCategory
{
Attack = 0,
Talent = 1,
Status = 2,
Creature = 3,
Battle = 4,
Side = 5,
Weather = 128,
}
}

View File

@ -369,5 +369,21 @@ namespace Creaturelib.Generated
[DllImport("libCreatureLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_Creature_SwapAttack")]
internal static extern byte SwapAttack(IntPtr p, ulong a, ulong b);
/// <param name="p">Creature *</param>
/// <param name="name">const char *</param>
/// <returns>unsigned char</returns>
[DllImport("libCreatureLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_Creature_SetStatus")]
internal static extern byte SetStatus(IntPtr p, IntPtr name);
/// <param name="p">Creature *</param>
/// <returns>unsigned char</returns>
[DllImport("libCreatureLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_Creature_ClearStatus")]
internal static extern byte ClearStatus(IntPtr p);
/// <param name="p">Creature *</param>
/// <returns>const char *</returns>
[DllImport("libCreatureLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_Creature_GetStatusName")]
internal static extern IntPtr GetStatusName(IntPtr p);
}
}

View File

@ -21,5 +21,6 @@ namespace Creaturelib
ChangeStatBoost = 12,
Fail = 13,
Swap = 14,
StatusChange = 15,
}
}

View File

@ -41,6 +41,13 @@ namespace Pkmnlib.Generated
[DllImport("libpkmnLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "PkmnLib_AngelScriptResolver_LoadScript")]
internal static extern byte LoadScript(ref IntPtr @out, IntPtr p, ScriptCategory category, IntPtr scriptName);
/// <param name="out">const EvolutionScript * &</param>
/// <param name="p">AngelScriptResolver *</param>
/// <param name="scriptName">const char *</param>
/// <returns>unsigned char</returns>
[DllImport("libpkmnLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "PkmnLib_AngelScriptResolver_LoadEvolutionScript")]
internal static extern byte LoadEvolutionScript(ref IntPtr @out, IntPtr p, IntPtr scriptName);
/// <param name="p">AngelScriptResolver *</param>
/// <param name="file">const char *</param>
/// <param name="stripDebugInfo">bool</param>

View File

@ -21,5 +21,6 @@ namespace Pkmnlib
ChangeStatBoost = 12,
Fail = 13,
Swap = 14,
StatusChange = 15,
}
}

View File

@ -0,0 +1,18 @@
// AUTOMATICALLY GENERATED, DO NOT EDIT
using System;
using System.Runtime.InteropServices;
namespace Pkmnlib.Generated
{
internal static class EvolutionScript
{
/// <param name="script">EvolutionScript *</param>
/// <param name="evoData">const EvolutionData *</param>
/// <param name="pokemon">const Pokemon *</param>
/// <param name="out">bool *</param>
/// <returns>unsigned char</returns>
[DllImport("libpkmnLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "PkmnLib_EvolutionScript_DoesEvolveFromLevelUp")]
internal static extern byte DoesEvolveFromLevelUp(IntPtr script, IntPtr evoData, IntPtr pokemon, IntPtr @out);
}
}

View File

@ -6,14 +6,23 @@ namespace Pkmnlib.Generated
{
internal static class MiscLibrary
{
/// <param name="getTime">Function *</param>
/// <returns>MiscLibrary *</returns>
[DllImport("libpkmnLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "PkmnLib_MiscLibrary_Construct")]
internal static extern IntPtr Construct();
internal static extern IntPtr Construct(IntPtr getTime);
/// <param name="p">MiscLibrary *</param>
/// <returns>void</returns>
[DllImport("libpkmnLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "PkmnLib_MiscLibrary_Destruct")]
internal static extern void Destruct(IntPtr p);
/// <param name="out">bool &</param>
/// <param name="p">MiscLibrary *</param>
/// <param name="evoData">const EvolutionData *</param>
/// <param name="pokemon">const Pokemon *</param>
/// <returns>unsigned char</returns>
[DllImport("libpkmnLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "PkmnLib_MiscLibrary_CanEvolveFromLevelUp")]
internal static extern byte CanEvolveFromLevelUp(ref byte @out, IntPtr p, IntPtr evoData, IntPtr pokemon);
}
}

View File

@ -7,6 +7,5 @@ namespace Pkmnlib
internal enum PkmnEventDataKind : byte
{
WeatherChange = 128,
StatusChange = 129,
}
}

View File

@ -7,6 +7,5 @@ namespace Pkmnlib
internal enum PkmnScriptCategory : byte
{
Weather = 128,
Status = 129,
}
}

View File

@ -81,22 +81,6 @@ namespace Pkmnlib.Generated
[DllImport("libpkmnLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "PkmnLib_Pokemon_SetEffortValue")]
internal static extern void SetEffortValue(IntPtr p, Statistic stat, byte value);
/// <param name="p">Pokemon *</param>
/// <param name="name">const char *</param>
/// <returns>unsigned char</returns>
[DllImport("libpkmnLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "PkmnLib_Pokemon_SetStatus")]
internal static extern byte SetStatus(IntPtr p, IntPtr name);
/// <param name="p">Pokemon *</param>
/// <returns>unsigned char</returns>
[DllImport("libpkmnLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "PkmnLib_Pokemon_ClearStatus")]
internal static extern byte ClearStatus(IntPtr p);
/// <param name="p">Pokemon *</param>
/// <returns>const char *</returns>
[DllImport("libpkmnLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "PkmnLib_Pokemon_GetStatusName")]
internal static extern IntPtr GetStatusName(IntPtr p);
/// <param name="p">const Pokemon *</param>
/// <returns>unsigned char</returns>
[DllImport("libpkmnLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "PkmnLib_Pokemon_GetFriendship")]

Binary file not shown.

BIN
PkmnLibSharp/Native/Linux/libpkmnLib.so (Stored with Git LFS)

Binary file not shown.

Binary file not shown.

BIN
PkmnLibSharp/Native/Windows/libpkmnLib.dll (Stored with Git LFS)

Binary file not shown.

Binary file not shown.

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long