PKHeX/PKHeX.Core/Legality/Analysis.cs

526 lines
20 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
2017-03-24 17:59:45 +00:00
using static PKHeX.Core.LegalityCheckStrings;
namespace PKHeX.Core
{
public partial class LegalityAnalysis
{
private PKM pkm;
private DexLevel[][] EvoChainsAllGens;
private readonly List<CheckResult> Parse = new List<CheckResult>();
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
private List<GBEncounterData> EncountersGBMatch;
Generation 1 and 2 legal Improvements (#1099) * Refactor parseMovesForEncounter to gather valid moves for species encounter, some Pokemon can have valid encounters with different source species from the encounter, the valid moves change if the encounter species change because some preevolutions moves are illegal if pokemon caught already evolved. Example, generation 1 Pikachu that can have a RBY Pikachu encounter and GSC Pichu encounter, the valid moves for the first encounters should not have any Pichu exclusive evolution moves Also assign the encounter match from gb when parsing moves like the variable Encounter Match, to store the encounter that is valid for the pokemon moves instead the first encounter. Store the species encounter, this will be needed to check if the evolution is valid for species that evolve leveling with a given learned move * Add Tradeback Status to the pokemon, this variable for generations 1 and 2 use data like the catch rate to determine if trade between generations 1 and 2 was possible. If analysis is for VC games tradeback have value NotTradeback for every gen 1 pokemon, but for cart saves some pokemon can be determine that have not been tradeback, if catch rate match species catch rate but do not match a valid generation 2 held item that means the pokemon habe been never traded to generation 2 games, that allow to discart encounters and moves from generation 2. Also if is not tradeback catch rate is used to filter encounters, catch rate determine in what species was captured the pokemon discarting some preevolutions moves Also add option for generation 1 cart save analysis to check legal status not allowing generation 2 games, like VC games but with Stadium allowed, like the generation 1 non tradeback rules from Smogon Also change evolution chains to included generation 2 preevolutions for gen 1 pokemon if tradeback was possible, it is needed to avoid parsemoves to check illegal pokemon like Hitmonchan with Tyrogue level up moves * Check legal values of generation 1 type and catch rate Replace pokemon catch rate after changind pokemon species always if pokemon was not tradeback from generation 2, the catch rate will keep unchanged only if it can be a held item and do not match species catch rate (default item) Also if catch rate is changed use base species catch rate to avoid legal errors if the catch rate of the evolution species if is not possible with the current moves * Filter ingame trades and static encounters with catch rate for generation 1 non tradeback * Fix min moves for generation 1 metapod encounter * Clean up * Fix encounter level for generation 1, valid moves are those with one level after the encounter level, pokemon can not learn a new move until level up Clean up type validation Fix generation 3 fatefull encounter eggs, the pokemon lost the fatefull mark when it hatch * Clean-up * Use new variable EncounterSpecies when it is needed to detect the species of the encounter, the old code wont work if the encounter is a wild slots array * Fix generation 1 evolution chains and catch rate as default held item * Fix Generation 1 Yellow Pikachu and Kadabra catch rates
2017-04-27 04:27:59 +00:00
private object EncounterOriginalGB;
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
private object EncounterMatch;
Generation 1 and 2 legal Improvements (#1099) * Refactor parseMovesForEncounter to gather valid moves for species encounter, some Pokemon can have valid encounters with different source species from the encounter, the valid moves change if the encounter species change because some preevolutions moves are illegal if pokemon caught already evolved. Example, generation 1 Pikachu that can have a RBY Pikachu encounter and GSC Pichu encounter, the valid moves for the first encounters should not have any Pichu exclusive evolution moves Also assign the encounter match from gb when parsing moves like the variable Encounter Match, to store the encounter that is valid for the pokemon moves instead the first encounter. Store the species encounter, this will be needed to check if the evolution is valid for species that evolve leveling with a given learned move * Add Tradeback Status to the pokemon, this variable for generations 1 and 2 use data like the catch rate to determine if trade between generations 1 and 2 was possible. If analysis is for VC games tradeback have value NotTradeback for every gen 1 pokemon, but for cart saves some pokemon can be determine that have not been tradeback, if catch rate match species catch rate but do not match a valid generation 2 held item that means the pokemon habe been never traded to generation 2 games, that allow to discart encounters and moves from generation 2. Also if is not tradeback catch rate is used to filter encounters, catch rate determine in what species was captured the pokemon discarting some preevolutions moves Also add option for generation 1 cart save analysis to check legal status not allowing generation 2 games, like VC games but with Stadium allowed, like the generation 1 non tradeback rules from Smogon Also change evolution chains to included generation 2 preevolutions for gen 1 pokemon if tradeback was possible, it is needed to avoid parsemoves to check illegal pokemon like Hitmonchan with Tyrogue level up moves * Check legal values of generation 1 type and catch rate Replace pokemon catch rate after changind pokemon species always if pokemon was not tradeback from generation 2, the catch rate will keep unchanged only if it can be a held item and do not match species catch rate (default item) Also if catch rate is changed use base species catch rate to avoid legal errors if the catch rate of the evolution species if is not possible with the current moves * Filter ingame trades and static encounters with catch rate for generation 1 non tradeback * Fix min moves for generation 1 metapod encounter * Clean up * Fix encounter level for generation 1, valid moves are those with one level after the encounter level, pokemon can not learn a new move until level up Clean up type validation Fix generation 3 fatefull encounter eggs, the pokemon lost the fatefull mark when it hatch * Clean-up * Use new variable EncounterSpecies when it is needed to detect the species of the encounter, the old code wont work if the encounter is a wild slots array * Fix generation 1 evolution chains and catch rate as default held item * Fix Generation 1 Yellow Pikachu and Kadabra catch rates
2017-04-27 04:27:59 +00:00
private int EncounterSpecies;
private Type Type; // Parent class when applicable (EncounterStatic / MysteryGift)
private Type MatchedType; // Child class if applicable (WC6, PGF, etc)
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
private string EncounterName => Legal.getEncounterTypeName(pkm, EncounterOriginalGB ?? EncounterMatch);
private List<MysteryGift> EventGiftMatch;
2017-04-04 02:59:29 +00:00
private List<EncounterStatic> EncounterStaticMatch;
private CheckResult Encounter, History;
private int[] RelearnBase;
// private bool SecondaryChecked;
public readonly bool Parsed;
public readonly bool Valid;
public readonly bool Error;
public bool ParsedValid => Parsed && Valid;
public bool ParsedInvalid => Parsed && !Valid;
public CheckResult[] vMoves = new CheckResult[4];
public CheckResult[] vRelearn = new CheckResult[4];
public string Report(bool verbose = false) => verbose ? getVerboseLegalityReport() : getLegalityReport();
private IEnumerable<int> AllSuggestedMoves
{
get
{
if (Error)
return new int[4];
if (_allSuggestedMoves == null)
return _allSuggestedMoves = !pkm.IsOriginValid ? new int[4] : getSuggestedMoves(true, true, true);
return _allSuggestedMoves;
}
}
private IEnumerable<int> AllSuggestedRelearnMoves
{
get
{
if (Error)
return new int[4];
if (_allSuggestedRelearnMoves == null)
return _allSuggestedRelearnMoves = !pkm.IsOriginValid ? new int[4] : Legal.getValidRelearn(pkm, -1).ToArray();
return _allSuggestedRelearnMoves;
}
}
private int[] _allSuggestedMoves, _allSuggestedRelearnMoves;
public int[] AllSuggestedMovesAndRelearn => AllSuggestedMoves.Concat(AllSuggestedRelearnMoves).ToArray();
public LegalityAnalysis(PKM pk)
{
for (int i = 0; i < 4; i++)
{
vMoves[i] = new CheckResult(CheckIdentifier.Move);
vRelearn[i] = new CheckResult(CheckIdentifier.RelearnMove);
}
try
{
switch (pk.Format) // prior to storing GameVersion
{
case 1: parsePK1(pk); break;
case 2: parsePK1(pk); break;
}
if (!Parse.Any())
switch (pk.GenNumber)
{
case 3: parsePK3(pk); break;
case 4: parsePK4(pk); break;
case 5: parsePK5(pk); break;
case 6: parsePK6(pk); break;
case 1: parsePK7(pk); break;
case 7: parsePK7(pk); break;
}
Valid = Parsed = Parse.Any();
if (Parsed)
{
if (Parse.Any(chk => !chk.Valid))
Valid = false;
else if (vMoves.Any(m => m.Valid != true))
Valid = false;
else if (vRelearn.Any(m => m.Valid != true))
Valid = false;
if (pkm.FatefulEncounter && vRelearn.Any(chk => !chk.Valid) && EncounterMatch == null)
AddLine(Severity.Indeterminate, V188, CheckIdentifier.Fateful);
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Valid = false;
Parsed = true;
AddLine(Severity.Invalid, V190, CheckIdentifier.Misc);
Error = true;
}
}
private void AddLine(Severity s, string c, CheckIdentifier i)
{
AddLine(new CheckResult(s, c, i));
}
private void AddLine(CheckResult chk)
{
Parse.Add(chk);
}
private void parsePK1(PKM pk)
{
pkm = pk;
if (!pkm.IsOriginValid)
{ AddLine(Severity.Invalid, V187, CheckIdentifier.None); return; }
updateTradebackG12();
updateEncounterChain();
updateMoveLegality();
updateTypeInfo();
verifyNickname();
verifyDVs();
verifyG1OT();
Generation 1 and 2 legal Improvements (#1099) * Refactor parseMovesForEncounter to gather valid moves for species encounter, some Pokemon can have valid encounters with different source species from the encounter, the valid moves change if the encounter species change because some preevolutions moves are illegal if pokemon caught already evolved. Example, generation 1 Pikachu that can have a RBY Pikachu encounter and GSC Pichu encounter, the valid moves for the first encounters should not have any Pichu exclusive evolution moves Also assign the encounter match from gb when parsing moves like the variable Encounter Match, to store the encounter that is valid for the pokemon moves instead the first encounter. Store the species encounter, this will be needed to check if the evolution is valid for species that evolve leveling with a given learned move * Add Tradeback Status to the pokemon, this variable for generations 1 and 2 use data like the catch rate to determine if trade between generations 1 and 2 was possible. If analysis is for VC games tradeback have value NotTradeback for every gen 1 pokemon, but for cart saves some pokemon can be determine that have not been tradeback, if catch rate match species catch rate but do not match a valid generation 2 held item that means the pokemon habe been never traded to generation 2 games, that allow to discart encounters and moves from generation 2. Also if is not tradeback catch rate is used to filter encounters, catch rate determine in what species was captured the pokemon discarting some preevolutions moves Also add option for generation 1 cart save analysis to check legal status not allowing generation 2 games, like VC games but with Stadium allowed, like the generation 1 non tradeback rules from Smogon Also change evolution chains to included generation 2 preevolutions for gen 1 pokemon if tradeback was possible, it is needed to avoid parsemoves to check illegal pokemon like Hitmonchan with Tyrogue level up moves * Check legal values of generation 1 type and catch rate Replace pokemon catch rate after changind pokemon species always if pokemon was not tradeback from generation 2, the catch rate will keep unchanged only if it can be a held item and do not match species catch rate (default item) Also if catch rate is changed use base species catch rate to avoid legal errors if the catch rate of the evolution species if is not possible with the current moves * Filter ingame trades and static encounters with catch rate for generation 1 non tradeback * Fix min moves for generation 1 metapod encounter * Clean up * Fix encounter level for generation 1, valid moves are those with one level after the encounter level, pokemon can not learn a new move until level up Clean up type validation Fix generation 3 fatefull encounter eggs, the pokemon lost the fatefull mark when it hatch * Clean-up * Use new variable EncounterSpecies when it is needed to detect the species of the encounter, the old code wont work if the encounter is a wild slots array * Fix generation 1 evolution chains and catch rate as default held item * Fix Generation 1 Yellow Pikachu and Kadabra catch rates
2017-04-27 04:27:59 +00:00
verifyMiscG1();
}
private void parsePK3(PKM pk)
{
pkm = pk;
if (!pkm.IsOriginValid)
{ AddLine(Severity.Invalid, V187, CheckIdentifier.None); return; }
updateEncounterChain();
updateMoveLegality();
updateTypeInfo();
updateChecks();
if (pkm.Version == 15)
verifyCXD();
}
private void parsePK4(PKM pk)
{
pkm = pk;
if (!pkm.IsOriginValid)
{ AddLine(Severity.Invalid, V187, CheckIdentifier.None); return; }
verifyPreRelearn();
updateEncounterChain();
updateMoveLegality();
updateTypeInfo();
updateChecks();
}
private void parsePK5(PKM pk)
{
pkm = pk;
if (!pkm.IsOriginValid)
{ AddLine(Severity.Invalid, V187, CheckIdentifier.None); return; }
verifyPreRelearn();
updateEncounterChain();
updateMoveLegality();
updateTypeInfo();
updateChecks();
}
private void parsePK6(PKM pk)
{
pkm = pk;
if (!pkm.IsOriginValid)
{ AddLine(Severity.Invalid, V187, CheckIdentifier.None); return; }
updateRelearnLegality();
updateEncounterChain();
updateMoveLegality();
updateTypeInfo();
updateChecks();
}
private void parsePK7(PKM pk)
{
pkm = pk;
if (!pkm.IsOriginValid)
{ AddLine(Severity.Invalid, V187, CheckIdentifier.None); return; }
updateRelearnLegality();
updateEncounterChain();
updateMoveLegality();
updateTypeInfo();
updateChecks();
}
private void updateRelearnLegality()
{
try { vRelearn = verifyRelearn(); }
catch { for (int i = 0; i < 4; i++) vRelearn[i] = new CheckResult(Severity.Invalid, V190, CheckIdentifier.RelearnMove); }
// SecondaryChecked = false;
}
private void updateMoveLegality()
{
try { vMoves = verifyMoves(); }
catch { for (int i = 0; i < 4; i++) vMoves[i] = new CheckResult(Severity.Invalid, V190, CheckIdentifier.Move); }
// SecondaryChecked = false;
}
private void updateEncounterChain()
{
if (EventGiftMatch?.Count > 1) // Multiple possible Mystery Gifts matched
EncounterMatch = EventGiftMatch.First(); // temporarily set one so that Encounter can be verified
Encounter = verifyEncounter();
Parse.Add(Encounter);
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
EvoChainsAllGens = Legal.getEvolutionChainsAllGens(pkm, EncounterOriginalGB ?? EncounterMatch);
}
private void updateTradebackG12()
Generation 1 and 2 legal Improvements (#1099) * Refactor parseMovesForEncounter to gather valid moves for species encounter, some Pokemon can have valid encounters with different source species from the encounter, the valid moves change if the encounter species change because some preevolutions moves are illegal if pokemon caught already evolved. Example, generation 1 Pikachu that can have a RBY Pikachu encounter and GSC Pichu encounter, the valid moves for the first encounters should not have any Pichu exclusive evolution moves Also assign the encounter match from gb when parsing moves like the variable Encounter Match, to store the encounter that is valid for the pokemon moves instead the first encounter. Store the species encounter, this will be needed to check if the evolution is valid for species that evolve leveling with a given learned move * Add Tradeback Status to the pokemon, this variable for generations 1 and 2 use data like the catch rate to determine if trade between generations 1 and 2 was possible. If analysis is for VC games tradeback have value NotTradeback for every gen 1 pokemon, but for cart saves some pokemon can be determine that have not been tradeback, if catch rate match species catch rate but do not match a valid generation 2 held item that means the pokemon habe been never traded to generation 2 games, that allow to discart encounters and moves from generation 2. Also if is not tradeback catch rate is used to filter encounters, catch rate determine in what species was captured the pokemon discarting some preevolutions moves Also add option for generation 1 cart save analysis to check legal status not allowing generation 2 games, like VC games but with Stadium allowed, like the generation 1 non tradeback rules from Smogon Also change evolution chains to included generation 2 preevolutions for gen 1 pokemon if tradeback was possible, it is needed to avoid parsemoves to check illegal pokemon like Hitmonchan with Tyrogue level up moves * Check legal values of generation 1 type and catch rate Replace pokemon catch rate after changind pokemon species always if pokemon was not tradeback from generation 2, the catch rate will keep unchanged only if it can be a held item and do not match species catch rate (default item) Also if catch rate is changed use base species catch rate to avoid legal errors if the catch rate of the evolution species if is not possible with the current moves * Filter ingame trades and static encounters with catch rate for generation 1 non tradeback * Fix min moves for generation 1 metapod encounter * Clean up * Fix encounter level for generation 1, valid moves are those with one level after the encounter level, pokemon can not learn a new move until level up Clean up type validation Fix generation 3 fatefull encounter eggs, the pokemon lost the fatefull mark when it hatch * Clean-up * Use new variable EncounterSpecies when it is needed to detect the species of the encounter, the old code wont work if the encounter is a wild slots array * Fix generation 1 evolution chains and catch rate as default held item * Fix Generation 1 Yellow Pikachu and Kadabra catch rates
2017-04-27 04:27:59 +00:00
{
if (pkm.Format == 1)
{
if (!Legal.AllowGen1Tradeback)
{
pkm.TradebackStatus = TradebackType.Gen1_NotTradeback;
((PK1)pkm).CatchRateIsItem = false;
return;
Generation 1 and 2 legal Improvements (#1099) * Refactor parseMovesForEncounter to gather valid moves for species encounter, some Pokemon can have valid encounters with different source species from the encounter, the valid moves change if the encounter species change because some preevolutions moves are illegal if pokemon caught already evolved. Example, generation 1 Pikachu that can have a RBY Pikachu encounter and GSC Pichu encounter, the valid moves for the first encounters should not have any Pichu exclusive evolution moves Also assign the encounter match from gb when parsing moves like the variable Encounter Match, to store the encounter that is valid for the pokemon moves instead the first encounter. Store the species encounter, this will be needed to check if the evolution is valid for species that evolve leveling with a given learned move * Add Tradeback Status to the pokemon, this variable for generations 1 and 2 use data like the catch rate to determine if trade between generations 1 and 2 was possible. If analysis is for VC games tradeback have value NotTradeback for every gen 1 pokemon, but for cart saves some pokemon can be determine that have not been tradeback, if catch rate match species catch rate but do not match a valid generation 2 held item that means the pokemon habe been never traded to generation 2 games, that allow to discart encounters and moves from generation 2. Also if is not tradeback catch rate is used to filter encounters, catch rate determine in what species was captured the pokemon discarting some preevolutions moves Also add option for generation 1 cart save analysis to check legal status not allowing generation 2 games, like VC games but with Stadium allowed, like the generation 1 non tradeback rules from Smogon Also change evolution chains to included generation 2 preevolutions for gen 1 pokemon if tradeback was possible, it is needed to avoid parsemoves to check illegal pokemon like Hitmonchan with Tyrogue level up moves * Check legal values of generation 1 type and catch rate Replace pokemon catch rate after changind pokemon species always if pokemon was not tradeback from generation 2, the catch rate will keep unchanged only if it can be a held item and do not match species catch rate (default item) Also if catch rate is changed use base species catch rate to avoid legal errors if the catch rate of the evolution species if is not possible with the current moves * Filter ingame trades and static encounters with catch rate for generation 1 non tradeback * Fix min moves for generation 1 metapod encounter * Clean up * Fix encounter level for generation 1, valid moves are those with one level after the encounter level, pokemon can not learn a new move until level up Clean up type validation Fix generation 3 fatefull encounter eggs, the pokemon lost the fatefull mark when it hatch * Clean-up * Use new variable EncounterSpecies when it is needed to detect the species of the encounter, the old code wont work if the encounter is a wild slots array * Fix generation 1 evolution chains and catch rate as default held item * Fix Generation 1 Yellow Pikachu and Kadabra catch rates
2017-04-27 04:27:59 +00:00
}
// Detect tradeback status by comparing the catch rate(Gen1)/held item(Gen2) to the species in the pkm's evolution chain.
var catch_rate = ((PK1)pkm).Catch_Rate;
// For species catch rate, discard any species that has no valid encounters and a different catch rate than their pre-evolutions
var Lineage = Legal.getLineage(pkm).Where(s => !Legal.Species_NotAvailable_CatchRate.Contains(s)).ToList();
// Dragonite's Catch Rate is different than Dragonair's in Yellow, but there is no Dragonite encounter.
var RGBCatchRate = Lineage.Any(s => catch_rate == PersonalTable.RB[s].CatchRate);
var YCatchRate = Lineage.Any(s => s != 149 && catch_rate == PersonalTable.Y[s].CatchRate);
2017-05-01 15:07:20 +00:00
// Krabby encounter trade special catch rate
var TradeCatchRate = ((pkm.Species == 098 || pkm.Species == 099) && catch_rate == 204);
var StadiumCatchRate = Legal.Stadium_GiftSpecies.Contains(pkm.Species) && Legal.Stadium_CatchRate.Contains(catch_rate);
bool matchAny = RGBCatchRate || YCatchRate || TradeCatchRate || StadiumCatchRate;
// If the catch rate value has been modified, the item has either been removed or swapped in Generation 2.
var HeldItemCatchRate = catch_rate == 0 || Legal.HeldItems_GSC.Any(h => h == catch_rate);
if (HeldItemCatchRate && !matchAny)
pkm.TradebackStatus = TradebackType.WasTradeback;
else if (!HeldItemCatchRate && matchAny)
pkm.TradebackStatus = TradebackType.Gen1_NotTradeback;
Generation 1 and 2 legal Improvements (#1099) * Refactor parseMovesForEncounter to gather valid moves for species encounter, some Pokemon can have valid encounters with different source species from the encounter, the valid moves change if the encounter species change because some preevolutions moves are illegal if pokemon caught already evolved. Example, generation 1 Pikachu that can have a RBY Pikachu encounter and GSC Pichu encounter, the valid moves for the first encounters should not have any Pichu exclusive evolution moves Also assign the encounter match from gb when parsing moves like the variable Encounter Match, to store the encounter that is valid for the pokemon moves instead the first encounter. Store the species encounter, this will be needed to check if the evolution is valid for species that evolve leveling with a given learned move * Add Tradeback Status to the pokemon, this variable for generations 1 and 2 use data like the catch rate to determine if trade between generations 1 and 2 was possible. If analysis is for VC games tradeback have value NotTradeback for every gen 1 pokemon, but for cart saves some pokemon can be determine that have not been tradeback, if catch rate match species catch rate but do not match a valid generation 2 held item that means the pokemon habe been never traded to generation 2 games, that allow to discart encounters and moves from generation 2. Also if is not tradeback catch rate is used to filter encounters, catch rate determine in what species was captured the pokemon discarting some preevolutions moves Also add option for generation 1 cart save analysis to check legal status not allowing generation 2 games, like VC games but with Stadium allowed, like the generation 1 non tradeback rules from Smogon Also change evolution chains to included generation 2 preevolutions for gen 1 pokemon if tradeback was possible, it is needed to avoid parsemoves to check illegal pokemon like Hitmonchan with Tyrogue level up moves * Check legal values of generation 1 type and catch rate Replace pokemon catch rate after changind pokemon species always if pokemon was not tradeback from generation 2, the catch rate will keep unchanged only if it can be a held item and do not match species catch rate (default item) Also if catch rate is changed use base species catch rate to avoid legal errors if the catch rate of the evolution species if is not possible with the current moves * Filter ingame trades and static encounters with catch rate for generation 1 non tradeback * Fix min moves for generation 1 metapod encounter * Clean up * Fix encounter level for generation 1, valid moves are those with one level after the encounter level, pokemon can not learn a new move until level up Clean up type validation Fix generation 3 fatefull encounter eggs, the pokemon lost the fatefull mark when it hatch * Clean-up * Use new variable EncounterSpecies when it is needed to detect the species of the encounter, the old code wont work if the encounter is a wild slots array * Fix generation 1 evolution chains and catch rate as default held item * Fix Generation 1 Yellow Pikachu and Kadabra catch rates
2017-04-27 04:27:59 +00:00
else
pkm.TradebackStatus = TradebackType.Any;
Generation 1 and 2 legal Improvements (#1099) * Refactor parseMovesForEncounter to gather valid moves for species encounter, some Pokemon can have valid encounters with different source species from the encounter, the valid moves change if the encounter species change because some preevolutions moves are illegal if pokemon caught already evolved. Example, generation 1 Pikachu that can have a RBY Pikachu encounter and GSC Pichu encounter, the valid moves for the first encounters should not have any Pichu exclusive evolution moves Also assign the encounter match from gb when parsing moves like the variable Encounter Match, to store the encounter that is valid for the pokemon moves instead the first encounter. Store the species encounter, this will be needed to check if the evolution is valid for species that evolve leveling with a given learned move * Add Tradeback Status to the pokemon, this variable for generations 1 and 2 use data like the catch rate to determine if trade between generations 1 and 2 was possible. If analysis is for VC games tradeback have value NotTradeback for every gen 1 pokemon, but for cart saves some pokemon can be determine that have not been tradeback, if catch rate match species catch rate but do not match a valid generation 2 held item that means the pokemon habe been never traded to generation 2 games, that allow to discart encounters and moves from generation 2. Also if is not tradeback catch rate is used to filter encounters, catch rate determine in what species was captured the pokemon discarting some preevolutions moves Also add option for generation 1 cart save analysis to check legal status not allowing generation 2 games, like VC games but with Stadium allowed, like the generation 1 non tradeback rules from Smogon Also change evolution chains to included generation 2 preevolutions for gen 1 pokemon if tradeback was possible, it is needed to avoid parsemoves to check illegal pokemon like Hitmonchan with Tyrogue level up moves * Check legal values of generation 1 type and catch rate Replace pokemon catch rate after changind pokemon species always if pokemon was not tradeback from generation 2, the catch rate will keep unchanged only if it can be a held item and do not match species catch rate (default item) Also if catch rate is changed use base species catch rate to avoid legal errors if the catch rate of the evolution species if is not possible with the current moves * Filter ingame trades and static encounters with catch rate for generation 1 non tradeback * Fix min moves for generation 1 metapod encounter * Clean up * Fix encounter level for generation 1, valid moves are those with one level after the encounter level, pokemon can not learn a new move until level up Clean up type validation Fix generation 3 fatefull encounter eggs, the pokemon lost the fatefull mark when it hatch * Clean-up * Use new variable EncounterSpecies when it is needed to detect the species of the encounter, the old code wont work if the encounter is a wild slots array * Fix generation 1 evolution chains and catch rate as default held item * Fix Generation 1 Yellow Pikachu and Kadabra catch rates
2017-04-27 04:27:59 +00:00
// Update the editing settings for the PKM to acknowledge the tradeback status if the species is changed.
2017-05-01 15:07:20 +00:00
((PK1)pkm).CatchRateIsItem = !pkm.Gen1_NotTradeback && HeldItemCatchRate && !matchAny;
Generation 1 and 2 legal Improvements (#1099) * Refactor parseMovesForEncounter to gather valid moves for species encounter, some Pokemon can have valid encounters with different source species from the encounter, the valid moves change if the encounter species change because some preevolutions moves are illegal if pokemon caught already evolved. Example, generation 1 Pikachu that can have a RBY Pikachu encounter and GSC Pichu encounter, the valid moves for the first encounters should not have any Pichu exclusive evolution moves Also assign the encounter match from gb when parsing moves like the variable Encounter Match, to store the encounter that is valid for the pokemon moves instead the first encounter. Store the species encounter, this will be needed to check if the evolution is valid for species that evolve leveling with a given learned move * Add Tradeback Status to the pokemon, this variable for generations 1 and 2 use data like the catch rate to determine if trade between generations 1 and 2 was possible. If analysis is for VC games tradeback have value NotTradeback for every gen 1 pokemon, but for cart saves some pokemon can be determine that have not been tradeback, if catch rate match species catch rate but do not match a valid generation 2 held item that means the pokemon habe been never traded to generation 2 games, that allow to discart encounters and moves from generation 2. Also if is not tradeback catch rate is used to filter encounters, catch rate determine in what species was captured the pokemon discarting some preevolutions moves Also add option for generation 1 cart save analysis to check legal status not allowing generation 2 games, like VC games but with Stadium allowed, like the generation 1 non tradeback rules from Smogon Also change evolution chains to included generation 2 preevolutions for gen 1 pokemon if tradeback was possible, it is needed to avoid parsemoves to check illegal pokemon like Hitmonchan with Tyrogue level up moves * Check legal values of generation 1 type and catch rate Replace pokemon catch rate after changind pokemon species always if pokemon was not tradeback from generation 2, the catch rate will keep unchanged only if it can be a held item and do not match species catch rate (default item) Also if catch rate is changed use base species catch rate to avoid legal errors if the catch rate of the evolution species if is not possible with the current moves * Filter ingame trades and static encounters with catch rate for generation 1 non tradeback * Fix min moves for generation 1 metapod encounter * Clean up * Fix encounter level for generation 1, valid moves are those with one level after the encounter level, pokemon can not learn a new move until level up Clean up type validation Fix generation 3 fatefull encounter eggs, the pokemon lost the fatefull mark when it hatch * Clean-up * Use new variable EncounterSpecies when it is needed to detect the species of the encounter, the old code wont work if the encounter is a wild slots array * Fix generation 1 evolution chains and catch rate as default held item * Fix Generation 1 Yellow Pikachu and Kadabra catch rates
2017-04-27 04:27:59 +00:00
}
else if (pkm.Format == 2 || pkm.VC2)
{
// Eggs, pokemon with non-empty crystal met location, and generation 2 species without generation 1 preevolutions can't be traded to generation 1.
Generation 1 and 2 legal Improvements (#1099) * Refactor parseMovesForEncounter to gather valid moves for species encounter, some Pokemon can have valid encounters with different source species from the encounter, the valid moves change if the encounter species change because some preevolutions moves are illegal if pokemon caught already evolved. Example, generation 1 Pikachu that can have a RBY Pikachu encounter and GSC Pichu encounter, the valid moves for the first encounters should not have any Pichu exclusive evolution moves Also assign the encounter match from gb when parsing moves like the variable Encounter Match, to store the encounter that is valid for the pokemon moves instead the first encounter. Store the species encounter, this will be needed to check if the evolution is valid for species that evolve leveling with a given learned move * Add Tradeback Status to the pokemon, this variable for generations 1 and 2 use data like the catch rate to determine if trade between generations 1 and 2 was possible. If analysis is for VC games tradeback have value NotTradeback for every gen 1 pokemon, but for cart saves some pokemon can be determine that have not been tradeback, if catch rate match species catch rate but do not match a valid generation 2 held item that means the pokemon habe been never traded to generation 2 games, that allow to discart encounters and moves from generation 2. Also if is not tradeback catch rate is used to filter encounters, catch rate determine in what species was captured the pokemon discarting some preevolutions moves Also add option for generation 1 cart save analysis to check legal status not allowing generation 2 games, like VC games but with Stadium allowed, like the generation 1 non tradeback rules from Smogon Also change evolution chains to included generation 2 preevolutions for gen 1 pokemon if tradeback was possible, it is needed to avoid parsemoves to check illegal pokemon like Hitmonchan with Tyrogue level up moves * Check legal values of generation 1 type and catch rate Replace pokemon catch rate after changind pokemon species always if pokemon was not tradeback from generation 2, the catch rate will keep unchanged only if it can be a held item and do not match species catch rate (default item) Also if catch rate is changed use base species catch rate to avoid legal errors if the catch rate of the evolution species if is not possible with the current moves * Filter ingame trades and static encounters with catch rate for generation 1 non tradeback * Fix min moves for generation 1 metapod encounter * Clean up * Fix encounter level for generation 1, valid moves are those with one level after the encounter level, pokemon can not learn a new move until level up Clean up type validation Fix generation 3 fatefull encounter eggs, the pokemon lost the fatefull mark when it hatch * Clean-up * Use new variable EncounterSpecies when it is needed to detect the species of the encounter, the old code wont work if the encounter is a wild slots array * Fix generation 1 evolution chains and catch rate as default held item * Fix Generation 1 Yellow Pikachu and Kadabra catch rates
2017-04-27 04:27:59 +00:00
if (pkm.IsEgg || pkm.HasOriginalMetLocation || (pkm.Species > Legal.MaxSpeciesID_1 && !Legal.FutureEvolutionsGen1.Contains(pkm.Species)))
pkm.TradebackStatus = TradebackType.Gen2_NotTradeback;
else
pkm.TradebackStatus = TradebackType.Any;
}
else if (pkm.VC1)
{
// If VC2 is ever released, we can assume it will be TradebackType.Any.
// Met date cannot be used definitively as the player can change their system clock.
Generation 1 and 2 legal Improvements (#1099) * Refactor parseMovesForEncounter to gather valid moves for species encounter, some Pokemon can have valid encounters with different source species from the encounter, the valid moves change if the encounter species change because some preevolutions moves are illegal if pokemon caught already evolved. Example, generation 1 Pikachu that can have a RBY Pikachu encounter and GSC Pichu encounter, the valid moves for the first encounters should not have any Pichu exclusive evolution moves Also assign the encounter match from gb when parsing moves like the variable Encounter Match, to store the encounter that is valid for the pokemon moves instead the first encounter. Store the species encounter, this will be needed to check if the evolution is valid for species that evolve leveling with a given learned move * Add Tradeback Status to the pokemon, this variable for generations 1 and 2 use data like the catch rate to determine if trade between generations 1 and 2 was possible. If analysis is for VC games tradeback have value NotTradeback for every gen 1 pokemon, but for cart saves some pokemon can be determine that have not been tradeback, if catch rate match species catch rate but do not match a valid generation 2 held item that means the pokemon habe been never traded to generation 2 games, that allow to discart encounters and moves from generation 2. Also if is not tradeback catch rate is used to filter encounters, catch rate determine in what species was captured the pokemon discarting some preevolutions moves Also add option for generation 1 cart save analysis to check legal status not allowing generation 2 games, like VC games but with Stadium allowed, like the generation 1 non tradeback rules from Smogon Also change evolution chains to included generation 2 preevolutions for gen 1 pokemon if tradeback was possible, it is needed to avoid parsemoves to check illegal pokemon like Hitmonchan with Tyrogue level up moves * Check legal values of generation 1 type and catch rate Replace pokemon catch rate after changind pokemon species always if pokemon was not tradeback from generation 2, the catch rate will keep unchanged only if it can be a held item and do not match species catch rate (default item) Also if catch rate is changed use base species catch rate to avoid legal errors if the catch rate of the evolution species if is not possible with the current moves * Filter ingame trades and static encounters with catch rate for generation 1 non tradeback * Fix min moves for generation 1 metapod encounter * Clean up * Fix encounter level for generation 1, valid moves are those with one level after the encounter level, pokemon can not learn a new move until level up Clean up type validation Fix generation 3 fatefull encounter eggs, the pokemon lost the fatefull mark when it hatch * Clean-up * Use new variable EncounterSpecies when it is needed to detect the species of the encounter, the old code wont work if the encounter is a wild slots array * Fix generation 1 evolution chains and catch rate as default held item * Fix Generation 1 Yellow Pikachu and Kadabra catch rates
2017-04-27 04:27:59 +00:00
pkm.TradebackStatus = TradebackType.Gen1_NotTradeback;
}
else
{
pkm.TradebackStatus = TradebackType.Any;
}
}
private void updateTypeInfo()
{
if (pkm.VC && pkm.Format == 7)
EncounterMatch = Legal.getRBYStaticTransfer(pkm.Species);
if (pkm.GenNumber <= 2 && pkm.TradebackStatus == TradebackType.Any && EncountersGBMatch?.All(e => e.Generation != pkm.GenNumber) == true)
2017-05-01 15:07:20 +00:00
// Example: GSC Pokemon with only possible encounters in RBY, like the legendary birds
pkm.TradebackStatus = TradebackType.WasTradeback;
MatchedType = Type = (EncounterOriginalGB ?? EncounterMatch ?? pkm.Species)?.GetType();
var bt = Type.GetTypeInfo().BaseType;
if (bt != null && !(bt == typeof(Array) || bt == typeof(object) || bt.GetTypeInfo().IsPrimitive)) // a parent exists
Type = bt; // use base type
}
private void updateChecks()
{
verifyECPID();
verifyNickname();
verifyOT();
verifyIVs();
verifyEVs();
verifyLevel();
verifyRibbons();
verifyAbility();
verifyBall();
verifyForm();
verifyMisc();
verifyGender();
verifyItem();
Special Eggs improvement and Generation 4 Encounter Type legal analysis (#1083) * Ignore relearn level 2-100 moves from Phione * Cave encounter types DPPt * Generation 4 EncounterType filter and validation Not every generation 4 static encounter have yet their encounter type defined, i temporally included Any to those encounters Generation 4 roaaming static encounters have been splitted in two, grass and surf * Added new legality texts * Added unreleased event DP Darkai, added check for surf in jhoto route 45, is impossible Moved unreleased DP locations to valid Platinum locations only * Improved generation 3 special egg check. Only check special egg if pokemon knows any of the special egg moves, also in that case do check for normal egg before special egg because special eggs will explicitly check for normal egg moves but normal eggs will not check special egg moves, it will improve the error output * Clean up * Fix gen 5 pokemon from issue #1011 Those pokemon have generation 4 static gift encounters and also wild encounters, the analysis was selecting the static encounter, but if there is a valid wild encounter and the static encounter does not match the pokemon ball the willd encounter should be selected instead Also move the transfer legality to check it before the static encounters and make that check to work like generation 3 transfer legality * Another fix for Issue 1011, suppress temporally OT and pokemon name analysis for generations 3 to 5 instead of format 3 to 5, there is no data stored yet to make those analysis * Do not make wild encounters prevail static encounter if the pokemon was an egg * Changed type of WildEncounter variable to EncounterSlot[] * Fix Jhoto Route 45 to avoid return error with fishing encounters
2017-04-22 18:49:49 +00:00
if (pkm.Format >= 4)
verifyEncounterType();
if (pkm.Format >= 6)
{
History = verifyHistory();
AddLine(History);
verifyOTMemory();
verifyHTMemory();
verifyHyperTraining();
verifyMedals();
verifyRegion();
verifyVersionEvolution();
}
// SecondaryChecked = true;
}
private string getLegalityReport()
{
if (!Parsed)
return V189;
var lines = new List<string>();
for (int i = 0; i < 4; i++)
if (!vMoves[i].Valid)
lines.Add(string.Format(V191, getString(vMoves[i].Judgement), i + 1, vMoves[i].Comment));
if (pkm.Format >= 6)
for (int i = 0; i < 4; i++)
if (!vRelearn[i].Valid)
lines.Add(string.Format(V192, getString(vRelearn[i].Judgement), i + 1, vRelearn[i].Comment));
if (lines.Count == 0 && Parse.All(chk => chk.Valid) && Valid)
return V193;
// Build result string...
var outputLines = Parse.Where(chk => !chk.Valid); // Only invalid
lines.AddRange(outputLines.Select(chk => string.Format(V196, getString(chk.Judgement), chk.Comment)));
if (lines.Count == 0)
return V190;
return string.Join(Environment.NewLine, lines);
}
private string getVerboseLegalityReport()
{
if (!Parsed)
return V189;
const string separator = "===";
string[] br = {separator, ""};
var lines = new List<string> {br[1]};
lines.AddRange(br);
int rl = lines.Count;
for (int i = 0; i < 4; i++)
if (vMoves[i].Valid)
lines.Add(string.Format(V191, getString(vMoves[i].Judgement), i + 1, vMoves[i].Comment));
if (pkm.Format >= 6)
for (int i = 0; i < 4; i++)
if (vRelearn[i].Valid)
lines.Add(string.Format(V192, getString(vRelearn[i].Judgement), i + 1, vRelearn[i].Comment));
if (rl != lines.Count) // move info added, break for next section
lines.Add(br[1]);
var outputLines = Parse.Where(chk => chk != null && chk.Valid && chk.Comment != V).OrderBy(chk => chk.Judgement); // Fishy sorted to top
lines.AddRange(outputLines.Select(chk => string.Format(V196, getString(chk.Judgement), chk.Comment)));
lines.AddRange(br);
lines.Add(string.Format(V195, EncounterName));
var pidiv = MethodFinder.Analyze(pkm);
if (pidiv != null)
{
if (!pidiv.NoSeed)
lines.Add(string.Format(V248, pidiv.OriginSeed.ToString("X8")));
lines.Add(string.Format(V249, pidiv.Type));
}
return getLegalityReport() + string.Join(Environment.NewLine, lines);
}
public int[] getSuggestedRelearn()
{
if (RelearnBase == null || pkm.GenNumber < 6 || !pkm.IsOriginValid)
return new int[4];
if (!pkm.WasEgg)
return RelearnBase;
List<int> window = new List<int>(RelearnBase);
window.AddRange(pkm.Moves.Where((v, i) => !vMoves[i].Valid || vMoves[i].Flag));
window = window.Distinct().ToList();
if (window.Count < 4)
window.AddRange(new int[4 - window.Count]);
return window.Skip(window.Count - 4).ToArray();
}
public int[] getSuggestedMoves(bool tm, bool tutor, bool reminder)
{
if (pkm == null || !pkm.IsOriginValid)
return null;
if (!Parsed)
return new int[4];
return Legal.getValidMoves(pkm, EvoChainsAllGens, Tutor: tutor, Machine: tm, MoveReminder: reminder).Skip(1).ToArray(); // skip move 0
}
public EncounterStatic getSuggestedMetInfo()
{
if (pkm == null)
return null;
int loc = getSuggestedTransferLocation(pkm);
if (pkm.WasEgg)
{
int lvl = 1; // gen5+
if (!pkm.IsNative)
lvl = pkm.CurrentLevel; // be generous with transfer conditions
else if (pkm.Format < 5) // and native
lvl = 0;
return new EncounterStatic
{
Species = Legal.getBaseSpecies(pkm),
Location = loc != -1 ? loc : getSuggestedEggMetLocation(pkm),
Level = lvl,
};
}
var area = Legal.getCaptureLocation(pkm);
if (area != null)
{
var slots = area.Slots.OrderBy(s => s.LevelMin);
return new EncounterStatic
{
Species = slots.First().Species,
Location = loc != -1 ? loc : area.Location,
Level = slots.First().LevelMin,
};
}
var encounter = Legal.getStaticLocation(pkm);
if (loc != -1 && encounter != null)
encounter.Location = loc;
return encounter;
}
private static int getSuggestedEggMetLocation(PKM pkm)
{
// Return one of legal hatch locations for game
switch ((GameVersion)pkm.Version)
{
case GameVersion.R:
case GameVersion.S:
case GameVersion.E:
case GameVersion.FR:
case GameVersion.LG:
switch (pkm.Format)
{
case 3:
return pkm.FRLG ? 146 /* Four Island */ : 32; // Route 117
case 4:
return 0x37; // Pal Park
default:
return 30001; // Transporter
}
case GameVersion.D:
case GameVersion.P:
case GameVersion.Pt:
return pkm.Format > 4 ? 30001 /* Transporter */ : 4; // Solaceon Town
case GameVersion.HG:
case GameVersion.SS:
return pkm.Format > 4 ? 30001 /* Transporter */ : 182; // Route 34
case GameVersion.B:
case GameVersion.W:
return 16; // Route 3
case GameVersion.X:
case GameVersion.Y:
return 38; // Route 7
case GameVersion.AS:
case GameVersion.OR:
return 318; // Battle Resort
case GameVersion.SN:
case GameVersion.MN:
2016-12-01 05:36:02 +00:00
return 50; // Route 4
}
return -1;
}
private static int getSuggestedTransferLocation(PKM pkm)
{
// Return one of legal hatch locations for game
if (pkm.HasOriginalMetLocation)
return -1;
if (pkm.VC1)
return 30013;
if (pkm.Format == 4) // Pal Park
return 0x37;
if (pkm.Format == 5) // Transporter
return 30001;
return -1;
}
2017-03-25 15:41:45 +00:00
private static int[] getGenMovesCheckOrder(PKM pkm)
{
if (pkm.Format == 1)
return new [] { 1, 2 };
if (pkm.Format == 2)
2017-03-25 15:41:45 +00:00
return new [] { 2, 1 };
if (pkm.Format == 7 && pkm.VC1)
2017-03-25 15:41:45 +00:00
return new [] { 7, 1 };
if (pkm.Format == 7 && pkm.VC2)
2017-03-25 15:41:45 +00:00
return new [] { 7, 2, 1 };
var order = new int[pkm.Format - pkm.GenNumber + 1];
for (int i = 0; i < order.Length; i++)
order[i] = pkm.Format - i;
return order;
2017-03-25 15:41:45 +00:00
}
}
}