using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; using PkmnLibSharp.Utils; using Interface = PkmnLibSharp.FFI.StaticData.Species; namespace PkmnLibSharp.StaticData { public class Species : HandleType { protected Species(FFIHandle handle) : base(handle) { } public static Species Create(ushort id, string name, float genderRate, string growthRate, byte captureRate, Form defaultForm, IReadOnlyCollection flags) { var flagsPtrArray = flags.Select(x => x.ToPtr()).ToArray(); var handle = Interface.species_new(id, name.ToPtr(), genderRate, growthRate.ToPtr(), captureRate, defaultForm.Handle, flagsPtrArray.ArrayPtr(), (ulong)flags.Count); var species = Resolver.Instance.ResolveSpecies(handle.Result().Resolve()); species._forms.Add("default", defaultForm); return species; } private ushort? _id; public ushort Id => _id ??= Interface.species_id(Handle); private string? _name; public string Name => _name ??= Interface.species_name(Handle).PtrString()!; private float? _genderRate; public float GenderRate => _genderRate ??= Interface.species_gender_rate(Handle); private string? _growthRate; public string GrowthRate => _growthRate ??= Interface.species_growth_rate(Handle).PtrString()!; private byte? _captureRate; public byte CaptureRate => _captureRate ??= Interface.species_capture_rate(Handle); public Form DefaultForm { get { TryGetForm("default", out var form); return form!; } } private Dictionary _forms = new(StringComparer.InvariantCultureIgnoreCase); public bool TryGetForm(string formName, [NotNullWhen(true)] out Form? form) { if (_forms.TryGetValue(formName, out form)) return true; var formPtr = Interface.species_get_form(Handle, formName.ToPtr()); if (formPtr.Handle == 0) { form = null; return false; } form = Resolver.Instance.ResolveForm(formPtr.Resolve()); _forms.Add(formName, form); return true; } public void AddForm(Form form) { Interface.species_add_form(Handle, form.Name.ToPtr(), form.Handle).Result(); _forms.Add(form.Name, form); } public Gender GetRandomGender(ulong seed) => Interface.species_get_random_gender(Handle, seed); } }