2023-03-26 00:55:55 +00:00
|
|
|
using System;
|
Refactoring: Move Source (Legality) (#3560)
Rewrites a good amount of legality APIs pertaining to:
* Legal moves that can be learned
* Evolution chains & cross-generation paths
* Memory validation with forgotten moves
In generation 8, there are 3 separate contexts an entity can exist in: SW/SH, BD/SP, and LA. Not every entity can cross between them, and not every entity from generation 7 can exist in generation 8 (Gogoat, etc). By creating class models representing the restrictions to cross each boundary, we are able to better track and validate data.
The old implementation of validating moves was greedy: it would iterate for all generations and evolutions, and build a full list of every move that can be learned, storing it on the heap. Now, we check one game group at a time to see if the entity can learn a move that hasn't yet been validated. End result is an algorithm that requires 0 allocation, and a smaller/quicker search space.
The old implementation of storing move parses was inefficient; for each move that was parsed, a new object is created and adjusted depending on the parse. Now, move parse results are `struct` and store the move parse contiguously in memory. End result is faster parsing and 0 memory allocation.
* `PersonalTable` objects have been improved with new API methods to check if a species+form can exist in the game.
* `IEncounterTemplate` objects have been improved to indicate the `EntityContext` they originate in (similar to `Generation`).
* Some APIs have been extended to accept `Span<T>` instead of Array/IEnumerable
2022-08-03 23:15:27 +00:00
|
|
|
using System.Collections.Generic;
|
2020-10-25 16:30:42 +00:00
|
|
|
using static PKHeX.Core.Species;
|
2020-10-25 16:15:16 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
namespace PKHeX.Core;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Contains logic for Alternate Form information.
|
|
|
|
/// </summary>
|
|
|
|
public static class FormInfo
|
2020-10-25 16:15:16 +00:00
|
|
|
{
|
2020-10-25 16:30:42 +00:00
|
|
|
/// <summary>
|
2023-12-04 04:13:20 +00:00
|
|
|
/// Checks if the form cannot exist outside a Battle.
|
2020-10-25 16:30:42 +00:00
|
|
|
/// </summary>
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <param name="species">Entity species</param>
|
|
|
|
/// <param name="form">Entity form</param>
|
|
|
|
/// <param name="format">Current generation format</param>
|
|
|
|
/// <returns>True if it can only exist in a battle, false if it can exist outside of battle.</returns>
|
2023-11-05 22:20:35 +00:00
|
|
|
public static bool IsBattleOnlyForm(ushort species, byte form, int format) => BattleOnly.Contains(species) && species switch
|
2020-10-25 16:15:16 +00:00
|
|
|
{
|
2023-11-05 22:20:35 +00:00
|
|
|
// Only continue checking if the species is in the list of Battle Only forms.
|
2022-06-18 18:04:24 +00:00
|
|
|
// Some species have battle only forms as well as out-of-battle forms (other than base form).
|
2023-11-05 22:20:35 +00:00
|
|
|
(ushort)Slowbro => form == 1, // Mega
|
|
|
|
(ushort)Darmanitan => (form & 1) == 1, // Zen
|
|
|
|
(ushort)Zygarde => form == 4, // Zygarde Complete
|
|
|
|
(ushort)Minior => form < 7, // Minior Shields-Down
|
|
|
|
(ushort)Mimikyu => (form & 1) == 1, // Busted
|
|
|
|
(ushort)Necrozma => form == 3, // Ultra Necrozma
|
|
|
|
(ushort)Ogerpon => form >= 4, // Embody Aspect
|
|
|
|
_ => form != 0,
|
|
|
|
};
|
2020-10-25 16:15:16 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Reverts the Battle Form to the form it would have outside of Battle.
|
|
|
|
/// </summary>
|
|
|
|
/// <remarks>Only call this if you've already checked that <see cref="IsBattleOnlyForm"/> returns true.</remarks>
|
|
|
|
/// <param name="species">Entity species</param>
|
|
|
|
/// <param name="form">Entity form</param>
|
|
|
|
/// <param name="format">Current generation format</param>
|
|
|
|
/// <returns>Suggested alt form value.</returns>
|
2022-08-27 06:43:36 +00:00
|
|
|
public static byte GetOutOfBattleForm(ushort species, byte form, int format) => species switch
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
2023-11-05 22:20:35 +00:00
|
|
|
(ushort)Darmanitan => (byte)(form & 2),
|
|
|
|
(ushort)Zygarde when format > 6 => 3,
|
|
|
|
(ushort)Minior => (byte)(form + 7),
|
|
|
|
(ushort)Mimikyu => (byte)(form & 2),
|
|
|
|
(ushort)Ogerpon => (byte)(form & 3),
|
2022-06-18 18:04:24 +00:00
|
|
|
_ => 0,
|
|
|
|
};
|
|
|
|
|
2022-11-25 01:42:17 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Indicates if the entity should be prevented from being traded away.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="species">Entity species</param>
|
|
|
|
/// <param name="form">Entity form</param>
|
|
|
|
/// <param name="formArg">Entity form argument</param>
|
|
|
|
/// <param name="format">Current generation format</param>
|
2023-12-04 04:13:20 +00:00
|
|
|
/// <returns>True if trading should be disallowed.</returns>
|
2022-11-25 01:42:17 +00:00
|
|
|
public static bool IsUntradable(ushort species, byte form, uint formArg, int format) => species switch
|
|
|
|
{
|
2023-11-05 22:20:35 +00:00
|
|
|
(ushort)Koraidon or (int)Miraidon => formArg == 1, // Ride-able Box Legend
|
|
|
|
(ushort)Pikachu => format == 7 && form == 8, // Let's Go Pikachu Starter
|
|
|
|
(ushort)Eevee => format == 7 && form == 1, // Let's Go Eevee Starter
|
2022-11-25 01:42:17 +00:00
|
|
|
_ => IsFusedForm(species, form, format),
|
|
|
|
};
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Checks if the <see cref="form"/> is a fused form, which indicates it cannot be traded away.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="species">Entity species</param>
|
|
|
|
/// <param name="form">Entity form</param>
|
|
|
|
/// <param name="format">Current generation format</param>
|
|
|
|
/// <returns>True if it is a fused species-form, false if it is not fused.</returns>
|
2022-08-27 19:53:30 +00:00
|
|
|
public static bool IsFusedForm(ushort species, byte form, int format) => species switch
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
2023-11-05 22:20:35 +00:00
|
|
|
(ushort)Kyurem => form != 0 && format >= 5,
|
|
|
|
(ushort)Necrozma => form != 0 && format >= 7,
|
|
|
|
(ushort)Calyrex => form != 0 && format >= 8,
|
2022-06-18 18:04:24 +00:00
|
|
|
_ => false,
|
|
|
|
};
|
|
|
|
|
2023-12-04 04:13:20 +00:00
|
|
|
/// <summary>Checks if the form may be different from the original encounter detail.</summary>
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <param name="species">Original species</param>
|
|
|
|
/// <param name="oldForm">Original form</param>
|
|
|
|
/// <param name="newForm">Current form</param>
|
2022-12-08 07:28:47 +00:00
|
|
|
/// <param name="origin">Encounter context</param>
|
|
|
|
/// <param name="current">Current context</param>
|
|
|
|
public static bool IsFormChangeable(ushort species, byte oldForm, byte newForm, EntityContext origin, EntityContext current)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
if (FormChange.Contains(species))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Zygarde Form Changing
|
|
|
|
// Gen6: Introduced; no form changing.
|
|
|
|
// Gen7: Form changing introduced; can only change to Form 2/3 (Power Construct), never to 0/1 (Aura Break). A form-1 can be boosted to form-0.
|
|
|
|
// Gen8: Form changing improved; can pick any Form & Ability combination.
|
|
|
|
if (species == (int)Zygarde)
|
2020-11-02 22:46:26 +00:00
|
|
|
{
|
2022-12-08 07:28:47 +00:00
|
|
|
return current switch
|
2020-11-02 22:46:26 +00:00
|
|
|
{
|
2022-12-08 07:28:47 +00:00
|
|
|
EntityContext.Gen6 => false,
|
|
|
|
EntityContext.Gen7 => newForm >= 2 || (oldForm == 1 && newForm == 0),
|
2022-06-18 18:04:24 +00:00
|
|
|
_ => true,
|
|
|
|
};
|
2020-11-02 22:46:26 +00:00
|
|
|
}
|
2022-12-08 07:28:47 +00:00
|
|
|
if (species is (int)Deerling or (int)Sawsbuck)
|
|
|
|
{
|
2023-07-07 02:41:27 +00:00
|
|
|
if (origin == EntityContext.Gen5)
|
2023-12-04 04:13:20 +00:00
|
|
|
return true; // B/W or B2/W2 change via seasons
|
2023-07-07 02:41:27 +00:00
|
|
|
if (current.Generation() >= 8)
|
2023-12-04 04:13:20 +00:00
|
|
|
return true; // Via S/V change via in-game province on startup.
|
2022-12-08 07:28:47 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
2020-11-02 22:46:26 +00:00
|
|
|
|
2023-04-21 04:23:15 +00:00
|
|
|
public static bool IsFormChangeEgg(ushort species) => FormChangeEgg.Contains(species);
|
2022-11-25 22:12:19 +00:00
|
|
|
|
2023-12-04 04:13:20 +00:00
|
|
|
private static ReadOnlySpan<ushort> FormChangeEgg =>
|
|
|
|
[
|
2022-11-25 22:12:19 +00:00
|
|
|
(int)Burmy,
|
|
|
|
(int)Furfrou,
|
|
|
|
(int)Oricorio,
|
2023-12-04 04:13:20 +00:00
|
|
|
];
|
2022-11-25 22:12:19 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Species that can change between their forms, regardless of origin.
|
|
|
|
/// </summary>
|
|
|
|
/// <remarks>Excludes Zygarde as it has special conditions. Check separately.</remarks>
|
2023-12-04 04:13:20 +00:00
|
|
|
private static readonly HashSet<ushort> FormChange =
|
|
|
|
[
|
2023-03-26 00:55:55 +00:00
|
|
|
(int)Burmy,
|
|
|
|
(int)Furfrou,
|
|
|
|
(int)Oricorio,
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Sometimes considered for wild encounters
|
|
|
|
(int)Rotom,
|
|
|
|
|
|
|
|
(int)Deoxys,
|
|
|
|
(int)Dialga,
|
|
|
|
(int)Palkia,
|
|
|
|
(int)Giratina,
|
|
|
|
(int)Shaymin,
|
|
|
|
(int)Arceus,
|
|
|
|
(int)Tornadus,
|
|
|
|
(int)Thundurus,
|
|
|
|
(int)Landorus,
|
|
|
|
(int)Kyurem,
|
|
|
|
(int)Keldeo,
|
|
|
|
(int)Genesect,
|
|
|
|
(int)Hoopa,
|
|
|
|
(int)Silvally,
|
|
|
|
(int)Necrozma,
|
|
|
|
(int)Calyrex,
|
|
|
|
(int)Enamorus,
|
2023-09-16 06:36:21 +00:00
|
|
|
(int)Ogerpon,
|
2023-12-04 04:13:20 +00:00
|
|
|
];
|
2020-10-25 16:15:16 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Species that have an alternate form that cannot exist outside of battle.
|
|
|
|
/// </summary>
|
2023-12-04 04:13:20 +00:00
|
|
|
private static ReadOnlySpan<ushort> BattleForms =>
|
|
|
|
[
|
2022-06-18 18:04:24 +00:00
|
|
|
(int)Castform,
|
2023-12-04 04:13:20 +00:00
|
|
|
(int)Kyogre,
|
|
|
|
(int)Groudon,
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
(int)Cherrim,
|
2023-12-04 04:13:20 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
(int)Darmanitan,
|
|
|
|
(int)Meloetta,
|
2023-12-04 04:13:20 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
(int)Aegislash,
|
|
|
|
(int)Xerneas,
|
|
|
|
(int)Zygarde,
|
|
|
|
|
|
|
|
(int)Wishiwashi,
|
|
|
|
(int)Minior,
|
|
|
|
(int)Mimikyu,
|
2023-12-04 04:13:20 +00:00
|
|
|
(int)Necrozma,
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
(int)Cramorant,
|
|
|
|
(int)Morpeko,
|
|
|
|
(int)Eiscue,
|
|
|
|
(int)Zacian,
|
|
|
|
(int)Zamazenta,
|
|
|
|
(int)Eternatus,
|
2022-11-25 01:42:17 +00:00
|
|
|
|
|
|
|
(int)Palafin,
|
2023-09-16 06:36:21 +00:00
|
|
|
(int)Ogerpon,
|
2023-12-18 00:41:15 +00:00
|
|
|
(int)Terapagos,
|
2023-12-04 04:13:20 +00:00
|
|
|
];
|
2020-10-25 16:15:16 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Species that have a mega form that cannot exist outside of battle.
|
|
|
|
/// </summary>
|
|
|
|
/// <remarks>Using a held item to change form during battle, via an in-battle transformation feature.</remarks>
|
2023-12-04 04:13:20 +00:00
|
|
|
private static ReadOnlySpan<ushort> BattleMegas =>
|
|
|
|
[
|
|
|
|
// X/Y
|
2022-06-18 18:04:24 +00:00
|
|
|
(int)Venusaur, (int)Charizard, (int)Blastoise,
|
|
|
|
(int)Alakazam, (int)Gengar, (int)Kangaskhan, (int)Pinsir,
|
|
|
|
(int)Gyarados, (int)Aerodactyl, (int)Mewtwo,
|
2020-10-25 16:15:16 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
(int)Ampharos, (int)Scizor, (int)Heracross, (int)Houndoom, (int)Tyranitar,
|
2020-10-25 16:15:16 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
(int)Blaziken, (int)Gardevoir, (int)Mawile, (int)Aggron, (int)Medicham,
|
|
|
|
(int)Manectric, (int)Banette, (int)Absol, (int)Latios, (int)Latias,
|
2020-10-25 16:15:16 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
(int)Garchomp, (int)Lucario, (int)Abomasnow,
|
2020-10-25 16:15:16 +00:00
|
|
|
|
2023-12-04 04:13:20 +00:00
|
|
|
// OR/AS
|
2022-06-18 18:04:24 +00:00
|
|
|
(int)Beedrill, (int)Pidgeot, (int)Slowbro,
|
2020-10-25 16:15:16 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
(int)Steelix,
|
2020-10-25 16:15:16 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
(int)Sceptile, (int)Swampert, (int)Sableye, (int)Sharpedo, (int)Camerupt,
|
|
|
|
(int)Altaria, (int)Glalie, (int)Salamence, (int)Metagross, (int)Rayquaza,
|
2020-10-25 16:15:16 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
(int)Lopunny, (int)Gallade,
|
|
|
|
(int)Audino, (int)Diancie,
|
2023-12-04 04:13:20 +00:00
|
|
|
];
|
2020-10-25 16:15:16 +00:00
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
private static readonly HashSet<ushort> BattleOnly = GetBattleFormSet();
|
2020-11-27 19:51:02 +00:00
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
private static HashSet<ushort> GetBattleFormSet()
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
2023-12-04 04:13:20 +00:00
|
|
|
var reg = BattleForms;
|
|
|
|
var mega = BattleMegas;
|
|
|
|
var count = reg.Length + mega.Length + 2;
|
|
|
|
var hs = new HashSet<ushort>(count);
|
|
|
|
foreach (var species in reg)
|
|
|
|
hs.Add(species);
|
|
|
|
foreach (var species in mega)
|
|
|
|
hs.Add(species);
|
2022-06-18 18:04:24 +00:00
|
|
|
return hs;
|
|
|
|
}
|
2020-11-27 19:51:02 +00:00
|
|
|
|
2023-04-21 04:23:15 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Species has a Totem form in Gen7 (S/M & US/UM) that can be captured and owned.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="species"></param>
|
|
|
|
/// <returns>True if the species exists as a Totem.</returns>
|
|
|
|
/// <remarks>Excludes <see cref="Wishiwashi"/> because it cannot be captured.</remarks>
|
|
|
|
public static bool HasTotemForm(ushort species) => species switch
|
|
|
|
{
|
|
|
|
(ushort)Raticate => true,
|
|
|
|
(ushort)Marowak => true,
|
|
|
|
(ushort)Gumshoos => true,
|
|
|
|
(ushort)Vikavolt => true,
|
|
|
|
(ushort)Ribombee => true,
|
|
|
|
(ushort)Araquanid => true,
|
|
|
|
(ushort)Lurantis => true,
|
|
|
|
(ushort)Salazzle => true,
|
|
|
|
(ushort)Mimikyu => true,
|
|
|
|
(ushort)Kommoo => true,
|
|
|
|
(ushort)Togedemaru => true,
|
|
|
|
_ => false,
|
|
|
|
};
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Checks if the <see cref="form"/> for the <see cref="species"/> is a Totem form.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="species">Entity species</param>
|
|
|
|
/// <param name="form">Entity form</param>
|
2022-12-18 08:16:29 +00:00
|
|
|
/// <param name="context">Current generation format</param>
|
|
|
|
public static bool IsTotemForm(ushort species, byte form, EntityContext context) => context == EntityContext.Gen7 && IsTotemForm(species, form);
|
2022-02-05 01:35:15 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Checks if the <see cref="form"/> for the <see cref="species"/> is a Totem form.
|
|
|
|
/// </summary>
|
2022-12-18 08:16:29 +00:00
|
|
|
/// <remarks>Use <see cref="IsTotemForm(ushort,byte,EntityContext)"/> if you aren't 100% sure the format is 7.</remarks>
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <param name="species">Entity species</param>
|
|
|
|
/// <param name="form">Entity form</param>
|
2022-08-27 19:53:30 +00:00
|
|
|
public static bool IsTotemForm(ushort species, byte form)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
if (form == 0)
|
|
|
|
return false;
|
2023-04-21 04:23:15 +00:00
|
|
|
if (!HasTotemForm(species))
|
2022-06-18 18:04:24 +00:00
|
|
|
return false;
|
|
|
|
if (species == (int)Mimikyu)
|
|
|
|
return form is 2 or 3;
|
2023-04-21 04:23:15 +00:00
|
|
|
if (species is (int)Raticate or (int)Marowak)
|
2022-06-18 18:04:24 +00:00
|
|
|
return form == 2;
|
|
|
|
return form == 1;
|
|
|
|
}
|
2020-11-27 19:51:02 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Gets the base <see cref="form"/> for the <see cref="species"/> when the Totem form is reverted (on transfer).
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="species">Entity species</param>
|
|
|
|
/// <param name="form">Entity form</param>
|
2022-08-27 06:43:36 +00:00
|
|
|
public static byte GetTotemBaseForm(ushort species, byte form)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
if (species == (int)Mimikyu)
|
2022-08-27 06:43:36 +00:00
|
|
|
return 0;
|
|
|
|
return --form;
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2020-11-27 19:51:02 +00:00
|
|
|
|
2022-12-18 08:16:29 +00:00
|
|
|
public static bool IsLordForm(ushort species, byte form, EntityContext context)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
2022-12-18 08:16:29 +00:00
|
|
|
if (context != EntityContext.Gen8a)
|
2022-06-18 18:04:24 +00:00
|
|
|
return false;
|
|
|
|
return IsLordForm(species, form);
|
|
|
|
}
|
2020-11-27 19:51:02 +00:00
|
|
|
|
2022-08-27 19:53:30 +00:00
|
|
|
private static bool IsLordForm(ushort species, byte form) => form != 0 && species switch
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
(int)Arcanine when form == 2 => true,
|
|
|
|
(int)Electrode when form == 2 => true,
|
|
|
|
(int)Lilligant when form == 2 => true,
|
|
|
|
(int)Avalugg when form == 2 => true,
|
|
|
|
(int)Kleavor when form == 1 => true,
|
|
|
|
_ => false,
|
|
|
|
};
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Checks if the <see cref="form"/> exists for the <see cref="species"/> without having an associated <see cref="PersonalInfo"/> index.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="species">Entity species</param>
|
|
|
|
/// <param name="form">Entity form</param>
|
|
|
|
/// <param name="format">Current generation format</param>
|
|
|
|
/// <seealso cref="HasFormValuesNotIndicatedByPersonal"/>
|
2022-08-27 19:53:30 +00:00
|
|
|
public static bool IsValidOutOfBoundsForm(ushort species, byte form, int format) => (Species) species switch
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
Unown => form < (format == 2 ? 26 : 28), // A-Z : A-Z?!
|
|
|
|
Mothim => form < 3, // Burmy base form is kept
|
|
|
|
|
|
|
|
Scatterbug => form <= Vivillon3DS.MaxWildFormID, // Vivillon Pre-evolutions
|
|
|
|
Spewpa => form <= Vivillon3DS.MaxWildFormID, // Vivillon Pre-evolutions
|
|
|
|
|
|
|
|
_ => false,
|
|
|
|
};
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Checks if the <see cref="PKM"/> data should have a drop-down selection visible for the <see cref="PKM.Form"/> value.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="pi">Game specific personal info</param>
|
|
|
|
/// <param name="species"><see cref="Species"/> ID</param>
|
|
|
|
/// <param name="format"><see cref="PKM.Form"/> ID</param>
|
2023-12-04 04:13:20 +00:00
|
|
|
/// <returns>True if it has forms that can be provided by <see cref="FormConverter.GetFormList"/>, otherwise false for none.</returns>
|
2022-08-27 06:43:36 +00:00
|
|
|
public static bool HasFormSelection(IPersonalFormInfo pi, ushort species, int format)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
if (format <= 3 && species != (int)Unown)
|
|
|
|
return false;
|
|
|
|
|
2023-04-21 04:23:15 +00:00
|
|
|
if (HasFormValuesNotIndicatedByPersonal(species))
|
2022-06-18 18:04:24 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
int count = pi.FormCount;
|
|
|
|
return count > 1;
|
2020-10-25 16:15:16 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <seealso cref="IsValidOutOfBoundsForm"/>
|
|
|
|
/// </summary>
|
2023-04-21 04:23:15 +00:00
|
|
|
private static bool HasFormValuesNotIndicatedByPersonal(ushort species) => species switch
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
2023-04-21 04:23:15 +00:00
|
|
|
(int)Unown => true,
|
|
|
|
(int)Mothim => true, // (Burmy form is not cleared on evolution)
|
|
|
|
(int)Scatterbug or (int)Spewpa => true, // Vivillon pre-evos
|
|
|
|
_ => false,
|
2022-06-18 18:04:24 +00:00
|
|
|
};
|
2020-10-25 16:15:16 +00:00
|
|
|
}
|