2020-07-18 14:49:11 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using PkmnLibSharp.Library;
|
|
|
|
using PkmnLibSharp.Library.Items;
|
|
|
|
using Random = PkmnLibSharp.Utilities.Random;
|
|
|
|
|
|
|
|
namespace PkmnLibSharp.Battling
|
|
|
|
{
|
|
|
|
public class PokemonBuilder
|
|
|
|
{
|
|
|
|
private 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 byte Level { get; }
|
|
|
|
|
|
|
|
public StatisticSet<byte> IVs;
|
|
|
|
public StatisticSet<byte> EVs;
|
|
|
|
|
|
|
|
public bool? IsForceShiny { get; private set; }
|
2020-08-08 12:32:27 +00:00
|
|
|
public string? HeldItem { get; private set; }
|
2020-07-18 14:49:11 +00:00
|
|
|
|
|
|
|
public List<(string moveName, MoveLearnMethod learnMethod)> LearnedMoves { get; } =
|
|
|
|
new List<(string moveName, MoveLearnMethod learnMethod)>();
|
|
|
|
|
|
|
|
public PokemonBuilder(BattleLibrary library, string species, byte level)
|
|
|
|
{
|
|
|
|
_library = library;
|
|
|
|
Species = species;
|
|
|
|
Level = level;
|
|
|
|
}
|
|
|
|
|
|
|
|
public PokemonBuilder WithForme(string forme)
|
|
|
|
{
|
|
|
|
Forme = forme;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public PokemonBuilder WithGender(Gender gender)
|
|
|
|
{
|
|
|
|
Gender = gender;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public PokemonBuilder ForceShiny(bool value)
|
|
|
|
{
|
|
|
|
IsForceShiny = value;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public PokemonBuilder WithHeldItem(string heldItem)
|
|
|
|
{
|
|
|
|
HeldItem = heldItem;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2020-07-19 10:33:22 +00:00
|
|
|
public PokemonBuilder WithNickname(string nickname)
|
|
|
|
{
|
|
|
|
Nickname = nickname;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2020-07-18 14:49:11 +00:00
|
|
|
public PokemonBuilder LearnMove(string moveName, MoveLearnMethod moveLearnMethod)
|
|
|
|
{
|
|
|
|
if (LearnedMoves.Count > _library.StaticLibrary.Settings.MaximalMoves)
|
|
|
|
{
|
|
|
|
throw new Exception("Too many moves for Pokemon.");
|
|
|
|
}
|
|
|
|
LearnedMoves.Add((moveName, moveLearnMethod));
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Pokemon Build()
|
|
|
|
{
|
|
|
|
if (!_library.StaticLibrary.SpeciesLibrary.TryGet(Species, out var species))
|
|
|
|
{
|
|
|
|
throw new Exception($"Species '{Species}' was not found.");
|
|
|
|
}
|
|
|
|
|
2020-08-08 12:32:27 +00:00
|
|
|
if (!species!.TryGetForme(Forme, out var forme))
|
2020-07-18 14:49:11 +00:00
|
|
|
{
|
|
|
|
throw new Exception($"Forme '{Forme}' was not found on species '{Species}'");
|
|
|
|
}
|
|
|
|
|
|
|
|
var experience = _library.StaticLibrary.GrowthRateLibrary.CalculateExperience(species.GrowthRate, Level);
|
|
|
|
var random = new Random();
|
|
|
|
var uid = random.GetUnsigned(0, uint.MaxValue);
|
|
|
|
if (Gender == (Gender) (-1))
|
|
|
|
{
|
|
|
|
Gender = species.GetRandomGender(random);
|
|
|
|
}
|
|
|
|
|
|
|
|
byte coloring = 0;
|
|
|
|
if (IsForceShiny.HasValue)
|
|
|
|
{
|
|
|
|
coloring = (byte) (IsForceShiny.Value ? 1 : 0);
|
|
|
|
}
|
|
|
|
else if (random.Get(_library.StaticLibrary.Settings.ShinyRate) == 0)
|
|
|
|
{
|
|
|
|
coloring = 1;
|
|
|
|
}
|
|
|
|
|
2020-08-08 12:32:27 +00:00
|
|
|
Item? heldItem = null;
|
2020-07-18 14:49:11 +00:00
|
|
|
if (HeldItem != null)
|
|
|
|
{
|
|
|
|
if (!_library.StaticLibrary.ItemLibrary.TryGet(HeldItem, out heldItem))
|
|
|
|
{
|
|
|
|
throw new Exception($"Item '{HeldItem}' was not found.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-19 10:33:22 +00:00
|
|
|
var abilityIndex = 0;
|
2020-07-18 14:49:11 +00:00
|
|
|
var isHiddenAbility = false;
|
|
|
|
if (string.IsNullOrEmpty(Ability))
|
|
|
|
{
|
2020-08-08 12:32:27 +00:00
|
|
|
abilityIndex = forme!.GetRandomAbility(random);
|
2020-07-18 14:49:11 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-08-08 12:32:27 +00:00
|
|
|
abilityIndex = forme!.Abilities.IndexOf(Ability);
|
2020-07-18 14:49:11 +00:00
|
|
|
if (abilityIndex == -1)
|
|
|
|
{
|
2020-07-19 10:33:22 +00:00
|
|
|
abilityIndex = forme.HiddenAbilities.IndexOf(Ability);
|
2020-07-18 14:49:11 +00:00
|
|
|
if (abilityIndex == -1)
|
|
|
|
{
|
|
|
|
throw new Exception(
|
|
|
|
$"Invalid ability '{Ability}' for Pokemon '{species.Name}' and forme '{forme.Name}'.");
|
|
|
|
}
|
|
|
|
|
|
|
|
isHiddenAbility = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var moves = new LearnedMove[_library.StaticLibrary.Settings.MaximalMoves];
|
|
|
|
for (var i = 0; i < LearnedMoves.Count; i++)
|
|
|
|
{
|
|
|
|
if (!_library.StaticLibrary.MoveLibrary.TryGet(LearnedMoves[i].moveName, out var move))
|
|
|
|
{
|
|
|
|
throw new Exception($"Move '{LearnedMoves[i].moveName}' was not found.");
|
|
|
|
}
|
|
|
|
|
2020-08-08 12:32:27 +00:00
|
|
|
moves[i] = new LearnedMove(move!, move!.BaseUsages, LearnedMoves[i].learnMethod);
|
2020-07-18 14:49:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(Nature))
|
|
|
|
{
|
|
|
|
Nature = _library.StaticLibrary.NatureLibrary.GetRandomNatureName(random);
|
|
|
|
}
|
|
|
|
|
|
|
|
var nature = _library.StaticLibrary.NatureLibrary.GetNature(Nature);
|
|
|
|
|
|
|
|
return new Pokemon(_library, species, forme, Level, experience, uid, Gender, coloring, heldItem, Nickname,
|
2020-07-19 10:33:22 +00:00
|
|
|
isHiddenAbility, (byte) abilityIndex, moves, IVs, EVs, nature);
|
2020-07-18 14:49:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|