Change PokemonBuilder interface to something cleaner
This commit is contained in:
parent
02afdbf479
commit
26566a284b
|
@ -10,25 +10,25 @@ namespace PkmnLibSharp.Battling
|
|||
{
|
||||
public abstract class BasePokemonBuilder<TPokemon, TLearnedMove>
|
||||
where TPokemon : Pokemon
|
||||
where TLearnedMove :LearnedMove
|
||||
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";
|
||||
public string Nickname { get; private set; } = "";
|
||||
public string Ability { get; private set; } = "";
|
||||
public string Nature { get; private set; } = "";
|
||||
public Gender Gender { get; private set; } = (Gender) (-1);
|
||||
public uint Identifier { get; private set; } = 0;
|
||||
public string Forme { get; set; } = "default";
|
||||
public string Nickname { get; set; } = "";
|
||||
public string Ability { get; set; } = "";
|
||||
public string Nature { get; set; } = "";
|
||||
public Gender Gender { get; set; } = (Gender) (-1);
|
||||
public uint Identifier { get; set; } = 0;
|
||||
public byte Level { get; }
|
||||
|
||||
public StatisticSet<byte> IVs;
|
||||
public StatisticSet<byte> EVs;
|
||||
public StatisticSet<byte> IVs { get; set; }
|
||||
public StatisticSet<byte> EVs { get; 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 IsAllowedExperienceGain { get; private set; } = true;
|
||||
|
||||
|
@ -42,53 +42,12 @@ namespace PkmnLibSharp.Battling
|
|||
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)
|
||||
{
|
||||
IsForceShiny = value;
|
||||
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()
|
||||
{
|
||||
IsEgg = true;
|
||||
|
@ -108,6 +67,7 @@ namespace PkmnLibSharp.Battling
|
|||
{
|
||||
throw new Exception("Too many moves for Pokemon.");
|
||||
}
|
||||
|
||||
LearnedMoves.Add((moveName, moveLearnMethod));
|
||||
return this;
|
||||
}
|
||||
|
@ -127,6 +87,7 @@ namespace PkmnLibSharp.Battling
|
|||
{
|
||||
Gender = species.GetRandomGender(random);
|
||||
}
|
||||
|
||||
Coloring = 0;
|
||||
if (IsForceShiny.HasValue)
|
||||
{
|
||||
|
@ -181,6 +142,7 @@ namespace PkmnLibSharp.Battling
|
|||
{
|
||||
random = _defaultRandom;
|
||||
}
|
||||
|
||||
PopulateUninitialized(species, forme!, random);
|
||||
|
||||
Item? heldItem = null;
|
||||
|
|
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>
|
||||
<Nullable>enable</Nullable>
|
||||
<WarningsAsErrors>CS8600;CS8601;CS8602;CS8603;CS8604;CS8618</WarningsAsErrors>
|
||||
<LangVersion>8</LangVersion>
|
||||
<LangVersion>9</LangVersion>
|
||||
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
|
||||
|
|
|
@ -24,8 +24,9 @@ namespace PkmnLibSharpTests.Battling
|
|||
{
|
||||
var lib = BattleLibraryHelper.GetLibrary();
|
||||
var pokemon = new PokemonBuilder(lib, "testSpecies", 50)
|
||||
.WithNickname("cuteNickname")
|
||||
.Build();
|
||||
{
|
||||
Nickname = "cuteNickname"
|
||||
}.Build();
|
||||
Assert.AreEqual("cuteNickname", pokemon.Value.Nickname);
|
||||
pokemon.Dispose();
|
||||
}
|
||||
|
@ -35,7 +36,9 @@ namespace PkmnLibSharpTests.Battling
|
|||
{
|
||||
var lib = BattleLibraryHelper.GetLibrary();
|
||||
var pokemon = new PokemonBuilder(lib, "testSpecies", 50)
|
||||
.WithGender(Gender.Female)
|
||||
{
|
||||
Gender = Gender.Female
|
||||
}
|
||||
.Build();
|
||||
Assert.AreEqual(Gender.Female, pokemon.Value.Gender);
|
||||
pokemon.Dispose();
|
||||
|
|
Loading…
Reference in New Issue