2018-06-24 05:00:01 +00:00
|
|
|
|
using System;
|
2018-06-30 22:01:16 +00:00
|
|
|
|
using System.Collections.Generic;
|
2018-06-24 05:00:01 +00:00
|
|
|
|
using static PKHeX.Core.LegalityCheckStrings;
|
|
|
|
|
|
|
|
|
|
namespace PKHeX.Core
|
|
|
|
|
{
|
2018-07-02 02:17:37 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Verifies the <see cref="PKM.AltForm"/> value.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public sealed class FormVerifier : Verifier
|
2018-06-24 05:00:01 +00:00
|
|
|
|
{
|
|
|
|
|
protected override CheckIdentifier Identifier => CheckIdentifier.Form;
|
|
|
|
|
|
|
|
|
|
public override void Verify(LegalityAnalysis data)
|
|
|
|
|
{
|
|
|
|
|
var pkm = data.pkm;
|
|
|
|
|
if (pkm.Format < 4)
|
|
|
|
|
return; // no forms exist
|
2018-06-30 22:01:16 +00:00
|
|
|
|
var result = VerifyForm(data);
|
|
|
|
|
data.AddLine(result);
|
|
|
|
|
}
|
2018-06-24 05:00:01 +00:00
|
|
|
|
|
2018-06-30 22:01:16 +00:00
|
|
|
|
private CheckResult VALID => GetValid(V318);
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2018-06-30 22:01:16 +00:00
|
|
|
|
private CheckResult VerifyForm(LegalityAnalysis data)
|
|
|
|
|
{
|
|
|
|
|
var pkm = data.pkm;
|
2018-06-24 05:00:01 +00:00
|
|
|
|
var PersonalInfo = data.PersonalInfo;
|
|
|
|
|
|
|
|
|
|
int count = PersonalInfo.FormeCount;
|
|
|
|
|
if (count <= 1 && pkm.AltForm == 0)
|
2018-06-30 22:01:16 +00:00
|
|
|
|
return VALID; // no forms to check
|
|
|
|
|
|
|
|
|
|
var EncounterMatch = data.EncounterMatch;
|
|
|
|
|
var Info = data.Info;
|
2018-06-24 05:00:01 +00:00
|
|
|
|
|
|
|
|
|
if (!PersonalInfo.IsFormeWithinRange(pkm.AltForm) && !FormConverter.IsValidOutOfBoundsForme(pkm.Species, pkm.AltForm, Info.Generation))
|
2018-06-30 22:01:16 +00:00
|
|
|
|
return GetInvalid(string.Format(V304, count - 1, pkm.AltForm));
|
2018-06-24 05:00:01 +00:00
|
|
|
|
|
|
|
|
|
if (EncounterMatch is EncounterSlot w && w.Type == SlotType.FriendSafari)
|
2018-07-27 02:34:27 +00:00
|
|
|
|
{
|
2018-06-24 05:00:01 +00:00
|
|
|
|
VerifyFormFriendSafari(data);
|
2018-07-27 02:34:27 +00:00
|
|
|
|
}
|
2018-06-24 05:00:01 +00:00
|
|
|
|
else if (EncounterMatch is EncounterEgg)
|
|
|
|
|
{
|
|
|
|
|
if (FormConverter.IsTotemForm(pkm.Species, pkm.AltForm))
|
2018-06-30 22:01:16 +00:00
|
|
|
|
return GetInvalid(V317);
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (pkm.Species)
|
|
|
|
|
{
|
|
|
|
|
case 25 when Info.Generation == 6: // Pikachu Cosplay
|
|
|
|
|
bool isStatic = EncounterMatch is EncounterStatic;
|
|
|
|
|
if (isStatic != (pkm.AltForm != 0))
|
2018-06-30 22:01:16 +00:00
|
|
|
|
return GetInvalid(isStatic ? V305 : V306);
|
2018-06-24 05:00:01 +00:00
|
|
|
|
break;
|
2018-06-30 22:01:16 +00:00
|
|
|
|
|
2018-06-24 05:00:01 +00:00
|
|
|
|
case 25 when Info.Generation == 7: // Pikachu Cap
|
|
|
|
|
bool IsValidPikachuCap()
|
|
|
|
|
{
|
|
|
|
|
switch (EncounterMatch)
|
|
|
|
|
{
|
|
|
|
|
default: return pkm.AltForm == 0;
|
|
|
|
|
case WC7 wc7: return wc7.Form == pkm.AltForm;
|
|
|
|
|
case EncounterStatic s: return s.Form == pkm.AltForm;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!IsValidPikachuCap())
|
|
|
|
|
{
|
|
|
|
|
bool gift = EncounterMatch is WC7 g && g.Form != pkm.AltForm;
|
|
|
|
|
var msg = gift ? V307 : V317;
|
2018-06-30 22:01:16 +00:00
|
|
|
|
return GetInvalid(msg);
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 201 when Info.Generation == 2 && pkm.AltForm >= 26:
|
2018-06-30 22:01:16 +00:00
|
|
|
|
return GetInvalid(string.Format(V304, "Z", pkm.AltForm == 26 ? "!" : "?"));
|
|
|
|
|
case 487 when pkm.AltForm == 1 ^ pkm.HeldItem == 112: // Giratina, Origin form only with Griseous Orb
|
|
|
|
|
return GetInvalid(V308);
|
|
|
|
|
|
|
|
|
|
case 493: // Arceus
|
2018-06-24 05:00:01 +00:00
|
|
|
|
{
|
2018-06-30 22:01:16 +00:00
|
|
|
|
int form = GetArceusFormFromHeldItem(pkm.HeldItem, pkm.Format);
|
|
|
|
|
return form != pkm.AltForm ? GetInvalid(V308) : GetValid(V309);
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
|
|
|
|
case 647: // Keldeo
|
|
|
|
|
{
|
|
|
|
|
if (pkm.Gen5) // can mismatch in gen5 via BW tutor and transfer up
|
|
|
|
|
break;
|
|
|
|
|
int index = Array.IndexOf(pkm.Moves, 548); // Secret Sword
|
|
|
|
|
bool noSword = index < 0;
|
|
|
|
|
if (pkm.AltForm == 0 ^ noSword) // mismatch
|
|
|
|
|
Info.Moves[noSword ? 0 : index] = new CheckMoveResult(Info.Moves[noSword ? 0 : index], Severity.Invalid, V169, CheckIdentifier.Move);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 649: // Genesect
|
|
|
|
|
{
|
2018-06-30 22:01:16 +00:00
|
|
|
|
int form = GetGenesectFormFromHeldItem(pkm.HeldItem);
|
|
|
|
|
return form != pkm.AltForm ? GetInvalid(V308) : GetValid(V309);
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
2018-06-30 22:01:16 +00:00
|
|
|
|
case 658: // Greninja
|
|
|
|
|
if (pkm.AltForm > 1) // Ash Battle Bond active
|
|
|
|
|
return GetInvalid(V310);
|
2018-06-24 05:00:01 +00:00
|
|
|
|
if (pkm.AltForm != 0 && !(EncounterMatch is MysteryGift)) // Formes are not breedable, MysteryGift already checked
|
2018-06-30 22:01:16 +00:00
|
|
|
|
return GetInvalid(string.Format(V304, 0, pkm.AltForm));
|
2018-06-24 05:00:01 +00:00
|
|
|
|
break;
|
2018-06-30 22:01:16 +00:00
|
|
|
|
|
2018-06-24 05:00:01 +00:00
|
|
|
|
case 664: // Scatterbug
|
|
|
|
|
case 665: // Spewpa
|
|
|
|
|
if (pkm.AltForm > 17) // Fancy & Pokéball
|
2018-06-30 22:01:16 +00:00
|
|
|
|
return GetInvalid(V311);
|
2018-06-24 05:00:01 +00:00
|
|
|
|
if (!Legal.CheckVivillonPattern(pkm.AltForm, pkm.Country, pkm.Region))
|
|
|
|
|
data.AddLine(Get(V312, Severity.Fishy));
|
|
|
|
|
break;
|
|
|
|
|
case 666: // Vivillon
|
|
|
|
|
if (pkm.AltForm > 17) // Fancy & Pokéball
|
|
|
|
|
{
|
|
|
|
|
if (!(EncounterMatch is MysteryGift))
|
2018-06-30 22:01:16 +00:00
|
|
|
|
return GetInvalid(V312);
|
|
|
|
|
return GetValid(V313);
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
|
|
|
|
if (!Legal.CheckVivillonPattern(pkm.AltForm, pkm.Country, pkm.Region))
|
|
|
|
|
data.AddLine(Get(V312, Severity.Fishy));
|
|
|
|
|
break;
|
|
|
|
|
|
2018-06-30 22:01:16 +00:00
|
|
|
|
case 670 when pkm.AltForm == 5: // Floette Eternal Flower -- Never Released
|
|
|
|
|
if (!(EncounterMatch is MysteryGift))
|
|
|
|
|
return GetInvalid(V314);
|
|
|
|
|
return GetValid(V315);
|
|
|
|
|
case 678 when pkm.AltForm != pkm.Gender: // Meowstic
|
|
|
|
|
return GetInvalid(V203);
|
|
|
|
|
|
2018-06-24 05:00:01 +00:00
|
|
|
|
case 773: // Silvally
|
2018-06-30 22:01:16 +00:00
|
|
|
|
{
|
|
|
|
|
int form = GetSilvallyFormFromHeldItem(pkm.HeldItem);
|
|
|
|
|
return form != pkm.AltForm ? GetInvalid(V308) : GetValid(V309);
|
|
|
|
|
}
|
2018-06-24 05:00:01 +00:00
|
|
|
|
|
|
|
|
|
case 744 when Info.EncounterMatch.EggEncounter && pkm.AltForm == 1 && pkm.SM:
|
|
|
|
|
case 745 when Info.EncounterMatch.EggEncounter && pkm.AltForm == 2 && pkm.SM:
|
2018-06-30 22:01:16 +00:00
|
|
|
|
return GetInvalid(V317);
|
2018-06-24 05:00:01 +00:00
|
|
|
|
|
|
|
|
|
// Impossible Egg forms
|
2018-06-30 22:01:16 +00:00
|
|
|
|
case 479 when pkm.IsEgg && pkm.AltForm != 0: // Rotom
|
|
|
|
|
case 676 when pkm.IsEgg && pkm.AltForm != 0: // Furfrou
|
|
|
|
|
return GetInvalid(V50);
|
2018-06-24 05:00:01 +00:00
|
|
|
|
|
|
|
|
|
// Party Only Forms
|
|
|
|
|
case 492: // Shaymin
|
|
|
|
|
case 676: // Furfrou
|
|
|
|
|
case 720: // Hoopa
|
|
|
|
|
if (pkm.AltForm != 0 && pkm.Box > -1 && pkm.Format <= 6) // has form but stored in box
|
2018-06-30 22:01:16 +00:00
|
|
|
|
return GetInvalid(V316);
|
2018-06-24 05:00:01 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
// Battle only Forms with other legal forms allowed
|
|
|
|
|
case 718 when pkm.AltForm >= 4: // Zygarde Complete
|
|
|
|
|
case 774 when pkm.AltForm < 7: // Minior Shield
|
|
|
|
|
case 800 when pkm.AltForm == 3: // Ultra Necrozma
|
2018-06-30 22:01:16 +00:00
|
|
|
|
return GetInvalid(V310);
|
2018-06-24 05:00:01 +00:00
|
|
|
|
case 800 when pkm.AltForm < 3: // Necrozma Fused forms & default
|
|
|
|
|
case 778 when pkm.AltForm == 2: // Totem disguise Mimikyu
|
2018-06-30 22:01:16 +00:00
|
|
|
|
return VALID;
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pkm.Format >= 7 && Info.Generation < 7 && pkm.AltForm != 0)
|
|
|
|
|
{
|
2018-06-30 22:01:16 +00:00
|
|
|
|
if (pkm.Species == 25 || Legal.AlolanOriginForms.Contains(pkm.Species) || Legal.AlolanVariantEvolutions12.Contains(data.EncounterOriginal.Species))
|
|
|
|
|
return GetInvalid(V317);
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-01 17:49:11 +00:00
|
|
|
|
if (pkm.AltForm != 0 && BattleOnly.Contains(pkm.Species))
|
2018-06-30 22:01:16 +00:00
|
|
|
|
return GetInvalid(V310);
|
|
|
|
|
|
|
|
|
|
return VALID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static int GetArceusFormFromHeldItem(int item, int format)
|
|
|
|
|
{
|
|
|
|
|
if (777 <= item && item <= 793)
|
|
|
|
|
return Array.IndexOf(Legal.Arceus_ZCrystal, item) + 1;
|
|
|
|
|
|
|
|
|
|
int form = 0;
|
|
|
|
|
if ((298 <= item && item <= 313) || item == 644)
|
|
|
|
|
form = Array.IndexOf(Legal.Arceus_Plate, item) + 1;
|
|
|
|
|
if (format == 4 && form >= 9)
|
|
|
|
|
return form + 1; // ??? type Form shifts everything by 1
|
|
|
|
|
return form;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static int GetSilvallyFormFromHeldItem(int item)
|
|
|
|
|
{
|
|
|
|
|
if ((904 <= item && item <= 920) || item == 644)
|
|
|
|
|
return item - 903;
|
|
|
|
|
return 0;
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-30 22:01:16 +00:00
|
|
|
|
private static int GetGenesectFormFromHeldItem(int item)
|
|
|
|
|
{
|
|
|
|
|
if (116 <= item && item <= 119)
|
|
|
|
|
return item - 115;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2018-06-24 05:00:01 +00:00
|
|
|
|
|
2018-07-27 02:34:27 +00:00
|
|
|
|
private static readonly HashSet<int> BattleOnly;
|
|
|
|
|
private static readonly HashSet<int> SafariFloette = new HashSet<int> { 0, 1, 3 }; // 0/1/3 - RBY
|
|
|
|
|
|
2018-07-01 17:49:11 +00:00
|
|
|
|
static FormVerifier()
|
|
|
|
|
{
|
|
|
|
|
BattleOnly = new HashSet<int>();
|
|
|
|
|
BattleOnly.UnionWith(Legal.BattleForms);
|
|
|
|
|
BattleOnly.UnionWith(Legal.BattleMegas);
|
|
|
|
|
BattleOnly.UnionWith(Legal.BattlePrimals);
|
|
|
|
|
}
|
2018-06-30 22:01:16 +00:00
|
|
|
|
|
2018-06-24 05:00:01 +00:00
|
|
|
|
private void VerifyFormFriendSafari(LegalityAnalysis data)
|
|
|
|
|
{
|
|
|
|
|
var pkm = data.pkm;
|
|
|
|
|
switch (pkm.Species)
|
|
|
|
|
{
|
2018-06-30 22:01:16 +00:00
|
|
|
|
case 670 when !SafariFloette.Contains(pkm.AltForm): // Floette
|
|
|
|
|
case 671 when !SafariFloette.Contains(pkm.AltForm): // Florges
|
|
|
|
|
data.AddLine(GetInvalid(V64));
|
2018-06-24 05:00:01 +00:00
|
|
|
|
break;
|
|
|
|
|
case 710 when pkm.AltForm != 0: // Pumpkaboo
|
|
|
|
|
case 711 when pkm.AltForm != 0: // Goregeist Average
|
|
|
|
|
data.AddLine(GetInvalid(V6));
|
|
|
|
|
break;
|
|
|
|
|
case 423 when pkm.AltForm != 0: // Gastrodon West
|
|
|
|
|
data.AddLine(GetInvalid(V64));
|
|
|
|
|
break;
|
|
|
|
|
case 586 when pkm.AltForm != 0: // Sawsbuck
|
|
|
|
|
data.AddLine(GetInvalid(V65));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|