Initial commit
This commit is contained in:
148
PkmnLib.Static/Species/Species.cs
Normal file
148
PkmnLib.Static/Species/Species.cs
Normal file
@@ -0,0 +1,148 @@
|
||||
using System.Collections.Immutable;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using PkmnLib.Static.Utils;
|
||||
|
||||
namespace PkmnLib.Static.Species;
|
||||
|
||||
/// <summary>
|
||||
/// The data belonging to a Pokemon with certain characteristics.
|
||||
/// </summary>
|
||||
public interface ISpecies
|
||||
{
|
||||
/// <summary>
|
||||
/// The national dex identifier of the Pokemon.
|
||||
/// </summary>
|
||||
ushort Id { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The name of the Pokemon.
|
||||
/// </summary>
|
||||
StringKey Name { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The chance between 0.0 and 1.0 that a Pokemon is female. 0.0 means always male, 1.0 means always female.
|
||||
/// If less than 0, the Pokemon is genderless.
|
||||
/// </summary>
|
||||
float GenderRate { get; }
|
||||
|
||||
/// <summary>
|
||||
/// How much experience is required for a level.
|
||||
/// </summary>
|
||||
StringKey GrowthRate { get; }
|
||||
|
||||
/// <summary>
|
||||
/// How hard it is to capture a Pokemon. 255 means this will be always caught, 0 means this is
|
||||
/// uncatchable.
|
||||
/// </summary>
|
||||
byte CaptureRate { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The base happiness of the Pokemon.
|
||||
/// </summary>
|
||||
byte BaseHappiness { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The forms that belong to this Pokemon.
|
||||
/// </summary>
|
||||
IReadOnlyDictionary<StringKey, IForm> Forms { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The arbitrary flags that can be set on a Pokemon for script use.
|
||||
/// </summary>
|
||||
ImmutableHashSet<StringKey> Flags { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a form by name.
|
||||
/// </summary>
|
||||
bool TryGetForm(StringKey id, [MaybeNullWhen(false)] out IForm form);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the form the Pokemon will have by default, if no other form is specified.
|
||||
/// </summary>
|
||||
IForm GetDefaultForm();
|
||||
|
||||
/// <summary>
|
||||
/// Gets a random gender.
|
||||
/// </summary>
|
||||
Gender GetRandomGender(IRandom rand);
|
||||
|
||||
/// <summary>
|
||||
/// Check whether the Pokemon has a specific flag set.
|
||||
/// </summary>
|
||||
bool HasFlag(string key);
|
||||
|
||||
/// <summary>
|
||||
/// The data regarding into which Pokemon this species can evolve, and how.
|
||||
/// </summary>
|
||||
IReadOnlyList<IEvolution> EvolutionData { get; }
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public class SpeciesImpl : ISpecies
|
||||
{
|
||||
/// <inheritdoc cref="SpeciesImpl" />
|
||||
public SpeciesImpl(ushort id, StringKey name, float genderRate, StringKey growthRate, byte captureRate,
|
||||
byte baseHappiness, IReadOnlyDictionary<StringKey, IForm> forms, ImmutableHashSet<StringKey> flags,
|
||||
IReadOnlyList<IEvolution> evolutionData)
|
||||
{
|
||||
Id = id;
|
||||
Name = name;
|
||||
GenderRate = genderRate;
|
||||
GrowthRate = growthRate;
|
||||
CaptureRate = captureRate;
|
||||
BaseHappiness = baseHappiness;
|
||||
Forms = forms;
|
||||
Flags = flags;
|
||||
EvolutionData = evolutionData;
|
||||
if (Forms.Count == 0)
|
||||
throw new ArgumentException("Species must have at least one form.");
|
||||
if (!Forms.ContainsKey("default"))
|
||||
throw new ArgumentException("Species must have a default form.");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public ushort Id { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public StringKey Name { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public float GenderRate { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public StringKey GrowthRate { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte CaptureRate { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte BaseHappiness { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyDictionary<StringKey, IForm> Forms { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public ImmutableHashSet<StringKey> Flags { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyList<IEvolution> EvolutionData { get; }
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool TryGetForm(StringKey id, [MaybeNullWhen(false)] out IForm form) => Forms.TryGetValue(id, out form);
|
||||
|
||||
/// <inheritdoc />
|
||||
public IForm GetDefaultForm() => Forms["default"];
|
||||
|
||||
/// <inheritdoc />
|
||||
public Gender GetRandomGender(IRandom rand)
|
||||
{
|
||||
if (GenderRate < 0.0f)
|
||||
return Gender.Genderless;
|
||||
var v = rand.GetFloat();
|
||||
return v < GenderRate ? Gender.Female : Gender.Male;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool HasFlag(string key) => Flags.Contains(key);
|
||||
}
|
||||
Reference in New Issue
Block a user