2020-12-23 20:15:49 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
2021-06-30 03:58:06 +00:00
|
|
|
|
using static PKHeX.Core.GroundTilePermission;
|
2020-12-23 20:15:49 +00:00
|
|
|
|
|
|
|
|
|
namespace PKHeX.Core
|
2020-08-21 23:35:49 +00:00
|
|
|
|
{
|
2020-11-27 19:51:02 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Generation 4 Static Encounter
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <inheritdoc cref="EncounterStatic"/>
|
2021-12-09 09:08:46 +00:00
|
|
|
|
public sealed record EncounterStatic4(GameVersion Version) : EncounterStatic(Version), IGroundTypeTile
|
2020-08-21 23:35:49 +00:00
|
|
|
|
{
|
2020-12-23 20:15:49 +00:00
|
|
|
|
public override int Generation => 4;
|
|
|
|
|
|
|
|
|
|
/// <summary> Indicates if the encounter is a Roamer (variable met location) </summary>
|
|
|
|
|
public bool Roaming { get; init; }
|
2020-08-30 23:10:24 +00:00
|
|
|
|
|
2021-06-30 03:58:06 +00:00
|
|
|
|
/// <summary> <see cref="PK4.GroundTile"/> values permitted for the encounter. </summary>
|
|
|
|
|
public GroundTilePermission GroundTile { get; init; } = None;
|
2020-12-23 20:15:49 +00:00
|
|
|
|
|
|
|
|
|
protected override bool IsMatchLocation(PKM pkm)
|
|
|
|
|
{
|
|
|
|
|
if (!Roaming)
|
|
|
|
|
return base.IsMatchLocation(pkm);
|
|
|
|
|
|
|
|
|
|
// Met location is lost on transfer
|
|
|
|
|
if (pkm is not G4PKM pk4)
|
|
|
|
|
return true;
|
|
|
|
|
|
2021-06-30 03:58:06 +00:00
|
|
|
|
var locs = GetRoamLocations(Species, pk4.GroundTile);
|
2021-05-21 20:57:07 +00:00
|
|
|
|
return locs.Contains(pk4.Met_Location);
|
2020-12-23 20:15:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool IsMatchEggLocation(PKM pkm)
|
2020-08-21 23:35:49 +00:00
|
|
|
|
{
|
2021-05-21 20:57:07 +00:00
|
|
|
|
var eggloc = pkm.Egg_Location;
|
|
|
|
|
if (!EggEncounter)
|
|
|
|
|
return eggloc == 0;
|
2020-08-21 23:35:49 +00:00
|
|
|
|
|
2021-05-21 20:57:07 +00:00
|
|
|
|
// Transferring 4->5 clears Pt/HG/SS location value and keeps Faraway Place
|
|
|
|
|
if (pkm is not G4PKM pk4)
|
2020-08-21 23:35:49 +00:00
|
|
|
|
{
|
2021-05-21 20:57:07 +00:00
|
|
|
|
if (eggloc == Locations.LinkTrade4)
|
|
|
|
|
return true;
|
|
|
|
|
var cmp = Locations.IsPtHGSSLocationEgg(EggLocation) ? Locations.Faraway4 : EggLocation;
|
|
|
|
|
return eggloc == cmp;
|
2020-08-21 23:35:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-21 20:57:07 +00:00
|
|
|
|
if (!pk4.IsEgg) // hatched
|
|
|
|
|
return eggloc == EggLocation || eggloc == Locations.LinkTrade4;
|
2020-08-21 23:35:49 +00:00
|
|
|
|
|
2021-05-21 20:57:07 +00:00
|
|
|
|
// Unhatched:
|
|
|
|
|
if (eggloc != EggLocation)
|
2020-08-21 23:35:49 +00:00
|
|
|
|
return false;
|
2021-10-14 03:05:19 +00:00
|
|
|
|
if (pk4.Met_Location is not (0 or Locations.LinkTrade4))
|
2020-08-21 23:35:49 +00:00
|
|
|
|
return false;
|
2021-05-21 20:57:07 +00:00
|
|
|
|
return true;
|
2020-08-21 23:35:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-23 04:15:56 +00:00
|
|
|
|
protected override void ApplyDetails(ITrainerInfo sav, EncounterCriteria criteria, PKM pk)
|
|
|
|
|
{
|
|
|
|
|
base.ApplyDetails(sav, criteria, pk);
|
|
|
|
|
SanityCheckVersion(pk);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SanityCheckVersion(PKM pk)
|
|
|
|
|
{
|
|
|
|
|
// Unavailable encounters in DP, morph them to Pt so they're legal.
|
|
|
|
|
switch (Species)
|
|
|
|
|
{
|
|
|
|
|
case (int)Core.Species.Darkrai when Location == 079: // DP Darkrai
|
|
|
|
|
case (int)Core.Species.Shaymin when Location == 063: // DP Shaymin
|
|
|
|
|
pk.Version = (int)GameVersion.Pt;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-08 01:29:36 +00:00
|
|
|
|
protected override bool IsMatchLevel(PKM pkm, EvoCriteria evo)
|
2020-08-21 23:35:49 +00:00
|
|
|
|
{
|
2021-02-22 02:41:42 +00:00
|
|
|
|
if (pkm.Format != 4) // Met Level lost on PK4=>PK5
|
2022-04-24 04:33:17 +00:00
|
|
|
|
return Level <= evo.LevelMax;
|
2020-08-21 23:35:49 +00:00
|
|
|
|
|
|
|
|
|
return pkm.Met_Level == (EggEncounter ? 0 : Level);
|
|
|
|
|
}
|
|
|
|
|
|
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 (Gift && pkm.Ball != Ball)
|
|
|
|
|
return true;
|
|
|
|
|
return base.IsMatchPartial(pkm);
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-23 20:15:49 +00:00
|
|
|
|
protected override void SetMetData(PKM pk, int level, DateTime today)
|
2020-08-21 23:35:49 +00:00
|
|
|
|
{
|
2020-12-23 20:15:49 +00:00
|
|
|
|
var pk4 = (PK4)pk;
|
2021-06-30 03:58:06 +00:00
|
|
|
|
var type = pk4.GroundTile = GroundTile.GetIndex();
|
2020-12-23 20:15:49 +00:00
|
|
|
|
pk.Met_Location = Roaming ? GetRoamLocations(Species, type)[0] : Location;
|
|
|
|
|
pk.Met_Level = level;
|
|
|
|
|
pk.MetDate = today;
|
2020-08-21 23:35:49 +00:00
|
|
|
|
}
|
2020-12-23 20:15:49 +00:00
|
|
|
|
|
2021-06-30 03:58:06 +00:00
|
|
|
|
private static int[] GetRoamLocations(int species, GroundTileType type) => species switch
|
2020-12-23 20:15:49 +00:00
|
|
|
|
{
|
2021-06-30 03:58:06 +00:00
|
|
|
|
481 or 488 or 144 or 145 or 146 => type == GroundTileType.Grass ? Roaming_MetLocation_DPPt_Grass : Roaming_MetLocation_DPPt_Surf,
|
|
|
|
|
243 or 244 => type == GroundTileType.Grass ? Roaming_MetLocation_HGSS_Johto_Grass : Roaming_MetLocation_HGSS_Johto_Surf,
|
|
|
|
|
380 or 381 => type == GroundTileType.Grass ? Roaming_MetLocation_HGSS_Kanto_Grass : Roaming_MetLocation_HGSS_Kanto_Surf,
|
2021-01-02 01:08:49 +00:00
|
|
|
|
_ => throw new IndexOutOfRangeException(nameof(species)),
|
|
|
|
|
};
|
2020-12-23 20:15:49 +00:00
|
|
|
|
|
|
|
|
|
private static readonly int[] Roaming_MetLocation_DPPt_Grass =
|
|
|
|
|
{
|
|
|
|
|
// Routes 201-218, 221-222 can be encountered in grass
|
|
|
|
|
16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
|
|
|
|
|
26, 27, 28, 29, 30, 31, 32, 33, 36, 37,
|
|
|
|
|
47, // Valley Windworks
|
|
|
|
|
49, // Fuego Ironworks
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private static readonly int[] Roaming_MetLocation_DPPt_Surf =
|
|
|
|
|
{
|
|
|
|
|
// Routes 203-205, 208-210, 212-214, 218-222 can be encountered in water
|
|
|
|
|
18, 19, 20, 23, 24, 25, 27, 28, 29, 33,
|
|
|
|
|
34, 35, 36, 37,
|
|
|
|
|
47, // Valley Windworks
|
|
|
|
|
49, // Fuego Ironworks
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Grass 29-39, 42-46, 47, 48
|
|
|
|
|
// Surf 30-32 34-35, 40-45, 47
|
|
|
|
|
// Route 45 inaccessible surf
|
|
|
|
|
private static readonly int[] Roaming_MetLocation_HGSS_Johto_Grass =
|
|
|
|
|
{
|
|
|
|
|
// Routes 29-48 can be encountered in grass
|
|
|
|
|
// Won't go to routes 40,41,47,48
|
|
|
|
|
177, 178, 179, 180, 181, 182, 183, 184, 185, 186,
|
|
|
|
|
187, 190, 191, 192, 193, 194,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private static readonly int[] Roaming_MetLocation_HGSS_Johto_Surf =
|
|
|
|
|
{
|
|
|
|
|
// Routes 30-32,34-35,40-45 and 47 can be encountered in water
|
|
|
|
|
// Won't go to routes 40,41,47,48
|
2021-08-20 20:49:20 +00:00
|
|
|
|
178, 179, 180, 182, 183, 190, 191, 192, 193,
|
2020-12-23 20:15:49 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private static readonly int[] Roaming_MetLocation_HGSS_Kanto_Grass =
|
|
|
|
|
{
|
|
|
|
|
// Route 01-18,21,22,24,26 and 28 can be encountered in grass
|
|
|
|
|
// Won't go to route 23 25 27
|
|
|
|
|
149, 150, 151, 152, 153, 154, 155, 156, 157, 158,
|
|
|
|
|
159, 160, 161, 162, 163, 164, 165, 166,
|
|
|
|
|
169, 170, 172, 174, 176,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private static readonly int[] Roaming_MetLocation_HGSS_Kanto_Surf =
|
|
|
|
|
{
|
|
|
|
|
// Route 4,6,9,10,12,13,19-22,24,26 and 28 can be encountered in water
|
|
|
|
|
// Won't go to route 23 25 27
|
|
|
|
|
152, 154, 157, 158, 160, 161, 167, 168, 169, 170,
|
|
|
|
|
172, 174, 176,
|
|
|
|
|
};
|
2020-08-21 23:35:49 +00:00
|
|
|
|
}
|
2020-12-23 20:15:49 +00:00
|
|
|
|
}
|