Adds ChangeStatBoostEvent, fixes issue where ExecutingMove would create default LearnedMove, instead of potential inheritor.

This commit is contained in:
Deukhoofd 2021-01-31 12:48:02 +01:00
parent d38338ddc3
commit 9f30f411cc
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
18 changed files with 121 additions and 18 deletions

View File

@ -15,8 +15,8 @@ namespace PkmnLibSharp.Battling
var ptr = Creaturelib.Generated.ExecutingAttack.GetAttack(Ptr); var ptr = Creaturelib.Generated.ExecutingAttack.GetAttack(Ptr);
if (TryResolvePointer(ptr, out _move)) if (TryResolvePointer(ptr, out _move))
return _move!; return _move!;
_move = new LearnedMove(ptr); _move = Constructor.Active.ConstructLearnedMove(ptr);
return _move; return _move!;
} }
} }
public Pokemon User public Pokemon User

View File

@ -84,12 +84,14 @@ namespace PkmnLibSharp.Battling.Events
return new ChangeFormeEvent(evtType, ptr); return new ChangeFormeEvent(evtType, ptr);
case EventDataKind.AttackUse: case EventDataKind.AttackUse:
return new MoveUseEvent(evtType, ptr); return new MoveUseEvent(evtType, ptr);
case EventDataKind.ChangeStatBoost:
return new ChangeStatBoostEvent(evtType, ptr);
case EventDataKind.WeatherChange: case EventDataKind.WeatherChange:
break; break;
case EventDataKind.StatusChange: case EventDataKind.StatusChange:
break; break;
default: default:
throw new ArgumentOutOfRangeException($"Unknown event kind: " + evtType); throw new ArgumentOutOfRangeException();
} }
throw new NotImplementedException($"Unhandled battle event: '{evtType}'"); throw new NotImplementedException($"Unhandled battle event: '{evtType}'");
} }

View File

@ -0,0 +1,37 @@
using System;
using PkmnLibSharp.Utilities;
using Statistic = PkmnLibSharp.Library.Statistic;
namespace PkmnLibSharp.Battling.Events
{
public class ChangeStatBoostEvent : EventData
{
internal ChangeStatBoostEvent(EventDataKind kind, IntPtr ptr) : base(kind, ptr)
{
}
public Pokemon Pokemon
{
get
{
if (_pokemon != null) return _pokemon;
var ptr = Creaturelib.Generated.ChangeStatBoostEvent.GetCreature(Ptr);
if (TryResolvePointer(ptr, out _pokemon))
return _pokemon!;
_pokemon = Constructor.Active.ConstructPokemon(ptr)!;
return _pokemon;
}
}
public Statistic Statistic => (Statistic) Creaturelib.Generated.ChangeStatBoostEvent.GetStatistic(Ptr);
public sbyte OldValue => Creaturelib.Generated.ChangeStatBoostEvent.GetOldValue(Ptr);
public sbyte NewValue => Creaturelib.Generated.ChangeStatBoostEvent.GetNewValue(Ptr);
private Pokemon? _pokemon;
protected override void DeletePtr()
{
Creaturelib.Generated.ChangeStatBoostEvent.Destruct(Ptr);
}
}
}

View File

@ -14,6 +14,7 @@ namespace PkmnLibSharp.Battling.Events
ChangeSpecies = 9, ChangeSpecies = 9,
ChangeVariant = 10, ChangeVariant = 10,
AttackUse = 11, AttackUse = 11,
ChangeStatBoost = 12,
WeatherChange = 128, WeatherChange = 128,
StatusChange = 129, StatusChange = 129,

View File

@ -1,3 +1,5 @@
using System;
using System.Runtime.InteropServices;
using PkmnLibSharp.Utilities; using PkmnLibSharp.Utilities;
namespace PkmnLibSharp.Battling namespace PkmnLibSharp.Battling
@ -18,6 +20,21 @@ namespace PkmnLibSharp.Battling
Pkmnlib.Generated.AngelScriptResolver.CreateScript(Ptr, name.ToPtr(), script.ToPtr()).Assert(); Pkmnlib.Generated.AngelScriptResolver.CreateScript(Ptr, name.ToPtr(), script.ToPtr()).Assert();
} }
public void LoadByteCodeFromMemory(byte[] data)
{
var pinnedArray = GCHandle.Alloc(data, GCHandleType.Pinned);
var pointer = pinnedArray.AddrOfPinnedObject();
Pkmnlib.Generated.AngelScriptResolver.LoadByteCodeFromMemory(Ptr, pointer, (ulong) data.Length).Assert();
pinnedArray.Free();
}
public unsafe delegate void* GlobalMethod(void* parameter);
public void RegisterGlobalMethod(string methodName, GlobalMethod method)
{
var methodPtr = Marshal.GetFunctionPointerForDelegate(method);
Pkmnlib.Generated.AngelScriptResolver.RegisterGlobalMethod(Ptr, methodName.ToPtr(), methodPtr).Assert();
}
public void FinalizeModule() public void FinalizeModule()
{ {
Pkmnlib.Generated.AngelScriptResolver.FinalizeModule(Ptr).Assert(); Pkmnlib.Generated.AngelScriptResolver.FinalizeModule(Ptr).Assert();

View File

@ -0,0 +1,35 @@
// AUTOMATICALLY GENERATED, DO NOT EDIT
using System;
using System.Runtime.InteropServices;
namespace Creaturelib.Generated
{
internal static class ChangeStatBoostEvent
{
/// <param name="p">const ChangeStatBoostEvent *</param>
/// <returns>const Creature *</returns>
[DllImport("libCreatureLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_ChangeStatBoostEvent_GetCreature")]
internal static extern IntPtr GetCreature(IntPtr p);
/// <param name="p">const ChangeStatBoostEvent *</param>
/// <returns>Statistic</returns>
[DllImport("libCreatureLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_ChangeStatBoostEvent_GetStatistic")]
internal static extern Statistic GetStatistic(IntPtr p);
/// <param name="p">const ChangeStatBoostEvent *</param>
/// <returns>signed char</returns>
[DllImport("libCreatureLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_ChangeStatBoostEvent_GetOldValue")]
internal static extern sbyte GetOldValue(IntPtr p);
/// <param name="p">const ChangeStatBoostEvent *</param>
/// <returns>signed char</returns>
[DllImport("libCreatureLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_ChangeStatBoostEvent_GetNewValue")]
internal static extern sbyte GetNewValue(IntPtr p);
/// <param name="p">const ChangeStatBoostEvent *</param>
/// <returns>void</returns>
[DllImport("libCreatureLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_ChangeStatBoostEvent_Destruct")]
internal static extern void Destruct(IntPtr p);
}
}

View File

@ -18,5 +18,6 @@ namespace Creaturelib
ChangeSpecies = 9, ChangeSpecies = 9,
ChangeVariant = 10, ChangeVariant = 10,
AttackUse = 11, AttackUse = 11,
ChangeStatBoost = 12,
} }
} }

View File

@ -10,5 +10,9 @@ namespace Pkmnlib.Generated
[DllImport("libpkmnLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "PkmnLib_C_GetLastException")] [DllImport("libpkmnLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "PkmnLib_C_GetLastException")]
internal static extern IntPtr GetLastException(); internal static extern IntPtr GetLastException();
/// <returns>const char *</returns>
[DllImport("libpkmnLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "PkmnLib_C_GetLastExceptionStacktrace")]
internal static extern IntPtr GetLastExceptionStacktrace();
} }
} }

View File

@ -18,5 +18,6 @@ namespace Pkmnlib
ChangeSpecies = 9, ChangeSpecies = 9,
ChangeVariant = 10, ChangeVariant = 10,
AttackUse = 11, AttackUse = 11,
ChangeStatBoost = 12,
} }
} }

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

Binary file not shown.

Binary file not shown.

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

Binary file not shown.

Binary file not shown.

Binary file not shown.

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

Binary file not shown.

View File

@ -12,12 +12,17 @@ namespace PkmnLibSharp.Utilities
case 1: case 1:
throw new NativeException("Arbutils", C.GetLastException().PtrString()!, null); throw new NativeException("Arbutils", C.GetLastException().PtrString()!, null);
case 2: case 2:
{
var message = Creaturelib.Generated.C.GetLastException().PtrString()!; var message = Creaturelib.Generated.C.GetLastException().PtrString()!;
var stack = Creaturelib.Generated.C.GetLastExceptionStacktrace().PtrString(); var stack = Creaturelib.Generated.C.GetLastExceptionStacktrace().PtrString();
throw new NativeException("CreatureLibLibrary", message, stack); throw new NativeException("CreatureLibLibrary", message, stack);
}
case 4: case 4:
throw new NativeException("PkmnLib", {
Pkmnlib.Generated.C.GetLastException().PtrString()!, null); var message = Pkmnlib.Generated.C.GetLastException().PtrString()!;
var stack = Pkmnlib.Generated.C.GetLastExceptionStacktrace().PtrString();
throw new NativeException("PkmnLib", message, stack);
}
} }
} }
} }

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long