Add generic LearnedMove in PokemonBuilder.
This commit is contained in:
parent
c797a4180b
commit
0a2ce2d6e4
|
@ -2,11 +2,14 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using PkmnLibSharp.Library;
|
using PkmnLibSharp.Library;
|
||||||
using PkmnLibSharp.Library.Items;
|
using PkmnLibSharp.Library.Items;
|
||||||
|
using PkmnLibSharp.Library.Moves;
|
||||||
using Random = PkmnLibSharp.Utilities.Random;
|
using Random = PkmnLibSharp.Utilities.Random;
|
||||||
|
|
||||||
namespace PkmnLibSharp.Battling
|
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;
|
protected readonly BattleLibrary Library;
|
||||||
public string Species { get; }
|
public string Species { get; }
|
||||||
|
@ -34,55 +37,55 @@ namespace PkmnLibSharp.Battling
|
||||||
Level = level;
|
Level = level;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BasePokemonBuilder<T> WithForme(string forme)
|
public BasePokemonBuilder<TPokemon, TLearnedMove> WithForme(string forme)
|
||||||
{
|
{
|
||||||
Forme = forme;
|
Forme = forme;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BasePokemonBuilder<T> WithGender(Gender gender)
|
public BasePokemonBuilder<TPokemon, TLearnedMove> WithGender(Gender gender)
|
||||||
{
|
{
|
||||||
Gender = gender;
|
Gender = gender;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BasePokemonBuilder<T> ForceShiny(bool value)
|
public BasePokemonBuilder<TPokemon, TLearnedMove> ForceShiny(bool value)
|
||||||
{
|
{
|
||||||
IsForceShiny = value;
|
IsForceShiny = value;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BasePokemonBuilder<T> WithHeldItem(string heldItem)
|
public BasePokemonBuilder<TPokemon, TLearnedMove> WithHeldItem(string heldItem)
|
||||||
{
|
{
|
||||||
HeldItem = heldItem;
|
HeldItem = heldItem;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BasePokemonBuilder<T> WithNickname(string nickname)
|
public BasePokemonBuilder<TPokemon, TLearnedMove> WithNickname(string nickname)
|
||||||
{
|
{
|
||||||
Nickname = nickname;
|
Nickname = nickname;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BasePokemonBuilder<T> WithNature(string nature)
|
public BasePokemonBuilder<TPokemon, TLearnedMove> WithNature(string nature)
|
||||||
{
|
{
|
||||||
Nature = nature;
|
Nature = nature;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BasePokemonBuilder<T> WithIVs(StatisticSet<byte> ivs)
|
public BasePokemonBuilder<TPokemon, TLearnedMove> WithIVs(StatisticSet<byte> ivs)
|
||||||
{
|
{
|
||||||
IVs = ivs;
|
IVs = ivs;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
public BasePokemonBuilder<T> WithEVs(StatisticSet<byte> evs)
|
public BasePokemonBuilder<TPokemon, TLearnedMove> WithEVs(StatisticSet<byte> evs)
|
||||||
{
|
{
|
||||||
EVs = evs;
|
EVs = evs;
|
||||||
return this;
|
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)
|
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);
|
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))
|
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.");
|
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))
|
if (string.IsNullOrEmpty(Nature))
|
||||||
|
|
|
@ -2,10 +2,11 @@ using System.Collections.Generic;
|
||||||
using PkmnLibSharp.Battling;
|
using PkmnLibSharp.Battling;
|
||||||
using PkmnLibSharp.Library;
|
using PkmnLibSharp.Library;
|
||||||
using PkmnLibSharp.Library.Items;
|
using PkmnLibSharp.Library.Items;
|
||||||
|
using PkmnLibSharp.Library.Moves;
|
||||||
|
|
||||||
namespace PkmnLibSharpTests.Battling
|
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)
|
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);
|
heldItem, Nickname, HiddenAbility, (byte) AbilityIndex, moves, IVs, EVs, nature);
|
||||||
return pkmn;
|
return pkmn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override LearnedMove CreateLearnedMove(MoveData move, byte maxUses, MoveLearnMethod learnMethod)
|
||||||
|
{
|
||||||
|
return new LearnedMove(move, maxUses, learnMethod);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue