PKHeX/PKHeX.Core/Saves/Substructures/Gen3/EReaderBerrySettings.cs

112 lines
3.4 KiB
C#
Raw Normal View History

using System.Collections.Generic;
using static PKHeX.Core.EReaderBerryMatch;
2020-07-19 03:51:55 +00:00
namespace PKHeX.Core
{
/// <summary>
/// Stores details about the Gen3 e-Reader Berry values.
/// </summary>
public static class EReaderBerrySettings
{
/// <summary> e-Reader Berry is Enigma or special berry (from e-Reader data)</summary>
public static bool IsEnigma { get; set; } = true;
/// <summary> e-Reader Berry Name </summary>
private static string Name { get; set; } = string.Empty;
/// <summary> e-Reader Berry Name formatted in Title Case </summary>
public static string DisplayName => string.Format(LegalityCheckStrings.L_XEnigmaBerry_0, Util.ToTitleCase(Name));
private static int Language { get; set; }
public static EReaderBerryMatch GetStatus()
{
if (IsEnigma) // no e-Reader Berry data provided, can't hold berry.
return NoData;
var matchUSA = EReaderBerriesNames_USA.Contains(Name);
2020-07-19 03:51:55 +00:00
if (matchUSA)
{
return Language switch
{
<= 0 => ValidAny,
not 1 => ValidUSA,
_ => InvalidUSA
};
2020-07-19 03:51:55 +00:00
}
var matchJP = EReaderBerriesNames_JP.Contains(Name);
2020-07-19 03:51:55 +00:00
if (matchJP)
{
return Language switch
{
<= 0 => ValidAny,
1 => ValidJPN,
_ => InvalidJPN
};
2020-07-19 03:51:55 +00:00
}
return NoMatch;
}
private static readonly HashSet<string> EReaderBerriesNames_USA = new()
{
// USA Series 1
"PUMKIN",
"DRASH",
"EGGANT",
"STRIB",
"CHILAN",
"NUTPEA",
};
private static readonly HashSet<string> EReaderBerriesNames_JP = new()
{
// JP Series 1
"カチャ", // PUMKIN
"ブ-カ", // DRASH
"ビスナ", // EGGANT
"エドマ", // STRIB
"ホズ", // CHILAN
"ラッカ", // NUTPEA
"クオ", // KU
// JP Series 2
"ギネマ", // GINEMA
"クオ", // KUO
"ヤゴ", // YAGO
"トウガ", // TOUGA
"ニニク", // NINIKU
"トポ" // TOPO
};
2020-07-19 03:51:55 +00:00
public static void LoadFrom(SAV3 sav3)
{
IsEnigma = sav3.IsEBerryIsEnigma;
Name = sav3.EBerryName;
Language = sav3.Japanese ? (int)LanguageID.Japanese : (int)LanguageID.English;
}
}
/// <summary>
/// For use in validating the current e-Reader Berry settings.
/// </summary>
public enum EReaderBerryMatch : byte
{
/// <summary> Invalid: Doesn't match either language </summary>
NoMatch,
/// <summary> Invalid: No data provided from a save file </summary>
NoData,
/// <summary> Invalid: USA berry name on JPN save file </summary>
InvalidUSA,
/// <summary> Invalid: JPN berry name on USA save file</summary>
InvalidJPN,
/// <summary> Valid: Berry name matches either USA/JPN (Ambiguous Save File Language) </summary>
ValidAny,
/// <summary> Valid: Berry name matches a USA berry name </summary>
ValidUSA,
/// <summary> Valid: Berry name matches a JPN berry name </summary>
ValidJPN,
}
}