using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Nodes; using System.Text.Json.Serialization; // ReSharper disable UnusedAutoPropertyAccessor.Global // ReSharper disable PropertyCanBeMadeInitOnly.Global namespace PkmnLib.Dynamic.Libraries.DataLoaders.Models; /// /// Represents a serialized species. /// public class SerializedSpecies { /// public string Species { get; set; } = null!; /// public ushort Id { get; set; } /// public float GenderRatio { get; set; } /// public string GrowthRate { get; set; } = null!; /// public byte BaseHappiness { get; set; } /// public byte CatchRate { get; set; } /// /// The color of the Pokémon, used for Pokédex sorting. /// public string Color { get; set; } = null!; /// /// Whether the Pokémon has a different form per gender /// public bool GenderDifference { get; set; } /// public string[] EggGroups { get; set; } = null!; /// /// The number of steps required to hatch the Pokémon's egg, in cycles (1 cycle = 255 steps). /// public int EggCycles { get; set; } /// public string[] Flags { get; set; } = []; /// public Dictionary Formes { get; set; } = null!; /// public SerializedEvolution[] Evolutions { get; set; } = []; /// /// Additional data that is not part of the standard species data. /// [JsonExtensionData] public Dictionary? ExtensionData { get; set; } } /// /// Represents a serialized form of a Pokémon species. /// public class SerializedForm { /// public string[] Abilities { get; set; } = null!; /// public string[] HiddenAbilities { get; set; } = []; /// public SerializedStats BaseStats { get; set; } = null!; /// /// The Pokémon's EV yield. This is the number of EVs gained when defeating a Pokémon of this species. /// public SerializedStats EVReward { get; set; } = null!; /// public string[] Types { get; set; } = null!; /// public float Height { get; set; } /// public float Weight { get; set; } /// public uint BaseExp { get; set; } /// /// Whether the form is a Mega Evolution. /// public bool IsMega { get; set; } /// public SerializedMoves Moves { get; set; } = null!; /// public string[] Flags { get; set; } = []; /// /// Check if the form is a battle-only form, meaning it should return to its original form after the battle ends. /// public bool IsBattleOnly { get; set; } public string? InheritFrom { get; set; } /// /// Additional data that is not part of the standard form data. /// [JsonExtensionData] public Dictionary? ExtensionData { get; set; } [SuppressMessage("ReSharper", "ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract"), SuppressMessage("ReSharper", "NullCoalescingConditionIsAlwaysNotNullAccordingToAPIContract")] internal void MakeInheritFrom(SerializedForm other) { Abilities ??= other.Abilities.ToArray(); HiddenAbilities ??= other.HiddenAbilities.ToArray(); BaseStats ??= other.BaseStats.Copy(); EVReward ??= other.EVReward.Copy(); Types ??= other.Types.ToArray(); if (Height == 0) Height = other.Height; if (Weight == 0) Weight = other.Weight; if (BaseExp == 0) BaseExp = other.BaseExp; Moves ??= new SerializedMoves(); if (Moves.LevelMoves == null || Moves.LevelMoves.Length == 0) Moves.LevelMoves = other.Moves.LevelMoves?.ToArray(); if (Moves.EggMoves == null || Moves.EggMoves.Length == 0) Moves.EggMoves = other.Moves.EggMoves?.ToArray(); if (Moves.TutorMoves == null || Moves.TutorMoves.Length == 0) Moves.TutorMoves = other.Moves.TutorMoves?.ToArray(); if (Moves.Machine == null || Moves.Machine.Length == 0) Moves.Machine = other.Moves.Machine?.ToArray(); Flags ??= other.Flags.ToArray(); } } /// /// Represents a serialized evolution of a Pokémon species. /// public class SerializedEvolution { /// public string Species { get; set; } = null!; /// /// The method of evolution. /// public string Method { get; set; } = null!; /// /// Additional data for the evolution method. /// public JsonNode Data { get; set; } = null!; } /// /// Represents the base stats of a Pokémon species. /// public record SerializedStats { /// public ushort Hp { get; set; } /// public ushort Attack { get; set; } /// public ushort Defense { get; set; } /// public ushort SpecialAttack { get; set; } /// public ushort SpecialDefense { get; set; } /// public ushort Speed { get; set; } public SerializedStats Copy() => new() { Hp = Hp, Attack = Attack, Defense = Defense, SpecialAttack = SpecialAttack, SpecialDefense = SpecialDefense, Speed = Speed, }; } /// /// Represents a serialized level move. /// public class SerializedLevelMove { /// /// The name of the move. /// public string Name { get; set; } = null!; /// /// The level at which the move is learned. /// public uint Level { get; set; } } /// /// Represents a serialized set of moves a Pokémon can learn. /// public class SerializedMoves { /// /// The moves the Pokémon can learn by leveling up. /// public SerializedLevelMove[]? LevelMoves { get; set; } = null!; /// /// The moves the Pokémon can learn by breeding. /// public string[]? EggMoves { get; set; } = null!; /// /// The moves the Pokémon can learn by tutoring. /// public string[]? TutorMoves { get; set; } = null!; /// /// The moves the Pokémon can learn by TM. /// public string[]? Machine { get; set; } = null!; }