Initial battle class tests.
This commit is contained in:
@@ -8,13 +8,14 @@ namespace PkmnLibSharp.Battling
|
||||
{
|
||||
public class Battle : PointerWrapper
|
||||
{
|
||||
public Battle(BattleLibrary library, BattleParty[] parties, bool canFlee, byte numberOfSides, byte creaturesPerSide,
|
||||
public Battle(BattleLibrary library, BattleParty[] parties, bool canFlee, byte numberOfSides, byte pokemonPerSide,
|
||||
ulong randomSeed)
|
||||
{
|
||||
var ptr = IntPtr.Zero;
|
||||
var arr = parties.Select(x => x.Ptr).ToArray();
|
||||
Pkmnlib.Generated.Battle.Construct(ref ptr, library.Ptr, arr.ArrayPtr(), (ulong) arr.Length,
|
||||
canFlee.ToNative(), numberOfSides, creaturesPerSide, randomSeed);
|
||||
canFlee.ToNative(), numberOfSides, pokemonPerSide, randomSeed);
|
||||
Initialize(ptr);
|
||||
}
|
||||
|
||||
public BattleLibrary Library
|
||||
|
||||
44
PkmnLibSharp/Battling/Battle/BattleBuilder.cs
Normal file
44
PkmnLibSharp/Battling/Battle/BattleBuilder.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace PkmnLibSharp.Battling
|
||||
{
|
||||
public class BattleBuilder
|
||||
{
|
||||
private readonly BattleLibrary _library;
|
||||
private readonly bool _canFlee;
|
||||
private readonly byte _numberOfSides;
|
||||
private readonly byte _pokemonPerSide;
|
||||
private ulong? _seed;
|
||||
private readonly List<BattleParty> _parties = new List<BattleParty>();
|
||||
|
||||
public BattleBuilder(BattleLibrary library, bool canFlee, byte numberOfSides = 2, byte pokemonPerSide = 1)
|
||||
{
|
||||
_library = library;
|
||||
_canFlee = canFlee;
|
||||
_numberOfSides = numberOfSides;
|
||||
_pokemonPerSide = pokemonPerSide;
|
||||
}
|
||||
|
||||
public BattleBuilder WithRandomSeed(ulong seed)
|
||||
{
|
||||
_seed = seed;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BattleBuilder WithPartyOnPositions(PokemonParty party, params BattlePosition[] positions)
|
||||
{
|
||||
var battleParty = new BattleParty(party, positions.SelectMany(x => new[] {x.Side, x.Index}).ToArray());
|
||||
_parties.Add(battleParty);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Battle Build()
|
||||
{
|
||||
// Use the milliseconds since epoch time as random seed if none is specified.
|
||||
_seed ??= (ulong) (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalMilliseconds;
|
||||
return new Battle(_library, _parties.ToArray(), _canFlee, _numberOfSides, _pokemonPerSide, _seed.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ namespace PkmnLibSharp.Battling
|
||||
{
|
||||
var ptr = IntPtr.Zero;
|
||||
Creaturelibbattling.Generated.BattleParty.Construct(ref ptr, party.Ptr, responsibleIndices.ArrayPtr(),
|
||||
(ulong) responsibleIndices.Length).Assert();
|
||||
(ulong) responsibleIndices.Length / 2).Assert();
|
||||
Initialize(ptr);
|
||||
}
|
||||
|
||||
|
||||
14
PkmnLibSharp/Battling/Battle/BattlePosition.cs
Normal file
14
PkmnLibSharp/Battling/Battle/BattlePosition.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
namespace PkmnLibSharp.Battling
|
||||
{
|
||||
public readonly struct BattlePosition
|
||||
{
|
||||
public readonly byte Side;
|
||||
public readonly byte Index;
|
||||
|
||||
public BattlePosition(byte side, byte index)
|
||||
{
|
||||
Side = side;
|
||||
Index = index;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -319,11 +319,11 @@ namespace PkmnLibSharp.Battling
|
||||
|
||||
protected internal override void MarkAsDeleted()
|
||||
{
|
||||
base.MarkAsDeleted();
|
||||
foreach (var move in Moves)
|
||||
{
|
||||
move.MarkAsDeleted();
|
||||
move?.MarkAsDeleted();
|
||||
}
|
||||
base.MarkAsDeleted();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ namespace PkmnLibSharp.Battling
|
||||
{
|
||||
private ReadOnlyNativePtrArray<Pokemon> _party;
|
||||
|
||||
public PokemonParty(ulong size) : base(Creaturelibbattling.Generated.CreatureParty.ConstructWithSize(size))
|
||||
public PokemonParty(ulong size = 6) : base(Creaturelibbattling.Generated.CreatureParty.ConstructWithSize(size))
|
||||
{}
|
||||
|
||||
public PokemonParty(Pokemon[] pokemon) : base(
|
||||
|
||||
BIN
PkmnLibSharp/Native/libArbutils.so
(Stored with Git LFS)
BIN
PkmnLibSharp/Native/libArbutils.so
(Stored with Git LFS)
Binary file not shown.
BIN
PkmnLibSharp/Native/libCreatureLibBattling.so
(Stored with Git LFS)
BIN
PkmnLibSharp/Native/libCreatureLibBattling.so
(Stored with Git LFS)
Binary file not shown.
BIN
PkmnLibSharp/Native/libCreatureLibLibrary.so
(Stored with Git LFS)
BIN
PkmnLibSharp/Native/libCreatureLibLibrary.so
(Stored with Git LFS)
Binary file not shown.
BIN
PkmnLibSharp/Native/libpkmnLib.so
(Stored with Git LFS)
BIN
PkmnLibSharp/Native/libpkmnLib.so
(Stored with Git LFS)
Binary file not shown.
Reference in New Issue
Block a user