From 385d70e5ed78bef25d40d1db9a1fc5c806318777 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sun, 25 Oct 2020 11:55:35 +0100 Subject: [PATCH] Allow random to be passed to PokemonBuilder build function, if none is passed use a static fallback. --- PkmnLibSharp/Battling/PokemonBuilder.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/PkmnLibSharp/Battling/PokemonBuilder.cs b/PkmnLibSharp/Battling/PokemonBuilder.cs index 41872cb..5dbca12 100644 --- a/PkmnLibSharp/Battling/PokemonBuilder.cs +++ b/PkmnLibSharp/Battling/PokemonBuilder.cs @@ -11,6 +11,8 @@ namespace PkmnLibSharp.Battling where TPokemon : Pokemon where TLearnedMove :LearnedMove { + private static readonly Random _defaultRandom = new Random(); + protected readonly BattleLibrary Library; public string Species { get; } public string Forme { get; private set; } = "default"; @@ -148,7 +150,7 @@ namespace PkmnLibSharp.Battling protected abstract TLearnedMove CreateLearnedMove(MoveData move, byte maxUses, MoveLearnMethod learnMethod); - public TPokemon Build() + public TPokemon Build(Random? random = null) { if (!Library.StaticLibrary.SpeciesLibrary.TryGet(Species, out var species)) { @@ -160,7 +162,10 @@ namespace PkmnLibSharp.Battling throw new Exception($"Forme '{Forme}' was not found on species '{Species}'"); } - var random = new Random(); + if (random == null) + { + random = _defaultRandom; + } Item? heldItem = null; if (HeldItem != null)