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; namespace PkmnLibSharp.Battling { public class MiscLibrary : PointerWrapper { private delegate TimeOfDay GetTimeDelegate(); internal MiscLibrary(IntPtr ptr) : base(ptr) { } 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) { byte b = 0; Creaturelib.Generated.MiscLibrary.IsCritical(ref b, Ptr, move, target.Ptr, hitNumber).Assert(); return b == MarshalHelper.True; } public bool CanFlee(IntPtr switchChoice) { byte b = 0; Creaturelib.Generated.MiscLibrary.CanFlee(ref b, Ptr, switchChoice).Assert(); return b == MarshalHelper.True; } public BaseTurnChoice ReplacementMove(Pokemon user, byte sideTarget, byte creatureTarget) { var b = IntPtr.Zero; Creaturelib.Generated.MiscLibrary.ReplacementAttack(ref b, Ptr, user.Ptr, sideTarget, creatureTarget) .Assert(); if (TryResolvePointer(b, out BaseTurnChoice? choice)) { return choice!; } 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() { Pkmnlib.Generated.MiscLibrary.Destruct(Ptr); } } }