Add rby encounters

Includes fishing slots
todo on trades/static encounters; feel free to pull request (look at
tables6/7 for ref).
This commit is contained in:
Kurt 2017-02-12 09:52:26 -08:00
parent dc7ac639d2
commit cbccc6a28b
18 changed files with 346 additions and 41 deletions

View file

@ -49,11 +49,9 @@ namespace PKHeX.WinForms
MessageBox.Show("Could not locate PKHeX.Core.dll. Make sure you're running PKHeX together with its code library. Usually caused when all files are not extracted.", "PKHeX Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
return;
}
else
{
// Exception came from Main
throw;
}
// Exception came from Main
throw;
}
}

View file

@ -13,6 +13,8 @@ namespace PKHeX.Core
// Gen 1
private static readonly Learnset[] LevelUpRB = Learnset1.getArray(Resources.lvlmove_rby);
private static readonly EvolutionTree Evolves1;
private static readonly EncounterArea[] SlotsRBY;
private static readonly EncounterStatic[] StaticRBY;
// Gen 6
private static readonly EggMoves[] EggMovesXY = EggMoves6.getArray(Data.unpackMini(Resources.eggmove_xy, "xy"));
@ -36,16 +38,16 @@ namespace PKHeX.Core
EncounterStatic[] table;
switch (Game)
{
case GameVersion.X:
case GameVersion.Y:
case GameVersion.RBY:
table = Encounter_RBY;
break;
case GameVersion.X: case GameVersion.Y:
table = Encounter_XY;
break;
case GameVersion.AS:
case GameVersion.OR:
case GameVersion.AS: case GameVersion.OR:
table = Encounter_AO;
break;
case GameVersion.SN:
case GameVersion.MN:
case GameVersion.SN: case GameVersion.MN:
table = Encounter_SM;
break;
@ -136,6 +138,20 @@ namespace PKHeX.Core
// Gen 1
{
Evolves1 = new EvolutionTree(new[] { Resources.evos_rby }, GameVersion.RBY, PersonalTable.RBY, MaxSpeciesID_1);
var red = EncounterArea.getArray1_GW(Resources.encounter_red);
var blu = EncounterArea.getArray1_GW(Resources.encounter_blue);
var ylw = EncounterArea.getArray1_GW(Resources.encounter_yellow);
var rb_fish = EncounterArea.getArray1_F(Resources.encounter_rb_f);
var ylw_fish = EncounterArea.getArray1_FY(Resources.encounter_yellow_f);
red = addExtraTableSlots(red, rb_fish);
blu = addExtraTableSlots(blu, rb_fish);
ylw = addExtraTableSlots(ylw, ylw_fish);
SlotsRBY = addExtraTableSlots(addExtraTableSlots(red, blu), ylw);
Array.Resize(ref SlotsRBY, SlotsRBY.Length + 1);
SlotsRBY[SlotsRBY.Length - 1] = FishOldGood_RBY;
StaticRBY = getStaticEncounters(GameVersion.RBY);
}
// Gen 6
{
@ -186,6 +202,9 @@ namespace PKHeX.Core
internal static IEnumerable<int> getValidRelearn(PKM pkm, int skipOption)
{
List<int> r = new List<int> { 0 };
if (pkm.Format < 6)
return r;
int species = getBaseSpecies(pkm, skipOption);
r.AddRange(getLVLMoves(pkm, species, 1, pkm.AltForm));
@ -241,7 +260,7 @@ namespace PKHeX.Core
case 6:
return LinkGifts6.FirstOrDefault(g => g.Species == pkm.Species && g.Level == pkm.Met_Level);
default:
return LinkGifts7.FirstOrDefault(g => g.Species == pkm.Species && g.Level == pkm.Met_Level);
return null;
}
}
internal static EncounterSlot[] getValidWildEncounters(PKM pkm)
@ -263,7 +282,7 @@ namespace PKHeX.Core
continue;
if (e.EggLocation != pkm.Egg_Location)
continue;
if (e.Location != 0 && e.Location != pkm.Met_Location)
if (pkm.HasOriginalMetLocation && e.Location != 0 && e.Location != pkm.Met_Location)
continue;
if (e.Gender != -1 && e.Gender != pkm.Gender)
continue;
@ -297,11 +316,13 @@ namespace PKHeX.Core
IEnumerable<DexLevel> p = getValidPreEvolutions(pkm);
EncounterTrade[] table = null;
if (pkm.XY)
if (pkm.VC1)
table = TradeGift_RBY;
else if (pkm.XY)
table = TradeGift_XY;
if (pkm.AO)
else if (pkm.AO)
table = TradeGift_AO;
if (pkm.SM)
else if (pkm.SM)
table = TradeGift_SM;
EncounterTrade z = table?.FirstOrDefault(f => p.Any(r => r.Species == f.Species));
@ -319,7 +340,7 @@ namespace PKHeX.Core
return null;
if (z.SID != pkm.SID)
return null;
if (z.Location != pkm.Met_Location)
if (pkm.HasOriginalMetLocation && z.Location != pkm.Met_Location)
return null;
if (z.Level != pkm.Met_Level)
return null;
@ -365,13 +386,16 @@ namespace PKHeX.Core
{
switch (pkm.Format)
{
case 1:
return Evolves1;
case 6:
return Evolves6;
case 7:
return Evolves7;
default:
return Evolves6;
return Evolves7;
}
}
@ -400,12 +424,11 @@ namespace PKHeX.Core
internal static int getMaxSpeciesOrigin(PKM pkm)
{
if (pkm.Format == 1 || pkm.VC1) //Gen1 VC could not trade with gen 2 yet
if (pkm.Format == 1 || pkm.VC1) // Gen1 VC could not trade with gen 2 yet
return getMaxSpeciesOrigin(1);
else if (pkm.Format == 2 || pkm.VC2)
if (pkm.Format == 2 || pkm.VC2)
return getMaxSpeciesOrigin(2);
else
return getMaxSpeciesOrigin(pkm.GenNumber);
return getMaxSpeciesOrigin(pkm.GenNumber);
}
internal static IEnumerable<MysteryGift> getValidGifts(PKM pkm)
@ -540,10 +563,23 @@ namespace PKHeX.Core
{
switch (pkm.GenNumber)
{
case 1:
return WildPokeBalls1;
case 2:
return WildPokeBalls2;
case 3:
return WildPokeBalls3;
case 4:
return pkm.HGSS ? WildPokeBalls4_HGSS : WildPokeBalls4_DPPt;
case 5:
return WildPokeBalls5;
case 6:
return WildPokeballs6;
case 7:
return WildPokeballs7;
default:
return WildPokeballs6;
return null;
}
}
@ -624,6 +660,9 @@ namespace PKHeX.Core
{
switch (gen)
{
case 1:
return getCanBeCaptured(species, SlotsRBY, StaticRBY);
case 6:
switch (version)
{
@ -761,6 +800,10 @@ namespace PKHeX.Core
private static IEnumerable<int> getLVLMoves(PKM pkm, int species, int lvl, int formnum)
{
List<int> moves = new List<int>();
if (pkm.InhabitedGeneration(1))
{
moves.AddRange(LevelUpRB[species].getMoves(lvl));
}
if (pkm.InhabitedGeneration(6))
{
int ind_XY = PersonalTable.XY.getFormeIndex(species, formnum);
@ -777,49 +820,62 @@ namespace PKHeX.Core
}
private static IEnumerable<EncounterArea> getEncounterSlots(PKM pkm, int lvl = -1)
{
switch (pkm.Version)
switch ((GameVersion)pkm.Version)
{
case (int)GameVersion.X:
case GameVersion.RD: case GameVersion.BU:
case GameVersion.GN: case GameVersion.YW:
return getSlots(pkm, SlotsRBY, lvl);
case GameVersion.X:
return getSlots(pkm, SlotsX, lvl);
case (int)GameVersion.Y:
case GameVersion.Y:
return getSlots(pkm, SlotsY, lvl);
case (int)GameVersion.AS:
case GameVersion.AS:
return getSlots(pkm, SlotsA, lvl);
case (int)GameVersion.OR:
case GameVersion.OR:
return getSlots(pkm, SlotsO, lvl);
case (int)GameVersion.SN:
case GameVersion.SN:
return getSlots(pkm, SlotsSN, lvl);
case (int)GameVersion.MN:
case GameVersion.MN:
return getSlots(pkm, SlotsMN, lvl);
default: return new List<EncounterArea>();
}
}
private static IEnumerable<EncounterStatic> getStaticEncounters(PKM pkm, int lvl = -1)
{
switch (pkm.Version)
switch ((GameVersion)pkm.Version)
{
case (int)GameVersion.X:
case GameVersion.RD: case GameVersion.BU:
case GameVersion.GN: case GameVersion.YW:
return getStatic(pkm, StaticRBY, lvl);
case GameVersion.X:
return getStatic(pkm, StaticX, lvl);
case (int)GameVersion.Y:
case GameVersion.Y:
return getStatic(pkm, StaticY, lvl);
case (int)GameVersion.AS:
case GameVersion.AS:
return getStatic(pkm, StaticA, lvl);
case (int)GameVersion.OR:
case GameVersion.OR:
return getStatic(pkm, StaticO, lvl);
case (int)GameVersion.SN:
case GameVersion.SN:
return getStatic(pkm, StaticSN, lvl);
case (int)GameVersion.MN:
case GameVersion.MN:
return getStatic(pkm, StaticMN, lvl);
default: return new List<EncounterStatic>();
}
}
private static IEnumerable<EncounterArea> getEncounterAreas(PKM pkm)
{
return getEncounterSlots(pkm).Where(l => l.Location == pkm.Met_Location);
var slots = getEncounterSlots(pkm);
bool noMet = !pkm.HasOriginalMetLocation;
return noMet ? slots : slots.Where(area => area.Location == pkm.Met_Location);
}
private static IEnumerable<EncounterSlot> getValidEncounterSlots(PKM pkm, EncounterArea loc, bool DexNav, bool ignoreLevel = false)
{
const int fluteBoost = 4;
int fluteBoost = pkm.Format < 3 ? 0 : 4;
const int dexnavBoost = 30;
int df = DexNav ? fluteBoost : 0;
@ -1036,6 +1092,9 @@ namespace PKHeX.Core
PersonalInfo info = pkm.PersonalInfo;
List<int> moves = new List<int>();
if (pkm.Format < 3)
return moves;
// Type Tutors -- Pledge moves and High BP moves switched places in G7+
if (pkm.Format <= 6)
moves.AddRange(TypeTutor6.Where((t, i) => info.TypeTutors[i]));

View file

@ -1,4 +1,5 @@
using System;
using System.Linq;
namespace PKHeX.Core
{
@ -24,6 +25,117 @@ namespace PKHeX.Core
};
}
}
private static EncounterSlot1[] getSlots1_GW(byte[] data, ref int ofs, SlotType t)
{
int rate = data[ofs++];
return rate == 0 ? new EncounterSlot1[0] : readSlots(data, ref ofs, 10, t, rate);
}
private static EncounterSlot1[] getSlots1_F(byte[] data, ref int ofs)
{
int count = data[ofs++];
return readSlots(data, ref ofs, count, SlotType.Super_Rod, -1);
}
/// <summary>
/// RBY Format Slot Getter from data.
/// </summary>
/// <param name="data">Byte array containing complete slot data table.</param>
/// <param name="ofs">Offset to start reading from.</param>
/// <param name="count">Amount of slots to read.</param>
/// <param name="t">Type of encounter slot.</param>
/// <param name="rate">Slot type encounter rate.</param>
/// <returns>Array of encounter slots.</returns>
private static EncounterSlot1[] readSlots(byte[] data, ref int ofs, int count, SlotType t, int rate)
{
EncounterSlot1[] slots = new EncounterSlot1[count];
for (int i = 0; i < count; i++)
{
int lvl = data[ofs++];
int spec = data[ofs++];
slots[i] = new EncounterSlot1
{
LevelMax = lvl,
LevelMin = lvl,
Species = spec,
Type = t,
Rate = rate,
};
}
return slots;
}
public static EncounterArea[] getArray1_GW(byte[] data)
{
// RBY Format
var ptr = new int[255];
int count = 0;
for (int i = 0; i < ptr.Length; i++)
{
ptr[i] = BitConverter.ToInt16(data, i*2);
if (ptr[i] != -1)
continue;
count = i;
break;
}
EncounterArea[] areas = new EncounterArea[count];
for (int i = 0; i < areas.Length; i++)
{
var grass = getSlots1_GW(data, ref ptr[i], SlotType.Grass);
var water = getSlots1_GW(data, ref ptr[i], SlotType.Surf);
areas[i] = new EncounterArea
{
Location = i,
Slots = grass.Concat(water).ToArray()
};
}
return areas.Where(area => area.Slots.Any()).ToArray();
}
public static EncounterArea[] getArray1_FY(byte[] data)
{
const int size = 9;
int count = data.Length/size;
EncounterArea[] areas = new EncounterArea[count];
for (int i = 0; i < count; i++)
{
int ofs = i*size + 1;
areas[i] = new EncounterArea
{
Location = data[i*size + 0],
Slots = readSlots(data, ref ofs, 4, SlotType.Super_Rod, -1)
};
}
return areas;
}
public static EncounterArea[] getArray1_F(byte[] data)
{
var ptr = new int[255];
var map = new int[255];
int count = 0;
for (int i = 0; i < ptr.Length; i++)
{
map[i] = data[i*3 + 0];
if (map[i] == 0xFF)
{
count = i;
break;
}
ptr[i] = BitConverter.ToInt16(data, i * 3 + 1);
}
EncounterArea[] areas = new EncounterArea[count];
for (int i = 0; i < areas.Length; i++)
{
areas[i] = new EncounterArea
{
Location = map[i],
Slots = getSlots1_F(data, ref ptr[i])
};
}
return areas;
}
public static EncounterArea[] getArray(byte[][] entries)
{
if (entries == null)
@ -35,5 +147,4 @@ namespace PKHeX.Core
return data;
}
}
}

View file

@ -27,4 +27,17 @@
public string Name => "Wild Encounter";
}
public class EncounterSlot1 : EncounterSlot
{
public int Rate;
public EncounterSlot1() { }
public EncounterSlot1(EncounterSlot1 template)
{
Species = template.Species;
LevelMax = template.LevelMax;
LevelMin = template.LevelMin;
Type = template.Type;
Rate = template.Rate;
}
}
}

View file

@ -30,5 +30,32 @@ namespace PKHeX.Core
};
internal static readonly int[] TransferSpeciesDefaultAbility_1 = {92, 93, 94, 109, 110, 151};
internal static readonly int[] TMHM_RBY =
{
005, 013, 014, 018, 025, 092, 032, 034, 036, 038,
061, 055, 058, 059, 063, 006, 066, 068, 069, 099,
072, 076, 082, 085, 087, 089, 090, 091, 094, 100,
102, 104, 115, 117, 118, 120, 121, 126, 129, 130,
135, 138, 143, 156, 086, 149, 153, 157, 161, 164,
015, 019, 057, 070, 148
};
internal static readonly int[] WildPokeBalls1 = {4};
internal static readonly EncounterStatic[] Encounter_RBY =
{
// todo
};
internal static readonly EncounterTrade[] TradeGift_RBY =
{
// todo
};
internal static readonly EncounterArea FishOldGood_RBY = new EncounterArea { Location = -1, Slots = new EncounterSlot[]
{
new EncounterSlot1 {Species = 129, LevelMin = 05, LevelMax = 05, Type = SlotType.Old_Rod, Rate = -1, }, // Magikarp
new EncounterSlot1 {Species = 118, LevelMin = 10, LevelMax = 10, Type = SlotType.Good_Rod, Rate = -1, }, // Goldeen
new EncounterSlot1 {Species = 060, LevelMin = 10, LevelMax = 10, Type = SlotType.Good_Rod, Rate = -1, }, // Poliwag
}};
}
}

View file

@ -35,5 +35,6 @@ namespace PKHeX.Core
10, 05, 10, 20, 20, 40, 15, 10, 20, 20, 25, 05, 15, 10, 05, 20, 15, 20, 25, 20, 05, 30, 05, 10, 20, 40, 05, 20, 40, 20, 15, 35, 10, 05, 05, 05, 15, 05, 20, 05, 05, 15, 20, 10, 05, 05, 15, 15, 15, 15,
10, 00, 00, 00, 00
};
internal static readonly int[] WildPokeBalls2 = { 4 };
}
}

View file

@ -81,5 +81,6 @@ namespace PKHeX.Core
580, 581, 582, 583, 584, 585, 586, 587, 588, 589,
590, 591, 592, 593
};
internal static readonly int[] WildPokeBalls3 = {1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 12};
}
}

View file

@ -118,5 +118,17 @@ namespace PKHeX.Core
10, 15, 20, 15, 10, 10, 10, 20, 05, 30, 05, 10, 15, 10, 10, 05, 20, 30, 10, 30, 15, 15, 15, 15, 30, 10, 20, 15, 10, 10, 20, 15, 05, 05, 15, 15, 05, 10, 05, 20, 05, 15, 20, 05, 20, 20, 20, 20, 10, 20,
10, 15, 20, 15, 10, 10, 05, 10, 05, 05, 10, 05, 05, 10, 05, 05, 05,
};
internal static readonly int[] WildPokeBalls4_DPPt =
{
1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
// Cherish ball not usable
};
internal static readonly int[] WildPokeBalls4_HGSS =
{
1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
// Cherish ball not usable
17, 18, 19, 20, 21, 22,
// Comp Ball not usable in wild
};
}
}

View file

@ -82,5 +82,12 @@ namespace PKHeX.Core
15, 15, 15, 15, 10, 10, 10, 10, 10, 15, 15, 15, 15, 05, 05, 15, 05, 10, 10, 10, 20, 20, 20, 10, 10, 30, 15, 15, 10, 15, 25, 10, 20, 10, 10, 10, 20, 10, 10, 10, 10, 10, 15, 15, 05, 05, 10, 10, 10, 05,
05, 10, 05, 05, 15, 10, 05, 05, 05,
};
internal static readonly int[] WildPokeBalls5 =
{
1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
// Cherish ball not usable
// HGSS balls not usable
// Dream ball not usable in wild
};
}
}

View file

@ -261,10 +261,15 @@
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<None Include="Resources\byte\eggmove_sm.pkl" />
<None Include="Resources\byte\encounter_blue.pkl" />
<None Include="Resources\byte\encounter_mn.pkl" />
<None Include="Resources\byte\encounter_mn_sos.pkl" />
<None Include="Resources\byte\encounter_rb_f.pkl" />
<None Include="Resources\byte\encounter_red.pkl" />
<None Include="Resources\byte\encounter_sn.pkl" />
<None Include="Resources\byte\encounter_sn_sos.pkl" />
<None Include="Resources\byte\encounter_yellow.pkl" />
<None Include="Resources\byte\encounter_yellow_f.pkl" />
<None Include="Resources\byte\evos_rby.pkl" />
<None Include="Resources\byte\evos_sm.pkl" />
<None Include="Resources\byte\fashion_f_sm" />

View file

@ -268,7 +268,7 @@ namespace PKHeX.Core
public bool AO => Version == (int)GameVersion.AS || Version == (int)GameVersion.OR;
public bool SM => Version == (int)GameVersion.SN || Version == (int)GameVersion.MN;
protected bool PtHGSS => GameVersion.Pt == (GameVersion)Version || HGSS;
protected bool HGSS => new[] {GameVersion.HG, GameVersion.SS}.Contains((GameVersion)Version);
public bool HGSS => new[] {GameVersion.HG, GameVersion.SS}.Contains((GameVersion)Version);
public bool VC => VC1 || VC2;
public bool Gen7 => Version >= 30 && Version <= 33;
public bool Gen6 => Version >= 24 && Version <= 29;
@ -478,6 +478,12 @@ namespace PKHeX.Core
}
}
/// <summary>
/// Checks if the PKM has its original met location.
/// </summary>
/// <returns>Returns false if the Met Location has been overwritten via generational transfer.</returns>
public bool HasOriginalMetLocation => !(GenNumber <= 4 && Format > 4 || VC);
/// <summary>
/// Checks if the current <see cref="Gender"/> is valid.
/// </summary>

View file

@ -12461,6 +12461,16 @@ namespace PKHeX.Core.Properties {
}
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// </summary>
public static byte[] encounter_blue {
get {
object obj = ResourceManager.GetObject("encounter_blue", resourceCulture);
return ((byte[])(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// </summary>
@ -12491,6 +12501,26 @@ namespace PKHeX.Core.Properties {
}
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// </summary>
public static byte[] encounter_rb_f {
get {
object obj = ResourceManager.GetObject("encounter_rb_f", resourceCulture);
return ((byte[])(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// </summary>
public static byte[] encounter_red {
get {
object obj = ResourceManager.GetObject("encounter_red", resourceCulture);
return ((byte[])(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// </summary>
@ -12531,6 +12561,26 @@ namespace PKHeX.Core.Properties {
}
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// </summary>
public static byte[] encounter_yellow {
get {
object obj = ResourceManager.GetObject("encounter_yellow", resourceCulture);
return ((byte[])(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// </summary>
public static byte[] encounter_yellow_f {
get {
object obj = ResourceManager.GetObject("encounter_yellow_f", resourceCulture);
return ((byte[])(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// </summary>

View file

@ -7390,4 +7390,19 @@
<data name="lvlmove_rby" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\byte\lvlmove_rby.pkl;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="encounter_blue" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\byte\encounter_blue.pkl;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="encounter_red" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\byte\encounter_red.pkl;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="encounter_yellow" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\byte\encounter_yellow.pkl;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="encounter_rb_f" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\byte\encounter_rb_f.pkl;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="encounter_yellow_f" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\byte\encounter_yellow_f.pkl;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
</root>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.