2020-08-31 02:24:24 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace PKHeX.Core
|
2020-08-21 23:35:49 +00:00
|
|
|
|
{
|
2020-11-27 19:51:02 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Generation 5 Static Encounter
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <inheritdoc cref="EncounterStatic"/>
|
2021-12-09 09:08:46 +00:00
|
|
|
|
public record EncounterStatic5(GameVersion Version) : EncounterStatic(Version)
|
2020-08-21 23:35:49 +00:00
|
|
|
|
{
|
2020-09-07 20:51:13 +00:00
|
|
|
|
public sealed override int Generation => 5;
|
2020-12-22 07:37:07 +00:00
|
|
|
|
public bool Roaming { get; init; }
|
2021-09-07 22:31:54 +00:00
|
|
|
|
public bool IsWildCorrelationPID => !Roaming && Shiny == Shiny.Random && Species != (int)Core.Species.Crustle;
|
2020-08-21 23:35:49 +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
|
|
|
|
protected sealed override bool IsMatchPartial(PKM pkm)
|
2020-08-21 23:35:49 +00:00
|
|
|
|
{
|
2022-01-09 06:34:04 +00:00
|
|
|
|
// BW/2 Jellicent collision with wild surf slot, resolved by duplicating the encounter with any abil
|
|
|
|
|
if (Ability == AbilityPermission.OnlyHidden && pkm.AbilityNumber != 4 && pkm.Format <= 7)
|
2020-08-21 23:35:49 +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-08-21 23:35:49 +00:00
|
|
|
|
}
|
2020-08-31 02:24:24 +00:00
|
|
|
|
|
|
|
|
|
protected sealed override bool IsMatchLocation(PKM pk)
|
|
|
|
|
{
|
|
|
|
|
if (!Roaming)
|
|
|
|
|
return base.IsMatchLocation(pk);
|
|
|
|
|
return Roaming_MetLocation_BW.Contains(pk.Met_Location);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-04 02:35:26 +00:00
|
|
|
|
protected override bool IsMatchEggLocation(PKM pkm)
|
|
|
|
|
{
|
2021-05-21 20:57:07 +00:00
|
|
|
|
var eggloc = pkm.Egg_Location;
|
|
|
|
|
if (!EggEncounter)
|
|
|
|
|
return eggloc == EggLocation;
|
|
|
|
|
|
|
|
|
|
if (!pkm.IsEgg) // hatched
|
|
|
|
|
return eggloc == EggLocation || eggloc == Locations.LinkTrade5;
|
|
|
|
|
|
|
|
|
|
// Unhatched:
|
|
|
|
|
if (eggloc != EggLocation)
|
|
|
|
|
return false;
|
2021-10-14 03:05:19 +00:00
|
|
|
|
if (pkm.Met_Location is not (0 or Locations.LinkTrade5))
|
2021-05-21 20:57:07 +00:00
|
|
|
|
return false;
|
|
|
|
|
return true;
|
2021-03-04 02:35:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-31 02:24:24 +00:00
|
|
|
|
private static readonly int[] Roaming_MetLocation_BW =
|
|
|
|
|
{
|
|
|
|
|
25,26,27,28, // Route 12, 13, 14, 15 Night latter half
|
|
|
|
|
15,16,31, // Route 2, 3, 18 Morning
|
|
|
|
|
17,18,29, // Route 4, 5, 16 Daytime
|
|
|
|
|
19,20,21, // Route 6, 7, 8 Evening
|
|
|
|
|
22,23,24, // Route 9, 10, 11 Night former half
|
|
|
|
|
};
|
|
|
|
|
}
|
2020-08-21 23:35:49 +00:00
|
|
|
|
}
|