Extract master ribbon check

Check visitation via API method instead of in verifier
This commit is contained in:
Kurt 2022-12-04 00:09:16 -08:00
parent 67c458d321
commit 3f4aa2f9f2
2 changed files with 22 additions and 19 deletions

View file

@ -73,14 +73,25 @@ public static class RibbonRules
return false;
}
public static bool IsRibbonValidMasterRank(PKM pk, IEncounterTemplate enc, EvolutionHistory evos)
{
// Legends can compete in Ranked starting from Series 10.
// Past gen Pokemon can get the ribbon only if they've been reset.
if (evos.HasVisitedSWSH && IsRibbonValidMasterRankSWSH(pk, enc))
return true;
// Only Paldea natives can compete in Ranked. No Legends/Sub-Legends/Paradoxes as of Series 1.
if (evos.HasVisitedGen9 && IsRibbonValidMasterRankSV(pk))
return true;
return false;
}
/// <summary>
/// Checks if the entity participated in SW/SH ranked battles for the <see cref="IRibbonSetCommon8.RibbonMasterRank"/> ribbon.
/// </summary>
public static bool IsRibbonValidMasterRankSWSH(PKM pk, IEncounterTemplate enc, EvolutionHistory evos)
private static bool IsRibbonValidMasterRankSWSH(PKM pk, IEncounterTemplate enc)
{
if (!evos.HasVisitedSWSH)
return false;
if (enc.Generation < 8 && pk is IBattleVersion { BattleVersion: 0 })
return false;
@ -99,20 +110,18 @@ public static class RibbonRules
return true;
}
public static bool IsRibbonValidMasterRankSV(PKM pk, IEncounterTemplate enc, EvolutionHistory evos)
private static bool IsRibbonValidMasterRankSV(ISpeciesForm pk)
{
if (pk.Format < 9)
var species = pk.Species;
if (Legal.Legends.Contains(species))
return false;
if (Legal.Legends.Contains(pk.Species))
if (Legal.SubLegends.Contains(species))
return false;
if (Legal.SubLegends.Contains(pk.Species))
return false;
if (pk.Species >= (int)Species.GreatTusk && pk.Species <= (int)Species.IronValiant)
if (species is >= (int)Species.GreatTusk and <= (int)Species.IronValiant)
return false;
var pt = PersonalTable.SV;
var pi = pt.GetFormEntry(pk.Species, pk.Form);
var pi = pt.GetFormEntry(species, pk.Form);
return pi.IsInDex; // no foreign species, such as Charmander, Wooper-0, and Meowth-2
}

View file

@ -41,13 +41,7 @@ public static class RibbonVerifierCommon8
list.Add(ChampionGalar, true);
}
// Legends can compete in Ranked starting from Series 10.
// Past gen Pokemon can get the ribbon only if they've been reset.
if (pk.Format == 8 && r.RibbonMasterRank && !RibbonRules.IsRibbonValidMasterRankSWSH(pk, enc, evos))
list.Add(MasterRank);
// Only Paldea natives can compete in Ranked. No Legends/Sub-Legends/Paradoxes as of Series 1.
if (pk.Format == 9 && r.RibbonMasterRank && !RibbonRules.IsRibbonValidMasterRankSV(pk, enc, evos))
if (r.RibbonMasterRank && !RibbonRules.IsRibbonValidMasterRank(pk, enc, evos))
list.Add(MasterRank);
if (!r.RibbonTowerMaster)