Change PokemonBuilder interface to something cleaner

This commit is contained in:
Deukhoofd 2021-06-26 12:57:21 +02:00
parent 02afdbf479
commit 26566a284b
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
4 changed files with 30 additions and 65 deletions

View File

@ -10,25 +10,25 @@ 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;
@ -42,53 +42,12 @@ namespace PkmnLibSharp.Battling
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;
@ -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;

BIN
PkmnLibSharp/Native/Linux/libpkmnLib.so (Stored with Git LFS)

Binary file not shown.

View File

@ -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>

View File

@ -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();