2018-03-31 07:43:41 +00:00
|
|
|
|
using System;
|
2020-01-19 00:31:24 +00:00
|
|
|
|
using System.Collections.Generic;
|
2018-12-27 09:00:08 +00:00
|
|
|
|
using System.Linq;
|
2018-03-31 07:43:41 +00:00
|
|
|
|
|
|
|
|
|
namespace PKHeX.Core
|
2016-11-08 16:43:57 +00:00
|
|
|
|
{
|
2017-10-24 06:12:58 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Static Encounter Data
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// Static Encounters are fixed position encounters with properties that are not subject to Wild Encounter conditions.
|
|
|
|
|
/// </remarks>
|
2020-05-20 04:46:05 +00:00
|
|
|
|
public class EncounterStatic : IEncounterable, IMoveset, IGenerationSet, ILocation, IContestStats, IRelearn, IVersionSet
|
2016-11-08 16:43:57 +00:00
|
|
|
|
{
|
2017-01-05 06:25:45 +00:00
|
|
|
|
public int Species { get; set; }
|
2020-01-19 00:46:38 +00:00
|
|
|
|
public IReadOnlyList<int> Moves { get; set; } = Array.Empty<int>();
|
2019-12-07 03:17:26 +00:00
|
|
|
|
public virtual int Level { get; set; }
|
2016-11-08 16:43:57 +00:00
|
|
|
|
|
2019-12-07 03:17:26 +00:00
|
|
|
|
public virtual int LevelMin => Level;
|
|
|
|
|
public virtual int LevelMax => Level;
|
Gen 1 move analysis improvement. Adapted the valid moves to take into account that move deleter and move reminder do not exits in generation 1 (#1037)
* Fix getMoves with min level, when SkipWhile and TakeWhile is used together the index i in TakeWhile is calculated from the enumerator that results of the SkipWhile function, not the index of the initial array, those giving an incorrect index to check Levels array in the TakeWhile
* Fix getMoves when levelmin or levelmax is above max level in the levels array, TakeWhile and SkipWhile return empty list if the while goes beyond the last element of the array
* Include player hatched egg in the list of possible encounters for parseMoves only if the pokemon was an egg
Also change the valur of WasEgg for gen1,2,3 pokemon if the encounter analyzed is not an egg
add the non egg encounters to the list instead of checking the non-egg encounter inside parseMovesWasEggPreRelearn
* Fix for gen3 egg encounters
Remove non-egg encounters without special moves if there is an egg encounter because egg encounter already cover every possible move combination
Do not add daycare egg encounter for gen3 unhatched egg if there is another encounter, that means is an event or gift egg, not a daycare egg
Remove duplicate encounters
* Gift egg should not allow inherited moves even it they dont have special moves
Those gift eggs are hatched only with the species base moves
* Added getEncounterMoves functions, to be used for generation 1 encounters to find what moves have a pokemon at the moment of being caught because there is no move reminder in generation 1
* Added GBEncounterData, structure for refactor the tuples used in generation 1 and 2 encounters
* Add LevelMin and LevelMax to IEncounterable to get the encounter moves by the min level of the generation 1 EncounterLink
Add iGeneration to difference generation 1 and generation 2 encounters for GB Era pokemon
* Mark generation in gen 1 and 2 encounters
There is no need to mark the generation in gen 3 to 7 encounters because in that generations it match the pokemon generation number
* Add min level for generation 1 moves in getMoves functions
Add function to return the default moves for a GB encounters, for generation 1 games that included both moves from level up table and level 1 moves from personal table
Fix getMoves with min level when the moves list is empty, like Raichu generation 1
* Add maxSpecies to getBaseSpecies function for gen1 pokemon with a gen2 egg encounter
Refactor VC Encounter changing Tuples for GBData class
* Fixed for gen 2 Checks
Also do not search for generation1 encounter if the gen2 pokemon have met location from crystal
* Fix VC wild encounters, should be stored as array or else other verifyEncounter functions wont work
* Add generation 1 parse moves function including default moves
* Clean-up get encounters
* Verify empty moves for generation 1 encounters, in generation 1 does not exits move deleter
That means when a move slot have been used by a level up move or a TM/HM/Tutor move it cant be empty again
Does not apply if generation 2 tradeback is allowed, in generation 2 there is a move deleter
* Added two edge cases for pokemon that learn in red/blue and yellow different moves at the same level, this combinations can not exits until a later level when they learn again one of the levels in the other game, only happen for flareon and vaporeon
* Check incompatible moves between evolution species, it is for species that learn a move in a level as an evolved species and a move at a upper level as a preevolution
Also added most edge cases for the min slots used for generation 1 games, i think every weird combination is already covered
* Fix gen 1 eevee and evolutions move checks
* Cleanup
* Move the code to change valid moves for generation 1 to a function
* Fix getMoveMinLevelGBEncounter
* getUsedMoveSlots, removed wild Butterfree edge case, it is not possible
* Filter the min level of the encounter by the possible games the pokemon could be originated, yellow pikachu and kadabra can be detected
2017-04-09 00:17:20 +00:00
|
|
|
|
public int Generation { get; set; } = -1;
|
2019-11-21 01:07:51 +00:00
|
|
|
|
public virtual int Location { get; set; }
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public int Ability { get; set; }
|
|
|
|
|
public int Form { get; set; }
|
2018-03-17 02:35:55 +00:00
|
|
|
|
public virtual Shiny Shiny { get; set; } = Shiny.Random;
|
2020-01-19 00:31:24 +00:00
|
|
|
|
public IReadOnlyList<int> Relearn { get; set; } = Array.Empty<int>();
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public int Gender { get; set; } = -1;
|
|
|
|
|
public int EggLocation { get; set; }
|
|
|
|
|
public Nature Nature { get; set; } = Nature.Random;
|
|
|
|
|
public bool Gift { get; set; }
|
|
|
|
|
public int Ball { get; set; } = 4; // Only checked when is Gift
|
2018-03-30 23:31:40 +00:00
|
|
|
|
public GameVersion Version { get; set; } = GameVersion.Any;
|
2020-01-19 03:11:29 +00:00
|
|
|
|
public IReadOnlyList<int> IVs { get; set; } = Array.Empty<int>();
|
2018-12-30 18:33:00 +00:00
|
|
|
|
public int FlawlessIVCount { get; set; }
|
2018-03-24 17:36:48 +00:00
|
|
|
|
|
2020-01-19 03:11:29 +00:00
|
|
|
|
internal IReadOnlyList<int> Contest { set => this.SetContestStats(value); }
|
2018-03-24 17:36:48 +00:00
|
|
|
|
public int CNT_Cool { get; set; }
|
|
|
|
|
public int CNT_Beauty { get; set; }
|
|
|
|
|
public int CNT_Cute { get; set; }
|
|
|
|
|
public int CNT_Smart { get; set; }
|
|
|
|
|
public int CNT_Tough { get; set; }
|
|
|
|
|
public int CNT_Sheen { get; set; }
|
|
|
|
|
|
2016-11-08 16:43:57 +00:00
|
|
|
|
public int HeldItem { get; set; }
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public int EggCycles { get; set; }
|
2016-11-13 17:37:28 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public bool Fateful { get; set; }
|
|
|
|
|
public bool RibbonWishing { get; set; }
|
|
|
|
|
public bool SkipFormCheck { get; set; }
|
|
|
|
|
public bool Roaming { get; set; }
|
Gen 1 move analysis improvement. Adapted the valid moves to take into account that move deleter and move reminder do not exits in generation 1 (#1037)
* Fix getMoves with min level, when SkipWhile and TakeWhile is used together the index i in TakeWhile is calculated from the enumerator that results of the SkipWhile function, not the index of the initial array, those giving an incorrect index to check Levels array in the TakeWhile
* Fix getMoves when levelmin or levelmax is above max level in the levels array, TakeWhile and SkipWhile return empty list if the while goes beyond the last element of the array
* Include player hatched egg in the list of possible encounters for parseMoves only if the pokemon was an egg
Also change the valur of WasEgg for gen1,2,3 pokemon if the encounter analyzed is not an egg
add the non egg encounters to the list instead of checking the non-egg encounter inside parseMovesWasEggPreRelearn
* Fix for gen3 egg encounters
Remove non-egg encounters without special moves if there is an egg encounter because egg encounter already cover every possible move combination
Do not add daycare egg encounter for gen3 unhatched egg if there is another encounter, that means is an event or gift egg, not a daycare egg
Remove duplicate encounters
* Gift egg should not allow inherited moves even it they dont have special moves
Those gift eggs are hatched only with the species base moves
* Added getEncounterMoves functions, to be used for generation 1 encounters to find what moves have a pokemon at the moment of being caught because there is no move reminder in generation 1
* Added GBEncounterData, structure for refactor the tuples used in generation 1 and 2 encounters
* Add LevelMin and LevelMax to IEncounterable to get the encounter moves by the min level of the generation 1 EncounterLink
Add iGeneration to difference generation 1 and generation 2 encounters for GB Era pokemon
* Mark generation in gen 1 and 2 encounters
There is no need to mark the generation in gen 3 to 7 encounters because in that generations it match the pokemon generation number
* Add min level for generation 1 moves in getMoves functions
Add function to return the default moves for a GB encounters, for generation 1 games that included both moves from level up table and level 1 moves from personal table
Fix getMoves with min level when the moves list is empty, like Raichu generation 1
* Add maxSpecies to getBaseSpecies function for gen1 pokemon with a gen2 egg encounter
Refactor VC Encounter changing Tuples for GBData class
* Fixed for gen 2 Checks
Also do not search for generation1 encounter if the gen2 pokemon have met location from crystal
* Fix VC wild encounters, should be stored as array or else other verifyEncounter functions wont work
* Add generation 1 parse moves function including default moves
* Clean-up get encounters
* Verify empty moves for generation 1 encounters, in generation 1 does not exits move deleter
That means when a move slot have been used by a level up move or a TM/HM/Tutor move it cant be empty again
Does not apply if generation 2 tradeback is allowed, in generation 2 there is a move deleter
* Added two edge cases for pokemon that learn in red/blue and yellow different moves at the same level, this combinations can not exits until a later level when they learn again one of the levels in the other game, only happen for flareon and vaporeon
* Check incompatible moves between evolution species, it is for species that learn a move in a level as an evolved species and a move at a upper level as a preevolution
Also added most edge cases for the min slots used for generation 1 games, i think every weird combination is already covered
* Fix gen 1 eevee and evolutions move checks
* Cleanup
* Move the code to change valid moves for generation 1 to a function
* Fix getMoveMinLevelGBEncounter
* getUsedMoveSlots, removed wild Butterfree edge case, it is not possible
* Filter the min level of the encounter by the possible games the pokemon could be originated, yellow pikachu and kadabra can be detected
2017-04-09 00:17:20 +00:00
|
|
|
|
public bool EggEncounter => EggLocation > 0;
|
2017-03-20 12:35:12 +00:00
|
|
|
|
|
2020-01-19 03:11:29 +00:00
|
|
|
|
internal EncounterStatic Clone() => (EncounterStatic)MemberwiseClone();
|
2017-03-24 22:50:00 +00:00
|
|
|
|
|
2018-03-09 05:18:32 +00:00
|
|
|
|
private const string _name = "Static Encounter";
|
2019-03-18 05:19:37 +00:00
|
|
|
|
public string Name => _name;
|
|
|
|
|
public string LongName => Version == GameVersion.Any ? _name : $"{_name} ({Version})";
|
2018-03-29 03:38:07 +00:00
|
|
|
|
|
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-31 07:43:41 +00:00
|
|
|
|
{
|
2018-11-20 00:14:49 +00:00
|
|
|
|
var pk = PKMConverter.GetBlank(Generation, Version);
|
2020-06-17 02:46:22 +00:00
|
|
|
|
sav.ApplyTo(pk);
|
2018-03-31 07:43:41 +00:00
|
|
|
|
|
|
|
|
|
pk.EncryptionConstant = Util.Rand32();
|
|
|
|
|
pk.Species = Species;
|
2019-02-09 19:37:20 +00:00
|
|
|
|
pk.AltForm = Form;
|
|
|
|
|
|
2020-06-17 02:46:22 +00:00
|
|
|
|
int lang = (int)Language.GetSafeLanguage(Generation, (LanguageID)sav.Language);
|
2019-11-16 01:34:18 +00:00
|
|
|
|
int level = GetMinimalLevel();
|
2020-06-17 02:46:22 +00:00
|
|
|
|
var version = this.GetCompatibleVersion((GameVersion)sav.Game);
|
2019-02-09 19:37:20 +00:00
|
|
|
|
SanityCheckVersion(ref version);
|
|
|
|
|
|
2018-05-08 05:12:12 +00:00
|
|
|
|
pk.Language = lang = GetEdgeCaseLanguage(pk, lang);
|
2019-09-19 02:58:23 +00:00
|
|
|
|
pk.Nickname = SpeciesName.GetSpeciesNameGeneration(Species, lang, Generation);
|
2019-02-09 19:37:20 +00:00
|
|
|
|
|
2018-03-31 07:43:41 +00:00
|
|
|
|
pk.CurrentLevel = level;
|
|
|
|
|
pk.Version = (int)version;
|
|
|
|
|
pk.Ball = Ball;
|
2018-12-30 06:24:34 +00:00
|
|
|
|
pk.HeldItem = HeldItem;
|
|
|
|
|
pk.OT_Friendship = pk.PersonalInfo.BaseFriendship;
|
2018-04-29 05:56:10 +00:00
|
|
|
|
|
2019-02-09 19:37:20 +00:00
|
|
|
|
var today = DateTime.Today;
|
|
|
|
|
SetMetData(pk, level, today);
|
2018-03-31 07:43:41 +00:00
|
|
|
|
if (EggEncounter)
|
2020-06-17 02:46:22 +00:00
|
|
|
|
SetEggMetData(pk, sav, today);
|
2018-03-31 07:43:41 +00:00
|
|
|
|
|
2019-02-09 19:37:20 +00:00
|
|
|
|
SetPINGA(pk, criteria);
|
|
|
|
|
SetEncounterMoves(pk, version, level);
|
2018-03-31 07:43:41 +00:00
|
|
|
|
|
2018-12-30 06:24:34 +00:00
|
|
|
|
switch (pk)
|
2018-03-31 07:43:41 +00:00
|
|
|
|
{
|
2018-12-30 06:24:34 +00:00
|
|
|
|
case PK3 pk3 when this is EncounterStaticShadow:
|
|
|
|
|
pk3.RibbonNational = true;
|
2018-04-29 05:56:10 +00:00
|
|
|
|
break;
|
2018-12-30 06:24:34 +00:00
|
|
|
|
case PK4 pk4 when this is EncounterStaticTyped t:
|
|
|
|
|
pk4.EncounterType = t.TypeEncounter.GetIndex();
|
2018-03-31 07:43:41 +00:00
|
|
|
|
break;
|
2018-12-30 06:24:34 +00:00
|
|
|
|
case PK6 pk6:
|
|
|
|
|
pk6.SetRandomMemory6();
|
2018-03-31 07:43:41 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-09 19:37:20 +00:00
|
|
|
|
if (RibbonWishing && pk is IRibbonSetEvent4 e4)
|
|
|
|
|
e4.RibbonWishing = true;
|
2020-01-25 20:31:56 +00:00
|
|
|
|
if (this is EncounterStatic5N n)
|
2019-02-09 19:37:20 +00:00
|
|
|
|
n.SetNPokemonData((PK5)pk, lang);
|
2018-06-03 04:19:03 +00:00
|
|
|
|
if (pk is IContestStats s)
|
|
|
|
|
this.CopyContestStatsTo(s);
|
2018-03-31 07:43:41 +00:00
|
|
|
|
if (Fateful)
|
|
|
|
|
pk.FatefulEncounter = true;
|
|
|
|
|
|
|
|
|
|
if (pk.Format < 6)
|
|
|
|
|
return pk;
|
|
|
|
|
|
2019-11-16 01:34:18 +00:00
|
|
|
|
pk.SetRelearnMoves(Relearn);
|
2020-06-17 02:46:22 +00:00
|
|
|
|
sav.ApplyHandlingTrainerInfo(pk);
|
2018-03-31 07:43:41 +00:00
|
|
|
|
pk.SetRandomEC();
|
|
|
|
|
|
2019-11-16 01:34:18 +00:00
|
|
|
|
if (this is IGigantamax g && pk is IGigantamax pg)
|
|
|
|
|
pg.CanGigantamax = g.CanGigantamax;
|
|
|
|
|
if (this is IDynamaxLevel d && pk is IDynamaxLevel pd)
|
|
|
|
|
pd.DynamaxLevel = d.DynamaxLevel;
|
|
|
|
|
|
2018-03-31 07:43:41 +00:00
|
|
|
|
return pk;
|
|
|
|
|
}
|
2018-04-29 16:31:13 +00:00
|
|
|
|
|
2019-11-16 01:34:18 +00:00
|
|
|
|
protected virtual int GetMinimalLevel() => LevelMin;
|
|
|
|
|
|
2019-02-09 19:37:20 +00:00
|
|
|
|
protected virtual void SetPINGA(PKM pk, EncounterCriteria criteria)
|
|
|
|
|
{
|
2020-06-21 23:16:34 +00:00
|
|
|
|
var pi = pk.PersonalInfo;
|
|
|
|
|
int gender = criteria.GetGender(Gender, pi);
|
2019-02-09 19:37:20 +00:00
|
|
|
|
int nature = (int)criteria.GetNature(Nature);
|
2020-06-23 03:01:42 +00:00
|
|
|
|
int ability = criteria.GetAbilityFromNumber(Ability, pi);
|
2019-02-09 19:37:20 +00:00
|
|
|
|
|
|
|
|
|
var pidtype = GetPIDType();
|
2019-11-16 01:34:18 +00:00
|
|
|
|
PIDGenerator.SetRandomWildPID(pk, pk.Format, nature, ability, gender, pidtype);
|
2019-02-09 19:37:20 +00:00
|
|
|
|
SetIVs(pk);
|
2020-06-27 16:46:23 +00:00
|
|
|
|
pk.StatNature = pk.Nature;
|
2019-02-09 19:37:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetEggMetData(PKM pk, ITrainerInfo tr, DateTime today)
|
|
|
|
|
{
|
|
|
|
|
pk.Met_Location = Math.Max(0, EncounterSuggestion.GetSuggestedEggMetLocation(pk));
|
|
|
|
|
pk.Met_Level = EncounterSuggestion.GetSuggestedEncounterEggMetLevel(pk);
|
|
|
|
|
|
2019-05-11 07:59:07 +00:00
|
|
|
|
if (Generation >= 4)
|
2019-02-09 19:37:20 +00:00
|
|
|
|
{
|
|
|
|
|
bool traded = (int)Version == tr.Game;
|
|
|
|
|
pk.Egg_Location = EncounterSuggestion.GetSuggestedEncounterEggLocationEgg(pk, traded);
|
|
|
|
|
pk.EggMetDate = today;
|
|
|
|
|
}
|
|
|
|
|
pk.Egg_Location = EggLocation;
|
|
|
|
|
pk.EggMetDate = today;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-18 20:36:30 +00:00
|
|
|
|
protected virtual void SetMetData(PKM pk, int level, DateTime today)
|
2019-02-09 19:37:20 +00:00
|
|
|
|
{
|
2020-07-18 20:36:30 +00:00
|
|
|
|
if (pk.Format <= 2)
|
|
|
|
|
return;
|
2019-02-09 19:37:20 +00:00
|
|
|
|
|
2020-07-18 20:36:30 +00:00
|
|
|
|
pk.Met_Location = Location;
|
|
|
|
|
pk.Met_Level = level;
|
|
|
|
|
if (pk.Format >= 4)
|
|
|
|
|
pk.MetDate = today;
|
2019-02-09 19:37:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetEncounterMoves(PKM pk, GameVersion version, int level)
|
|
|
|
|
{
|
2020-01-19 00:46:38 +00:00
|
|
|
|
var moves = Moves.Count > 0 ? Moves : MoveLevelUp.GetEncounterMoves(pk, level, version);
|
|
|
|
|
pk.SetMoves(moves);
|
2019-02-09 19:37:20 +00:00
|
|
|
|
pk.SetMaximumPPCurrent(moves);
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-10 00:50:56 +00:00
|
|
|
|
private void SanityCheckVersion(ref GameVersion version)
|
|
|
|
|
{
|
2018-08-03 03:11:42 +00:00
|
|
|
|
if (Generation != 4 || version == GameVersion.Pt)
|
|
|
|
|
return;
|
2018-05-10 00:50:56 +00:00
|
|
|
|
switch (Species)
|
|
|
|
|
{
|
2019-06-01 17:22:49 +00:00
|
|
|
|
case (int)Core.Species.Darkrai when Location == 079: // DP Darkrai
|
|
|
|
|
case (int)Core.Species.Shaymin when Location == 063: // DP Shaymin
|
2018-05-10 00:50:56 +00:00
|
|
|
|
version = GameVersion.Pt;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-09 19:37:20 +00:00
|
|
|
|
protected void SetIVs(PKM pk)
|
2018-05-10 00:50:56 +00:00
|
|
|
|
{
|
2020-01-19 03:11:29 +00:00
|
|
|
|
if (IVs.Count != 0)
|
2018-05-10 00:50:56 +00:00
|
|
|
|
pk.SetRandomIVs(IVs, FlawlessIVCount);
|
|
|
|
|
else if (FlawlessIVCount > 0)
|
|
|
|
|
pk.SetRandomIVs(flawless: FlawlessIVCount);
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-08 05:12:12 +00:00
|
|
|
|
private int GetEdgeCaseLanguage(PKM pk, int lang)
|
|
|
|
|
{
|
|
|
|
|
switch (pk.Format)
|
|
|
|
|
{
|
2019-06-01 17:22:49 +00:00
|
|
|
|
case 1 when Species == (int)Core.Species.Mew && Version == GameVersion.VCEvents: // VC Mew
|
2018-05-08 05:12:12 +00:00
|
|
|
|
pk.TID = 22796;
|
2018-06-23 19:37:01 +00:00
|
|
|
|
pk.OT_Name = Legal.GetG1OT_GFMew(lang);
|
2018-05-08 05:12:12 +00:00
|
|
|
|
return lang;
|
2018-05-08 05:53:36 +00:00
|
|
|
|
case 1 when Version == GameVersion.EventsGBGen1:
|
|
|
|
|
case 2 when Version == GameVersion.EventsGBGen2:
|
|
|
|
|
case 3 when this is EncounterStaticShadow s && s.EReader:
|
2019-06-01 17:22:49 +00:00
|
|
|
|
case 3 when Species == (int)Core.Species.Mew:
|
2018-05-08 05:12:12 +00:00
|
|
|
|
pk.OT_Name = "ゲーフリ";
|
2019-06-01 17:22:49 +00:00
|
|
|
|
return (int)LanguageID.Japanese; // Old Sea Map was only distributed to Japanese games.
|
2018-05-08 05:12:12 +00:00
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return lang;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-29 16:31:13 +00:00
|
|
|
|
private PIDType GetPIDType()
|
|
|
|
|
{
|
2018-05-08 04:16:54 +00:00
|
|
|
|
switch (Generation)
|
|
|
|
|
{
|
2018-05-09 04:17:31 +00:00
|
|
|
|
case 3 when Roaming && Version != GameVersion.E: // Roamer IV glitch was fixed in Emerald
|
2018-05-08 04:16:54 +00:00
|
|
|
|
return PIDType.Method_1_Roamer;
|
|
|
|
|
case 4 when Shiny == Shiny.Always: // Lake of Rage Gyarados
|
|
|
|
|
return PIDType.ChainShiny;
|
2019-06-01 17:22:49 +00:00
|
|
|
|
case 4 when Species == (int)Core.Species.Pichu: // Spiky Eared Pichu
|
|
|
|
|
case 4 when Location == Locations.PokeWalker4: // Pokéwalker
|
2018-05-08 04:16:54 +00:00
|
|
|
|
return PIDType.Pokewalker;
|
|
|
|
|
case 5 when Shiny == Shiny.Always:
|
|
|
|
|
return PIDType.G5MGShiny;
|
|
|
|
|
|
|
|
|
|
default: return PIDType.None;
|
|
|
|
|
}
|
2018-04-29 16:31:13 +00:00
|
|
|
|
}
|
2018-12-27 09:00:08 +00:00
|
|
|
|
|
2019-11-16 01:34:18 +00:00
|
|
|
|
public virtual bool IsMatch(PKM pkm, int lvl)
|
2018-12-27 09:00:08 +00:00
|
|
|
|
{
|
2019-11-16 01:34:18 +00:00
|
|
|
|
if (Nature != Nature.Random && pkm.Nature != (int) Nature)
|
2018-12-27 09:00:08 +00:00
|
|
|
|
return false;
|
2019-05-11 03:46:49 +00:00
|
|
|
|
|
2019-07-26 00:42:15 +00:00
|
|
|
|
if (Generation > 3 && pkm.Format > 3 && pkm.WasEgg != EggEncounter && pkm.Egg_Location == 0 && !pkm.IsEgg)
|
2018-12-27 09:00:08 +00:00
|
|
|
|
return false;
|
2019-11-16 01:34:18 +00:00
|
|
|
|
|
|
|
|
|
if (!IsMatchEggLocation(pkm, ref lvl))
|
|
|
|
|
return false;
|
2019-11-17 23:50:41 +00:00
|
|
|
|
if (!IsMatchLocation(pkm))
|
|
|
|
|
return false;
|
2019-11-16 01:34:18 +00:00
|
|
|
|
if (!IsMatchLevel(pkm, lvl))
|
|
|
|
|
return false;
|
|
|
|
|
if (!IsMatchGender(pkm))
|
|
|
|
|
return false;
|
|
|
|
|
if (!IsMatchForm(pkm))
|
|
|
|
|
return false;
|
|
|
|
|
|
2020-01-19 00:31:24 +00:00
|
|
|
|
if (EggLocation == Locations.Daycare5 && Relearn.Count == 0 && pkm.RelearnMoves.Any(z => z != 0)) // gen7 eevee edge case
|
2019-11-16 01:34:18 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (!IsMatchIVs(pkm))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (pkm is IContestStats s && s.IsContestBelow(this))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// Defer to EC/PID check
|
|
|
|
|
// if (e.Shiny != null && e.Shiny != pkm.IsShiny)
|
|
|
|
|
// continue;
|
|
|
|
|
|
|
|
|
|
// Defer ball check to later
|
|
|
|
|
// if (e.Gift && pkm.Ball != 4) // PokéBall
|
|
|
|
|
// continue;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool IsMatchIVs(PKM pkm)
|
|
|
|
|
{
|
2020-01-19 03:11:29 +00:00
|
|
|
|
if (IVs.Count == 0)
|
2019-11-16 01:34:18 +00:00
|
|
|
|
return true; // nothing to check, IVs are random
|
|
|
|
|
if (Generation <= 2 && pkm.Format > 2)
|
|
|
|
|
return true; // IVs are regenerated on VC transfer upward
|
|
|
|
|
|
|
|
|
|
return Legal.GetIsFixedIVSequenceValidSkipRand(IVs, pkm);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool IsMatchForm(PKM pkm)
|
|
|
|
|
{
|
|
|
|
|
if (SkipFormCheck)
|
|
|
|
|
return true;
|
2020-02-12 04:11:33 +00:00
|
|
|
|
if (FormConverter.IsTotemForm(Species, Form, Generation))
|
|
|
|
|
{
|
|
|
|
|
var expectForm = pkm.Format == 7 ? Form : FormConverter.GetTotemBaseForm(Species, Form);
|
|
|
|
|
return expectForm == pkm.AltForm;
|
|
|
|
|
}
|
2020-05-26 23:59:47 +00:00
|
|
|
|
return Form == pkm.AltForm || Legal.IsFormChangeable(pkm, Species, Form);
|
2019-11-16 01:34:18 +00:00
|
|
|
|
}
|
2018-12-27 09:00:08 +00:00
|
|
|
|
|
2020-07-18 20:36:30 +00:00
|
|
|
|
protected virtual bool IsMatchEggLocation(PKM pkm, ref int lvl)
|
2019-11-16 01:34:18 +00:00
|
|
|
|
{
|
2019-05-11 07:59:07 +00:00
|
|
|
|
if (Generation == 3 && EggLocation != 0) // Gen3 Egg
|
2018-12-27 09:00:08 +00:00
|
|
|
|
{
|
|
|
|
|
if (pkm.Format == 3 && pkm.IsEgg && EggLocation != pkm.Met_Location)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else if (EggLocation != pkm.Egg_Location)
|
|
|
|
|
{
|
|
|
|
|
if (pkm.IsEgg) // unhatched
|
|
|
|
|
{
|
|
|
|
|
if (EggLocation != pkm.Met_Location)
|
|
|
|
|
return false;
|
|
|
|
|
if (pkm.Egg_Location != 0)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2019-05-11 07:59:07 +00:00
|
|
|
|
else if (Generation == 4)
|
2018-12-27 09:00:08 +00:00
|
|
|
|
{
|
2019-05-11 03:46:49 +00:00
|
|
|
|
if (pkm.Egg_Location != Locations.LinkTrade4) // Link Trade
|
2018-12-27 09:00:08 +00:00
|
|
|
|
{
|
|
|
|
|
// check Pt/HGSS data
|
|
|
|
|
if (pkm.Format <= 4)
|
2019-11-16 01:34:18 +00:00
|
|
|
|
return false;
|
2019-05-11 03:46:49 +00:00
|
|
|
|
if (!Locations.IsPtHGSSLocationEgg(EggLocation)) // non-Pt/HGSS egg gift
|
2018-12-27 09:00:08 +00:00
|
|
|
|
return false;
|
|
|
|
|
// transferring 4->5 clears pt/hgss location value and keeps Faraway Place
|
2020-07-18 20:36:30 +00:00
|
|
|
|
if (pkm.Egg_Location != Locations.Faraway4) // Faraway Place
|
2018-12-27 09:00:08 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-04-16 16:30:20 +00:00
|
|
|
|
if (!EggEncounter || pkm.Egg_Location != Locations.LinkTrade6) // Link Trade
|
2018-12-27 09:00:08 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-05-11 07:59:07 +00:00
|
|
|
|
else if (EggLocation != 0 && Generation == 4)
|
2018-12-27 09:00:08 +00:00
|
|
|
|
{
|
|
|
|
|
// Check the inverse scenario for 4->5 eggs
|
2019-05-11 03:46:49 +00:00
|
|
|
|
if (Locations.IsPtHGSSLocationEgg(EggLocation)) // egg gift
|
2018-12-27 09:00:08 +00:00
|
|
|
|
{
|
|
|
|
|
if (pkm.Format > 4)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-16 01:34:18 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2018-12-27 09:00:08 +00:00
|
|
|
|
|
2019-11-16 01:34:18 +00:00
|
|
|
|
private bool IsMatchGender(PKM pkm)
|
|
|
|
|
{
|
|
|
|
|
if (Gender == -1 || Gender == pkm.Gender)
|
|
|
|
|
return true;
|
2018-12-27 09:00:08 +00:00
|
|
|
|
|
2019-11-16 01:34:18 +00:00
|
|
|
|
if (Species == (int) Core.Species.Azurill && Generation == 4 && Location == 233 && pkm.Gender == 0)
|
|
|
|
|
return PKX.GetGenderFromPIDAndRatio(pkm.PID, 0xBF) == 1;
|
2018-12-27 09:00:08 +00:00
|
|
|
|
|
2019-11-16 01:34:18 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2018-12-27 09:00:08 +00:00
|
|
|
|
|
2019-11-21 01:07:51 +00:00
|
|
|
|
protected virtual bool IsMatchLocation(PKM pkm)
|
2019-11-17 23:50:41 +00:00
|
|
|
|
{
|
|
|
|
|
if (EggEncounter)
|
|
|
|
|
return true;
|
|
|
|
|
if (Location == 0)
|
|
|
|
|
return true;
|
2019-11-18 05:45:53 +00:00
|
|
|
|
if (!pkm.HasOriginalMetLocation)
|
|
|
|
|
return true;
|
2019-11-17 23:50:41 +00:00
|
|
|
|
return Location == pkm.Met_Location;
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-16 01:34:18 +00:00
|
|
|
|
protected virtual bool IsMatchLevel(PKM pkm, int lvl)
|
|
|
|
|
{
|
|
|
|
|
if (!pkm.HasOriginalMetLocation)
|
|
|
|
|
return lvl >= Level;
|
|
|
|
|
|
2020-05-26 23:59:47 +00:00
|
|
|
|
return lvl == Level || IsGen3EggEncounter(pkm, lvl);
|
2018-12-27 09:00:08 +00:00
|
|
|
|
}
|
2019-11-22 04:02:08 +00:00
|
|
|
|
|
2020-05-26 23:59:47 +00:00
|
|
|
|
// met level 0, origin level 5
|
|
|
|
|
private bool IsGen3EggEncounter(PKM pkm, int lvl) => pkm.Format == 3 && EggEncounter && lvl == 0;
|
|
|
|
|
|
2019-11-22 04:02:08 +00:00
|
|
|
|
public virtual bool IsMatchDeferred(PKM pkm)
|
|
|
|
|
{
|
|
|
|
|
if (pkm.FatefulEncounter != Fateful)
|
|
|
|
|
return true;
|
|
|
|
|
if (Ability == 4 && pkm.AbilityNumber != 4) // BW/2 Jellicent collision with wild surf slot, resolved by duplicating the encounter with any abil
|
|
|
|
|
return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2017-04-23 16:18:42 +00:00
|
|
|
|
}
|
2016-11-08 16:43:57 +00:00
|
|
|
|
}
|