PKHeX/PKHeX.Core/Legality/Verifiers/Ribbons/RibbonVerifierEvent3.cs
Kurt 768047cd80
Legality: Rewrite Ribbon Verifier (#3570)
* Rewrite ribbon verification
* Explicitly verifies all ribbons instead of chained iterators.
* Verifies using only the stack, using `struct` and `Span<T>`. No allocation on heap, or `IEnumerable` iterators.
* Verifies all egg ribbons using a separate method, explicitly implemented. No reflection overhead.
* Separates each ribbon interface to separate `static` classes. Easier to identify code needing change on new game update.
* Extracted logic for specific ribbons. Can easily revise complicated ribbon's acquisition rules.
* Simplifies GiveAll/RemoveAll legal ribbon mutations. No reflection overhead, and no allocation.
* Can be expanded in the future if we need to track conditions for ribbon acquisition (was Sinnoh Champ received in BDSP or Gen4?)

End result is a more performant implementation and easier to maintain & reuse logic.
2022-08-15 21:04:30 -07:00

73 lines
2.7 KiB
C#

using static PKHeX.Core.RibbonIndex;
namespace PKHeX.Core;
/// <summary>
/// Parsing logic for <see cref="IRibbonSetEvent3"/>.
/// </summary>
public static class RibbonVerifierEvent3
{
public static void Parse(this IRibbonSetEvent3 r, RibbonVerifierArguments args, ref RibbonResultList list)
{
var enc = args.Encounter;
if (enc is IRibbonSetEvent3 e)
{
// The Earth Ribbon is a ribbon exclusive to Pokémon Colosseum and Pokémon XD: Gale of Darkness
// Awarded to all Pokémon on the player's team when they complete the Mt. Battle challenge without switching the team at any point.
if (e.RibbonEarth)
{
if (!r.RibbonEarth)
list.Add(Earth);
}
else if (r.RibbonEarth && enc.Generation != 3)
{
list.Add(Earth);
}
if (r.RibbonNational != e.RibbonNational)
list.Add(National);
if (r.RibbonCountry != e.RibbonCountry)
list.Add(Country);
if (r.RibbonChampionBattle != e.RibbonChampionBattle)
list.Add(ChampionBattle);
if (r.RibbonChampionRegional != e.RibbonChampionRegional)
list.Add(ChampionRegional);
if (r.RibbonChampionNational != e.RibbonChampionNational)
list.Add(ChampionNational);
}
else
{
// The Earth Ribbon is a ribbon exclusive to Pokémon Colosseum and Pokémon XD: Gale of Darkness
// Awarded to all Pokémon on the player's team when they complete the Mt. Battle challenge without switching the team at any point.
if (r.RibbonEarth && enc.Generation != 3)
list.Add(Earth);
if (r.RibbonNational != RibbonRules.GetValidRibbonStateNational(args.Entity, enc))
list.Add(National);
if (r.RibbonCountry)
list.Add(Country);
if (r.RibbonChampionBattle)
list.Add(ChampionBattle);
if (r.RibbonChampionRegional)
list.Add(ChampionRegional);
if (r.RibbonChampionNational)
list.Add(ChampionNational);
}
}
public static void ParseEgg(this IRibbonSetEvent3 r, ref RibbonResultList list)
{
if (r.RibbonEarth)
list.Add(Earth);
if (r.RibbonNational)
list.Add(National);
if (r.RibbonCountry)
list.Add(Country);
if (r.RibbonChampionBattle)
list.Add(ChampionBattle);
if (r.RibbonChampionRegional)
list.Add(ChampionRegional);
if (r.RibbonChampionNational)
list.Add(ChampionNational);
}
}