2022-06-22 23:24:11 +00:00
|
|
|
using System;
|
2020-12-29 06:22:52 +00:00
|
|
|
using static PKHeX.Core.Species;
|
2018-03-31 07:43:41 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
namespace PKHeX.Core;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Wild Encounter Slot data
|
|
|
|
/// </summary>
|
|
|
|
/// <remarks>Wild encounter slots are found as random encounters in-game.</remarks>
|
2022-08-27 06:43:36 +00:00
|
|
|
public abstract record EncounterSlot(EncounterArea Area, ushort Species, byte Form, byte LevelMin, byte LevelMax) : IEncounterable, IEncounterMatch
|
2016-11-08 16:43:57 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
public abstract int Generation { get; }
|
Refactoring: Move Source (Legality) (#3560)
Rewrites a good amount of legality APIs pertaining to:
* Legal moves that can be learned
* Evolution chains & cross-generation paths
* Memory validation with forgotten moves
In generation 8, there are 3 separate contexts an entity can exist in: SW/SH, BD/SP, and LA. Not every entity can cross between them, and not every entity from generation 7 can exist in generation 8 (Gogoat, etc). By creating class models representing the restrictions to cross each boundary, we are able to better track and validate data.
The old implementation of validating moves was greedy: it would iterate for all generations and evolutions, and build a full list of every move that can be learned, storing it on the heap. Now, we check one game group at a time to see if the entity can learn a move that hasn't yet been validated. End result is an algorithm that requires 0 allocation, and a smaller/quicker search space.
The old implementation of storing move parses was inefficient; for each move that was parsed, a new object is created and adjusted depending on the parse. Now, move parse results are `struct` and store the move parse contiguously in memory. End result is faster parsing and 0 memory allocation.
* `PersonalTable` objects have been improved with new API methods to check if a species+form can exist in the game.
* `IEncounterTemplate` objects have been improved to indicate the `EntityContext` they originate in (similar to `Generation`).
* Some APIs have been extended to accept `Span<T>` instead of Array/IEnumerable
2022-08-03 23:15:27 +00:00
|
|
|
public abstract EntityContext Context { get; }
|
2022-06-18 18:04:24 +00:00
|
|
|
public bool EggEncounter => false;
|
|
|
|
public virtual bool IsShiny => false;
|
|
|
|
|
|
|
|
protected readonly EncounterArea Area = Area;
|
|
|
|
public GameVersion Version => Area.Version;
|
|
|
|
public int Location => Area.Location;
|
|
|
|
public int EggLocation => 0;
|
|
|
|
public virtual Ball FixedBall => Ball.None;
|
|
|
|
public virtual Shiny Shiny => Shiny.Random;
|
|
|
|
|
|
|
|
public bool IsFixedLevel => LevelMin == LevelMax;
|
|
|
|
public bool IsRandomLevel => LevelMin != LevelMax;
|
|
|
|
|
|
|
|
private protected const string wild = "Wild Encounter";
|
|
|
|
public string Name => wild;
|
|
|
|
|
2017-10-24 06:12:58 +00:00
|
|
|
/// <summary>
|
2022-06-18 18:04:24 +00:00
|
|
|
/// Gets if the specified level inputs are within range of the <see cref="LevelMin"/> and <see cref="LevelMax"/>
|
2017-10-24 06:12:58 +00:00
|
|
|
/// </summary>
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <param name="lvl">Single level</param>
|
|
|
|
/// <returns>True if within slot's range, false if impossible.</returns>
|
|
|
|
public bool IsLevelWithinRange(int lvl) => LevelMin <= lvl && lvl <= LevelMax;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets if the specified level inputs are within range of the <see cref="LevelMin"/> and <see cref="LevelMax"/>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="min">Highest value the low end of levels can be</param>
|
|
|
|
/// <param name="max">Lowest value the high end of levels can be</param>
|
|
|
|
/// <returns>True if within slot's range, false if impossible.</returns>
|
|
|
|
public bool IsLevelWithinRange(byte min, byte max) => LevelMin <= max && min <= LevelMax;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets if the specified level inputs are within range of the <see cref="LevelMin"/> and <see cref="LevelMax"/>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="lvl">Single level</param>
|
|
|
|
/// <param name="minDecrease">Highest value the low end of levels can be</param>
|
|
|
|
/// <param name="maxIncrease">Lowest value the high end of levels can be</param>
|
|
|
|
/// <returns>True if within slot's range, false if impossible.</returns>
|
|
|
|
public bool IsLevelWithinRange(int lvl, int minDecrease, int maxIncrease) => LevelMin - minDecrease <= lvl && lvl <= LevelMax + maxIncrease;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets if the specified level inputs are within range of the <see cref="LevelMin"/> and <see cref="LevelMax"/>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="min">Lowest level allowed</param>
|
|
|
|
/// <param name="max">Highest level allowed</param>
|
|
|
|
/// <param name="minDecrease">Highest value the low end of levels can be</param>
|
|
|
|
/// <param name="maxIncrease">Lowest value the high end of levels can be</param>
|
|
|
|
/// <returns>True if within slot's range, false if impossible.</returns>
|
|
|
|
public bool IsLevelWithinRange(byte min, byte max, int minDecrease, int maxIncrease) => LevelMin - minDecrease <= max && min <= LevelMax + maxIncrease;
|
|
|
|
|
|
|
|
public virtual string LongName
|
2016-11-08 16:43:57 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
get
|
2017-02-15 06:06:15 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (Area.Type == SlotType.Any)
|
|
|
|
return wild;
|
|
|
|
return $"{wild} {Area.Type.ToString().Replace('_', ' ')}";
|
2017-02-15 06:06:15 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2018-03-29 03:38:07 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public PKM ConvertToPKM(ITrainerInfo tr) => ConvertToPKM(tr, EncounterCriteria.Unrestricted);
|
2018-12-30 06:24:34 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public PKM ConvertToPKM(ITrainerInfo tr, EncounterCriteria criteria)
|
|
|
|
{
|
|
|
|
var pk = GetBlank();
|
|
|
|
tr.ApplyTo(pk);
|
|
|
|
ApplyDetails(tr, criteria, pk);
|
|
|
|
return pk;
|
|
|
|
}
|
2018-04-01 03:37:36 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
protected virtual PKM GetBlank() => EntityBlank.GetBlank(Generation, Version);
|
2022-05-31 04:43:52 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
protected virtual void ApplyDetails(ITrainerInfo sav, EncounterCriteria criteria, PKM pk)
|
|
|
|
{
|
|
|
|
var version = this.GetCompatibleVersion((GameVersion) sav.Game);
|
|
|
|
int lang = (int)Language.GetSafeLanguage(Generation, (LanguageID) sav.Language, version);
|
|
|
|
int level = LevelMin;
|
|
|
|
pk.Species = Species;
|
|
|
|
pk.Form = GetWildForm(pk, Form, sav);
|
|
|
|
pk.Language = lang;
|
|
|
|
pk.CurrentLevel = level;
|
|
|
|
pk.Version = (int)version;
|
|
|
|
pk.Nickname = SpeciesName.GetSpeciesNameGeneration(Species, lang, Generation);
|
|
|
|
|
|
|
|
ApplyDetailsBall(pk);
|
|
|
|
pk.Language = lang;
|
|
|
|
pk.OT_Friendship = pk.PersonalInfo.BaseFriendship;
|
|
|
|
|
|
|
|
SetMetData(pk, level, Location);
|
|
|
|
SetPINGA(pk, criteria);
|
2022-06-22 23:24:11 +00:00
|
|
|
SetEncounterMoves(pk, version, pk.CurrentLevel);
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
SetFormatSpecificData(pk);
|
|
|
|
|
|
|
|
if (pk.Format < 6)
|
|
|
|
return;
|
|
|
|
|
|
|
|
sav.ApplyHandlingTrainerInfo(pk);
|
|
|
|
if (pk is IScaledSize { HeightScalar: 0, WeightScalar: 0 } s)
|
2020-07-19 18:32:40 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
s.HeightScalar = PokeSizeUtil.GetRandomScalar();
|
|
|
|
s.WeightScalar = PokeSizeUtil.GetRandomScalar();
|
2018-03-31 07:43:41 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2018-04-29 16:31:13 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
protected virtual void ApplyDetailsBall(PKM pk)
|
|
|
|
{
|
|
|
|
var ball = FixedBall;
|
|
|
|
pk.Ball = (int)(ball == Ball.None ? Ball.Poke : ball);
|
|
|
|
}
|
2022-02-05 01:35:15 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
protected virtual void SetEncounterMoves(PKM pk, GameVersion version, int level)
|
|
|
|
{
|
2022-09-02 17:20:19 +00:00
|
|
|
Span<ushort> moves = stackalloc ushort[4];
|
|
|
|
MoveLevelUp.GetEncounterMoves(moves, pk, level, version);
|
2022-06-18 18:04:24 +00:00
|
|
|
pk.SetMoves(moves);
|
|
|
|
pk.SetMaximumPPCurrent(moves);
|
|
|
|
}
|
2019-02-09 19:37:20 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
protected virtual void SetFormatSpecificData(PKM pk) { }
|
2018-12-30 06:24:34 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
protected virtual void SetPINGA(PKM pk, EncounterCriteria criteria)
|
|
|
|
{
|
|
|
|
var pi = pk.PersonalInfo;
|
|
|
|
int gender = criteria.GetGender(-1, pi);
|
|
|
|
int nature = (int)criteria.GetNature(Nature.Random);
|
|
|
|
var ability = criteria.GetAbilityFromNumber(Ability);
|
2018-12-30 06:24:34 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (Generation == 3 && Species == (int)Unown)
|
|
|
|
{
|
|
|
|
do
|
2020-09-04 02:00:46 +00:00
|
|
|
{
|
|
|
|
PIDGenerator.SetRandomWildPID(pk, pk.Format, nature, ability, gender);
|
2022-06-18 18:04:24 +00:00
|
|
|
ability ^= 1; // some nature-forms cannot have a certain PID-ability set, so just flip it as Unown doesn't have dual abilities.
|
|
|
|
} while (pk.Form != Form);
|
2018-12-30 06:24:34 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
else
|
2018-12-30 06:24:34 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
PIDGenerator.SetRandomWildPID(pk, pk.Format, nature, ability, gender);
|
|
|
|
}
|
2018-12-30 06:24:34 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
pk.Gender = gender;
|
|
|
|
pk.StatNature = nature;
|
|
|
|
}
|
2018-12-30 06:24:34 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void SetMetData(PKM pk, int level, int location)
|
|
|
|
{
|
|
|
|
if (pk.Format <= 2 && Version != GameVersion.C)
|
|
|
|
return;
|
2018-12-30 06:24:34 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
pk.Met_Location = location;
|
|
|
|
pk.Met_Level = level;
|
2020-11-27 19:51:02 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (pk.Format >= 4)
|
|
|
|
pk.MetDate = DateTime.Today;
|
|
|
|
}
|
2021-08-01 05:41:52 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public bool IsRandomUnspecificForm => Form >= FormDynamic;
|
|
|
|
private const int FormDynamic = FormVivillon;
|
2022-08-27 06:43:36 +00:00
|
|
|
protected internal const byte FormVivillon = 30;
|
|
|
|
protected internal const byte FormRandom = 31;
|
2019-09-10 07:21:51 +00:00
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
private static byte GetWildForm(PKM pk, byte form, ITrainerInfo sav)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
if (form < FormDynamic) // specified form
|
|
|
|
return form;
|
|
|
|
|
|
|
|
if (form == FormRandom) // flagged as totally random
|
|
|
|
{
|
|
|
|
if (pk.Species == (int)Minior)
|
2022-08-27 06:43:36 +00:00
|
|
|
return (byte)Util.Rand.Next(7, 14);
|
|
|
|
return (byte)Util.Rand.Next(pk.PersonalInfo.FormCount);
|
2018-05-10 02:21:44 +00:00
|
|
|
}
|
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
ushort species = pk.Species;
|
2022-06-18 18:04:24 +00:00
|
|
|
if (species is >= (int)Scatterbug and <= (int)Vivillon)
|
2018-04-29 16:31:13 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (sav is IRegionOrigin o)
|
|
|
|
return Vivillon3DS.GetPattern(o.Country, o.Region);
|
2018-04-29 16:31:13 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
return 0;
|
|
|
|
}
|
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
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public virtual string GetConditionString(out bool valid)
|
|
|
|
{
|
|
|
|
valid = true;
|
|
|
|
return LegalityCheckStrings.LEncCondition;
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool IsMatchExact(PKM pk, EvoCriteria evo) => true; // Matched by Area
|
|
|
|
|
|
|
|
public virtual EncounterMatchRating GetMatchRating(PKM pk)
|
|
|
|
{
|
|
|
|
if (IsDeferredWurmple(pk))
|
|
|
|
return EncounterMatchRating.PartialMatch;
|
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
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (pk.Format >= 5)
|
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
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
bool isHidden = pk.AbilityNumber == 4;
|
|
|
|
if (isHidden && this.IsPartialMatchHidden(pk.Species, Species))
|
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 EncounterMatchRating.PartialMatch;
|
2022-06-18 18:04:24 +00:00
|
|
|
if (IsDeferredHiddenAbility(isHidden))
|
|
|
|
return EncounterMatchRating.Deferred;
|
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
|
|
|
}
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
return EncounterMatchRating.Match;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected virtual HiddenAbilityPermission IsHiddenAbilitySlot() => HiddenAbilityPermission.Never;
|
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
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public AbilityPermission Ability => IsHiddenAbilitySlot() switch
|
|
|
|
{
|
|
|
|
HiddenAbilityPermission.Never => AbilityPermission.Any12,
|
|
|
|
HiddenAbilityPermission.Always => AbilityPermission.OnlyHidden,
|
|
|
|
_ => AbilityPermission.Any12H,
|
|
|
|
};
|
2021-02-01 05:42:24 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private bool IsDeferredWurmple(PKM pk) => Species == (int)Wurmple && pk.Species != (int)Wurmple && !WurmpleUtil.IsWurmpleEvoValid(pk);
|
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
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private bool IsDeferredHiddenAbility(bool IsHidden) => IsHiddenAbilitySlot() switch
|
|
|
|
{
|
|
|
|
HiddenAbilityPermission.Never => IsHidden,
|
|
|
|
HiddenAbilityPermission.Always => !IsHidden,
|
|
|
|
_ => 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
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
protected enum HiddenAbilityPermission
|
|
|
|
{
|
|
|
|
Always,
|
|
|
|
Never,
|
|
|
|
Possible,
|
2016-11-08 16:43:57 +00:00
|
|
|
}
|
|
|
|
}
|