2016-10-29 22:41:55 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
2017-01-08 07:54:09 +00:00
|
|
|
|
namespace PKHeX.Core
|
2016-10-29 22:41:55 +00:00
|
|
|
|
{
|
|
|
|
|
public static class GameInfo
|
|
|
|
|
{
|
2018-06-15 00:03:56 +00:00
|
|
|
|
private static readonly string[] ptransp = { "ポケシフター", "Poké Transfer", "Poké Fret", "Pokétrasporto", "Poképorter", "Pokétransfer", "포케시프터", "宝可传送", "寶可傳送" };
|
|
|
|
|
private static readonly string[] lang_val = { "ja", "en", "fr", "it", "de", "es", "ko", "zh", "zh2" };
|
2018-05-19 04:35:57 +00:00
|
|
|
|
private static readonly string[] lang_geo = { "ja", "en", "fr", "de", "it", "es", "zh", "ko" };
|
2016-10-29 22:41:55 +00:00
|
|
|
|
private const string DefaultLanguage = "en";
|
2017-05-23 04:55:05 +00:00
|
|
|
|
public static string CurrentLanguage { get; set; } = DefaultLanguage;
|
|
|
|
|
public static int Language(string lang = null) => Array.IndexOf(lang_val, lang ?? CurrentLanguage);
|
|
|
|
|
public static string Language2Char(uint lang) => lang > lang_val.Length ? DefaultLanguage : lang_val[lang];
|
2016-10-29 22:41:55 +00:00
|
|
|
|
private static readonly GameStrings[] Languages = new GameStrings[lang_val.Length];
|
|
|
|
|
|
|
|
|
|
// Lazy fetch implementation
|
2017-03-22 04:40:33 +00:00
|
|
|
|
private static int DefaultLanguageIndex => Array.IndexOf(lang_val, DefaultLanguage);
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static int GetLanguageIndex(string lang)
|
2016-10-29 22:41:55 +00:00
|
|
|
|
{
|
|
|
|
|
int l = Array.IndexOf(lang_val, lang);
|
2017-03-22 04:40:33 +00:00
|
|
|
|
return l < 0 ? DefaultLanguageIndex : l;
|
2016-10-29 22:41:55 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public static GameStrings GetStrings(string lang)
|
2016-10-29 22:41:55 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
int index = GetLanguageIndex(lang);
|
2016-10-29 22:41:55 +00:00
|
|
|
|
return Languages[index] ?? (Languages[index] = new GameStrings(lang_val[index]));
|
|
|
|
|
}
|
2018-05-19 04:35:57 +00:00
|
|
|
|
public static string GetTransporterName(string lang)
|
2016-10-29 22:41:55 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
int index = GetLanguageIndex(lang);
|
2017-03-22 04:40:33 +00:00
|
|
|
|
if (index >= ptransp.Length)
|
|
|
|
|
index = DefaultLanguageIndex;
|
|
|
|
|
return ptransp[index];
|
2016-10-29 22:41:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-05-19 04:35:57 +00:00
|
|
|
|
public static GameStrings Strings { get; set; } = GetStrings(DefaultLanguage);
|
2017-10-12 03:00:18 +00:00
|
|
|
|
public static string[] GetStrings(string ident, string lang, string type = "text")
|
|
|
|
|
{
|
|
|
|
|
string[] data = Util.GetStringList(ident, lang, type);
|
|
|
|
|
if (data == null || data.Length == 0)
|
|
|
|
|
data = Util.GetStringList(ident, DefaultLanguage, type);
|
|
|
|
|
|
|
|
|
|
return data;
|
|
|
|
|
}
|
2016-10-29 22:41:55 +00:00
|
|
|
|
|
|
|
|
|
// DataSource providing
|
2018-06-30 16:59:48 +00:00
|
|
|
|
public static IReadOnlyList<ComboItem> ItemDataSource => Strings.ItemDataSource;
|
|
|
|
|
public static IReadOnlyList<ComboItem> SpeciesDataSource => Strings.SpeciesDataSource;
|
|
|
|
|
public static IReadOnlyList<ComboItem> BallDataSource => Strings.BallDataSource;
|
|
|
|
|
public static IReadOnlyList<ComboItem> NatureDataSource => Strings.NatureDataSource;
|
|
|
|
|
public static IReadOnlyList<ComboItem> AbilityDataSource => Strings.AbilityDataSource;
|
|
|
|
|
public static IReadOnlyList<ComboItem> VersionDataSource => Strings.VersionDataSource;
|
|
|
|
|
public static IReadOnlyList<ComboItem> LegalMoveDataSource => Strings.LegalMoveDataSource;
|
|
|
|
|
public static IReadOnlyList<ComboItem> HaXMoveDataSource => Strings.HaXMoveDataSource;
|
|
|
|
|
public static IReadOnlyList<ComboItem> MoveDataSource => Strings.MoveDataSource;
|
2018-07-07 00:37:07 +00:00
|
|
|
|
public static IReadOnlyList<ComboItem> LanguageDataSource(int gen) => GameStrings.LanguageDataSource(gen);
|
2017-01-25 11:29:38 +00:00
|
|
|
|
|
2017-02-05 02:27:28 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets Country and Region strings for corresponding IDs and language.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="country">Country ID</param>
|
|
|
|
|
/// <param name="region">Region ID</param>
|
|
|
|
|
/// <param name="language">Language ID</param>
|
|
|
|
|
/// <returns></returns>
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public static Tuple<string, string> GetCountryRegionText(int country, int region, string language)
|
2017-02-05 02:27:28 +00:00
|
|
|
|
{
|
|
|
|
|
// Get Language we're fetching for
|
2018-05-19 04:35:57 +00:00
|
|
|
|
int lang = Array.IndexOf(lang_geo, language);
|
2017-06-18 01:37:19 +00:00
|
|
|
|
string c = GetCountryString(country, lang);
|
|
|
|
|
string r = GetRegionString(country, region, lang);
|
2017-02-05 02:27:28 +00:00
|
|
|
|
return new Tuple<string, string>(c, r); // country, region
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the Country string for a given Country ID
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="country">Country ID</param>
|
|
|
|
|
/// <param name="language">Language ID</param>
|
|
|
|
|
/// <returns>Country ID string</returns>
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static string GetCountryString(int country, int language)
|
2017-02-05 02:27:28 +00:00
|
|
|
|
{
|
|
|
|
|
string c;
|
|
|
|
|
// Get Country Text
|
|
|
|
|
try
|
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
string[] inputCSV = Util.GetStringList("countries");
|
2017-02-05 02:27:28 +00:00
|
|
|
|
// Set up our Temporary Storage
|
|
|
|
|
string[] unsortedList = new string[inputCSV.Length - 1];
|
|
|
|
|
int[] indexes = new int[inputCSV.Length - 1];
|
|
|
|
|
|
|
|
|
|
// Gather our data from the input file
|
|
|
|
|
for (int i = 1; i < inputCSV.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
string[] countryData = inputCSV[i].Split(',');
|
|
|
|
|
if (countryData.Length <= 1) continue;
|
|
|
|
|
indexes[i - 1] = Convert.ToInt32(countryData[0]);
|
|
|
|
|
unsortedList[i - 1] = countryData[language + 1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int countrynum = Array.IndexOf(indexes, country);
|
|
|
|
|
c = unsortedList[countrynum];
|
|
|
|
|
}
|
|
|
|
|
catch { c = "Illegal"; }
|
|
|
|
|
|
|
|
|
|
return c;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the Region string for a specified country ID.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="country">Country ID</param>
|
|
|
|
|
/// <param name="region">Region ID</param>
|
|
|
|
|
/// <param name="language">Language ID</param>
|
|
|
|
|
/// <returns>Region ID string</returns>
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static string GetRegionString(int country, int region, int language)
|
2017-02-05 02:27:28 +00:00
|
|
|
|
{
|
|
|
|
|
// Get Region Text
|
|
|
|
|
try
|
|
|
|
|
{
|
2017-09-30 05:58:25 +00:00
|
|
|
|
string[] inputCSV = Util.GetStringList($"sr_{country:000}");
|
2017-02-05 02:27:28 +00:00
|
|
|
|
// Set up our Temporary Storage
|
|
|
|
|
string[] unsortedList = new string[inputCSV.Length - 1];
|
|
|
|
|
int[] indexes = new int[inputCSV.Length - 1];
|
|
|
|
|
|
|
|
|
|
// Gather our data from the input file
|
|
|
|
|
for (int i = 1; i < inputCSV.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
string[] countryData = inputCSV[i].Split(',');
|
|
|
|
|
if (countryData.Length <= 1) continue;
|
|
|
|
|
indexes[i - 1] = Convert.ToInt32(countryData[0]);
|
|
|
|
|
unsortedList[i - 1] = countryData[language + 1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int regionnum = Array.IndexOf(indexes, region);
|
|
|
|
|
return unsortedList[regionnum];
|
|
|
|
|
}
|
|
|
|
|
catch { return "Illegal"; }
|
|
|
|
|
}
|
2017-02-24 00:39:03 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the location names array for a specified generation.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="gen">Generation to get location names for.</param>
|
|
|
|
|
/// <param name="bankID">BankID used to choose the text bank.</param>
|
|
|
|
|
/// <returns>List of location names.</returns>
|
2018-06-30 16:59:48 +00:00
|
|
|
|
private static IReadOnlyList<string> GetLocationNames(int gen, int bankID)
|
2017-02-24 00:39:03 +00:00
|
|
|
|
{
|
|
|
|
|
switch (gen)
|
|
|
|
|
{
|
|
|
|
|
case 2: return Strings.metGSC_00000;
|
|
|
|
|
case 3: return Strings.metRSEFRLG_00000;
|
|
|
|
|
case 4:
|
|
|
|
|
switch (bankID)
|
|
|
|
|
{
|
|
|
|
|
case 0: return Strings.metHGSS_00000;
|
|
|
|
|
case 2: return Strings.metHGSS_02000;
|
2018-03-27 06:22:11 +00:00
|
|
|
|
case 3: return Strings.metHGSS_03000;
|
2017-02-24 00:39:03 +00:00
|
|
|
|
default: return null;
|
|
|
|
|
}
|
|
|
|
|
case 5:
|
|
|
|
|
switch (bankID)
|
|
|
|
|
{
|
|
|
|
|
case 0: return Strings.metBW2_00000;
|
|
|
|
|
case 3: return Strings.metBW2_30000;
|
|
|
|
|
case 4: return Strings.metBW2_40000;
|
|
|
|
|
case 6: return Strings.metBW2_60000;
|
|
|
|
|
default: return null;
|
|
|
|
|
}
|
|
|
|
|
case 6:
|
|
|
|
|
switch (bankID)
|
|
|
|
|
{
|
|
|
|
|
case 0: return Strings.metXY_00000;
|
|
|
|
|
case 3: return Strings.metXY_30000;
|
|
|
|
|
case 4: return Strings.metXY_40000;
|
|
|
|
|
case 6: return Strings.metXY_60000;
|
|
|
|
|
default: return null;
|
|
|
|
|
}
|
|
|
|
|
case 7:
|
|
|
|
|
switch (bankID)
|
|
|
|
|
{
|
|
|
|
|
case 0: return Strings.metSM_00000;
|
|
|
|
|
case 3: return Strings.metSM_30000;
|
|
|
|
|
case 4: return Strings.metSM_40000;
|
|
|
|
|
case 6: return Strings.metSM_60000;
|
|
|
|
|
default: return null;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-16 18:38:58 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the location name for the specified parameters.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="eggmet">Location is from the <see cref="PKM.Egg_Location"/></param>
|
|
|
|
|
/// <param name="locval">Location value</param>
|
|
|
|
|
/// <param name="format">Current <see cref="PKM.Format"/></param>
|
|
|
|
|
/// <param name="generation"><see cref="PKM.GenNumber"/> of origin</param>
|
|
|
|
|
/// <returns>Location name</returns>
|
|
|
|
|
public static string GetLocationName(bool eggmet, int locval, int format, int generation)
|
|
|
|
|
{
|
|
|
|
|
int gen = -1;
|
|
|
|
|
int bankID = 0;
|
|
|
|
|
|
|
|
|
|
if (format == 2)
|
|
|
|
|
gen = 2;
|
|
|
|
|
else if (format == 3)
|
|
|
|
|
gen = 3;
|
|
|
|
|
else if (generation == 4 && (eggmet || format == 4)) // 4
|
|
|
|
|
{
|
|
|
|
|
const int size = 1000;
|
|
|
|
|
bankID = locval / size;
|
|
|
|
|
gen = 4;
|
|
|
|
|
locval %= size;
|
|
|
|
|
}
|
|
|
|
|
else // 5-7+
|
|
|
|
|
{
|
|
|
|
|
const int size = 10000;
|
|
|
|
|
bankID = locval / size;
|
|
|
|
|
|
|
|
|
|
int g = generation;
|
|
|
|
|
if (g >= 5)
|
|
|
|
|
gen = g;
|
|
|
|
|
else if (format >= 5)
|
|
|
|
|
gen = format;
|
|
|
|
|
|
|
|
|
|
locval %= size;
|
|
|
|
|
if (bankID >= 3)
|
2018-05-12 19:28:48 +00:00
|
|
|
|
locval--;
|
2017-09-16 18:38:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var bank = GetLocationNames(gen, bankID);
|
2018-06-30 16:59:48 +00:00
|
|
|
|
if (bank == null || bank.Count <= locval)
|
2017-09-16 18:38:58 +00:00
|
|
|
|
return string.Empty;
|
|
|
|
|
return bank[locval];
|
|
|
|
|
}
|
2018-05-19 04:35:57 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the location list for a specific version, which can retrieve either met locations or egg locations.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="version">Version to retrieve for</param>
|
|
|
|
|
/// <param name="pkmFormat">Generation to retrieve for</param>
|
|
|
|
|
/// <param name="egg">Egg Locations are to be retrieved instead of regular Met Locations</param>
|
|
|
|
|
/// <returns>Consumable list of met locations</returns>
|
2018-06-30 16:59:48 +00:00
|
|
|
|
public static IReadOnlyList<ComboItem> GetLocationList(GameVersion version, int pkmFormat, bool egg = false)
|
2018-05-19 04:35:57 +00:00
|
|
|
|
{
|
|
|
|
|
return Strings.GetLocationList(version, pkmFormat, egg);
|
|
|
|
|
}
|
2016-10-29 22:41:55 +00:00
|
|
|
|
}
|
|
|
|
|
}
|