2019-09-13 06:20:52 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace PKHeX.Core
|
|
|
|
|
{
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <see cref="GameVersion.RBY"/> encounter area
|
|
|
|
|
/// </summary>
|
2020-07-19 18:32:40 +00:00
|
|
|
|
public sealed class EncounterArea1 : EncounterArea
|
2019-09-13 06:20:52 +00:00
|
|
|
|
{
|
|
|
|
|
private static EncounterSlot1[] ReadSlots1FishingYellow(byte[] data, ref int ofs, int count, SlotType t, int rate)
|
|
|
|
|
{
|
|
|
|
|
// Convert byte to actual number
|
2020-07-19 19:08:56 +00:00
|
|
|
|
byte[] levels = { 0xFF, 0x15, 0x67, 0x1D, 0x3B, 0x5C, 0x72, 0x16, 0x71, 0x18, 0x00, 0x6D, 0x80, };
|
|
|
|
|
byte[] g1DexIDs = { 0x47, 0x6E, 0x18, 0x9B, 0x17, 0x4E, 0x8A, 0x5C, 0x5D, 0x9D, 0x9E, 0x1B, 0x85, 0x16, 0x58, 0x59, };
|
|
|
|
|
int[] speciesIDs = { 060, 061, 072, 073, 090, 098, 099, 116, 117, 118, 119, 120, 129, 130, 147, 148, };
|
2019-09-13 06:20:52 +00:00
|
|
|
|
|
2020-07-19 19:08:56 +00:00
|
|
|
|
var slots = new EncounterSlot1[count];
|
|
|
|
|
for (int slot = 0; slot < count; slot++)
|
2019-09-13 06:20:52 +00:00
|
|
|
|
{
|
2020-07-19 19:08:56 +00:00
|
|
|
|
int species = speciesIDs[Array.IndexOf(g1DexIDs, data[ofs++])];
|
|
|
|
|
int lvl = Array.IndexOf(levels, data[ofs++]) * 5;
|
|
|
|
|
slots[slot] = new EncounterSlot1(species, lvl, lvl, rate, t, slot);
|
2019-09-13 06:20:52 +00:00
|
|
|
|
}
|
|
|
|
|
return slots;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the encounter areas with <see cref="EncounterSlot"/> information from Generation 1 Grass/Water data.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="data">Input raw data.</param>
|
2020-07-19 19:08:56 +00:00
|
|
|
|
/// <param name="count">Count of areas in the binary.</param>
|
2019-09-13 06:20:52 +00:00
|
|
|
|
/// <returns>Array of encounter areas.</returns>
|
2020-07-19 19:08:56 +00:00
|
|
|
|
public static EncounterArea1[] GetArray1GrassWater(byte[] data, int count)
|
2019-09-13 06:20:52 +00:00
|
|
|
|
{
|
|
|
|
|
EncounterArea1[] areas = new EncounterArea1[count];
|
|
|
|
|
for (int i = 0; i < areas.Length; i++)
|
|
|
|
|
{
|
2020-07-19 19:08:56 +00:00
|
|
|
|
int ptr = BitConverter.ToInt16(data, i * 2);
|
|
|
|
|
var grass = GetSlots1GrassWater(data, ref ptr, SlotType.Grass);
|
|
|
|
|
var water = GetSlots1GrassWater(data, ref ptr, SlotType.Surf);
|
2019-09-13 06:20:52 +00:00
|
|
|
|
areas[i] = new EncounterArea1
|
|
|
|
|
{
|
|
|
|
|
Location = i,
|
2020-07-19 18:32:40 +00:00
|
|
|
|
Slots = ArrayUtil.ConcatAll(grass, water),
|
2019-09-13 06:20:52 +00:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
return areas.Where(area => area.Slots.Length != 0).ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the encounter areas with <see cref="EncounterSlot"/> information from Pokémon Yellow (Generation 1) Fishing data.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="data">Input raw data.</param>
|
|
|
|
|
/// <returns>Array of encounter areas.</returns>
|
|
|
|
|
public static EncounterArea1[] GetArray1FishingYellow(byte[] data)
|
|
|
|
|
{
|
|
|
|
|
const int size = 9;
|
|
|
|
|
int count = data.Length / size;
|
|
|
|
|
EncounterArea1[] areas = new EncounterArea1[count];
|
|
|
|
|
for (int i = 0; i < count; i++)
|
|
|
|
|
{
|
|
|
|
|
int ofs = (i * size) + 1;
|
|
|
|
|
areas[i] = new EncounterArea1
|
|
|
|
|
{
|
|
|
|
|
Location = data[(i * size) + 0],
|
|
|
|
|
Slots = ReadSlots1FishingYellow(data, ref ofs, 4, SlotType.Super_Rod, -1)
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
return areas;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the encounter areas with <see cref="EncounterSlot"/> information from Generation 1 Fishing data.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="data">Input raw data.</param>
|
2020-07-19 19:08:56 +00:00
|
|
|
|
/// <param name="count">Count of areas in the binary.</param>
|
2019-09-13 06:20:52 +00:00
|
|
|
|
/// <returns>Array of encounter areas.</returns>
|
2020-07-19 19:08:56 +00:00
|
|
|
|
public static EncounterArea1[] GetArray1Fishing(byte[] data, int count)
|
2019-09-13 06:20:52 +00:00
|
|
|
|
{
|
|
|
|
|
EncounterArea1[] areas = new EncounterArea1[count];
|
|
|
|
|
for (int i = 0; i < areas.Length; i++)
|
|
|
|
|
{
|
2020-07-19 19:08:56 +00:00
|
|
|
|
int loc = data[(i * 3) + 0];
|
|
|
|
|
int ptr = BitConverter.ToInt16(data, (i * 3) + 1);
|
2019-09-13 06:20:52 +00:00
|
|
|
|
areas[i] = new EncounterArea1
|
|
|
|
|
{
|
2020-07-19 19:08:56 +00:00
|
|
|
|
Location = loc,
|
|
|
|
|
Slots = GetSlots1Fishing(data, ptr)
|
2019-09-13 06:20:52 +00:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
return areas;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-19 18:32:40 +00:00
|
|
|
|
private static EncounterSlot1[] GetSlots1GrassWater(byte[] data, ref int ofs, SlotType t)
|
2019-09-13 06:20:52 +00:00
|
|
|
|
{
|
|
|
|
|
int rate = data[ofs++];
|
2020-07-19 18:32:40 +00:00
|
|
|
|
return rate == 0 ? Array.Empty<EncounterSlot1>() : EncounterSlot1.ReadSlots(data, ref ofs, 10, t, rate);
|
2019-09-13 06:20:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-19 19:08:56 +00:00
|
|
|
|
private static EncounterSlot1[] GetSlots1Fishing(byte[] data, int ofs)
|
2019-09-13 06:20:52 +00:00
|
|
|
|
{
|
|
|
|
|
int count = data[ofs++];
|
2020-07-19 18:32:40 +00:00
|
|
|
|
return EncounterSlot1.ReadSlots(data, ref ofs, count, SlotType.Super_Rod, -1);
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-21 23:35:49 +00:00
|
|
|
|
public override IEnumerable<EncounterSlot> GetMatchingSlots(PKM pkm, IReadOnlyList<EvoCriteria> chain)
|
2020-07-19 18:32:40 +00:00
|
|
|
|
{
|
2020-08-21 23:35:49 +00:00
|
|
|
|
int rate = pkm is PK1 pk1 && pkm.Gen1_NotTradeback ? pk1.Catch_Rate : -1;
|
|
|
|
|
foreach (var slot in Slots)
|
|
|
|
|
{
|
|
|
|
|
foreach (var evo in chain)
|
|
|
|
|
{
|
|
|
|
|
if (slot.Species != evo.Species)
|
|
|
|
|
continue;
|
2020-07-19 18:32:40 +00:00
|
|
|
|
|
2020-08-21 23:35:49 +00:00
|
|
|
|
if (!slot.IsLevelWithinRange(evo.MinLevel, evo.Level))
|
|
|
|
|
break;
|
|
|
|
|
if (slot.Form != evo.Form)
|
|
|
|
|
break;
|
2020-07-19 18:32:40 +00:00
|
|
|
|
|
2020-08-21 23:35:49 +00:00
|
|
|
|
if (rate != -1)
|
|
|
|
|
{
|
|
|
|
|
var expect = (slot.Version == GameVersion.YW ? PersonalTable.Y : PersonalTable.RB)[slot.Species].CatchRate;
|
|
|
|
|
if (expect != rate)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
yield return slot;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-09-13 06:20:52 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-07-19 18:32:40 +00:00
|
|
|
|
}
|