mirror of
https://github.com/kwsch/PKHeX
synced 2024-12-23 19:03:11 +00:00
768047cd80
* 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.
70 lines
2.3 KiB
C#
70 lines
2.3 KiB
C#
using static PKHeX.Core.RibbonIndex;
|
|
|
|
namespace PKHeX.Core;
|
|
|
|
/// <summary>
|
|
/// Parsing logic for <see cref="IRibbonSetCommon4"/>.
|
|
/// </summary>
|
|
public static class RibbonVerifierCommon4
|
|
{
|
|
public static void Parse(this IRibbonSetCommon4 r, RibbonVerifierArguments args, ref RibbonResultList list)
|
|
{
|
|
var pk = args.Entity;
|
|
var evos = args.History;
|
|
if (r.RibbonFootprint && !RibbonRules.IsRibbonValidFootprint(pk, evos))
|
|
list.Add(Footprint);
|
|
if (r.RibbonRecord)
|
|
list.Add(Record); // Unobtainable
|
|
|
|
bool gen4 = evos.HasVisitedGen4;
|
|
bool gen6 = evos.HasVisitedGen6;
|
|
bool bdsp = evos.HasVisitedBDSP;
|
|
bool oras6 = gen6 && !(pk.IsUntraded && pk.XY);
|
|
bool sinnoh4 = gen4 && args.Encounter is not EncounterStatic4 { Species: (int)Species.Pichu, Form: 1 };
|
|
bool sinnohChamp = sinnoh4 || bdsp; // no gen4 hg/ss
|
|
bool cosmetic = sinnoh4 || oras6 || bdsp; // no gen4 hg/ss
|
|
bool daily = gen4 || gen6 || bdsp;
|
|
|
|
if (r.RibbonLegend && !gen4)
|
|
list.Add(Legend);
|
|
if (r.RibbonChampionSinnoh && !sinnohChamp)
|
|
list.Add(ChampionSinnoh);
|
|
if (!daily)
|
|
FlagDaily(r, ref list);
|
|
if (!cosmetic)
|
|
FlagCosmetic(r, ref list);
|
|
}
|
|
|
|
private static void FlagDaily(IRibbonSetCommon4 r, ref RibbonResultList list)
|
|
{
|
|
if (r.RibbonAlert) list.Add(Alert);
|
|
if (r.RibbonShock) list.Add(Shock);
|
|
if (r.RibbonDowncast) list.Add(Downcast);
|
|
if (r.RibbonCareless) list.Add(Careless);
|
|
if (r.RibbonRelax) list.Add(Relax);
|
|
if (r.RibbonSnooze) list.Add(Snooze);
|
|
if (r.RibbonSmile) list.Add(Smile);
|
|
}
|
|
|
|
private static void FlagCosmetic(IRibbonSetCommon4 r, ref RibbonResultList list)
|
|
{
|
|
if (r.RibbonGorgeous) list.Add(Gorgeous);
|
|
if (r.RibbonRoyal) list.Add(Royal);
|
|
if (r.RibbonGorgeousRoyal) list.Add(GorgeousRoyal);
|
|
}
|
|
|
|
public static void ParseEgg(this IRibbonSetCommon4 r, ref RibbonResultList list)
|
|
{
|
|
if (r.RibbonFootprint)
|
|
list.Add(Footprint);
|
|
if (r.RibbonRecord)
|
|
list.Add(Record);
|
|
if (r.RibbonLegend)
|
|
list.Add(Legend);
|
|
if (r.RibbonChampionSinnoh)
|
|
list.Add(ChampionSinnoh);
|
|
|
|
FlagDaily(r, ref list);
|
|
FlagCosmetic(r, ref list);
|
|
}
|
|
}
|