Allow random to be passed to PokemonBuilder build function, if none is passed use a static fallback.
This commit is contained in:
parent
c34d7960ab
commit
385d70e5ed
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue