Add generic LearnedMove in PokemonBuilder.

This commit is contained in:
Deukhoofd 2020-09-07 18:54:09 +02:00
parent c797a4180b
commit 0a2ce2d6e4
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
2 changed files with 25 additions and 14 deletions

View File

@ -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<T> where T : Pokemon
public abstract class BasePokemonBuilder<TPokemon, TLearnedMove>
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<T> WithForme(string forme)
public BasePokemonBuilder<TPokemon, TLearnedMove> WithForme(string forme)
{
Forme = forme;
return this;
}
public BasePokemonBuilder<T> WithGender(Gender gender)
public BasePokemonBuilder<TPokemon, TLearnedMove> WithGender(Gender gender)
{
Gender = gender;
return this;
}
public BasePokemonBuilder<T> ForceShiny(bool value)
public BasePokemonBuilder<TPokemon, TLearnedMove> ForceShiny(bool value)
{
IsForceShiny = value;
return this;
}
public BasePokemonBuilder<T> WithHeldItem(string heldItem)
public BasePokemonBuilder<TPokemon, TLearnedMove> WithHeldItem(string heldItem)
{
HeldItem = heldItem;
return this;
}
public BasePokemonBuilder<T> WithNickname(string nickname)
public BasePokemonBuilder<TPokemon, TLearnedMove> WithNickname(string nickname)
{
Nickname = nickname;
return this;
}
public BasePokemonBuilder<T> WithNature(string nature)
public BasePokemonBuilder<TPokemon, TLearnedMove> WithNature(string nature)
{
Nature = nature;
return this;
}
public BasePokemonBuilder<T> WithIVs(StatisticSet<byte> ivs)
public BasePokemonBuilder<TPokemon, TLearnedMove> WithIVs(StatisticSet<byte> ivs)
{
IVs = ivs;
return this;
}
public BasePokemonBuilder<T> WithEVs(StatisticSet<byte> evs)
public BasePokemonBuilder<TPokemon, TLearnedMove> WithEVs(StatisticSet<byte> evs)
{
EVs = evs;
return this;
}
public BasePokemonBuilder<T> LearnMove(string moveName, MoveLearnMethod moveLearnMethod)
public BasePokemonBuilder<TPokemon, TLearnedMove> 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<LearnedMove> 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))

View File

@ -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<Pokemon>
public class PokemonBuilder : BasePokemonBuilder<Pokemon, LearnedMove>
{
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);
}
}
}