109 lines
4.5 KiB
C#
109 lines
4.5 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using PkmnLibSharp.Utils;
|
|
using Interface = PkmnLibSharp.FFI.StaticData.Form;
|
|
|
|
namespace PkmnLibSharp.StaticData
|
|
{
|
|
/// <summary>
|
|
/// A form is a variant of a specific species. A species always has at least one form, but can have
|
|
/// many more.
|
|
/// </summary>
|
|
public class Form : HandleType
|
|
{
|
|
/// <inheritdoc cref="Form"/>
|
|
protected Form(FFIHandle handle) : base(handle)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Instantiates a new form.
|
|
/// </summary>
|
|
public static Form Create(string name, float height, float weight, uint baseExperience, TypeIdentifier[] types,
|
|
StaticStatisticSet<ushort> baseStats, IReadOnlyCollection<string> abilities,
|
|
IReadOnlyCollection<string> hiddenAbilities, LearnableMoves learnableMoves,
|
|
IReadOnlyCollection<string> flags)
|
|
{
|
|
var typesArr = types.ArrayPtr();
|
|
|
|
var abilitiesPtrArray = abilities.Select(x => x.ToPtr()).ToArray();
|
|
var hiddenAbilitiesPtrArray = hiddenAbilities.Select(x => x.ToPtr()).ToArray();
|
|
var flagsPtrArray = flags.Select(x => x.ToPtr()).ToArray();
|
|
|
|
var handle = Interface.form_new(name.ToPtr(), height, weight, baseExperience, typesArr, (ulong)types.Length,
|
|
baseStats.Handle, abilitiesPtrArray.ArrayPtr(), (ulong)abilities.Count,
|
|
hiddenAbilitiesPtrArray.ArrayPtr(), (ulong)hiddenAbilities.Count,
|
|
learnableMoves.Handle, flagsPtrArray.ArrayPtr(), (ulong)flags.Count);
|
|
var form = Resolver.Instance.ResolveForm(handle.Result().Resolve());
|
|
return form;
|
|
}
|
|
|
|
|
|
private string? _name;
|
|
/// <summary>
|
|
/// The name of the form.
|
|
/// </summary>
|
|
public string Name => _name ??= Interface.form_name(Handle).Result().PtrString()!;
|
|
private float? _height;
|
|
|
|
/// <summary>
|
|
/// The height of the form in meters.
|
|
/// </summary>
|
|
public float Height => _height ??= Interface.form_height(Handle);
|
|
private float? _weight;
|
|
|
|
/// <summary>
|
|
/// The weight of the form in kilograms.
|
|
/// </summary>
|
|
public float Weight => _weight ??= Interface.form_weight(Handle);
|
|
private uint? _baseExperience;
|
|
|
|
/// <summary>
|
|
/// The base amount of experience that is gained when beating a Pokemon with this form.
|
|
/// </summary>
|
|
public uint BaseExperience => _baseExperience ??= Interface.form_base_experience(Handle);
|
|
|
|
private IReadOnlyList<TypeIdentifier>? _types;
|
|
|
|
/// <summary>
|
|
/// The normal types a Pokemon with this form has.
|
|
/// </summary>
|
|
public IReadOnlyList<TypeIdentifier> Types =>
|
|
_types ??= new CachedExternValueArray<TypeIdentifier>(Interface.form_types_length(Handle),
|
|
arg => Interface.form_types_get(Handle, arg));
|
|
|
|
private StaticStatisticSet<ushort>? _baseStats;
|
|
|
|
/// <summary>
|
|
/// The inherent values of a form of species that are used for the stats of a Pokemon.
|
|
/// </summary>
|
|
public StaticStatisticSet<ushort> BaseStats =>
|
|
_baseStats ??= Resolver.Instance.ResolveStaticStatisticSet<ushort>(Interface.form_base_stats(Handle).Resolve());
|
|
|
|
private IReadOnlyList<string>? _abilities;
|
|
|
|
/// <summary>
|
|
/// The possible abilities a Pokemon with this form can have.
|
|
/// </summary>
|
|
public IReadOnlyList<string> Abilities =>
|
|
_abilities ??= new CachedExternArray<string>(Interface.form_abilities_length(Handle),
|
|
arg => Interface.form_abilities_get(Handle, arg).PtrString()!);
|
|
|
|
private IReadOnlyList<string>? _hiddenAbilities;
|
|
|
|
/// <summary>
|
|
/// The possible hidden abilities a Pokemon with this form can have.
|
|
/// </summary>
|
|
public IReadOnlyList<string> HiddenAbilities =>
|
|
_hiddenAbilities ??= new CachedExternArray<string>(Interface.form_hidden_abilities_length(Handle),
|
|
arg => Interface.form_hidden_abilities_get(Handle, arg).PtrString()!);
|
|
|
|
private LearnableMoves? _learnableMoves;
|
|
|
|
/// <summary>
|
|
/// The moves a Pokemon with this form can learn.
|
|
/// </summary>
|
|
public LearnableMoves LearnableMoves =>
|
|
_learnableMoves ??= Resolver.Instance.ResolveLearnableMoves(Interface.form_moves(Handle).Resolve());
|
|
}
|
|
} |