Allow random to be passed to PokemonBuilder build function, if none is passed use a static fallback.

This commit is contained in:
Deukhoofd 2020-10-25 11:55:35 +01:00
parent c34d7960ab
commit 385d70e5ed
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
1 changed files with 7 additions and 2 deletions

View File

@ -11,6 +11,8 @@ namespace PkmnLibSharp.Battling
where TPokemon : Pokemon where TPokemon : Pokemon
where TLearnedMove :LearnedMove where TLearnedMove :LearnedMove
{ {
private static readonly Random _defaultRandom = new Random();
protected readonly BattleLibrary Library; protected readonly BattleLibrary Library;
public string Species { get; } public string Species { get; }
public string Forme { get; private set; } = "default"; public string Forme { get; private set; } = "default";
@ -148,7 +150,7 @@ namespace PkmnLibSharp.Battling
protected abstract TLearnedMove CreateLearnedMove(MoveData move, byte maxUses, MoveLearnMethod learnMethod); 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)) 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}'"); throw new Exception($"Forme '{Forme}' was not found on species '{Species}'");
} }
var random = new Random(); if (random == null)
{
random = _defaultRandom;
}
Item? heldItem = null; Item? heldItem = null;
if (HeldItem != null) if (HeldItem != null)