Initial work on battle side.
This commit is contained in:
@@ -2,19 +2,23 @@ using System;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using Creatureliblibrary;
|
||||
using Creatureliblibrary.Generated;
|
||||
using PkmnLibSharp.Utilities;
|
||||
using Random = PkmnLibSharp.Utilities.Random;
|
||||
|
||||
namespace PkmnLibSharp.Library
|
||||
{
|
||||
public class Forme : PointerWrapper
|
||||
{
|
||||
private string _name;
|
||||
private ImmutableArray<byte> _types;
|
||||
private ImmutableArray<string> _abilities;
|
||||
private ImmutableArray<string> _hiddenAbilities;
|
||||
private LearnableMoves _moves;
|
||||
private string _name;
|
||||
private ImmutableArray<byte> _types;
|
||||
|
||||
internal Forme(IntPtr parent) : base(parent)
|
||||
{
|
||||
}
|
||||
|
||||
public string Name => _name ??= SpeciesVariant.GetName(Ptr).PtrString();
|
||||
public float Height => SpeciesVariant.GetHeight(Ptr);
|
||||
@@ -30,10 +34,7 @@ namespace PkmnLibSharp.Library
|
||||
|
||||
var typesCount = SpeciesVariant.GetTypeCount(Ptr);
|
||||
var types = new byte[typesCount];
|
||||
for (ulong i = 0; i < typesCount; i++)
|
||||
{
|
||||
types[i] = SpeciesVariant.GetType(Ptr, i);
|
||||
}
|
||||
for (ulong i = 0; i < typesCount; i++) types[i] = SpeciesVariant.GetType(Ptr, i);
|
||||
|
||||
_types = types.ToImmutableArray();
|
||||
return _types;
|
||||
@@ -63,7 +64,7 @@ namespace PkmnLibSharp.Library
|
||||
var abilities = new string[abilityCount];
|
||||
for (byte i = 0; i < abilityCount; i++)
|
||||
{
|
||||
IntPtr s = IntPtr.Zero;
|
||||
var s = IntPtr.Zero;
|
||||
SpeciesVariant.GetTalent(Ptr, MarshalHelper.False, i, ref s).Assert();
|
||||
abilities[i] = s.PtrString();
|
||||
}
|
||||
@@ -84,7 +85,7 @@ namespace PkmnLibSharp.Library
|
||||
var abilities = new string[abilityCount];
|
||||
for (byte i = 0; i < abilityCount; i++)
|
||||
{
|
||||
IntPtr s = IntPtr.Zero;
|
||||
var s = IntPtr.Zero;
|
||||
SpeciesVariant.GetTalent(Ptr, MarshalHelper.True, i, ref s).Assert();
|
||||
abilities[i] = s.PtrString();
|
||||
}
|
||||
@@ -100,10 +101,7 @@ namespace PkmnLibSharp.Library
|
||||
{
|
||||
if (_moves != null) return _moves;
|
||||
var movesPtr = SpeciesVariant.GetLearnableAttacks(Ptr);
|
||||
if (!TryResolvePointer(movesPtr, out _moves))
|
||||
{
|
||||
_moves = new LearnableMoves(movesPtr);
|
||||
}
|
||||
if (!TryResolvePointer(movesPtr, out _moves)) _moves = new LearnableMoves(movesPtr);
|
||||
|
||||
return _moves;
|
||||
}
|
||||
@@ -114,33 +112,30 @@ namespace PkmnLibSharp.Library
|
||||
return Types[index];
|
||||
}
|
||||
|
||||
public static unsafe Forme Create(string name, float height, float weight, uint baseExperience, byte[] types,
|
||||
public static Forme Create(string name, float height, float weight, uint baseExperience, byte[] types,
|
||||
ushort baseHealth, ushort baseAttack, ushort baseDefense, ushort baseSpecialAttack,
|
||||
ushort baseSpecialDefense, ushort baseSpeed, string[] abilities, string[] hiddenAbilities,
|
||||
LearnableMoves moves)
|
||||
{
|
||||
var abilitiesConverted = abilities.Select(x => x.ToPtr()).ToArray();
|
||||
var hiddenAbilitiesConverted = hiddenAbilities.Select(x => x.ToPtr()).ToArray();
|
||||
fixed (IntPtr* ab = abilitiesConverted)
|
||||
{
|
||||
fixed (IntPtr* hab = hiddenAbilitiesConverted)
|
||||
{
|
||||
var ptr = SpeciesVariant.Construct(name.ToPtr(), height, weight, baseExperience, types.ArrayPtr(),
|
||||
(ulong) types.Length, baseHealth, baseAttack, baseDefense, baseSpecialAttack,
|
||||
baseSpecialDefense, baseSpeed, (IntPtr) ab, (ulong) abilities.Length, (IntPtr) hab,
|
||||
(ulong) hiddenAbilities.Length, moves.Ptr);
|
||||
var f = new Forme(ptr);
|
||||
foreach (var intPtr in abilitiesConverted)
|
||||
Marshal.FreeHGlobal(intPtr);
|
||||
foreach (var intPtr in hiddenAbilitiesConverted)
|
||||
Marshal.FreeHGlobal(intPtr);
|
||||
return f;
|
||||
}
|
||||
}
|
||||
var ab = abilitiesConverted.ArrayPtr();
|
||||
var hab = abilitiesConverted.ArrayPtr();
|
||||
var ptr = SpeciesVariant.Construct(name.ToPtr(), height, weight, baseExperience, types.ArrayPtr(),
|
||||
(ulong) types.Length, baseHealth, baseAttack, baseDefense, baseSpecialAttack,
|
||||
baseSpecialDefense, baseSpeed, (IntPtr) ab, (ulong) abilities.Length, (IntPtr) hab,
|
||||
(ulong) hiddenAbilities.Length, moves.Ptr);
|
||||
var f = new Forme(ptr);
|
||||
foreach (var intPtr in abilitiesConverted)
|
||||
Marshal.FreeHGlobal(intPtr);
|
||||
foreach (var intPtr in hiddenAbilitiesConverted)
|
||||
Marshal.FreeHGlobal(intPtr);
|
||||
return f;
|
||||
}
|
||||
|
||||
internal Forme(IntPtr parent) : base(parent)
|
||||
public byte GetRandomAbility(Random rand)
|
||||
{
|
||||
return SpeciesVariant.GetRandomTalent(Ptr, rand.Ptr);
|
||||
}
|
||||
|
||||
protected internal override void MarkAsDeleted()
|
||||
|
||||
@@ -6,6 +6,6 @@ namespace PkmnLibSharp.Library.Items
|
||||
Healing = 1,
|
||||
StatusHealing = 2,
|
||||
Pokeball = 3,
|
||||
MiscBattleItem = 4,
|
||||
MiscBattleItem = 4
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,10 @@ namespace PkmnLibSharp.Library.Items
|
||||
{
|
||||
private string _name;
|
||||
|
||||
internal Item(IntPtr ptr) : base(ptr)
|
||||
{
|
||||
}
|
||||
|
||||
public string Name => _name ??= Creatureliblibrary.Generated.Item.GetName(Ptr).PtrString();
|
||||
public ItemCategory Category => (ItemCategory) Creatureliblibrary.Generated.Item.GetCategory(Ptr);
|
||||
|
||||
@@ -22,10 +26,6 @@ namespace PkmnLibSharp.Library.Items
|
||||
return Creatureliblibrary.Generated.Item.HasFlag(Ptr, s.ToPtr()) == MarshalHelper.True;
|
||||
}
|
||||
|
||||
internal Item(IntPtr ptr) : base(ptr)
|
||||
{
|
||||
}
|
||||
|
||||
public static Item Create(string name, ItemCategory category, BattleItemCategory battleCategory,
|
||||
int price,
|
||||
string[] flags, byte flingPower)
|
||||
|
||||
@@ -9,6 +9,6 @@ namespace PkmnLibSharp.Library
|
||||
TechnicalMachine = 4,
|
||||
FormeChanger = 5,
|
||||
KeyItem = 6,
|
||||
Mail = 7,
|
||||
Mail = 7
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,18 @@ namespace PkmnLibSharp.Library.Items
|
||||
{
|
||||
public class ItemLibrary : PointerWrapper
|
||||
{
|
||||
private readonly Dictionary<string, Item> _cache = new Dictionary<string, Item>(StringComparer.InvariantCultureIgnoreCase);
|
||||
private readonly Dictionary<string, Item> _cache =
|
||||
new Dictionary<string, Item>(StringComparer.InvariantCultureIgnoreCase);
|
||||
|
||||
internal ItemLibrary(IntPtr ptr) : base(ptr)
|
||||
{
|
||||
}
|
||||
|
||||
public ItemLibrary(ulong initialCapacity) : base(
|
||||
Creatureliblibrary.Generated.ItemLibrary.Construct(initialCapacity))
|
||||
{
|
||||
}
|
||||
|
||||
public ulong Count => Creatureliblibrary.Generated.ItemLibrary.GetCount(Ptr);
|
||||
|
||||
public void Insert(string key, Item item)
|
||||
@@ -26,13 +37,14 @@ namespace PkmnLibSharp.Library.Items
|
||||
if (_cache.TryGetValue(key, out item))
|
||||
return true;
|
||||
var ptr = IntPtr.Zero;
|
||||
if (Creatureliblibrary.Generated.ItemLibrary.TryGet(Ptr, key.ToPtr(), ref ptr) != MarshalHelper.True)
|
||||
if (Creatureliblibrary.Generated.ItemLibrary.TryGet(Ptr, key.ToPtr(), ref ptr) != MarshalHelper.True)
|
||||
return false;
|
||||
if (TryResolvePointer(ptr, out item))
|
||||
{
|
||||
_cache.Add(key, item);
|
||||
return true;
|
||||
}
|
||||
|
||||
item = new Item(ptr);
|
||||
_cache.Add(key, item);
|
||||
return true;
|
||||
@@ -49,33 +61,21 @@ namespace PkmnLibSharp.Library.Items
|
||||
_cache.Add(key, item);
|
||||
return item;
|
||||
}
|
||||
|
||||
item = new Item(ptr);
|
||||
_cache.Add(key, item);
|
||||
return item;
|
||||
}
|
||||
|
||||
internal ItemLibrary(IntPtr ptr) : base(ptr)
|
||||
{
|
||||
}
|
||||
|
||||
public ItemLibrary(ulong initialCapacity) : base(
|
||||
Creatureliblibrary.Generated.ItemLibrary.Construct(initialCapacity))
|
||||
{
|
||||
}
|
||||
|
||||
protected internal override void MarkAsDeleted()
|
||||
{
|
||||
base.MarkAsDeleted();
|
||||
foreach (var item in _cache)
|
||||
{
|
||||
item.Value.MarkAsDeleted();
|
||||
}
|
||||
foreach (var item in _cache) item.Value.MarkAsDeleted();
|
||||
}
|
||||
|
||||
protected override void DeletePtr()
|
||||
{
|
||||
Creatureliblibrary.Generated.ItemLibrary.Destruct(Ptr);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,6 @@ namespace PkmnLibSharp.Library.Moves
|
||||
{
|
||||
Physical = 0,
|
||||
Special = 1,
|
||||
Status = 2,
|
||||
Status = 2
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,8 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Creatureliblibrary;
|
||||
using Creatureliblibrary.Generated;
|
||||
using Pkmnlib;
|
||||
using PkmnLibSharp.Utilities;
|
||||
using AttackCategory = Creatureliblibrary.AttackCategory;
|
||||
|
||||
namespace PkmnLibSharp.Library.Moves
|
||||
{
|
||||
@@ -12,6 +11,10 @@ namespace PkmnLibSharp.Library.Moves
|
||||
private string _name;
|
||||
private string _secondaryEffectName;
|
||||
|
||||
internal MoveData(IntPtr ptr) : base(ptr)
|
||||
{
|
||||
}
|
||||
|
||||
public string Name => _name ??= AttackData.GetName(Ptr).PtrString();
|
||||
public byte Type => AttackData.GetType(Ptr);
|
||||
public MoveCategory Category => (MoveCategory) AttackData.GetCategory(Ptr);
|
||||
@@ -40,15 +43,11 @@ namespace PkmnLibSharp.Library.Moves
|
||||
var f = flags.Select(x => x.ToPtr()).ToArray().ArrayPtr();
|
||||
|
||||
AttackData.Construct(ref ptr, name.ToPtr(), type, (AttackCategory) category, power, accuracy, baseUsage,
|
||||
(Creatureliblibrary.AttackTarget) target, priority, effectChance, effectName.ToPtr(), pars,
|
||||
(AttackTarget) target, priority, effectChance, effectName.ToPtr(), pars,
|
||||
(ulong) parameters.Length, f, (ulong) flags.Length).Assert();
|
||||
return new MoveData(ptr);
|
||||
}
|
||||
|
||||
internal MoveData(IntPtr ptr) : base(ptr)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void DeletePtr()
|
||||
{
|
||||
AttackData.Destruct(Ptr);
|
||||
|
||||
@@ -7,7 +7,13 @@ namespace PkmnLibSharp.Library.Moves
|
||||
{
|
||||
public class MoveLibrary : PointerWrapper
|
||||
{
|
||||
private readonly Dictionary<string, MoveData> _cache = new Dictionary<string, MoveData>(StringComparer.InvariantCultureIgnoreCase);
|
||||
private readonly Dictionary<string, MoveData> _cache =
|
||||
new Dictionary<string, MoveData>(StringComparer.InvariantCultureIgnoreCase);
|
||||
|
||||
internal MoveLibrary(IntPtr ptr) : base(ptr)
|
||||
{
|
||||
}
|
||||
|
||||
public ulong Count => AttackLibrary.GetCount(Ptr);
|
||||
|
||||
public void Insert(string key, MoveData move)
|
||||
@@ -27,13 +33,14 @@ namespace PkmnLibSharp.Library.Moves
|
||||
if (_cache.TryGetValue(key, out move))
|
||||
return true;
|
||||
var ptr = IntPtr.Zero;
|
||||
if (AttackLibrary.TryGet(Ptr, key.ToPtr(), ref ptr) != MarshalHelper.True)
|
||||
if (AttackLibrary.TryGet(Ptr, key.ToPtr(), ref ptr) != MarshalHelper.True)
|
||||
return false;
|
||||
if (TryResolvePointer(ptr, out move))
|
||||
{
|
||||
_cache.Add(key, move);
|
||||
return true;
|
||||
}
|
||||
|
||||
move = new MoveData(ptr);
|
||||
_cache.Add(key, move);
|
||||
return true;
|
||||
@@ -50,6 +57,7 @@ namespace PkmnLibSharp.Library.Moves
|
||||
_cache.Add(key, move);
|
||||
return move;
|
||||
}
|
||||
|
||||
move = new MoveData(ptr);
|
||||
_cache.Add(key, move);
|
||||
return move;
|
||||
@@ -61,18 +69,11 @@ namespace PkmnLibSharp.Library.Moves
|
||||
AttackLibrary.Construct(ref ptr, defaultCapacity).Assert();
|
||||
return new MoveLibrary(ptr);
|
||||
}
|
||||
|
||||
internal MoveLibrary(IntPtr ptr) : base(ptr)
|
||||
{
|
||||
}
|
||||
|
||||
protected internal override void MarkAsDeleted()
|
||||
{
|
||||
base.MarkAsDeleted();
|
||||
foreach (var moveData in _cache)
|
||||
{
|
||||
moveData.Value.MarkAsDeleted();
|
||||
}
|
||||
foreach (var moveData in _cache) moveData.Value.MarkAsDeleted();
|
||||
}
|
||||
|
||||
protected override void DeletePtr()
|
||||
|
||||
@@ -13,6 +13,6 @@ namespace PkmnLibSharp.Library.Moves
|
||||
AllOpponent = 8,
|
||||
Any = 9,
|
||||
RandomOpponent = 10,
|
||||
Self = 11,
|
||||
Self = 11
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using PkmnLibSharp.Utilities;
|
||||
using Random = PkmnLibSharp.Utilities.Random;
|
||||
|
||||
namespace PkmnLibSharp.Library
|
||||
{
|
||||
@@ -54,6 +55,11 @@ namespace PkmnLibSharp.Library
|
||||
return ptr.PtrString();
|
||||
}
|
||||
|
||||
public string GetRandomNatureName(Random random)
|
||||
{
|
||||
return Pkmnlib.Generated.NatureLibrary.GetRandomNatureName(Ptr, random.Ptr).PtrString();
|
||||
}
|
||||
|
||||
protected override void DeletePtr()
|
||||
{
|
||||
Pkmnlib.Generated.NatureLibrary.Destruct(Ptr);
|
||||
|
||||
@@ -115,7 +115,7 @@ namespace PkmnLibSharp.Library
|
||||
}
|
||||
|
||||
|
||||
private PokemonLibrary(IntPtr ptr) : base(ptr)
|
||||
internal PokemonLibrary(IntPtr ptr) : base(ptr)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Creatureliblibrary.Generated;
|
||||
using Pkmnlib;
|
||||
using Pkmnlib.Generated;
|
||||
using PkmnLibSharp.Utilities;
|
||||
using Gender = PkmnLibSharp.Battling.Gender;
|
||||
using Random = PkmnLibSharp.Utilities.Random;
|
||||
|
||||
namespace PkmnLibSharp.Library
|
||||
{
|
||||
@@ -68,6 +71,11 @@ namespace PkmnLibSharp.Library
|
||||
CreatureSpecies.SetVariant(Ptr, s.ToPtr(), forme.Ptr).Assert();
|
||||
}
|
||||
|
||||
public Gender GetRandomGender(Random random)
|
||||
{
|
||||
return (Gender) CreatureSpecies.GetRandomGender(Ptr, random.Ptr);
|
||||
}
|
||||
|
||||
|
||||
internal Species(IntPtr ptr) : base(ptr)
|
||||
{
|
||||
|
||||
24
PkmnLibSharp/Library/StatisticSet.cs
Normal file
24
PkmnLibSharp/Library/StatisticSet.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
|
||||
namespace PkmnLibSharp.Library
|
||||
{
|
||||
public class StatisticSet<T> where T : IComparable<T>
|
||||
{
|
||||
public T HP { get; set; }
|
||||
public T Attack { get; set; }
|
||||
public T Defense { get; set; }
|
||||
public T SpecialAttack { get; set; }
|
||||
public T SpecialDefense { get; set; }
|
||||
public T Speed { get; set; }
|
||||
|
||||
public StatisticSet(T hp, T attack, T defense, T specialAttack, T specialDefense, T speed)
|
||||
{
|
||||
HP = hp;
|
||||
Attack = attack;
|
||||
Defense = defense;
|
||||
SpecialAttack = specialAttack;
|
||||
SpecialDefense = specialDefense;
|
||||
Speed = speed;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user