2018-03-29 03:40:07 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
namespace PKHeX.Core
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
2017-10-24 06:12:58 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Egg Encounter Data
|
|
|
|
|
/// </summary>
|
2021-12-09 09:08:46 +00:00
|
|
|
|
public sealed record EncounterEgg(int Species, int Form, int Level, int Generation, GameVersion Version) : IEncounterable
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
|
|
|
|
public string Name => "Egg";
|
2019-03-18 05:19:37 +00:00
|
|
|
|
public string LongName => "Egg";
|
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
|
|
|
|
|
2017-05-28 04:17:53 +00:00
|
|
|
|
public bool EggEncounter => true;
|
|
|
|
|
public int LevelMin => Level;
|
|
|
|
|
public int LevelMax => Level;
|
2021-05-18 17:36:45 +00:00
|
|
|
|
public bool IsShiny => false;
|
2022-01-06 00:46:23 +00:00
|
|
|
|
public int Location => 0;
|
|
|
|
|
public int EggLocation => Locations.GetDaycareLocation(Generation, Version);
|
|
|
|
|
public Ball FixedBall => BallBreedLegality.GetDefaultBall(Version, Species);
|
|
|
|
|
public Shiny Shiny => Shiny.Random;
|
2022-01-09 06:34:04 +00:00
|
|
|
|
public AbilityPermission Ability => AbilityPermission.Any12H;
|
2019-11-19 04:01:48 +00:00
|
|
|
|
|
2021-09-16 01:43:18 +00:00
|
|
|
|
public bool CanHaveVoltTackle => Species is (int)Core.Species.Pichu && (Generation > 3 || Version is GameVersion.E);
|
|
|
|
|
|
2020-06-17 02:46:22 +00:00
|
|
|
|
public PKM ConvertToPKM(ITrainerInfo sav) => ConvertToPKM(sav, EncounterCriteria.Unrestricted);
|
2018-12-30 06:24:34 +00:00
|
|
|
|
|
2020-06-17 02:46:22 +00:00
|
|
|
|
public PKM ConvertToPKM(ITrainerInfo sav, EncounterCriteria criteria)
|
2018-03-29 03:40:07 +00:00
|
|
|
|
{
|
2020-05-31 19:12:48 +00:00
|
|
|
|
int gen = Generation;
|
2019-02-09 19:37:20 +00:00
|
|
|
|
var version = Version;
|
|
|
|
|
var pk = PKMConverter.GetBlank(gen, version);
|
2018-12-30 06:24:34 +00:00
|
|
|
|
|
2020-06-17 02:46:22 +00:00
|
|
|
|
sav.ApplyTo(pk);
|
2018-03-29 03:40:07 +00:00
|
|
|
|
|
2021-05-23 19:50:42 +00:00
|
|
|
|
int lang = (int)Language.GetSafeLanguage(Generation, (LanguageID)sav.Language, version);
|
2018-03-29 03:40:07 +00:00
|
|
|
|
pk.Species = Species;
|
2021-01-31 09:20:35 +00:00
|
|
|
|
pk.Form = Form;
|
2021-06-27 22:43:35 +00:00
|
|
|
|
pk.Language = lang;
|
2021-05-23 19:50:42 +00:00
|
|
|
|
pk.Nickname = SpeciesName.GetSpeciesNameGeneration(Species, lang, gen);
|
2018-03-29 03:40:07 +00:00
|
|
|
|
pk.CurrentLevel = Level;
|
2019-02-09 19:37:20 +00:00
|
|
|
|
pk.Version = (int)version;
|
2022-01-06 00:46:23 +00:00
|
|
|
|
|
|
|
|
|
var ball = FixedBall;
|
|
|
|
|
pk.Ball = ball is Ball.None ? (int)Ball.Poke : (int)ball;
|
2018-03-29 03:56:58 +00:00
|
|
|
|
pk.OT_Friendship = pk.PersonalInfo.BaseFriendship;
|
|
|
|
|
|
2021-04-05 01:30:01 +00:00
|
|
|
|
SetEncounterMoves(pk, version);
|
|
|
|
|
pk.HealPP();
|
2019-02-09 19:37:20 +00:00
|
|
|
|
SetPINGA(pk, criteria);
|
2018-03-29 03:40:07 +00:00
|
|
|
|
|
2021-05-23 19:50:42 +00:00
|
|
|
|
if (gen <= 2)
|
|
|
|
|
{
|
|
|
|
|
if (version != GameVersion.C)
|
|
|
|
|
{
|
|
|
|
|
pk.OT_Gender = 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pk.Met_Location = Locations.HatchLocationC;
|
|
|
|
|
pk.Met_Level = 1;
|
|
|
|
|
}
|
2018-03-29 03:40:07 +00:00
|
|
|
|
return pk;
|
2021-05-23 19:50:42 +00:00
|
|
|
|
}
|
2018-03-29 03:40:07 +00:00
|
|
|
|
|
2018-12-30 06:24:34 +00:00
|
|
|
|
SetMetData(pk);
|
2018-03-29 03:40:07 +00:00
|
|
|
|
|
2020-05-31 19:12:48 +00:00
|
|
|
|
if (gen >= 4)
|
2020-06-17 02:46:22 +00:00
|
|
|
|
pk.SetEggMetData(version, (GameVersion)sav.Game);
|
2018-03-29 03:40:07 +00:00
|
|
|
|
|
2020-05-31 19:12:48 +00:00
|
|
|
|
if (gen < 6)
|
2018-03-29 03:40:07 +00:00
|
|
|
|
return pk;
|
2020-08-01 00:25:14 +00:00
|
|
|
|
if (pk is PK6 pk6)
|
|
|
|
|
pk6.SetHatchMemory6();
|
2018-03-29 03:40:07 +00:00
|
|
|
|
|
2020-12-11 04:42:30 +00:00
|
|
|
|
SetForm(pk, sav);
|
2018-12-30 06:24:34 +00:00
|
|
|
|
|
|
|
|
|
pk.SetRandomEC();
|
2021-04-05 01:30:01 +00:00
|
|
|
|
pk.RelearnMove1 = pk.Move1;
|
|
|
|
|
pk.RelearnMove2 = pk.Move2;
|
|
|
|
|
pk.RelearnMove3 = pk.Move3;
|
|
|
|
|
pk.RelearnMove4 = pk.Move4;
|
2021-11-25 03:29:02 +00:00
|
|
|
|
if (pk is IScaledSize s)
|
|
|
|
|
{
|
|
|
|
|
s.HeightScalar = PokeSizeUtil.GetRandomScalar();
|
|
|
|
|
s.WeightScalar = PokeSizeUtil.GetRandomScalar();
|
|
|
|
|
}
|
2018-12-30 06:24:34 +00:00
|
|
|
|
|
|
|
|
|
return pk;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-11 04:42:30 +00:00
|
|
|
|
private void SetForm(PKM pk, ITrainerInfo sav)
|
2018-12-30 06:24:34 +00:00
|
|
|
|
{
|
2018-05-10 02:21:44 +00:00
|
|
|
|
switch (Species)
|
|
|
|
|
{
|
2019-09-10 07:21:51 +00:00
|
|
|
|
case (int)Core.Species.Minior:
|
2020-12-11 04:42:30 +00:00
|
|
|
|
pk.Form = Util.Rand.Next(7, 14);
|
2018-05-10 02:21:44 +00:00
|
|
|
|
break;
|
2020-12-25 18:58:33 +00:00
|
|
|
|
case (int)Core.Species.Scatterbug or (int)Core.Species.Spewpa or (int)Core.Species.Vivillon:
|
2020-07-31 20:53:42 +00:00
|
|
|
|
if (sav is IRegionOrigin o)
|
2021-08-03 02:43:57 +00:00
|
|
|
|
pk.Form = Vivillon3DS.GetPattern(o.Country, o.Region);
|
2020-07-31 20:53:42 +00:00
|
|
|
|
// else 0
|
2018-05-10 02:21:44 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2018-12-30 06:24:34 +00:00
|
|
|
|
}
|
2018-05-10 02:21:44 +00:00
|
|
|
|
|
2019-02-09 19:37:20 +00:00
|
|
|
|
private static void SetPINGA(PKM pk, EncounterCriteria criteria)
|
2018-12-30 06:24:34 +00:00
|
|
|
|
{
|
2019-02-09 19:37:20 +00:00
|
|
|
|
pk.SetRandomIVs(flawless: 3);
|
|
|
|
|
if (pk.Format <= 2)
|
|
|
|
|
return;
|
|
|
|
|
|
2018-12-30 06:24:34 +00:00
|
|
|
|
int gender = criteria.GetGender(-1, pk.PersonalInfo);
|
|
|
|
|
int nature = (int)criteria.GetNature(Nature.Random);
|
2018-03-29 03:40:07 +00:00
|
|
|
|
|
2018-12-30 06:24:34 +00:00
|
|
|
|
if (pk.Format <= 5)
|
|
|
|
|
{
|
|
|
|
|
pk.SetPIDGender(gender);
|
|
|
|
|
pk.Gender = gender;
|
|
|
|
|
pk.SetPIDNature(nature);
|
|
|
|
|
pk.Nature = nature;
|
|
|
|
|
pk.RefreshAbility(pk.PIDAbility);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pk.PID = Util.Rand32();
|
|
|
|
|
pk.Nature = nature;
|
|
|
|
|
pk.Gender = gender;
|
|
|
|
|
pk.RefreshAbility(Util.Rand.Next(2));
|
|
|
|
|
}
|
2020-06-27 16:46:23 +00:00
|
|
|
|
pk.StatNature = nature;
|
2018-12-30 06:24:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-02-25 07:14:40 +00:00
|
|
|
|
private void SetMetData(PKM pk)
|
2018-12-30 06:24:34 +00:00
|
|
|
|
{
|
2022-02-25 07:14:40 +00:00
|
|
|
|
pk.Met_Level = EggStateLegality.GetEggLevelMet(Version, Generation);
|
|
|
|
|
pk.Met_Location = Math.Max(0, EggStateLegality.GetEggHatchLocation(Version, Generation));
|
2018-03-29 03:40:07 +00:00
|
|
|
|
}
|
2018-05-10 02:21:44 +00:00
|
|
|
|
|
2021-04-05 01:30:01 +00:00
|
|
|
|
private void SetEncounterMoves(PKM pk, GameVersion version)
|
2019-02-09 19:37:20 +00:00
|
|
|
|
{
|
2021-04-05 01:30:01 +00:00
|
|
|
|
var learnset = GameData.GetLearnset(version, Species, Form);
|
|
|
|
|
var baseMoves = learnset.GetBaseEggMoves(Level);
|
|
|
|
|
if (baseMoves.Length == 0) return; pk.Move1 = baseMoves[0];
|
|
|
|
|
if (baseMoves.Length == 1) return; pk.Move2 = baseMoves[1];
|
|
|
|
|
if (baseMoves.Length == 2) return; pk.Move3 = baseMoves[2];
|
|
|
|
|
if (baseMoves.Length == 3) return; pk.Move4 = baseMoves[3];
|
2019-02-09 19:37:20 +00:00
|
|
|
|
}
|
2018-07-04 16:15:20 +00:00
|
|
|
|
}
|
2017-05-28 04:17:53 +00:00
|
|
|
|
}
|