2020-01-04 19:44:16 +00:00
|
|
|
|
using System;
|
|
|
|
|
using static PKHeX.Core.Encounters8Nest;
|
2022-01-09 06:34:04 +00:00
|
|
|
|
using static PKHeX.Core.AbilityPermission;
|
2020-01-04 19:44:16 +00:00
|
|
|
|
|
|
|
|
|
namespace PKHeX.Core
|
|
|
|
|
{
|
2020-11-27 19:51:02 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Generation 8 Nest Encounter (Raid)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <inheritdoc cref="EncounterStatic"/>
|
2021-12-09 09:08:46 +00:00
|
|
|
|
public abstract record EncounterStatic8Nest<T>(GameVersion Version) : EncounterStatic(Version), IGigantamax, IDynamaxLevel where T : EncounterStatic8Nest<T>
|
2020-01-04 19:44:16 +00:00
|
|
|
|
{
|
2020-11-27 19:51:02 +00:00
|
|
|
|
public sealed override int Generation => 8;
|
2020-01-04 19:44:16 +00:00
|
|
|
|
public static Func<PKM, T, bool>? VerifyCorrelation { private get; set; }
|
|
|
|
|
public static Action<PKM, T, EncounterCriteria>? GenerateData { private get; set; }
|
|
|
|
|
|
|
|
|
|
public bool CanGigantamax { get; set; }
|
|
|
|
|
public byte DynamaxLevel { get; set; }
|
2020-12-22 01:05:05 +00:00
|
|
|
|
public override int Location { get => SharedNest; init { } }
|
2020-01-04 19:44:16 +00:00
|
|
|
|
|
Fracture the encounter matching checks to allow progressive validation (#3137)
## Issue
We want to discard-but-remember any slots that aren't a perfect fit, on the off chance that a better one exists later in the search space. If there's no better match, then we gotta go with what we got.
## Example:
Wurmple exists in area `X`, and also has a more rare slot for Silcoon, with the same level for both slots.
* We have a Silcoon that we've leveled up a few times.
Was our Silcoon originally a Wurmple, or was it caught as a Silcoon?
* To be sure, we have to check the EC/PID if the Wurmple wouldn't evolve into Cascoon instead.
* We don't want to wholly reject that Wurmple slot, as maybe the Met Level isn't within Silcoon's slot range.
---
Existing implementation would store "deferred" matches in a list; we only need to keep 1 of these matches around (less allocation!). We also want to differentiate between a "good" deferral and a "bad" deferral; I don't think this is necessary but it's currently used by Mystery Gift matching (implemented for the Eeveelution mystery gifts which matter for evolution moves).
The existing logic didn't use inheritance, and instead had static methods being reused across generations. Quite kludgy. Also, the existing logic was a pain to modify the master encounter yield methods, as one generation's quirks had to not impact all other generations that used the method.
---
The new implementation splits out the encounter yielding methods to be separate for each generation / subset. Now, things don't have to check `WasLink` for Gen7 origin, because Pokémon Link wasn't a thing in Gen7.
---
## Future
Maybe refactoring yielders into "GameCores" that expose yielding behaviors / properties, rather than the static logic. As more generations and side-gamegroups get added (thanks LGPE/GO/GameCube), all this switch stuff gets annoying to maintain instead of just overriding/inheritance.
## Conclusion
This shouldn't impact any legality results negatively; if you notice any regressions, report them! This should reduce false flags where we didn't defer-discard an encounter when we should have (wild area mons being confused with raids).
2021-01-30 01:55:27 +00:00
|
|
|
|
public override bool IsMatchExact(PKM pkm, DexLevel evo)
|
2020-01-04 19:44:16 +00:00
|
|
|
|
{
|
|
|
|
|
if (pkm is IDynamaxLevel d && d.DynamaxLevel < DynamaxLevel)
|
|
|
|
|
return false;
|
|
|
|
|
|
2020-12-03 05:39:45 +00:00
|
|
|
|
// Required Ability
|
2022-01-09 06:34:04 +00:00
|
|
|
|
if (Ability == AbilityPermission.OnlyHidden && pkm.AbilityNumber != 4)
|
2020-12-03 05:39:45 +00:00
|
|
|
|
return false; // H
|
|
|
|
|
|
2020-01-04 19:44:16 +00:00
|
|
|
|
if (Version != GameVersion.SWSH && pkm.Version != (int)Version && pkm.Met_Location != SharedNest)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (VerifyCorrelation != null && !VerifyCorrelation(pkm, (T)this))
|
|
|
|
|
return false;
|
|
|
|
|
|
2021-01-23 04:28:54 +00:00
|
|
|
|
if (pkm is IRibbonSetMark8 m8 && m8.HasMark())
|
|
|
|
|
return false;
|
2021-04-21 22:20:16 +00:00
|
|
|
|
if (pkm.Species == (int)Core.Species.Shedinja && pkm is PK8 { AffixedRibbon: >= (int)RibbonIndex.MarkLunchtime })
|
|
|
|
|
return false;
|
2021-01-23 04:28:54 +00:00
|
|
|
|
|
Fracture the encounter matching checks to allow progressive validation (#3137)
## Issue
We want to discard-but-remember any slots that aren't a perfect fit, on the off chance that a better one exists later in the search space. If there's no better match, then we gotta go with what we got.
## Example:
Wurmple exists in area `X`, and also has a more rare slot for Silcoon, with the same level for both slots.
* We have a Silcoon that we've leveled up a few times.
Was our Silcoon originally a Wurmple, or was it caught as a Silcoon?
* To be sure, we have to check the EC/PID if the Wurmple wouldn't evolve into Cascoon instead.
* We don't want to wholly reject that Wurmple slot, as maybe the Met Level isn't within Silcoon's slot range.
---
Existing implementation would store "deferred" matches in a list; we only need to keep 1 of these matches around (less allocation!). We also want to differentiate between a "good" deferral and a "bad" deferral; I don't think this is necessary but it's currently used by Mystery Gift matching (implemented for the Eeveelution mystery gifts which matter for evolution moves).
The existing logic didn't use inheritance, and instead had static methods being reused across generations. Quite kludgy. Also, the existing logic was a pain to modify the master encounter yield methods, as one generation's quirks had to not impact all other generations that used the method.
---
The new implementation splits out the encounter yielding methods to be separate for each generation / subset. Now, things don't have to check `WasLink` for Gen7 origin, because Pokémon Link wasn't a thing in Gen7.
---
## Future
Maybe refactoring yielders into "GameCores" that expose yielding behaviors / properties, rather than the static logic. As more generations and side-gamegroups get added (thanks LGPE/GO/GameCube), all this switch stuff gets annoying to maintain instead of just overriding/inheritance.
## Conclusion
This shouldn't impact any legality results negatively; if you notice any regressions, report them! This should reduce false flags where we didn't defer-discard an encounter when we should have (wild area mons being confused with raids).
2021-01-30 01:55:27 +00:00
|
|
|
|
return base.IsMatchExact(pkm, evo);
|
2020-01-04 19:44:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-15 15:40:44 +00:00
|
|
|
|
protected sealed override EncounterMatchRating IsMatchDeferred(PKM pkm)
|
2020-01-04 19:44:16 +00:00
|
|
|
|
{
|
2022-01-09 06:34:04 +00:00
|
|
|
|
if (Ability != Any12H)
|
2020-06-20 18:14:44 +00:00
|
|
|
|
{
|
2020-12-03 05:39:45 +00:00
|
|
|
|
// HA-Only is a strict match. Ability Capsule and Patch can potentially change these.
|
2021-08-15 18:07:59 +00:00
|
|
|
|
var num = pkm.AbilityNumber;
|
|
|
|
|
if (num == 4)
|
2021-08-15 15:40:44 +00:00
|
|
|
|
{
|
2022-01-09 06:34:04 +00:00
|
|
|
|
if (Ability is not OnlyHidden && !AbilityVerifier.CanAbilityPatch(8, PersonalTable.SWSH.GetFormEntry(Species, Form).Abilities, pkm.Species))
|
2021-08-15 15:40:44 +00:00
|
|
|
|
return EncounterMatchRating.DeferredErrors;
|
|
|
|
|
}
|
2022-01-09 06:34:04 +00:00
|
|
|
|
else if (Ability.IsSingleValue(out int index) && 1 << index != num) // Fixed regular ability
|
2021-08-15 15:40:44 +00:00
|
|
|
|
{
|
2022-01-09 06:34:04 +00:00
|
|
|
|
if (Ability is OnlyFirst or OnlySecond && !AbilityVerifier.CanAbilityCapsule(8, PersonalTable.SWSH.GetFormEntry(Species, Form).Abilities))
|
2021-08-15 15:40:44 +00:00
|
|
|
|
return EncounterMatchRating.DeferredErrors;
|
|
|
|
|
}
|
2020-06-20 18:14:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-15 18:07:59 +00:00
|
|
|
|
return base.IsMatchDeferred(pkm);
|
Fracture the encounter matching checks to allow progressive validation (#3137)
## Issue
We want to discard-but-remember any slots that aren't a perfect fit, on the off chance that a better one exists later in the search space. If there's no better match, then we gotta go with what we got.
## Example:
Wurmple exists in area `X`, and also has a more rare slot for Silcoon, with the same level for both slots.
* We have a Silcoon that we've leveled up a few times.
Was our Silcoon originally a Wurmple, or was it caught as a Silcoon?
* To be sure, we have to check the EC/PID if the Wurmple wouldn't evolve into Cascoon instead.
* We don't want to wholly reject that Wurmple slot, as maybe the Met Level isn't within Silcoon's slot range.
---
Existing implementation would store "deferred" matches in a list; we only need to keep 1 of these matches around (less allocation!). We also want to differentiate between a "good" deferral and a "bad" deferral; I don't think this is necessary but it's currently used by Mystery Gift matching (implemented for the Eeveelution mystery gifts which matter for evolution moves).
The existing logic didn't use inheritance, and instead had static methods being reused across generations. Quite kludgy. Also, the existing logic was a pain to modify the master encounter yield methods, as one generation's quirks had to not impact all other generations that used the method.
---
The new implementation splits out the encounter yielding methods to be separate for each generation / subset. Now, things don't have to check `WasLink` for Gen7 origin, because Pokémon Link wasn't a thing in Gen7.
---
## Future
Maybe refactoring yielders into "GameCores" that expose yielding behaviors / properties, rather than the static logic. As more generations and side-gamegroups get added (thanks LGPE/GO/GameCube), all this switch stuff gets annoying to maintain instead of just overriding/inheritance.
## Conclusion
This shouldn't impact any legality results negatively; if you notice any regressions, report them! This should reduce false flags where we didn't defer-discard an encounter when we should have (wild area mons being confused with raids).
2021-01-30 01:55:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool IsMatchPartial(PKM pkm)
|
|
|
|
|
{
|
|
|
|
|
if (pkm is IGigantamax g && g.CanGigantamax != CanGigantamax && !g.CanToggleGigantamax(pkm.Species, pkm.Form, Species, Form))
|
|
|
|
|
return true;
|
|
|
|
|
if (Species == (int)Core.Species.Alcremie && pkm is IFormArgument { FormArgument: not 0 })
|
|
|
|
|
return true;
|
|
|
|
|
if (Species == (int)Core.Species.Runerigus && pkm is IFormArgument { FormArgument: not 0 })
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
switch (Shiny)
|
2020-04-16 01:30:29 +00:00
|
|
|
|
{
|
Fracture the encounter matching checks to allow progressive validation (#3137)
## Issue
We want to discard-but-remember any slots that aren't a perfect fit, on the off chance that a better one exists later in the search space. If there's no better match, then we gotta go with what we got.
## Example:
Wurmple exists in area `X`, and also has a more rare slot for Silcoon, with the same level for both slots.
* We have a Silcoon that we've leveled up a few times.
Was our Silcoon originally a Wurmple, or was it caught as a Silcoon?
* To be sure, we have to check the EC/PID if the Wurmple wouldn't evolve into Cascoon instead.
* We don't want to wholly reject that Wurmple slot, as maybe the Met Level isn't within Silcoon's slot range.
---
Existing implementation would store "deferred" matches in a list; we only need to keep 1 of these matches around (less allocation!). We also want to differentiate between a "good" deferral and a "bad" deferral; I don't think this is necessary but it's currently used by Mystery Gift matching (implemented for the Eeveelution mystery gifts which matter for evolution moves).
The existing logic didn't use inheritance, and instead had static methods being reused across generations. Quite kludgy. Also, the existing logic was a pain to modify the master encounter yield methods, as one generation's quirks had to not impact all other generations that used the method.
---
The new implementation splits out the encounter yielding methods to be separate for each generation / subset. Now, things don't have to check `WasLink` for Gen7 origin, because Pokémon Link wasn't a thing in Gen7.
---
## Future
Maybe refactoring yielders into "GameCores" that expose yielding behaviors / properties, rather than the static logic. As more generations and side-gamegroups get added (thanks LGPE/GO/GameCube), all this switch stuff gets annoying to maintain instead of just overriding/inheritance.
## Conclusion
This shouldn't impact any legality results negatively; if you notice any regressions, report them! This should reduce false flags where we didn't defer-discard an encounter when we should have (wild area mons being confused with raids).
2021-01-30 01:55:27 +00:00
|
|
|
|
case Shiny.Never when pkm.IsShiny:
|
|
|
|
|
case Shiny.Always when !pkm.IsShiny:
|
2020-04-16 01:30:29 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
Fracture the encounter matching checks to allow progressive validation (#3137)
## Issue
We want to discard-but-remember any slots that aren't a perfect fit, on the off chance that a better one exists later in the search space. If there's no better match, then we gotta go with what we got.
## Example:
Wurmple exists in area `X`, and also has a more rare slot for Silcoon, with the same level for both slots.
* We have a Silcoon that we've leveled up a few times.
Was our Silcoon originally a Wurmple, or was it caught as a Silcoon?
* To be sure, we have to check the EC/PID if the Wurmple wouldn't evolve into Cascoon instead.
* We don't want to wholly reject that Wurmple slot, as maybe the Met Level isn't within Silcoon's slot range.
---
Existing implementation would store "deferred" matches in a list; we only need to keep 1 of these matches around (less allocation!). We also want to differentiate between a "good" deferral and a "bad" deferral; I don't think this is necessary but it's currently used by Mystery Gift matching (implemented for the Eeveelution mystery gifts which matter for evolution moves).
The existing logic didn't use inheritance, and instead had static methods being reused across generations. Quite kludgy. Also, the existing logic was a pain to modify the master encounter yield methods, as one generation's quirks had to not impact all other generations that used the method.
---
The new implementation splits out the encounter yielding methods to be separate for each generation / subset. Now, things don't have to check `WasLink` for Gen7 origin, because Pokémon Link wasn't a thing in Gen7.
---
## Future
Maybe refactoring yielders into "GameCores" that expose yielding behaviors / properties, rather than the static logic. As more generations and side-gamegroups get added (thanks LGPE/GO/GameCube), all this switch stuff gets annoying to maintain instead of just overriding/inheritance.
## Conclusion
This shouldn't impact any legality results negatively; if you notice any regressions, report them! This should reduce false flags where we didn't defer-discard an encounter when we should have (wild area mons being confused with raids).
2021-01-30 01:55:27 +00:00
|
|
|
|
return base.IsMatchPartial(pkm);
|
2020-01-04 19:44:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-02-14 20:27:14 +00:00
|
|
|
|
protected override void ApplyDetails(ITrainerInfo sav, EncounterCriteria criteria, PKM pk)
|
|
|
|
|
{
|
|
|
|
|
base.ApplyDetails(sav, criteria, pk);
|
|
|
|
|
if (GenerateData == null)
|
|
|
|
|
pk.SetRandomEC();
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-27 19:51:02 +00:00
|
|
|
|
protected sealed override void SetPINGA(PKM pk, EncounterCriteria criteria)
|
2020-01-04 19:44:16 +00:00
|
|
|
|
{
|
|
|
|
|
if (GenerateData != null)
|
2021-01-31 03:58:05 +00:00
|
|
|
|
{
|
2020-01-04 19:44:16 +00:00
|
|
|
|
GenerateData(pk, (T)this, criteria);
|
2021-01-31 03:58:05 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
base.SetPINGA(pk, criteria);
|
|
|
|
|
if (Species == (int) Core.Species.Toxtricity)
|
|
|
|
|
{
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
var result = EvolutionMethod.GetAmpLowKeyResult(pk.Nature);
|
|
|
|
|
if (result == pk.Form)
|
|
|
|
|
break;
|
|
|
|
|
pk.Nature = Util.Rand.Next(25);
|
|
|
|
|
}
|
2021-05-08 15:29:20 +00:00
|
|
|
|
|
|
|
|
|
// Might be originally generated with a Neutral nature, then above logic changes to another.
|
|
|
|
|
// Realign the stat nature to Serious mint.
|
|
|
|
|
if (pk.Nature != pk.StatNature && ((Nature)pk.StatNature).IsNeutral())
|
|
|
|
|
pk.StatNature = (int)Nature.Serious;
|
2021-01-31 03:58:05 +00:00
|
|
|
|
}
|
2021-06-04 00:50:48 +00:00
|
|
|
|
var pid = pk.PID;
|
|
|
|
|
RaidRNG.ForceShinyState(pk, Shiny == Shiny.Always, ref pid);
|
|
|
|
|
pk.PID = pid;
|
2020-01-04 19:44:16 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|