Support for Pokemon building.

This commit is contained in:
Deukhoofd 2020-07-19 12:33:22 +02:00
parent 049eb480c0
commit c143235495
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
23 changed files with 250 additions and 76 deletions

View File

@ -10,13 +10,9 @@ Global
Release|Any CPU = Release|Any CPU Release|Any CPU = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4CB6DA3C-017B-4AE0-B889-3DFE6B969CD0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {4CB6DA3C-017B-4AE0-B889-3DFE6B969CD0}.Debug|Any CPU.ActiveCfg = Release|x86_64
{4CB6DA3C-017B-4AE0-B889-3DFE6B969CD0}.Debug|Any CPU.Build.0 = Debug|Any CPU {4CB6DA3C-017B-4AE0-B889-3DFE6B969CD0}.Debug|Any CPU.Build.0 = Release|x86_64
{4CB6DA3C-017B-4AE0-B889-3DFE6B969CD0}.Release|Any CPU.ActiveCfg = Release|Any CPU {0D15FD33-1AEA-44F4-8211-AA8AF97EA534}.Debug|Any CPU.ActiveCfg = Debug|x86_64
{4CB6DA3C-017B-4AE0-B889-3DFE6B969CD0}.Release|Any CPU.Build.0 = Release|Any CPU {0D15FD33-1AEA-44F4-8211-AA8AF97EA534}.Debug|Any CPU.Build.0 = Debug|x86_64
{0D15FD33-1AEA-44F4-8211-AA8AF97EA534}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0D15FD33-1AEA-44F4-8211-AA8AF97EA534}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0D15FD33-1AEA-44F4-8211-AA8AF97EA534}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0D15FD33-1AEA-44F4-8211-AA8AF97EA534}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal

View File

@ -1,4 +1,6 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq; using System.Linq;
using PkmnLibSharp.Library; using PkmnLibSharp.Library;
using PkmnLibSharp.Utilities; using PkmnLibSharp.Utilities;
@ -9,19 +11,79 @@ namespace PkmnLibSharp.Battling
{ {
public class Pokemon : PointerWrapper public class Pokemon : PointerWrapper
{ {
public Pokemon(BattleLibrary library, Species species, Forme forme, byte level, uint experience, uint uid, public Pokemon([NotNull] BattleLibrary library, [NotNull] Species species, [NotNull] Forme forme,
Gender gender, byte coloring, Item heldItem, string nickname, bool hiddenAbility, byte abilityIndex, byte level, uint experience, uint uid,
IReadOnlyCollection<LearnedMove> moves, StatisticSet<byte> ivs, StatisticSet<byte> evs, Nature nature) : Gender gender, byte coloring, [MaybeNull] Item heldItem, [MaybeNull] string nickname, bool hiddenAbility, byte abilityIndex,
base(Pkmnlib.Generated.Pokemon.Construct(library.Ptr, species.Ptr, forme.Ptr, level, experience, [NotNull] IReadOnlyCollection<LearnedMove> moves, StatisticSet<byte> ivs, StatisticSet<byte> evs, [NotNull] Nature nature)
uid, (Pkmnlib.Gender) gender, coloring, heldItem.Ptr, nickname.ToPtr(), hiddenAbility.ToNative(), : base(Pkmnlib.Generated.Pokemon.Construct(
abilityIndex, library.Ptr, species.Ptr, forme.Ptr, level, experience,
moves.Select(x => x.Ptr).ToArray().ArrayPtr(), uid, (Pkmnlib.Gender) gender, coloring, heldItem?.Ptr ?? IntPtr.Zero, nickname.ToPtr(),
hiddenAbility.ToNative(), abilityIndex,
moves.Select(x => x?.Ptr ?? IntPtr.Zero).ToArray().ArrayPtr(),
(ulong) moves.Count, (ulong) moves.Count,
ivs.HP, ivs.Attack, ivs.Defense, ivs.SpecialAttack, ivs.HP, ivs.Attack, ivs.Defense, ivs.SpecialAttack,
ivs.SpecialDefense, ivs.Speed, evs.HP, evs.Attack, evs.Defense, ivs.SpecialDefense, ivs.Speed, evs.HP, evs.Attack, evs.Defense,
evs.SpecialAttack, evs.SpecialDefense, evs.Speed, nature.Ptr)) evs.SpecialAttack, evs.SpecialDefense, evs.Speed, nature.Ptr))
{} {}
public Species Species
{
get
{
if (_species != null) return _species;
var ptr = Creaturelibbattling.Generated.Creature.GetSpecies(Ptr);
if (TryResolvePointer(ptr, out _species))
return _species;
_species = new Species(ptr);
return _species;
}
}
public Forme Forme
{
get
{
if (_forme != null) return _forme;
var ptr = Creaturelibbattling.Generated.Creature.GetVariant(Ptr);
if (TryResolvePointer(ptr, out _forme))
return _forme;
_forme = new Forme(ptr);
return _forme;
}
}
public byte Level => Creaturelibbattling.Generated.Creature.GetLevel(Ptr);
public uint Experience => Creaturelibbattling.Generated.Creature.GetExperience(Ptr);
public Gender Gender => (Gender) Creaturelibbattling.Generated.Creature.GetGender(Ptr);
public byte Coloring => Creaturelibbattling.Generated.Creature.GetColoring(Ptr);
public bool IsShiny => Coloring == 1;
public string Nickname
{
get
{
if (_nickname != null) return _nickname;
_nickname = Creaturelibbattling.Generated.Creature.GetNickname(Ptr).PtrString();
return _nickname;
}
}
public void ChangeForme(Forme forme)
{
_forme = null;
Creaturelibbattling.Generated.Creature.ChangeVariant(Ptr, forme.Ptr);
}
public bool HasHeldItem(string itemName)
{
return Creaturelibbattling.Generated.Creature.HasHeldItem(Ptr, itemName.ToPtr()) == 1;
}
private Species _species;
private Forme _forme;
private string _nickname;
protected override void DeletePtr() protected override void DeletePtr()
{ {
Pkmnlib.Generated.Pokemon.Destruct(Ptr); Pkmnlib.Generated.Pokemon.Destruct(Ptr);

View File

@ -58,6 +58,12 @@ namespace PkmnLibSharp.Battling
return this; return this;
} }
public PokemonBuilder WithNickname(string nickname)
{
Nickname = nickname;
return this;
}
public PokemonBuilder LearnMove(string moveName, MoveLearnMethod moveLearnMethod) public PokemonBuilder LearnMove(string moveName, MoveLearnMethod moveLearnMethod)
{ {
if (LearnedMoves.Count > _library.StaticLibrary.Settings.MaximalMoves) if (LearnedMoves.Count > _library.StaticLibrary.Settings.MaximalMoves)
@ -107,7 +113,7 @@ namespace PkmnLibSharp.Battling
} }
} }
byte abilityIndex = 0; var abilityIndex = 0;
var isHiddenAbility = false; var isHiddenAbility = false;
if (string.IsNullOrEmpty(Ability)) if (string.IsNullOrEmpty(Ability))
{ {
@ -115,10 +121,10 @@ namespace PkmnLibSharp.Battling
} }
else else
{ {
abilityIndex = (byte) forme.Abilities.IndexOf(Ability); abilityIndex = forme.Abilities.IndexOf(Ability);
if (abilityIndex == -1) if (abilityIndex == -1)
{ {
abilityIndex = (byte) forme.HiddenAbilities.IndexOf(Ability); abilityIndex = forme.HiddenAbilities.IndexOf(Ability);
if (abilityIndex == -1) if (abilityIndex == -1)
{ {
throw new Exception( throw new Exception(
@ -148,7 +154,7 @@ namespace PkmnLibSharp.Battling
var nature = _library.StaticLibrary.NatureLibrary.GetNature(Nature); var nature = _library.StaticLibrary.NatureLibrary.GetNature(Nature);
return new Pokemon(_library, species, forme, Level, experience, uid, Gender, coloring, heldItem, Nickname, return new Pokemon(_library, species, forme, Level, experience, uid, Gender, coloring, heldItem, Nickname,
isHiddenAbility, abilityIndex, moves, IVs, EVs, nature); isHiddenAbility, (byte) abilityIndex, moves, IVs, EVs, nature);
} }
} }
} }

View File

@ -0,0 +1,14 @@
// AUTOMATICALLY GENERATED, DO NOT EDIT
using System;
using System.Runtime.InteropServices;
namespace Arbutils.Generated
{
internal static class C
{
/// <returns>const char *</returns>
[DllImport("Arbutils", CallingConvention = CallingConvention.Cdecl, EntryPoint= "Arbutils_C_GetLastException")]
internal static extern IntPtr GetLastException();
}
}

View File

@ -37,16 +37,18 @@ namespace Arbutils.Generated
/// <param name="p">Random *</param> /// <param name="p">Random *</param>
/// <param name="max">int</param> /// <param name="max">int</param>
/// <returns>int</returns> /// <param name="out">int &</param>
/// <returns>unsigned char</returns>
[DllImport("Arbutils", CallingConvention = CallingConvention.Cdecl, EntryPoint= "Arbutils_Random_GetWithMax")] [DllImport("Arbutils", CallingConvention = CallingConvention.Cdecl, EntryPoint= "Arbutils_Random_GetWithMax")]
internal static extern int GetWithMax(IntPtr p, int max); internal static extern byte GetWithMax(IntPtr p, int max, ref int @out);
/// <param name="p">Random *</param> /// <param name="p">Random *</param>
/// <param name="min">int</param> /// <param name="min">int</param>
/// <param name="max">int</param> /// <param name="max">int</param>
/// <returns>int</returns> /// <param name="out">int &</param>
/// <returns>unsigned char</returns>
[DllImport("Arbutils", CallingConvention = CallingConvention.Cdecl, EntryPoint= "Arbutils_Random_GetInLimits")] [DllImport("Arbutils", CallingConvention = CallingConvention.Cdecl, EntryPoint= "Arbutils_Random_GetInLimits")]
internal static extern int GetInLimits(IntPtr p, int min, int max); internal static extern byte GetInLimits(IntPtr p, int min, int max, ref int @out);
/// <param name="p">Random *</param> /// <param name="p">Random *</param>
/// <returns>unsigned int</returns> /// <returns>unsigned int</returns>
@ -55,16 +57,18 @@ namespace Arbutils.Generated
/// <param name="p">Random *</param> /// <param name="p">Random *</param>
/// <param name="max">unsigned int</param> /// <param name="max">unsigned int</param>
/// <returns>unsigned int</returns> /// <param name="out">unsigned int &</param>
/// <returns>unsigned char</returns>
[DllImport("Arbutils", CallingConvention = CallingConvention.Cdecl, EntryPoint= "Arbutils_Random_GetUnsignedWithMax")] [DllImport("Arbutils", CallingConvention = CallingConvention.Cdecl, EntryPoint= "Arbutils_Random_GetUnsignedWithMax")]
internal static extern uint GetUnsignedWithMax(IntPtr p, uint max); internal static extern byte GetUnsignedWithMax(IntPtr p, uint max, ref uint @out);
/// <param name="p">Random *</param> /// <param name="p">Random *</param>
/// <param name="min">unsigned int</param> /// <param name="min">unsigned int</param>
/// <param name="max">unsigned int</param> /// <param name="max">unsigned int</param>
/// <returns>unsigned int</returns> /// <param name="out">unsigned int &</param>
/// <returns>unsigned char</returns>
[DllImport("Arbutils", CallingConvention = CallingConvention.Cdecl, EntryPoint= "Arbutils_Random_GetUnsignedInLimits")] [DllImport("Arbutils", CallingConvention = CallingConvention.Cdecl, EntryPoint= "Arbutils_Random_GetUnsignedInLimits")]
internal static extern uint GetUnsignedInLimits(IntPtr p, uint min, uint max); internal static extern byte GetUnsignedInLimits(IntPtr p, uint min, uint max, ref uint @out);
/// <param name="p">Random *</param> /// <param name="p">Random *</param>
/// <returns>long unsigned int</returns> /// <returns>long unsigned int</returns>

View File

@ -32,9 +32,10 @@ namespace Pkmnlib.Generated
/// <param name="p">NatureLibrary *</param> /// <param name="p">NatureLibrary *</param>
/// <param name="rand">Random *</param> /// <param name="rand">Random *</param>
/// <returns>const char *</returns> /// <param name="out">const char * &</param>
/// <returns>unsigned char</returns>
[DllImport("pkmnLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "PkmnLib_NatureLibrary_GetRandomNatureName")] [DllImport("pkmnLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "PkmnLib_NatureLibrary_GetRandomNatureName")]
internal static extern IntPtr GetRandomNatureName(IntPtr p, IntPtr rand); internal static extern byte GetRandomNatureName(IntPtr p, IntPtr rand, ref IntPtr @out);
/// <param name="p">NatureLibrary *</param> /// <param name="p">NatureLibrary *</param>
/// <param name="nature">const Nature *</param> /// <param name="nature">const Nature *</param>

View File

@ -120,10 +120,10 @@ namespace PkmnLibSharp.Library
var abilitiesConverted = abilities.Select(x => x.ToPtr()).ToArray(); var abilitiesConverted = abilities.Select(x => x.ToPtr()).ToArray();
var hiddenAbilitiesConverted = hiddenAbilities.Select(x => x.ToPtr()).ToArray(); var hiddenAbilitiesConverted = hiddenAbilities.Select(x => x.ToPtr()).ToArray();
var ab = abilitiesConverted.ArrayPtr(); var ab = abilitiesConverted.ArrayPtr();
var hab = abilitiesConverted.ArrayPtr(); var hab = hiddenAbilitiesConverted.ArrayPtr();
var ptr = SpeciesVariant.Construct(name.ToPtr(), height, weight, baseExperience, types.ArrayPtr(), var ptr = SpeciesVariant.Construct(name.ToPtr(), height, weight, baseExperience, types.ArrayPtr(),
(ulong) types.Length, baseHealth, baseAttack, baseDefense, baseSpecialAttack, (ulong) types.Length, baseHealth, baseAttack, baseDefense, baseSpecialAttack,
baseSpecialDefense, baseSpeed, (IntPtr) ab, (ulong) abilities.Length, (IntPtr) hab, baseSpecialDefense, baseSpeed, (IntPtr) ab, (ulong) abilities.Length, hab,
(ulong) hiddenAbilities.Length, moves.Ptr); (ulong) hiddenAbilities.Length, moves.Ptr);
var f = new Forme(ptr); var f = new Forme(ptr);
foreach (var intPtr in abilitiesConverted) foreach (var intPtr in abilitiesConverted)

View File

@ -57,7 +57,9 @@ namespace PkmnLibSharp.Library
public string GetRandomNatureName(Random random) public string GetRandomNatureName(Random random)
{ {
return Pkmnlib.Generated.NatureLibrary.GetRandomNatureName(Ptr, random.Ptr).PtrString(); IntPtr val = IntPtr.Zero;
Pkmnlib.Generated.NatureLibrary.GetRandomNatureName(Ptr, random.Ptr, ref val).Assert();
return val.PtrString();
} }
protected override void DeletePtr() protected override void DeletePtr()

View File

@ -2,7 +2,7 @@ using System;
namespace PkmnLibSharp.Library namespace PkmnLibSharp.Library
{ {
public class StatisticSet<T> where T : IComparable<T> public struct StatisticSet<T> where T : IComparable<T>
{ {
public T HP { get; set; } public T HP { get; set; }
public T Attack { get; set; } public T Attack { get; set; }

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

Binary file not shown.

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

Binary file not shown.

Binary file not shown.

Binary file not shown.

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

Binary file not shown.

View File

@ -2,23 +2,12 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework> <TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup> <Configurations>Release;Debug</Configurations>
<Platforms>x86_64</Platforms>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Content Include="Native/*.so.*" CopyToOutputDirectory="Always" CopyToPublishDirectory="Always" Link="%(Filename)%(Extension)"></Content> <Content Include="Native/*.so.*" CopyToOutputDirectory="Always" CopyToPublishDirectory="Always" Link="%(Filename)%(Extension)"></Content>
</ItemGroup> </ItemGroup>
<ItemGroup>
<Reference Include="System.Collections.Immutable, Version=1.2.5.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<HintPath>..\..\..\..\..\..\usr\share\dotnet\packs\Microsoft.NETCore.App.Ref\3.1.0\ref\netcoreapp3.1\System.Collections.Immutable.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="System.Collections.Immutable" Version="1.7.0" /> <PackageReference Include="System.Collections.Immutable" Version="1.7.0" />
</ItemGroup> </ItemGroup>

View File

@ -8,12 +8,14 @@ namespace PkmnLibSharp.Utilities
{ {
internal static IntPtr ToPtr(this string s) internal static IntPtr ToPtr(this string s)
{ {
return Marshal.StringToHGlobalAuto(s); if (s == null) return IntPtr.Zero;
return Marshal.StringToHGlobalAnsi(s);
} }
internal static string PtrString(this IntPtr i) internal static string PtrString(this IntPtr i)
{ {
return Marshal.PtrToStringAuto(i); if (i == IntPtr.Zero) return null;
return Marshal.PtrToStringAnsi(i);
} }
internal static IntPtr ArrayPtr(this Array a) internal static IntPtr ArrayPtr(this Array a)

View File

@ -1,3 +1,5 @@
using System;
namespace PkmnLibSharp.Utilities namespace PkmnLibSharp.Utilities
{ {
public class Random : PointerWrapper public class Random : PointerWrapper
@ -27,12 +29,16 @@ namespace PkmnLibSharp.Utilities
public int Get(int max) public int Get(int max)
{ {
return Arbutils.Generated.Random.GetWithMax(Ptr, max); int val = 0;
Arbutils.Generated.Random.GetWithMax(Ptr, max, ref val).Assert();
return val;
} }
public int Get(int min, int max) public int Get(int min, int max)
{ {
return Arbutils.Generated.Random.GetInLimits(Ptr, min, max); int val = 0;
Arbutils.Generated.Random.GetInLimits(Ptr, min, max, ref val).Assert();
return val;
} }
public uint GetUnsigned() public uint GetUnsigned()
@ -42,12 +48,16 @@ namespace PkmnLibSharp.Utilities
public uint GetUnsigned(uint max) public uint GetUnsigned(uint max)
{ {
return Arbutils.Generated.Random.GetUnsignedWithMax(Ptr, max); uint val = 0;
Arbutils.Generated.Random.GetUnsignedWithMax(Ptr, max, ref val).Assert();
return val;
} }
public uint GetUnsigned(uint min, uint max) public uint GetUnsigned(uint min, uint max)
{ {
return Arbutils.Generated.Random.GetUnsignedInLimits(Ptr, min, max); uint val = 0;
Arbutils.Generated.Random.GetUnsignedInLimits(Ptr, min, max, ref val).Assert();
return val;
} }

View File

@ -6,14 +6,16 @@ namespace PkmnLibSharp.Utilities
{ {
internal static void Assert(this byte result) internal static void Assert(this byte result)
{ {
if (result == 0) return; switch (result)
if (result == 1)
{ {
throw new NativeException("CreatureLib", Creatureliblibrary.Generated.C.GetLastException().PtrString()); case 0: return;
} case 1:
if (result == 2) throw new NativeException("CreatureLib",
{ Creatureliblibrary.Generated.C.GetLastException().PtrString());
throw new NativeException("PkmnLib", Pkmnlib.Generated.C.GetLastException().PtrString()); case 2:
throw new NativeException("PkmnLib", Pkmnlib.Generated.C.GetLastException().PtrString());
case 3:
throw new NativeException("Arbutils", Arbutils.Generated.C.GetLastException().PtrString());
} }
} }
} }

View File

@ -1 +1 @@
{"enums":[],"functions":[{"filename":"Arbutils","name":"Arbutils_Random_Construct","parameters":[],"returns":"Random *"},{"filename":"Arbutils","name":"Arbutils_Random_ConstructWithSeed","parameters":[{"name":"seed","type":"long unsigned int"}],"returns":"Random *"},{"filename":"Arbutils","name":"Arbutils_Random_Destruct","parameters":[{"name":"p","type":"Random *"}],"returns":"void"},{"filename":"Arbutils","name":"Arbutils_Random_GetFloat","parameters":[{"name":"p","type":"Random *"}],"returns":"float"},{"filename":"Arbutils","name":"Arbutils_Random_GetDouble","parameters":[{"name":"p","type":"Random *"}],"returns":"double"},{"filename":"Arbutils","name":"Arbutils_Random_Get","parameters":[{"name":"p","type":"Random *"}],"returns":"int"},{"filename":"Arbutils","name":"Arbutils_Random_GetWithMax","parameters":[{"name":"p","type":"Random *"},{"name":"max","type":"int"}],"returns":"int"},{"filename":"Arbutils","name":"Arbutils_Random_GetInLimits","parameters":[{"name":"p","type":"Random *"},{"name":"min","type":"int"},{"name":"max","type":"int"}],"returns":"int"},{"filename":"Arbutils","name":"Arbutils_Random_GetUnsigned","parameters":[{"name":"p","type":"Random *"}],"returns":"unsigned int"},{"filename":"Arbutils","name":"Arbutils_Random_GetUnsignedWithMax","parameters":[{"name":"p","type":"Random *"},{"name":"max","type":"unsigned int"}],"returns":"unsigned int"},{"filename":"Arbutils","name":"Arbutils_Random_GetUnsignedInLimits","parameters":[{"name":"p","type":"Random *"},{"name":"min","type":"unsigned int"},{"name":"max","type":"unsigned int"}],"returns":"unsigned int"},{"filename":"Arbutils","name":"Arbutils_Random_GetSeed","parameters":[{"name":"p","type":"Random *"}],"returns":"long unsigned int"}]} {"enums":[],"functions":[{"filename":"Arbutils","name":"Arbutils_C_GetLastException","parameters":[],"returns":"const char *"},{"filename":"Arbutils","name":"Arbutils_Random_Construct","parameters":[],"returns":"Random *"},{"filename":"Arbutils","name":"Arbutils_Random_ConstructWithSeed","parameters":[{"name":"seed","type":"long unsigned int"}],"returns":"Random *"},{"filename":"Arbutils","name":"Arbutils_Random_Destruct","parameters":[{"name":"p","type":"Random *"}],"returns":"void"},{"filename":"Arbutils","name":"Arbutils_Random_GetFloat","parameters":[{"name":"p","type":"Random *"}],"returns":"float"},{"filename":"Arbutils","name":"Arbutils_Random_GetDouble","parameters":[{"name":"p","type":"Random *"}],"returns":"double"},{"filename":"Arbutils","name":"Arbutils_Random_Get","parameters":[{"name":"p","type":"Random *"}],"returns":"int"},{"filename":"Arbutils","name":"Arbutils_Random_GetWithMax","parameters":[{"name":"p","type":"Random *"},{"name":"max","type":"int"},{"name":"out","type":"int &"}],"returns":"unsigned char"},{"filename":"Arbutils","name":"Arbutils_Random_GetInLimits","parameters":[{"name":"p","type":"Random *"},{"name":"min","type":"int"},{"name":"max","type":"int"},{"name":"out","type":"int &"}],"returns":"unsigned char"},{"filename":"Arbutils","name":"Arbutils_Random_GetUnsigned","parameters":[{"name":"p","type":"Random *"}],"returns":"unsigned int"},{"filename":"Arbutils","name":"Arbutils_Random_GetUnsignedWithMax","parameters":[{"name":"p","type":"Random *"},{"name":"max","type":"unsigned int"},{"name":"out","type":"unsigned int &"}],"returns":"unsigned char"},{"filename":"Arbutils","name":"Arbutils_Random_GetUnsignedInLimits","parameters":[{"name":"p","type":"Random *"},{"name":"min","type":"unsigned int"},{"name":"max","type":"unsigned int"},{"name":"out","type":"unsigned int &"}],"returns":"unsigned char"},{"filename":"Arbutils","name":"Arbutils_Random_GetSeed","parameters":[{"name":"p","type":"Random *"}],"returns":"long unsigned int"}]}

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,49 @@
using System.Linq;
using PkmnLibSharp.Battling;
using PkmnLibSharp.Library;
using PkmnLibSharp.Library.GrowthRates;
using PkmnLibSharp.Library.Items;
using PkmnLibSharp.Library.Moves;
namespace PkmnLibSharpTests.Battling
{
public static class BattleLibraryHelper
{
private static BattleLibrary _cache;
public static BattleLibrary GetLibrary()
{
if (_cache != null) return _cache;
_cache = BattleLibrary.Create(BuildStatic(), new StatCalculator(), new DamageLibrary(),
new ExperienceLibrary(),
new AngelScriptResolver(), new MiscLibrary());
return _cache;
}
private static PokemonLibrary BuildStatic()
{
var settings = new LibrarySettings(100, 4, 4096);
var species = new SpeciesLibrary(10);
species.Insert("testSpecies", Species.Create(1, "testSpecies",
Forme.Create("default", 10f, 10f, 100, new byte[] {0, 1}, 100,
100, 100, 100, 100, 100, new[] {"testAbility", "testAbility2"},
new[] {"testHiddenAbility"}, LearnableMoves.Create(100)), 0.5f, "growthRate",
20, 100));
var moves = MoveLibrary.Create(10);
var items = new ItemLibrary(10);
items.Insert("testItem", Item.Create("testItem", ItemCategory.MiscItem, BattleItemCategory.None,
500, new string[] { }, 20));
var gr = new GrowthRateLibrary(10);
gr.AddGrowthRate("growthRate",
new LookupGrowthRate(
Enumerable.Range(1, 100).Select(x => (uint)x * 100).ToArray()));
var types = new TypeLibrary(10);
var natures = new NatureLibrary(10);
natures.LoadNature("testNature", new Nature());
var lib = PokemonLibrary.Create(settings, species, moves, items, gr, types, natures);
return lib;
}
}
}

View File

@ -0,0 +1,40 @@
using NUnit.Framework;
using PkmnLibSharp.Battling;
namespace PkmnLibSharpTests.Battling
{
public class PokemonBuilderTests
{
[Test]
public void SimpleBuildPokemon()
{
var lib = BattleLibraryHelper.GetLibrary();
var pokemon = new PokemonBuilder(lib, "testSpecies", 50)
.Build();
Assert.AreEqual("testSpecies", pokemon.Species.Name);
Assert.AreEqual(50, pokemon.Level);
Assert.AreEqual("default", pokemon.Forme.Name);
}
[Test]
public void BuildPokemonWithNickname()
{
var lib = BattleLibraryHelper.GetLibrary();
var pokemon = new PokemonBuilder(lib, "testSpecies", 50)
.WithNickname("cuteNickname")
.Build();
Assert.AreEqual("cuteNickname", pokemon.Nickname);
}
[Test]
public void BuildPokemonWithGender()
{
var lib = BattleLibraryHelper.GetLibrary();
var pokemon = new PokemonBuilder(lib, "testSpecies", 50)
.WithGender(Gender.Female)
.Build();
Assert.AreEqual(Gender.Female, pokemon.Gender);
}
}
}

View File

@ -4,6 +4,10 @@
<TargetFramework>netcoreapp3.1</TargetFramework> <TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable> <IsPackable>false</IsPackable>
<Configurations>Debug;Release</Configurations>
<Platforms>x86_64</Platforms>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
@ -16,8 +20,4 @@
<ProjectReference Include="..\PkmnLibSharp\PkmnLibSharp.csproj" /> <ProjectReference Include="..\PkmnLibSharp\PkmnLibSharp.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="Battling" />
</ItemGroup>
</Project> </Project>