2016-07-18 05:39:18 +00:00
|
|
|
|
using System;
|
2017-07-02 02:43:51 +00:00
|
|
|
|
using System.Diagnostics;
|
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
|
|
|
|
using System.Linq;
|
2016-07-18 05:39:18 +00:00
|
|
|
|
|
2017-01-08 07:54:09 +00:00
|
|
|
|
namespace PKHeX.Core
|
2016-07-18 05:39:18 +00:00
|
|
|
|
{
|
|
|
|
|
public class PersonalTable
|
|
|
|
|
{
|
2017-09-01 05:37:28 +00:00
|
|
|
|
public static readonly PersonalTable USUM = GetTable("sm", GameVersion.USUM);
|
2017-07-29 18:54:52 +00:00
|
|
|
|
public static readonly PersonalTable SM = GetTable("sm", GameVersion.SM);
|
|
|
|
|
public static readonly PersonalTable AO = GetTable("ao", GameVersion.ORAS);
|
|
|
|
|
public static readonly PersonalTable XY = GetTable("xy", GameVersion.XY);
|
|
|
|
|
public static readonly PersonalTable B2W2 = GetTable("b2w2", GameVersion.B2W2);
|
|
|
|
|
public static readonly PersonalTable BW = GetTable("bw", GameVersion.BW);
|
|
|
|
|
public static readonly PersonalTable HGSS = GetTable("hgss", GameVersion.HGSS);
|
|
|
|
|
public static readonly PersonalTable Pt = GetTable("pt", GameVersion.Pt);
|
|
|
|
|
public static readonly PersonalTable DP = GetTable("dp", GameVersion.DP);
|
|
|
|
|
public static readonly PersonalTable LG = GetTable("lg", GameVersion.LG);
|
|
|
|
|
public static readonly PersonalTable FR = GetTable("fr", GameVersion.FR);
|
|
|
|
|
public static readonly PersonalTable E = GetTable("e", GameVersion.E);
|
|
|
|
|
public static readonly PersonalTable RS = GetTable("rs", GameVersion.RS);
|
|
|
|
|
public static readonly PersonalTable C = GetTable("c", GameVersion.C);
|
|
|
|
|
public static readonly PersonalTable GS = GetTable("c", GameVersion.GS);
|
|
|
|
|
public static readonly PersonalTable RB = GetTable("rb", GameVersion.RBY);
|
|
|
|
|
public static readonly PersonalTable Y = GetTable("y", GameVersion.RBY);
|
|
|
|
|
private static PersonalTable GetTable(string game, GameVersion format)
|
|
|
|
|
{
|
|
|
|
|
return new PersonalTable(Util.GetBinaryResource($"personal_{game}"), format);
|
|
|
|
|
}
|
2016-07-18 05:39:18 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static byte[][] SplitBytes(byte[] data, int size)
|
2016-07-18 05:39:18 +00:00
|
|
|
|
{
|
|
|
|
|
byte[][] r = new byte[data.Length / size][];
|
|
|
|
|
for (int i = 0; i < data.Length; i += size)
|
|
|
|
|
{
|
|
|
|
|
r[i / size] = new byte[size];
|
|
|
|
|
Array.Copy(data, i, r[i / size], 0, size);
|
|
|
|
|
}
|
|
|
|
|
return r;
|
|
|
|
|
}
|
2017-07-29 18:54:52 +00:00
|
|
|
|
private static Func<byte[], PersonalInfo> GetConstructor(GameVersion format)
|
2016-07-18 05:39:18 +00:00
|
|
|
|
{
|
|
|
|
|
switch (format)
|
|
|
|
|
{
|
2016-08-27 09:48:04 +00:00
|
|
|
|
case GameVersion.RBY:
|
2017-07-29 18:54:52 +00:00
|
|
|
|
return z => new PersonalInfoG1(z);
|
2017-06-18 20:02:02 +00:00
|
|
|
|
case GameVersion.GS: case GameVersion.C:
|
2017-07-29 18:54:52 +00:00
|
|
|
|
return z => new PersonalInfoG2(z);
|
2017-06-18 20:02:02 +00:00
|
|
|
|
case GameVersion.RS: case GameVersion.E: case GameVersion.FR: case GameVersion.LG:
|
2017-07-29 18:54:52 +00:00
|
|
|
|
return z => new PersonalInfoG3(z);
|
2017-06-18 20:02:02 +00:00
|
|
|
|
case GameVersion.DP: case GameVersion.Pt: case GameVersion.HGSS:
|
2017-07-29 18:54:52 +00:00
|
|
|
|
return z => new PersonalInfoG4(z);
|
2017-06-18 20:02:02 +00:00
|
|
|
|
case GameVersion.BW:
|
2017-07-29 18:54:52 +00:00
|
|
|
|
return z => new PersonalInfoBW(z);
|
2017-06-18 20:02:02 +00:00
|
|
|
|
case GameVersion.B2W2:
|
2017-07-29 18:54:52 +00:00
|
|
|
|
return z => new PersonalInfoB2W2(z);
|
2017-06-18 20:02:02 +00:00
|
|
|
|
case GameVersion.XY:
|
2017-07-29 18:54:52 +00:00
|
|
|
|
return z => new PersonalInfoXY(z);
|
2017-06-18 20:02:02 +00:00
|
|
|
|
case GameVersion.ORAS:
|
2017-07-29 18:54:52 +00:00
|
|
|
|
return z => new PersonalInfoORAS(z);
|
2017-06-18 20:02:02 +00:00
|
|
|
|
case GameVersion.SM:
|
2017-07-29 18:54:52 +00:00
|
|
|
|
return z => new PersonalInfoSM(z);
|
2017-09-01 05:37:28 +00:00
|
|
|
|
case GameVersion.USUM:
|
|
|
|
|
return z => new PersonalInfoSM(z);
|
2017-06-18 20:02:02 +00:00
|
|
|
|
}
|
2017-07-29 18:54:52 +00:00
|
|
|
|
return null;
|
2017-06-18 20:02:02 +00:00
|
|
|
|
}
|
|
|
|
|
private static int GetEntrySize(GameVersion format)
|
|
|
|
|
{
|
|
|
|
|
switch (format)
|
|
|
|
|
{
|
|
|
|
|
case GameVersion.RBY: return PersonalInfoG1.SIZE;
|
2016-09-02 21:20:39 +00:00
|
|
|
|
case GameVersion.GS:
|
2017-06-18 20:02:02 +00:00
|
|
|
|
case GameVersion.C: return PersonalInfoG2.SIZE;
|
2016-07-18 05:39:18 +00:00
|
|
|
|
case GameVersion.RS:
|
|
|
|
|
case GameVersion.E:
|
|
|
|
|
case GameVersion.FR:
|
2017-06-18 20:02:02 +00:00
|
|
|
|
case GameVersion.LG: return PersonalInfoG3.SIZE;
|
2016-07-18 05:39:18 +00:00
|
|
|
|
case GameVersion.DP:
|
|
|
|
|
case GameVersion.Pt:
|
2017-06-18 20:02:02 +00:00
|
|
|
|
case GameVersion.HGSS: return PersonalInfoG4.SIZE;
|
|
|
|
|
case GameVersion.BW: return PersonalInfoBW.SIZE;
|
|
|
|
|
case GameVersion.B2W2: return PersonalInfoB2W2.SIZE;
|
|
|
|
|
case GameVersion.XY: return PersonalInfoXY.SIZE;
|
|
|
|
|
case GameVersion.ORAS: return PersonalInfoORAS.SIZE;
|
2017-09-01 05:37:28 +00:00
|
|
|
|
case GameVersion.SM:
|
|
|
|
|
case GameVersion.USUM: return PersonalInfoSM.SIZE;
|
2017-06-18 20:02:02 +00:00
|
|
|
|
|
|
|
|
|
default: return -1;
|
2016-07-18 05:39:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-07-29 18:54:52 +00:00
|
|
|
|
static PersonalTable() // Finish Setup
|
|
|
|
|
{
|
2017-09-06 16:12:56 +00:00
|
|
|
|
FixPersonalTableG1();
|
2017-07-29 18:54:52 +00:00
|
|
|
|
PopulateGen3Tutors();
|
|
|
|
|
PopulateGen4Tutors();
|
|
|
|
|
}
|
2017-09-06 16:12:56 +00:00
|
|
|
|
private static void FixPersonalTableG1()
|
2017-07-29 18:54:52 +00:00
|
|
|
|
{
|
|
|
|
|
// Update Yellow's catch rates; currently matches Red/Blue's values.
|
|
|
|
|
Y[25].CatchRate = 163; // Pikachu
|
|
|
|
|
Y[64].CatchRate = 96; // Kadabra
|
2017-09-06 16:12:56 +00:00
|
|
|
|
|
|
|
|
|
// Load Gen2 Gender Ratios into Gen1
|
|
|
|
|
for (int i = 0; i < 151; i++)
|
|
|
|
|
RB[i].Gender = Y[i].Gender = GS[i].Gender;
|
2017-07-29 18:54:52 +00:00
|
|
|
|
}
|
|
|
|
|
private static void PopulateGen3Tutors()
|
|
|
|
|
{
|
|
|
|
|
// Update Gen3 data with Emerald's data, FR/LG is a subset of Emerald's compatibility.
|
|
|
|
|
var TMHM = Data.UnpackMini(Util.GetBinaryResource("hmtm_g3.pkl"), "g3");
|
|
|
|
|
var tutors = Data.UnpackMini(Util.GetBinaryResource("tutors_g3.pkl"), "g3");
|
|
|
|
|
for (int i = 0; i <= Legal.MaxSpeciesID_3; i++)
|
|
|
|
|
{
|
|
|
|
|
E[i].AddTMHM(TMHM[i]);
|
|
|
|
|
E[i].AddTypeTutors(tutors[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private static void PopulateGen4Tutors()
|
|
|
|
|
{
|
|
|
|
|
var tutors = Data.UnpackMini(Util.GetBinaryResource("tutors_g4.pkl"), "g4");
|
2017-08-27 18:04:31 +00:00
|
|
|
|
for (int i = 0; i < tutors.Length; i++)
|
2017-07-29 18:54:52 +00:00
|
|
|
|
HGSS[i].AddTypeTutors(tutors[i]);
|
|
|
|
|
}
|
2016-07-18 05:39:18 +00:00
|
|
|
|
|
2017-06-18 20:02:02 +00:00
|
|
|
|
private PersonalTable(byte[] data, GameVersion format)
|
|
|
|
|
{
|
2017-07-29 18:54:52 +00:00
|
|
|
|
Func<byte[], PersonalInfo> get = GetConstructor(format);
|
2017-06-18 20:02:02 +00:00
|
|
|
|
int size = GetEntrySize(format);
|
2017-07-29 18:54:52 +00:00
|
|
|
|
byte[][] entries = SplitBytes(data, size);
|
|
|
|
|
Table = new PersonalInfo[data.Length / size];
|
|
|
|
|
for (int i = 0; i < Table.Length; i++)
|
|
|
|
|
Table[i] = get(entries[i]);
|
2017-06-18 20:02:02 +00:00
|
|
|
|
}
|
2016-07-18 05:39:18 +00:00
|
|
|
|
private readonly PersonalInfo[] Table;
|
|
|
|
|
public PersonalInfo this[int index]
|
|
|
|
|
{
|
2016-10-24 04:57:43 +00:00
|
|
|
|
get
|
|
|
|
|
{
|
2017-05-28 04:17:53 +00:00
|
|
|
|
if (0 <= index && index < Table.Length)
|
2016-10-24 04:57:43 +00:00
|
|
|
|
return Table[index];
|
|
|
|
|
return Table[0];
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2017-05-28 04:17:53 +00:00
|
|
|
|
if (index < 0 || index >= Table.Length)
|
2016-10-24 04:57:43 +00:00
|
|
|
|
return;
|
|
|
|
|
Table[index] = value;
|
|
|
|
|
}
|
2016-07-18 05:39:18 +00:00
|
|
|
|
}
|
2016-07-18 06:04:39 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public int[] GetAbilities(int species, int forme)
|
2016-07-18 06:04:39 +00:00
|
|
|
|
{
|
2016-07-21 03:43:18 +00:00
|
|
|
|
if (species >= Table.Length)
|
2017-07-02 02:43:51 +00:00
|
|
|
|
{ species = 0; Debug.WriteLine("Requested out of bounds SpeciesID"); }
|
2017-06-18 01:37:19 +00:00
|
|
|
|
return this[GetFormeIndex(species, forme)].Abilities;
|
2016-07-18 06:04:39 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public int GetFormeIndex(int species, int forme)
|
2016-07-18 06:04:39 +00:00
|
|
|
|
{
|
2016-07-21 03:43:18 +00:00
|
|
|
|
if (species >= Table.Length)
|
2017-07-02 02:43:51 +00:00
|
|
|
|
{ species = 0; Debug.WriteLine("Requested out of bounds SpeciesID"); }
|
2016-07-18 06:04:39 +00:00
|
|
|
|
return this[species].FormeIndex(species, forme);
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public PersonalInfo GetFormeEntry(int species, int forme)
|
2016-07-18 06:04:39 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
return this[GetFormeIndex(species, forme)];
|
2016-07-18 06:04:39 +00:00
|
|
|
|
}
|
2016-11-12 18:19:17 +00:00
|
|
|
|
|
|
|
|
|
public int TableLength => Table.Length;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public string[][] GetFormList(string[] species, int MaxSpecies)
|
2016-11-12 18:19:17 +00:00
|
|
|
|
{
|
|
|
|
|
string[][] FormList = new string[MaxSpecies+1][];
|
2017-07-29 18:54:52 +00:00
|
|
|
|
for (int i = 0; i < FormList.Length; i++)
|
2016-11-12 18:19:17 +00:00
|
|
|
|
{
|
|
|
|
|
int FormCount = this[i].FormeCount;
|
|
|
|
|
FormList[i] = new string[FormCount];
|
|
|
|
|
if (FormCount <= 0) continue;
|
|
|
|
|
FormList[i][0] = species[i];
|
|
|
|
|
for (int j = 1; j < FormCount; j++)
|
|
|
|
|
FormList[i][j] = $"{species[i]} " + j;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return FormList;
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public string[] GetPersonalEntryList(string[][] AltForms, string[] species, int MaxSpecies, out int[] baseForm, out int[] formVal)
|
2016-11-12 18:19:17 +00:00
|
|
|
|
{
|
|
|
|
|
string[] result = new string[Table.Length];
|
|
|
|
|
baseForm = new int[result.Length];
|
|
|
|
|
formVal = new int[result.Length];
|
|
|
|
|
for (int i = 0; i <= MaxSpecies; i++)
|
|
|
|
|
{
|
|
|
|
|
result[i] = species[i];
|
|
|
|
|
if (AltForms[i].Length == 0) continue;
|
|
|
|
|
int altformpointer = this[i].FormStatsIndex;
|
|
|
|
|
if (altformpointer <= 0) continue;
|
|
|
|
|
for (int j = 1; j < AltForms[i].Length; j++)
|
|
|
|
|
{
|
|
|
|
|
int ptr = altformpointer + j - 1;
|
|
|
|
|
baseForm[ptr] = i;
|
|
|
|
|
formVal[ptr] = j;
|
|
|
|
|
result[ptr] = AltForms[i][j];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
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
|
|
|
|
public bool IsValidTypeCombination(int Type1, int Type2)
|
|
|
|
|
{
|
|
|
|
|
return Table.Any(p => p.Types[0] == Type1 && p.Types[1] == Type2);
|
|
|
|
|
}
|
2016-07-18 05:39:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|