2020-07-18 20:36:30 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
namespace PKHeX.Core
|
|
|
|
|
{
|
2020-11-27 19:51:02 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Generation 2 Static Encounter
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <inheritdoc cref="EncounterStatic"/>
|
2020-12-24 04:40:59 +00:00
|
|
|
|
public record EncounterStatic2 : EncounterStatic
|
2020-07-18 20:36:30 +00:00
|
|
|
|
{
|
2020-09-07 20:51:13 +00:00
|
|
|
|
public sealed override int Generation => 2;
|
2020-12-22 01:05:05 +00:00
|
|
|
|
public sealed override int Level { get; init; }
|
2020-07-18 20:36:30 +00:00
|
|
|
|
|
2021-01-04 00:49:49 +00:00
|
|
|
|
public EncounterStatic2(int species, int level, GameVersion game) : base(game)
|
2020-07-18 20:36:30 +00:00
|
|
|
|
{
|
|
|
|
|
Species = species;
|
|
|
|
|
Level = level;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-02 18:41:28 +00:00
|
|
|
|
public override bool IsMatchExact(PKM pkm, DexLevel evo)
|
|
|
|
|
{
|
|
|
|
|
if (Shiny == Shiny.Always && !pkm.IsShiny)
|
|
|
|
|
return false;
|
|
|
|
|
return base.IsMatchExact(pkm, evo);
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-21 23:35:49 +00:00
|
|
|
|
protected override bool IsMatchEggLocation(PKM pkm)
|
2020-07-18 20:36:30 +00:00
|
|
|
|
{
|
|
|
|
|
if (pkm.Format > 2)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
if (pkm.IsEgg)
|
|
|
|
|
{
|
2020-10-07 22:28:58 +00:00
|
|
|
|
if (!EggEncounter)
|
|
|
|
|
return false;
|
2020-07-18 20:36:30 +00:00
|
|
|
|
if (pkm.Met_Location != 0 && pkm.Met_Level != 0)
|
|
|
|
|
return false;
|
|
|
|
|
if (pkm.OT_Friendship > EggCycles) // Dizzy Punch eggs start with below-normal hatch counters.
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
switch (pkm.Met_Level)
|
|
|
|
|
{
|
|
|
|
|
case 0 when pkm.Met_Location != 0:
|
|
|
|
|
return false;
|
2021-10-20 04:53:22 +00:00
|
|
|
|
case 1: // 0 = second floor of every Pokémon Center, valid
|
|
|
|
|
return true;
|
2020-07-18 20:36:30 +00:00
|
|
|
|
default:
|
|
|
|
|
if (pkm.Met_Location == 0 && pkm.Met_Level != 0)
|
|
|
|
|
return false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-21 23:35:49 +00:00
|
|
|
|
protected override bool IsMatchLevel(PKM pkm, DexLevel evo)
|
|
|
|
|
{
|
2020-12-29 08:58:08 +00:00
|
|
|
|
if (pkm is ICaughtData2 {CaughtData: not 0})
|
2020-08-21 23:35:49 +00:00
|
|
|
|
return pkm.Met_Level == (EggEncounter ? 1 : Level);
|
|
|
|
|
|
|
|
|
|
return Level <= evo.Level;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool IsMatchLocation(PKM pkm)
|
|
|
|
|
{
|
|
|
|
|
if (EggEncounter)
|
|
|
|
|
return true;
|
|
|
|
|
if (Location == 0)
|
|
|
|
|
return true;
|
2020-12-29 08:58:08 +00:00
|
|
|
|
if (pkm is ICaughtData2 {CaughtData: not 0})
|
2020-08-21 23:35:49 +00:00
|
|
|
|
return Location == pkm.Met_Location;
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
protected override bool IsMatchPartial(PKM pkm) => false;
|
2021-02-02 18:41:28 +00:00
|
|
|
|
|
|
|
|
|
protected override void ApplyDetails(ITrainerInfo sav, EncounterCriteria criteria, PKM pk)
|
|
|
|
|
{
|
|
|
|
|
base.ApplyDetails(sav, criteria, pk);
|
|
|
|
|
var pk2 = (PK2)pk;
|
|
|
|
|
if (Shiny == Shiny.Always)
|
|
|
|
|
pk2.SetShiny();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void SetMetData(PKM pk, int level, DateTime today)
|
|
|
|
|
{
|
|
|
|
|
if (Version != GameVersion.C && pk.OT_Gender != 1)
|
|
|
|
|
return;
|
|
|
|
|
var pk2 = (PK2)pk;
|
|
|
|
|
pk2.Met_Location = Location;
|
|
|
|
|
pk2.Met_Level = level;
|
|
|
|
|
pk2.Met_TimeOfDay = EncounterTime.Any.RandomValidTime();
|
|
|
|
|
}
|
2020-07-18 20:36:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-24 04:40:59 +00:00
|
|
|
|
public sealed record EncounterStatic2Odd : EncounterStatic2
|
2020-07-18 20:36:30 +00:00
|
|
|
|
{
|
2020-10-07 02:35:03 +00:00
|
|
|
|
public EncounterStatic2Odd(int species) : base(species, 5, GameVersion.C)
|
2020-07-18 20:36:30 +00:00
|
|
|
|
{
|
|
|
|
|
EggLocation = 256;
|
|
|
|
|
EggCycles = 20;
|
|
|
|
|
}
|
|
|
|
|
|
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-07-18 20:36:30 +00:00
|
|
|
|
{
|
|
|
|
|
// Let it get picked up as regular EncounterEgg under other conditions.
|
|
|
|
|
if (pkm.Format > 2)
|
|
|
|
|
return false;
|
2022-01-11 05:27:04 +00:00
|
|
|
|
if (!pkm.HasMove((int)Move.DizzyPunch))
|
2020-07-18 20:36:30 +00:00
|
|
|
|
return false;
|
|
|
|
|
if (pkm.IsEgg && pkm.EXP != 125)
|
|
|
|
|
return false;
|
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-07-18 20:36:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-24 04:40:59 +00:00
|
|
|
|
public sealed record EncounterStatic2Roam : EncounterStatic2
|
2020-07-18 20:36:30 +00:00
|
|
|
|
{
|
2021-04-14 20:29:23 +00:00
|
|
|
|
// Routes 29-46, except 40 & 41; total 16.
|
|
|
|
|
// 02, 04, 05, 08, 11, 15, 18, 20,
|
|
|
|
|
// 21, 25, 26, 34, 37, 39, 43, 45,
|
2021-04-23 20:51:56 +00:00
|
|
|
|
private const ulong RoamLocations = 0b10_1000_1010_0100_0000_0110_0011_0100_1000_1001_0011_0100;
|
2021-04-14 20:29:23 +00:00
|
|
|
|
public override int Location => 2;
|
2020-07-18 20:36:30 +00:00
|
|
|
|
|
2020-10-07 02:35:03 +00:00
|
|
|
|
public EncounterStatic2Roam(int species, int level, GameVersion ver) : base(species, level, ver) { }
|
2020-07-18 20:36:30 +00:00
|
|
|
|
|
|
|
|
|
protected override bool IsMatchLocation(PKM pkm)
|
|
|
|
|
{
|
|
|
|
|
if (!pkm.HasOriginalMetLocation)
|
|
|
|
|
return true;
|
2021-04-14 20:29:23 +00:00
|
|
|
|
// Gen2 met location is always u8
|
|
|
|
|
var loc = pkm.Met_Location;
|
|
|
|
|
return loc <= 45 && ((RoamLocations & (1UL << loc)) != 0);
|
2020-07-18 20:36:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|