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 _parties = new List(); 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); } } }