Change PokemonBuilder interface to something cleaner
This commit is contained in:
parent
02afdbf479
commit
26566a284b
|
@ -9,92 +9,51 @@ using Random = PkmnLibSharp.Utilities.Random;
|
||||||
namespace PkmnLibSharp.Battling
|
namespace PkmnLibSharp.Battling
|
||||||
{
|
{
|
||||||
public abstract class BasePokemonBuilder<TPokemon, TLearnedMove>
|
public abstract class BasePokemonBuilder<TPokemon, TLearnedMove>
|
||||||
where TPokemon : Pokemon
|
where TPokemon : Pokemon
|
||||||
where TLearnedMove :LearnedMove
|
where TLearnedMove : LearnedMove
|
||||||
{
|
{
|
||||||
private static readonly Random _defaultRandom = new Random();
|
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; set; } = "default";
|
||||||
public string Nickname { get; private set; } = "";
|
public string Nickname { get; set; } = "";
|
||||||
public string Ability { get; private set; } = "";
|
public string Ability { get; set; } = "";
|
||||||
public string Nature { get; private set; } = "";
|
public string Nature { get; set; } = "";
|
||||||
public Gender Gender { get; private set; } = (Gender) (-1);
|
public Gender Gender { get; set; } = (Gender) (-1);
|
||||||
public uint Identifier { get; private set; } = 0;
|
public uint Identifier { get; set; } = 0;
|
||||||
public byte Level { get; }
|
public byte Level { get; }
|
||||||
|
|
||||||
public StatisticSet<byte> IVs;
|
public StatisticSet<byte> IVs { get; set; }
|
||||||
public StatisticSet<byte> EVs;
|
public StatisticSet<byte> EVs { get; set; }
|
||||||
|
|
||||||
public bool? IsForceShiny { get; private set; }
|
public bool? IsForceShiny { get; private set; }
|
||||||
public string? HeldItem { get; private set; }
|
public string? HeldItem { get; set; }
|
||||||
public bool IsEgg { get; private set; }
|
public bool IsEgg { get; private set; }
|
||||||
public bool IsAllowedExperienceGain { get; private set; } = true;
|
public bool IsAllowedExperienceGain { get; private set; } = true;
|
||||||
|
|
||||||
public List<(string moveName, MoveLearnMethod learnMethod)> LearnedMoves { get; } =
|
public List<(string moveName, MoveLearnMethod learnMethod)> LearnedMoves { get; } =
|
||||||
new List<(string moveName, MoveLearnMethod learnMethod)>();
|
new List<(string moveName, MoveLearnMethod learnMethod)>();
|
||||||
|
|
||||||
public BasePokemonBuilder(BattleLibrary library, string species, byte level)
|
public BasePokemonBuilder(BattleLibrary library, string species, byte level)
|
||||||
{
|
{
|
||||||
Library = library;
|
Library = library;
|
||||||
Species = species;
|
Species = species;
|
||||||
Level = level;
|
Level = level;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BasePokemonBuilder<TPokemon, TLearnedMove> WithForme(string forme)
|
|
||||||
{
|
|
||||||
Forme = forme;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BasePokemonBuilder<TPokemon, TLearnedMove> WithGender(Gender gender)
|
|
||||||
{
|
|
||||||
Gender = gender;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BasePokemonBuilder<TPokemon, TLearnedMove> ForceShiny(bool value)
|
public BasePokemonBuilder<TPokemon, TLearnedMove> ForceShiny(bool value)
|
||||||
{
|
{
|
||||||
IsForceShiny = value;
|
IsForceShiny = value;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BasePokemonBuilder<TPokemon, TLearnedMove> WithHeldItem(string heldItem)
|
|
||||||
{
|
|
||||||
HeldItem = heldItem;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BasePokemonBuilder<TPokemon, TLearnedMove> WithNickname(string nickname)
|
|
||||||
{
|
|
||||||
Nickname = nickname;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BasePokemonBuilder<TPokemon, TLearnedMove> WithNature(string nature)
|
|
||||||
{
|
|
||||||
Nature = nature;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BasePokemonBuilder<TPokemon, TLearnedMove> WithIVs(StatisticSet<byte> ivs)
|
|
||||||
{
|
|
||||||
IVs = ivs;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
public BasePokemonBuilder<TPokemon, TLearnedMove> WithEVs(StatisticSet<byte> evs)
|
|
||||||
{
|
|
||||||
EVs = evs;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BasePokemonBuilder<TPokemon, TLearnedMove> MakeEgg()
|
public BasePokemonBuilder<TPokemon, TLearnedMove> MakeEgg()
|
||||||
{
|
{
|
||||||
IsEgg = true;
|
IsEgg = true;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BasePokemonBuilder<TPokemon, TLearnedMove> AllowedExperienceGain(bool value)
|
public BasePokemonBuilder<TPokemon, TLearnedMove> AllowedExperienceGain(bool value)
|
||||||
{
|
{
|
||||||
IsAllowedExperienceGain = value;
|
IsAllowedExperienceGain = value;
|
||||||
|
@ -108,6 +67,7 @@ namespace PkmnLibSharp.Battling
|
||||||
{
|
{
|
||||||
throw new Exception("Too many moves for Pokemon.");
|
throw new Exception("Too many moves for Pokemon.");
|
||||||
}
|
}
|
||||||
|
|
||||||
LearnedMoves.Add((moveName, moveLearnMethod));
|
LearnedMoves.Add((moveName, moveLearnMethod));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -127,6 +87,7 @@ namespace PkmnLibSharp.Battling
|
||||||
{
|
{
|
||||||
Gender = species.GetRandomGender(random);
|
Gender = species.GetRandomGender(random);
|
||||||
}
|
}
|
||||||
|
|
||||||
Coloring = 0;
|
Coloring = 0;
|
||||||
if (IsForceShiny.HasValue)
|
if (IsForceShiny.HasValue)
|
||||||
{
|
{
|
||||||
|
@ -181,6 +142,7 @@ namespace PkmnLibSharp.Battling
|
||||||
{
|
{
|
||||||
random = _defaultRandom;
|
random = _defaultRandom;
|
||||||
}
|
}
|
||||||
|
|
||||||
PopulateUninitialized(species, forme!, random);
|
PopulateUninitialized(species, forme!, random);
|
||||||
|
|
||||||
Item? heldItem = null;
|
Item? heldItem = null;
|
||||||
|
@ -191,7 +153,7 @@ namespace PkmnLibSharp.Battling
|
||||||
throw new Exception($"Item '{HeldItem}' was not found.");
|
throw new Exception($"Item '{HeldItem}' was not found.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var moves = new LearnedMove[Library.StaticLibrary.Settings.MaximalMoves];
|
var moves = new LearnedMove[Library.StaticLibrary.Settings.MaximalMoves];
|
||||||
for (var i = 0; i < LearnedMoves.Count; i++)
|
for (var i = 0; i < LearnedMoves.Count; i++)
|
||||||
{
|
{
|
||||||
|
@ -214,7 +176,7 @@ namespace PkmnLibSharp.Battling
|
||||||
{
|
{
|
||||||
Gender = species.GetRandomGender(random);
|
Gender = species.GetRandomGender(random);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ScopedOwner<TPokemon>(Finalize(species, forme!, heldItem, moves, nature));
|
return new ScopedOwner<TPokemon>(Finalize(species, forme!, heldItem, moves, nature));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
BIN
PkmnLibSharp/Native/Linux/libpkmnLib.so (Stored with Git LFS)
BIN
PkmnLibSharp/Native/Linux/libpkmnLib.so (Stored with Git LFS)
Binary file not shown.
|
@ -5,7 +5,7 @@
|
||||||
<Platforms>x64</Platforms>
|
<Platforms>x64</Platforms>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<WarningsAsErrors>CS8600;CS8601;CS8602;CS8603;CS8604;CS8618</WarningsAsErrors>
|
<WarningsAsErrors>CS8600;CS8601;CS8602;CS8603;CS8604;CS8618</WarningsAsErrors>
|
||||||
<LangVersion>8</LangVersion>
|
<LangVersion>9</LangVersion>
|
||||||
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
|
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
|
|
@ -24,8 +24,9 @@ namespace PkmnLibSharpTests.Battling
|
||||||
{
|
{
|
||||||
var lib = BattleLibraryHelper.GetLibrary();
|
var lib = BattleLibraryHelper.GetLibrary();
|
||||||
var pokemon = new PokemonBuilder(lib, "testSpecies", 50)
|
var pokemon = new PokemonBuilder(lib, "testSpecies", 50)
|
||||||
.WithNickname("cuteNickname")
|
{
|
||||||
.Build();
|
Nickname = "cuteNickname"
|
||||||
|
}.Build();
|
||||||
Assert.AreEqual("cuteNickname", pokemon.Value.Nickname);
|
Assert.AreEqual("cuteNickname", pokemon.Value.Nickname);
|
||||||
pokemon.Dispose();
|
pokemon.Dispose();
|
||||||
}
|
}
|
||||||
|
@ -35,7 +36,9 @@ namespace PkmnLibSharpTests.Battling
|
||||||
{
|
{
|
||||||
var lib = BattleLibraryHelper.GetLibrary();
|
var lib = BattleLibraryHelper.GetLibrary();
|
||||||
var pokemon = new PokemonBuilder(lib, "testSpecies", 50)
|
var pokemon = new PokemonBuilder(lib, "testSpecies", 50)
|
||||||
.WithGender(Gender.Female)
|
{
|
||||||
|
Gender = Gender.Female
|
||||||
|
}
|
||||||
.Build();
|
.Build();
|
||||||
Assert.AreEqual(Gender.Female, pokemon.Value.Gender);
|
Assert.AreEqual(Gender.Female, pokemon.Value.Gender);
|
||||||
pokemon.Dispose();
|
pokemon.Dispose();
|
||||||
|
|
Loading…
Reference in New Issue