Z-A: Allow farfetch'd-1/sirfetch'd formarg

Revises the API for requesting a suggested Form Argument, based on visitation to various games with different rules.
This commit is contained in:
Kurt
2025-12-17 02:11:51 -06:00
parent b078e0e735
commit 64f655b5b6
2 changed files with 68 additions and 8 deletions

View File

@@ -56,6 +56,8 @@ private CheckResult VerifyFormArgument(LegalityAnalysis data, IFormArgument f)
> 9_999 => GetInvalid(FormArgumentLEQ_0, 9999),
_ => GetValid(FormArgumentValid),
},
Farfetchd when pk.Form is 1 => CheckFarfetchd(data, pk, arg), // Galar
Sirfetchd => CheckSirfetchd(data, arg, enc),
Qwilfish when pk.Form is 1 => CheckQwilfish(data, pk, arg),
Overqwil => CheckOverqwil(data, pk, arg, enc),
Stantler => arg switch
@@ -120,6 +122,41 @@ private CheckResult VerifyFormArgument(LegalityAnalysis data, IFormArgument f)
};
}
private CheckResult CheckFarfetchd(LegalityAnalysis data, PKM pk, uint arg)
{
if (arg == 0)
return GetValid(FormArgumentValid);
if (arg > 9_999)
return GetInvalid(FormArgumentLEQ_0, 9999);
if (pk.IsEgg)
return GetInvalid(FormArgumentNotAllowed);
var history = data.Info.EvoChainsAllGens;
if (history.HasVisitedZA) // Can increase.
return GetValid(FormArgumentValid);
return GetInvalid(FormArgumentLEQ_0, 0); // Can't increase from 0.
}
private CheckResult CheckSirfetchd(LegalityAnalysis data, uint arg, IEncounterTemplate enc)
{
var history = data.Info.EvoChainsAllGens;
if (arg is 0)
{
if (enc.Species is (ushort)Sirfetchd)
return GetValid(FormArgumentValid);
if (history.HasVisitedGen9 || history.HasVisitedSWSH)
return GetValid(FormArgumentValid);
}
else if (arg > 9999)
{
return GetInvalid(FormArgumentLEQ_0, 9999);
}
if (history.HasVisitedZA && arg >= 3) // Can increase.
return GetValid(FormArgumentValid);
return GetInvalid(FormArgumentLEQ_0, 0); // Can't increase from 0.
}
private CheckResult CheckQwilfish(LegalityAnalysis data, PKM pk, uint arg)
{
if (arg == 0)

View File

@@ -53,18 +53,39 @@ public static class FormArgumentUtil
/// <summary>
/// Sets the suggested Form Argument to the <see cref="pk"/>.
/// </summary>
public static void SetSuggestedFormArgument(this PKM pk, ushort originalSpecies = 0)
public static void SetSuggestedFormArgument(this PKM pk, EvolutionHistory history, ushort originalSpecies = 0)
{
if (pk is not IFormArgument)
return;
uint value = IsFormArgumentTypeDatePair(pk.Species, pk.Form)
? GetFormArgumentMax(pk.Species, pk.Form, pk.Context)
: GetFormArgumentMinEvolution(pk.Species, originalSpecies);
if (pk.Species is (int)Hoopa && pk.Format >= 8)
value = 0; // S/V does not set the argument for Hoopa
var (species, form) = (pk.Species, pk.Form);
uint value = IsFormArgumentTypeDatePair(species, form)
? GetFormArgumentMax(species, form, pk.Context)
: GetFormArgumentMinEvolution(species, originalSpecies);
if (IsFormArgumentAbleToStay0(species, form, history))
value = 0;
pk.ChangeFormArgument(value);
}
/// <summary>
/// Checks if the Form Argument can stay zero due to different games having different uses/behaviors of the value.
/// </summary>
public static bool IsFormArgumentAbleToStay0(ushort species, byte form, EvolutionHistory history) => species switch
{
// S/V does not set the argument for Hoopa
(int)Hoopa => history.HasVisitedGen9 || history.HasVisitedZA,
// S/V does not set the argument for Farfetch'd (Galar)
(int)Farfetchd when form == 1 => history.HasVisitedGen9,
(int)Sirfetchd => history.HasVisitedGen9,
// Z-A does not set the argument for Gimmighoul/Gholdengo
(int)Gimmighoul or (int)Gholdengo => history.HasVisitedZA,
_ => false,
};
/// <summary>
/// Modifies the <see cref="IFormArgument"/> values for the provided <see cref="pk"/> to the requested <see cref="value"/>.
/// </summary>
@@ -128,9 +149,11 @@ public static uint GetFormArgumentMax(ushort species, byte form, EntityContext c
(int)Basculegion => 9999, // 294
(int)Primeape or (int)Annihilape when gen >= 8 => 9999,
(int)Bisharp or (int)Kingambit when gen >= 8 => 9999,
(int)Gimmighoul when context is EntityContext.Gen9 => 998,
(int)Gholdengo when context is EntityContext.Gen9 => 999,
(int)Gimmighoul => 998,
(int)Gholdengo => 999,
(int)Koraidon or (int)Miraidon => 1,
(int)Farfetchd when form == 1 && gen >= 8 => 9999,
(int)Sirfetchd when gen >= 8 => 9999,
_ => 0,
};
}