2018-06-06 01:27:08 +00:00
|
|
|
using System;
|
|
|
|
|
|
|
|
namespace PKHeX.Core
|
|
|
|
{
|
2019-09-10 07:21:51 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Restriction Flags for receiving 3DS/NDS era events.
|
|
|
|
/// </summary>
|
2018-06-06 01:27:08 +00:00
|
|
|
[Flags]
|
2018-06-06 05:20:30 +00:00
|
|
|
public enum MysteryGiftRestriction
|
2018-06-06 01:27:08 +00:00
|
|
|
{
|
|
|
|
None = 0,
|
|
|
|
LangJapanese = 1 << LanguageID.Japanese,
|
|
|
|
LangEnglish = 1 << LanguageID.English,
|
|
|
|
LangFrench = 1 << LanguageID.French,
|
|
|
|
LangItalian = 1 << LanguageID.Italian,
|
|
|
|
LangGerman = 1 << LanguageID.German,
|
|
|
|
LangSpanish = 1 << LanguageID.Spanish,
|
|
|
|
LangKorean = 1 << LanguageID.Korean,
|
|
|
|
|
|
|
|
RegionBase = LangKorean,
|
2020-01-06 02:46:30 +00:00
|
|
|
LangRestrict = LangJapanese | LangEnglish | LangFrench | LangItalian | LangGerman | LangSpanish | LangKorean,
|
2018-06-06 01:27:08 +00:00
|
|
|
|
2021-08-03 03:59:40 +00:00
|
|
|
RegJP = RegionBase << Region3DSIndex.Japan,
|
|
|
|
RegNA = RegionBase << Region3DSIndex.NorthAmerica,
|
|
|
|
RegEU = RegionBase << Region3DSIndex.Europe,
|
|
|
|
RegZH = RegionBase << Region3DSIndex.China,
|
|
|
|
RegKO = RegionBase << Region3DSIndex.Korea,
|
|
|
|
RegTW = RegionBase << Region3DSIndex.Taiwan,
|
2018-06-06 01:27:08 +00:00
|
|
|
|
|
|
|
RegionRestrict = RegJP | RegNA | RegEU | RegZH | RegKO | RegTW,
|
|
|
|
|
|
|
|
OTReplacedOnTrade = RegTW << 1,
|
|
|
|
}
|
|
|
|
|
|
|
|
public static class MysteryGiftRestrictionExtensions
|
|
|
|
{
|
|
|
|
public static bool HasFlagFast(this MysteryGiftRestriction value, MysteryGiftRestriction flag)
|
|
|
|
{
|
|
|
|
return (value & flag) != 0;
|
|
|
|
}
|
|
|
|
|
2019-09-10 07:21:51 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Checks the flags to pick out a language that can receive the gift.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="value">Flag value</param>
|
|
|
|
/// <returns>Language ID; -1 if none</returns>
|
2018-06-06 01:27:08 +00:00
|
|
|
public static int GetSuggestedLanguage(this MysteryGiftRestriction value)
|
|
|
|
{
|
|
|
|
for (int i = (int)LanguageID.Japanese; i <= (int)LanguageID.Korean; i++)
|
2018-08-03 03:11:42 +00:00
|
|
|
{
|
2018-06-06 01:27:08 +00:00
|
|
|
if (value.HasFlagFast((MysteryGiftRestriction)(1 << i)))
|
|
|
|
return i;
|
2018-08-03 03:11:42 +00:00
|
|
|
}
|
2018-06-06 01:27:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
2018-06-06 01:27:08 +00:00
|
|
|
public static int GetSuggestedRegion(this MysteryGiftRestriction value)
|
|
|
|
{
|
2021-08-03 03:59:40 +00:00
|
|
|
for (int i = (int)Region3DSIndex.Japan; i <= (int)Region3DSIndex.Taiwan; i++)
|
2018-08-03 03:11:42 +00:00
|
|
|
{
|
2018-06-06 01:27:08 +00:00
|
|
|
if (value.HasFlagFast((MysteryGiftRestriction)((int)MysteryGiftRestriction.RegionBase << i)))
|
|
|
|
return i;
|
2018-08-03 03:11:42 +00:00
|
|
|
}
|
2018-06-06 01:27:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|