From 0a2ce2d6e4ae5b397edc18e30156e41ec4f6de2c Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Mon, 7 Sep 2020 18:54:09 +0200 Subject: [PATCH] Add generic LearnedMove in PokemonBuilder. --- PkmnLibSharp/Battling/PokemonBuilder.cs | 31 ++++++++++++-------- PkmnLibSharpTests/Battling/PokemonBuilder.cs | 8 ++++- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/PkmnLibSharp/Battling/PokemonBuilder.cs b/PkmnLibSharp/Battling/PokemonBuilder.cs index bedb84b..0516522 100644 --- a/PkmnLibSharp/Battling/PokemonBuilder.cs +++ b/PkmnLibSharp/Battling/PokemonBuilder.cs @@ -2,11 +2,14 @@ using System; using System.Collections.Generic; using PkmnLibSharp.Library; using PkmnLibSharp.Library.Items; +using PkmnLibSharp.Library.Moves; using Random = PkmnLibSharp.Utilities.Random; namespace PkmnLibSharp.Battling { - public abstract class BasePokemonBuilder where T : Pokemon + public abstract class BasePokemonBuilder + where TPokemon : Pokemon + where TLearnedMove :LearnedMove { protected readonly BattleLibrary Library; public string Species { get; } @@ -34,55 +37,55 @@ namespace PkmnLibSharp.Battling Level = level; } - public BasePokemonBuilder WithForme(string forme) + public BasePokemonBuilder WithForme(string forme) { Forme = forme; return this; } - public BasePokemonBuilder WithGender(Gender gender) + public BasePokemonBuilder WithGender(Gender gender) { Gender = gender; return this; } - public BasePokemonBuilder ForceShiny(bool value) + public BasePokemonBuilder ForceShiny(bool value) { IsForceShiny = value; return this; } - public BasePokemonBuilder WithHeldItem(string heldItem) + public BasePokemonBuilder WithHeldItem(string heldItem) { HeldItem = heldItem; return this; } - public BasePokemonBuilder WithNickname(string nickname) + public BasePokemonBuilder WithNickname(string nickname) { Nickname = nickname; return this; } - public BasePokemonBuilder WithNature(string nature) + public BasePokemonBuilder WithNature(string nature) { Nature = nature; return this; } - public BasePokemonBuilder WithIVs(StatisticSet ivs) + public BasePokemonBuilder WithIVs(StatisticSet ivs) { IVs = ivs; return this; } - public BasePokemonBuilder WithEVs(StatisticSet evs) + public BasePokemonBuilder WithEVs(StatisticSet evs) { EVs = evs; return this; } - public BasePokemonBuilder LearnMove(string moveName, MoveLearnMethod moveLearnMethod) + public BasePokemonBuilder LearnMove(string moveName, MoveLearnMethod moveLearnMethod) { if (LearnedMoves.Count > Library.StaticLibrary.Settings.MaximalMoves) { @@ -140,10 +143,12 @@ namespace PkmnLibSharp.Battling } } - protected abstract T Finalize(Species species, Forme forme, Item? heldItem, + protected abstract TPokemon Finalize(Species species, Forme forme, Item? heldItem, IReadOnlyCollection moves, Nature nature); - public T Build() + protected abstract TLearnedMove CreateLearnedMove(MoveData move, byte maxUses, MoveLearnMethod learnMethod); + + public TPokemon Build() { if (!Library.StaticLibrary.SpeciesLibrary.TryGet(Species, out var species)) { @@ -174,7 +179,7 @@ namespace PkmnLibSharp.Battling throw new Exception($"Move '{LearnedMoves[i].moveName}' was not found."); } - moves[i] = new LearnedMove(move!, move!.BaseUsages, LearnedMoves[i].learnMethod); + moves[i] = CreateLearnedMove(move!, move!.BaseUsages, LearnedMoves[i].learnMethod); } if (string.IsNullOrEmpty(Nature)) diff --git a/PkmnLibSharpTests/Battling/PokemonBuilder.cs b/PkmnLibSharpTests/Battling/PokemonBuilder.cs index 8e798d6..e6072d1 100644 --- a/PkmnLibSharpTests/Battling/PokemonBuilder.cs +++ b/PkmnLibSharpTests/Battling/PokemonBuilder.cs @@ -2,10 +2,11 @@ using System.Collections.Generic; using PkmnLibSharp.Battling; using PkmnLibSharp.Library; using PkmnLibSharp.Library.Items; +using PkmnLibSharp.Library.Moves; namespace PkmnLibSharpTests.Battling { - public class PokemonBuilder : BasePokemonBuilder + public class PokemonBuilder : BasePokemonBuilder { public PokemonBuilder(BattleLibrary library, string species, byte level) : base(library, species, level) { @@ -18,5 +19,10 @@ namespace PkmnLibSharpTests.Battling heldItem, Nickname, HiddenAbility, (byte) AbilityIndex, moves, IVs, EVs, nature); return pkmn; } + + protected override LearnedMove CreateLearnedMove(MoveData move, byte maxUses, MoveLearnMethod learnMethod) + { + return new LearnedMove(move, maxUses, learnMethod); + } } } \ No newline at end of file