2017-11-09 06:59:18 +00:00
|
|
|
|
#define SUPPRESS
|
2017-07-18 23:21:31 +00:00
|
|
|
|
|
|
|
|
|
using System;
|
2016-03-25 07:10:11 +00:00
|
|
|
|
using System.Collections.Generic;
|
2016-03-05 04:43:00 +00:00
|
|
|
|
using System.Linq;
|
2017-03-24 17:59:45 +00:00
|
|
|
|
using static PKHeX.Core.LegalityCheckStrings;
|
2016-02-23 06:52:48 +00:00
|
|
|
|
|
2017-01-08 07:54:09 +00:00
|
|
|
|
namespace PKHeX.Core
|
2016-02-23 06:52:48 +00:00
|
|
|
|
{
|
2017-10-24 06:12:58 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Legality Check object containing the <see cref="CheckResult"/> data and overview values from the parse.
|
|
|
|
|
/// </summary>
|
2016-03-14 03:19:04 +00:00
|
|
|
|
public partial class LegalityAnalysis
|
2016-02-23 06:52:48 +00:00
|
|
|
|
{
|
2016-10-23 19:48:49 +00:00
|
|
|
|
private PKM pkm;
|
2017-06-21 00:57:23 +00:00
|
|
|
|
private readonly bool Error;
|
2016-10-23 19:48:49 +00:00
|
|
|
|
private readonly List<CheckResult> Parse = new List<CheckResult>();
|
|
|
|
|
|
2017-05-28 04:17:53 +00:00
|
|
|
|
private IEncounterable EncounterOriginalGB;
|
2017-06-21 00:57:23 +00:00
|
|
|
|
private IEncounterable EncounterMatch => Info.EncounterMatch;
|
2017-11-07 02:06:23 +00:00
|
|
|
|
|
2016-10-23 19:48:49 +00:00
|
|
|
|
private CheckResult Encounter, History;
|
|
|
|
|
|
2017-08-16 04:16:47 +00:00
|
|
|
|
public readonly bool Parsed;
|
|
|
|
|
public readonly bool Valid;
|
2017-11-07 03:31:24 +00:00
|
|
|
|
private readonly PersonalInfo PersonalInfo;
|
2017-06-21 00:57:23 +00:00
|
|
|
|
public LegalInfo Info { get; private set; }
|
2017-03-18 23:50:34 +00:00
|
|
|
|
public bool ParsedValid => Parsed && Valid;
|
|
|
|
|
public bool ParsedInvalid => Parsed && !Valid;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public string Report(bool verbose = false) => verbose ? GetVerboseLegalityReport() : GetLegalityReport();
|
2017-04-23 04:00:06 +00:00
|
|
|
|
private IEnumerable<int> AllSuggestedMoves
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2017-06-07 03:52:21 +00:00
|
|
|
|
if (_allSuggestedMoves != null)
|
|
|
|
|
return _allSuggestedMoves;
|
|
|
|
|
if (Error || pkm == null || !pkm.IsOriginValid)
|
2017-04-23 04:00:06 +00:00
|
|
|
|
return new int[4];
|
2017-06-18 01:37:19 +00:00
|
|
|
|
return _allSuggestedMoves = GetSuggestedMoves(true, true, true);
|
2017-04-23 04:00:06 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private IEnumerable<int> AllSuggestedRelearnMoves
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2017-06-07 03:52:21 +00:00
|
|
|
|
if (_allSuggestedRelearnMoves != null)
|
|
|
|
|
return _allSuggestedRelearnMoves;
|
|
|
|
|
if (Error || pkm == null || !pkm.IsOriginValid)
|
2017-04-23 04:00:06 +00:00
|
|
|
|
return new int[4];
|
2017-06-07 03:52:21 +00:00
|
|
|
|
var gender = pkm.PersonalInfo.Gender;
|
2017-06-21 00:57:23 +00:00
|
|
|
|
var inheritLvlMoves = gender > 0 && gender < 255 || Legal.MixedGenderBreeding.Contains(Info.EncounterMatch.Species);
|
|
|
|
|
return _allSuggestedRelearnMoves = Legal.GetValidRelearn(pkm, Info.EncounterMatch.Species, inheritLvlMoves).ToArray();
|
2017-04-23 04:00:06 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private int[] _allSuggestedMoves, _allSuggestedRelearnMoves;
|
|
|
|
|
public int[] AllSuggestedMovesAndRelearn => AllSuggestedMoves.Concat(AllSuggestedRelearnMoves).ToArray();
|
2017-11-07 02:06:23 +00:00
|
|
|
|
private string EncounterName
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var enc = EncounterOriginalGB ?? EncounterMatch;
|
|
|
|
|
return $"{enc.GetEncounterTypeName()} ({SpeciesStrings[enc.Species]})";
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-01-02 20:00:41 +00:00
|
|
|
|
private string EncounterLocation
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var enc = (EncounterOriginalGB ?? EncounterMatch) as ILocation;
|
2018-01-31 04:24:45 +00:00
|
|
|
|
return enc?.GetEncounterLocation(Info.Generation, pkm.Version);
|
2018-01-02 20:00:41 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-03-14 03:19:04 +00:00
|
|
|
|
|
2017-10-24 06:12:58 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Checks the input <see cref="PKM"/> data for legality.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="pk">Input data to check</param>
|
2017-11-07 03:31:24 +00:00
|
|
|
|
/// <param name="table"><see cref="SaveFile"/> specific personal data</param>
|
|
|
|
|
public LegalityAnalysis(PKM pk, PersonalTable table = null)
|
2016-02-23 06:52:48 +00:00
|
|
|
|
{
|
2017-07-18 23:21:31 +00:00
|
|
|
|
#if SUPPRESS
|
2016-06-30 05:59:20 +00:00
|
|
|
|
try
|
2017-07-18 23:21:31 +00:00
|
|
|
|
#endif
|
2016-06-30 05:59:20 +00:00
|
|
|
|
{
|
2017-11-07 03:31:24 +00:00
|
|
|
|
PersonalInfo = table?.GetFormeEntry(pk.Species, pk.AltForm) ?? pk.PersonalInfo;
|
2017-12-05 04:16:54 +00:00
|
|
|
|
ParseLegality(pk);
|
2017-02-14 06:49:32 +00:00
|
|
|
|
|
2017-12-05 04:16:54 +00:00
|
|
|
|
if (Parse.Count <= 0)
|
|
|
|
|
return;
|
2017-02-14 02:06:01 +00:00
|
|
|
|
|
2018-05-12 15:13:39 +00:00
|
|
|
|
Valid = Parse.All(chk => chk.Valid)
|
|
|
|
|
&& Info.Moves.All(m => m.Valid)
|
2017-12-05 04:16:54 +00:00
|
|
|
|
&& Info.Relearn.All(m => m.Valid);
|
2016-11-15 00:27:15 +00:00
|
|
|
|
|
2017-12-05 04:16:54 +00:00
|
|
|
|
if (pkm.FatefulEncounter && Info.Relearn.Any(chk => !chk.Valid) && EncounterMatch == null)
|
|
|
|
|
AddLine(Severity.Indeterminate, V188, CheckIdentifier.Fateful);
|
2016-06-30 05:59:20 +00:00
|
|
|
|
}
|
2017-07-18 23:21:31 +00:00
|
|
|
|
#if SUPPRESS
|
2017-03-24 06:15:49 +00:00
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
2017-07-18 23:21:31 +00:00
|
|
|
|
System.Diagnostics.Debug.WriteLine(e.Message);
|
2017-03-24 06:15:49 +00:00
|
|
|
|
Valid = false;
|
|
|
|
|
AddLine(Severity.Invalid, V190, CheckIdentifier.Misc);
|
2017-06-10 04:43:46 +00:00
|
|
|
|
pkm = pk;
|
2017-04-23 04:00:06 +00:00
|
|
|
|
Error = true;
|
2017-03-24 06:15:49 +00:00
|
|
|
|
}
|
2017-07-18 23:21:31 +00:00
|
|
|
|
#endif
|
2017-05-18 04:50:52 +00:00
|
|
|
|
Parsed = true;
|
2016-10-23 19:48:49 +00:00
|
|
|
|
}
|
2017-12-05 04:16:54 +00:00
|
|
|
|
private void ParseLegality(PKM pk)
|
|
|
|
|
{
|
|
|
|
|
if (pk.Format == 1 || pk.Format == 2) // prior to storing GameVersion
|
|
|
|
|
{
|
|
|
|
|
ParsePK1(pk);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
switch (pk.GenNumber)
|
|
|
|
|
{
|
|
|
|
|
case 3: ParsePK3(pk); return;
|
|
|
|
|
case 4: ParsePK4(pk); return;
|
|
|
|
|
case 5: ParsePK5(pk); return;
|
|
|
|
|
case 6: ParsePK6(pk); return;
|
|
|
|
|
|
|
|
|
|
case 1: case 2:
|
|
|
|
|
case 7: ParsePK7(pk); return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void ParsePK1(PKM pk)
|
2017-02-13 01:00:03 +00:00
|
|
|
|
{
|
|
|
|
|
pkm = pk;
|
2017-02-15 08:11:12 +00:00
|
|
|
|
if (!pkm.IsOriginValid)
|
2017-06-18 20:02:02 +00:00
|
|
|
|
{ AddLine(Severity.Invalid, V187, CheckIdentifier.GameOrigin); return; }
|
2017-06-18 01:37:19 +00:00
|
|
|
|
UpdateTradebackG12();
|
2017-05-28 04:17:53 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
UpdateInfo();
|
|
|
|
|
UpdateTypeInfo();
|
|
|
|
|
VerifyNickname();
|
|
|
|
|
VerifyDVs();
|
2017-06-27 03:12:49 +00:00
|
|
|
|
VerifyEVs();
|
2018-01-26 17:19:20 +00:00
|
|
|
|
VerifyLevelG1();
|
|
|
|
|
VerifyOTG1();
|
2017-06-18 01:37:19 +00:00
|
|
|
|
VerifyMiscG1();
|
2017-02-13 01:00:03 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void ParsePK3(PKM pk)
|
2017-03-18 23:50:34 +00:00
|
|
|
|
{
|
|
|
|
|
pkm = pk;
|
|
|
|
|
if (!pkm.IsOriginValid)
|
2017-06-18 20:02:02 +00:00
|
|
|
|
{ AddLine(Severity.Invalid, V187, CheckIdentifier.GameOrigin); return; }
|
2017-05-28 04:17:53 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
UpdateInfo();
|
|
|
|
|
UpdateTypeInfo();
|
|
|
|
|
UpdateChecks();
|
2017-05-28 04:17:53 +00:00
|
|
|
|
if (pkm.Format > 3)
|
2017-06-18 01:37:19 +00:00
|
|
|
|
VerifyTransferLegalityG3();
|
2017-04-30 19:17:27 +00:00
|
|
|
|
|
2017-04-30 23:53:54 +00:00
|
|
|
|
if (pkm.Version == 15)
|
2017-06-18 01:37:19 +00:00
|
|
|
|
VerifyCXD();
|
2017-06-09 03:57:30 +00:00
|
|
|
|
|
2017-06-21 00:57:23 +00:00
|
|
|
|
if (Info.EncounterMatch is WC3 z && z.NotDistributed)
|
2017-06-09 03:57:30 +00:00
|
|
|
|
AddLine(Severity.Invalid, V413, CheckIdentifier.Encounter);
|
2017-03-18 23:50:34 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void ParsePK4(PKM pk)
|
2017-03-18 23:50:34 +00:00
|
|
|
|
{
|
|
|
|
|
pkm = pk;
|
|
|
|
|
if (!pkm.IsOriginValid)
|
2017-06-18 20:02:02 +00:00
|
|
|
|
{ AddLine(Severity.Invalid, V187, CheckIdentifier.GameOrigin); return; }
|
2017-03-24 04:42:33 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
UpdateInfo();
|
|
|
|
|
UpdateTypeInfo();
|
|
|
|
|
UpdateChecks();
|
2017-05-28 04:17:53 +00:00
|
|
|
|
if (pkm.Format > 4)
|
2017-06-18 01:37:19 +00:00
|
|
|
|
VerifyTransferLegalityG4();
|
2017-03-18 23:50:34 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void ParsePK5(PKM pk)
|
2017-03-18 23:50:34 +00:00
|
|
|
|
{
|
|
|
|
|
pkm = pk;
|
|
|
|
|
if (!pkm.IsOriginValid)
|
2017-06-18 20:02:02 +00:00
|
|
|
|
{ AddLine(Severity.Invalid, V187, CheckIdentifier.GameOrigin); return; }
|
2017-03-24 04:42:33 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
UpdateInfo();
|
|
|
|
|
UpdateTypeInfo();
|
|
|
|
|
UpdateChecks();
|
2017-03-18 23:50:34 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void ParsePK6(PKM pk)
|
2016-10-23 19:48:49 +00:00
|
|
|
|
{
|
|
|
|
|
pkm = pk;
|
2017-02-15 08:11:12 +00:00
|
|
|
|
if (!pkm.IsOriginValid)
|
2017-06-18 20:02:02 +00:00
|
|
|
|
{ AddLine(Severity.Invalid, V187, CheckIdentifier.GameOrigin); return; }
|
2016-10-23 19:48:49 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
UpdateInfo();
|
|
|
|
|
UpdateTypeInfo();
|
|
|
|
|
UpdateChecks();
|
2016-10-23 19:48:49 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void ParsePK7(PKM pk)
|
2016-10-23 19:48:49 +00:00
|
|
|
|
{
|
|
|
|
|
pkm = pk;
|
2017-02-15 08:11:12 +00:00
|
|
|
|
if (!pkm.IsOriginValid)
|
2017-06-18 20:02:02 +00:00
|
|
|
|
{ AddLine(Severity.Invalid, V187, CheckIdentifier.GameOrigin); return; }
|
2016-10-23 19:48:49 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
UpdateInfo();
|
2017-07-09 15:47:17 +00:00
|
|
|
|
if (pkm.VC)
|
|
|
|
|
UpdateVCTransferInfo();
|
2017-06-18 01:37:19 +00:00
|
|
|
|
UpdateTypeInfo();
|
|
|
|
|
UpdateChecks();
|
2016-03-12 04:56:40 +00:00
|
|
|
|
}
|
2016-03-14 03:19:04 +00:00
|
|
|
|
|
2017-12-12 00:01:24 +00:00
|
|
|
|
private void AddLine(Severity s, string c, CheckIdentifier i) => AddLine(new CheckResult(s, c, i));
|
|
|
|
|
private void AddLine(CheckResult chk) => Parse.Add(chk);
|
|
|
|
|
|
2017-07-09 15:47:17 +00:00
|
|
|
|
private void UpdateVCTransferInfo()
|
|
|
|
|
{
|
|
|
|
|
EncounterOriginalGB = EncounterMatch;
|
2018-03-11 03:51:09 +00:00
|
|
|
|
Info.EncounterMatch = EncounterStaticGenerator.GetVCStaticTransferEncounter(pkm);
|
|
|
|
|
if (!(Info.EncounterMatch is EncounterStatic s) || !EncounterStaticGenerator.IsVCStaticTransferEncounterValid(pkm, s))
|
2017-10-21 04:07:15 +00:00
|
|
|
|
{ AddLine(Severity.Invalid, V80, CheckIdentifier.Encounter); return; }
|
|
|
|
|
|
2018-01-26 03:17:42 +00:00
|
|
|
|
foreach (var z in VerifyVCEncounter(pkm, EncounterOriginalGB, s, Info.Moves))
|
2017-07-09 15:47:17 +00:00
|
|
|
|
AddLine(z);
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void UpdateInfo()
|
2016-03-12 04:56:40 +00:00
|
|
|
|
{
|
2017-06-21 00:57:23 +00:00
|
|
|
|
Info = EncounterFinder.FindVerifiedEncounter(pkm);
|
|
|
|
|
Encounter = Info.Parse[0];
|
|
|
|
|
Parse.AddRange(Info.Parse);
|
2017-01-04 04:51:33 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
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)
|
|
|
|
|
{
|
2017-09-24 17:36:16 +00:00
|
|
|
|
Legal.SetTradebackStatusRBY(pkm);
|
2017-07-30 19:31:17 +00:00
|
|
|
|
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
|
|
|
|
}
|
2017-07-30 19:31:17 +00:00
|
|
|
|
|
|
|
|
|
if (pkm.Format == 2 || pkm.VC2)
|
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
|
|
|
|
{
|
2017-09-24 17:36:16 +00:00
|
|
|
|
// Check for impossible tradeback scenarios
|
|
|
|
|
// Korean Gen2 games can't tradeback because there are no Gen1 Korean games released
|
|
|
|
|
bool g2only = pkm.Korean || pkm.IsEgg || pkm.HasOriginalMetLocation ||
|
|
|
|
|
pkm.Species > Legal.MaxSpeciesID_1 && !Legal.FutureEvolutionsGen1.Contains(pkm.Species);
|
|
|
|
|
pkm.TradebackStatus = g2only ? TradebackType.Gen2_NotTradeback : TradebackType.Any;
|
|
|
|
|
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
|
|
|
|
}
|
2017-09-23 10:58:46 +00:00
|
|
|
|
|
|
|
|
|
// VC2 is released, we can assume it will be TradebackType.Any.
|
2017-09-24 17:36:16 +00:00
|
|
|
|
// Is impossible to differentiate a VC1 pokemon traded to Gen7 after VC2 is available.
|
|
|
|
|
// Met Date cannot be used definitively as the player can change their system clock.
|
2017-09-23 10:58:46 +00:00
|
|
|
|
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
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void UpdateTypeInfo()
|
2017-01-04 04:51:33 +00:00
|
|
|
|
{
|
2018-01-11 00:16:35 +00:00
|
|
|
|
if (pkm.GenNumber <= 2 && pkm.TradebackStatus == TradebackType.Any && EncounterMatch is IGeneration g && g.Generation != pkm.GenNumber)
|
Encounter Type fix and detection of pokemon that should have evolve on trade (#1105)
* Detect encounter trades that evolve on trade and have not been evolved
Detect generation 1 pokemon with special catch rates : krabby trade and Pokemon Stadium
Detect generation 1 pokemon that evolve on trade and have been traded but not evolved
Detect pokemon with tradeback status any but with only encounters from the other GB generation, that means they are WasTradeback
Detect pokemon with moves from the other GB generation, change tradebackstatus to WasTradeback
* Fix dppt surfing and fishing encounter type, is is surfing because the battle background is the same as other surfingfishing encounters
Fix headbutt encounter type, the encounter type depends on the battle background used when battle a pokemon, for headbutt it changes with the player tile, is the player is in a city it will be building encounter, in a grass tile tall grass, in water it is surfingfishing and cave inside a cave. Some locations have more than one possible encounter type, for example routes with trees near the grass, near the water and near non-combat tiles.
Also added slot type headbutt special for the special trees, those trees are all in routes and are only adjacent to non-combat tiles
* Fix encounter type for missing areas with multiple grass encounters types: Mt Coronet, Mt Silver Cave and Stark Mountain (Issue # 1095)
* Fixes and typos
* Check for non-japanese e-reader pokemon, is unreleased
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;
|
2017-02-15 01:33:57 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void UpdateChecks()
|
2017-02-15 01:33:57 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
VerifyECPID();
|
|
|
|
|
VerifyNickname();
|
|
|
|
|
VerifyOT();
|
|
|
|
|
VerifyIVs();
|
|
|
|
|
VerifyEVs();
|
|
|
|
|
VerifyLevel();
|
|
|
|
|
VerifyRibbons();
|
|
|
|
|
VerifyAbility();
|
|
|
|
|
VerifyBall();
|
|
|
|
|
VerifyForm();
|
|
|
|
|
VerifyMisc();
|
|
|
|
|
VerifyGender();
|
|
|
|
|
VerifyItem();
|
2017-12-12 00:01:24 +00:00
|
|
|
|
if (pkm.Format <= 6 && pkm.Format >= 4)
|
|
|
|
|
VerifyEncounterType(); // Gen 6->7 transfer deletes encounter type data
|
2017-03-18 23:50:34 +00:00
|
|
|
|
if (pkm.Format >= 6)
|
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
History = VerifyHistory();
|
2017-03-18 23:50:34 +00:00
|
|
|
|
AddLine(History);
|
2017-06-18 01:37:19 +00:00
|
|
|
|
VerifyOTMemory();
|
|
|
|
|
VerifyHTMemory();
|
|
|
|
|
VerifyHyperTraining();
|
|
|
|
|
VerifyMedals();
|
2017-09-05 01:55:15 +00:00
|
|
|
|
VerifyConsoleRegion();
|
2017-06-18 01:37:19 +00:00
|
|
|
|
VerifyVersionEvolution();
|
2017-03-18 23:50:34 +00:00
|
|
|
|
}
|
2016-02-23 06:52:48 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private string GetLegalityReport()
|
2016-03-09 03:20:26 +00:00
|
|
|
|
{
|
2017-11-09 06:56:42 +00:00
|
|
|
|
if (!Parsed || pkm == null || Info == null)
|
2017-03-21 07:18:38 +00:00
|
|
|
|
return V189;
|
2018-05-12 15:13:39 +00:00
|
|
|
|
|
2017-04-29 22:45:21 +00:00
|
|
|
|
var lines = new List<string>();
|
2017-06-21 00:57:23 +00:00
|
|
|
|
var vMoves = Info.Moves;
|
|
|
|
|
var vRelearn = Info.Relearn;
|
2016-03-12 04:56:40 +00:00
|
|
|
|
for (int i = 0; i < 4; i++)
|
2016-03-12 17:16:41 +00:00
|
|
|
|
if (!vMoves[i].Valid)
|
2017-12-12 00:01:24 +00:00
|
|
|
|
lines.Add(string.Format(V191, vMoves[i].Rating, i + 1, vMoves[i].Comment));
|
2017-02-13 01:00:03 +00:00
|
|
|
|
|
|
|
|
|
if (pkm.Format >= 6)
|
2016-03-12 04:56:40 +00:00
|
|
|
|
for (int i = 0; i < 4; i++)
|
2016-03-12 17:16:41 +00:00
|
|
|
|
if (!vRelearn[i].Valid)
|
2017-12-12 00:01:24 +00:00
|
|
|
|
lines.Add(string.Format(V192, vRelearn[i].Rating, i + 1, vRelearn[i].Comment));
|
2016-03-12 04:56:40 +00:00
|
|
|
|
|
2017-04-29 22:45:21 +00:00
|
|
|
|
if (lines.Count == 0 && Parse.All(chk => chk.Valid) && Valid)
|
2017-03-21 07:18:38 +00:00
|
|
|
|
return V193;
|
2018-05-12 15:13:39 +00:00
|
|
|
|
|
2016-03-12 03:43:40 +00:00
|
|
|
|
// Build result string...
|
2017-03-21 07:18:38 +00:00
|
|
|
|
var outputLines = Parse.Where(chk => !chk.Valid); // Only invalid
|
2017-12-12 00:01:24 +00:00
|
|
|
|
lines.AddRange(outputLines.Select(chk => string.Format(V196, chk.Rating, chk.Comment)));
|
2016-03-12 04:56:40 +00:00
|
|
|
|
|
2017-04-29 22:45:21 +00:00
|
|
|
|
if (lines.Count == 0)
|
|
|
|
|
return V190;
|
2016-11-08 16:43:57 +00:00
|
|
|
|
|
2017-04-29 22:45:21 +00:00
|
|
|
|
return string.Join(Environment.NewLine, lines);
|
2016-04-04 00:11:58 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private string GetVerboseLegalityReport()
|
2016-04-04 00:11:58 +00:00
|
|
|
|
{
|
2017-11-09 06:56:42 +00:00
|
|
|
|
if (!Parsed || pkm == null || Info == null)
|
2017-04-29 22:45:21 +00:00
|
|
|
|
return V189;
|
|
|
|
|
|
|
|
|
|
const string separator = "===";
|
|
|
|
|
string[] br = {separator, ""};
|
|
|
|
|
var lines = new List<string> {br[1]};
|
|
|
|
|
lines.AddRange(br);
|
|
|
|
|
int rl = lines.Count;
|
2016-04-16 18:36:01 +00:00
|
|
|
|
|
2017-06-21 00:57:23 +00:00
|
|
|
|
var vMoves = Info.Moves;
|
|
|
|
|
var vRelearn = Info.Relearn;
|
2016-04-16 18:36:01 +00:00
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
|
if (vMoves[i].Valid)
|
2017-12-12 00:01:24 +00:00
|
|
|
|
lines.Add(string.Format(V191, vMoves[i].Rating, i + 1, vMoves[i].Comment));
|
2017-02-13 01:00:03 +00:00
|
|
|
|
|
|
|
|
|
if (pkm.Format >= 6)
|
2017-03-21 07:18:38 +00:00
|
|
|
|
for (int i = 0; i < 4; i++)
|
2016-04-16 18:36:01 +00:00
|
|
|
|
if (vRelearn[i].Valid)
|
2017-12-12 00:01:24 +00:00
|
|
|
|
lines.Add(string.Format(V192, vRelearn[i].Rating, i + 1, vRelearn[i].Comment));
|
2016-04-16 18:36:01 +00:00
|
|
|
|
|
2017-04-29 22:45:21 +00:00
|
|
|
|
if (rl != lines.Count) // move info added, break for next section
|
|
|
|
|
lines.Add(br[1]);
|
2018-05-12 15:13:39 +00:00
|
|
|
|
|
2018-05-12 19:28:48 +00:00
|
|
|
|
var outputLines = Parse.Where(chk => chk?.Valid == true && chk.Comment != V).OrderBy(chk => chk.Judgement); // Fishy sorted to top
|
2017-12-12 00:01:24 +00:00
|
|
|
|
lines.AddRange(outputLines.Select(chk => string.Format(V196, chk.Rating, chk.Comment)));
|
2016-12-31 01:13:22 +00:00
|
|
|
|
|
2017-04-29 22:45:21 +00:00
|
|
|
|
lines.AddRange(br);
|
|
|
|
|
lines.Add(string.Format(V195, EncounterName));
|
2018-01-02 20:00:41 +00:00
|
|
|
|
var loc = EncounterLocation;
|
|
|
|
|
if (!string.IsNullOrEmpty(loc))
|
|
|
|
|
lines.Add(string.Format(V196, "Location", loc));
|
2017-09-08 06:53:12 +00:00
|
|
|
|
if (pkm.VC)
|
|
|
|
|
lines.Add(string.Format(V196, nameof(GameVersion), Info.Game));
|
2017-06-21 00:57:23 +00:00
|
|
|
|
var pidiv = Info.PIDIV ?? MethodFinder.Analyze(pkm);
|
2017-04-30 03:04:54 +00:00
|
|
|
|
if (pidiv != null)
|
|
|
|
|
{
|
|
|
|
|
if (!pidiv.NoSeed)
|
|
|
|
|
lines.Add(string.Format(V248, pidiv.OriginSeed.ToString("X8")));
|
|
|
|
|
lines.Add(string.Format(V249, pidiv.Type));
|
|
|
|
|
}
|
2017-07-12 16:02:03 +00:00
|
|
|
|
if (!Valid && Info.InvalidMatches != null)
|
|
|
|
|
{
|
|
|
|
|
lines.Add("Other match(es):");
|
|
|
|
|
lines.AddRange(Info.InvalidMatches.Select(z => $"{z.Name}: {z.Reason}"));
|
|
|
|
|
}
|
2018-05-12 15:13:39 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
return GetLegalityReport() + string.Join(Environment.NewLine, lines);
|
2016-03-09 03:20:26 +00:00
|
|
|
|
}
|
2016-03-25 07:10:11 +00:00
|
|
|
|
|
2017-08-16 04:16:47 +00:00
|
|
|
|
// Suggestions
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public int[] GetSuggestedRelearn()
|
2016-03-25 07:10:11 +00:00
|
|
|
|
{
|
2017-06-21 00:57:23 +00:00
|
|
|
|
if (Info.RelearnBase == null || pkm.GenNumber < 6 || !pkm.IsOriginValid)
|
2016-10-23 19:48:49 +00:00
|
|
|
|
return new int[4];
|
2016-03-25 07:10:11 +00:00
|
|
|
|
|
2016-10-23 19:48:49 +00:00
|
|
|
|
if (!pkm.WasEgg)
|
2017-06-21 00:57:23 +00:00
|
|
|
|
return Info.RelearnBase;
|
2016-03-25 07:10:11 +00:00
|
|
|
|
|
2017-09-27 03:09:18 +00:00
|
|
|
|
List<int> window = new List<int>(Info.RelearnBase.Where(z => z != 0));
|
2018-05-12 19:28:48 +00:00
|
|
|
|
window.AddRange(pkm.Moves.Where((_, i) => !Info.Moves[i].Valid || Info.Moves[i].Flag));
|
2017-04-05 06:11:47 +00:00
|
|
|
|
window = window.Distinct().ToList();
|
2017-08-16 04:16:47 +00:00
|
|
|
|
int[] moves = new int[4];
|
|
|
|
|
int start = Math.Max(0, window.Count - 4);
|
|
|
|
|
int count = Math.Min(4, window.Count);
|
|
|
|
|
window.CopyTo(start, moves, 0, count);
|
|
|
|
|
return moves;
|
2016-03-25 07:10:11 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public int[] GetSuggestedMoves(bool tm, bool tutor, bool reminder)
|
2016-11-15 06:13:15 +00:00
|
|
|
|
{
|
2017-02-15 08:11:12 +00:00
|
|
|
|
if (pkm == null || !pkm.IsOriginValid)
|
2016-11-15 06:13:15 +00:00
|
|
|
|
return null;
|
2017-02-14 06:49:32 +00:00
|
|
|
|
if (!Parsed)
|
2017-02-13 01:00:03 +00:00
|
|
|
|
return new int[4];
|
2017-06-21 00:57:23 +00:00
|
|
|
|
return Legal.GetValidMoves(pkm, Info.EvoChainsAllGens, Tutor: tutor, Machine: tm, MoveReminder: reminder).Skip(1).ToArray(); // skip move 0
|
2016-12-31 01:13:22 +00:00
|
|
|
|
}
|
2017-08-16 04:16:47 +00:00
|
|
|
|
public EncounterStatic GetSuggestedMetInfo() => EncounterSuggestion.GetSuggestedMetInfo(pkm);
|
2016-02-23 06:52:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|