2020-08-30 17:23:22 +00:00
|
|
|
|
using System.Collections.Generic;
|
2019-09-13 06:20:52 +00:00
|
|
|
|
|
|
|
|
|
namespace PKHeX.Core
|
|
|
|
|
{
|
2021-01-01 18:55:33 +00:00
|
|
|
|
/// <inheritdoc cref="EncounterArea" />
|
2019-09-13 06:20:52 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// <see cref="GameVersion.RBY"/> encounter area
|
|
|
|
|
/// </summary>
|
2021-01-01 18:55:33 +00:00
|
|
|
|
public sealed record EncounterArea1 : EncounterArea
|
2019-09-13 06:20:52 +00:00
|
|
|
|
{
|
2020-08-30 17:23:22 +00:00
|
|
|
|
public readonly int Rate;
|
2021-06-30 03:58:06 +00:00
|
|
|
|
public readonly EncounterSlot1[] Slots;
|
|
|
|
|
|
|
|
|
|
protected override IReadOnlyList<EncounterSlot> Raw => Slots;
|
2019-09-13 06:20:52 +00:00
|
|
|
|
|
2020-08-30 17:23:22 +00:00
|
|
|
|
public static EncounterArea1[] GetAreas(byte[][] input, GameVersion game)
|
2019-09-13 06:20:52 +00:00
|
|
|
|
{
|
2020-08-30 17:23:22 +00:00
|
|
|
|
var result = new EncounterArea1[input.Length];
|
|
|
|
|
for (int i = 0; i < input.Length; i++)
|
|
|
|
|
result[i] = new EncounterArea1(input[i], game);
|
|
|
|
|
return result;
|
2019-09-13 06:20:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-30 18:08:21 +00:00
|
|
|
|
private EncounterArea1(byte[] data, GameVersion game) : base(game)
|
2019-09-13 06:20:52 +00:00
|
|
|
|
{
|
2020-08-30 17:23:22 +00:00
|
|
|
|
Location = data[0];
|
|
|
|
|
// 1 byte unused
|
|
|
|
|
Type = (SlotType)data[2];
|
|
|
|
|
Rate = data[3];
|
2019-09-13 06:20:52 +00:00
|
|
|
|
|
2020-08-30 17:23:22 +00:00
|
|
|
|
int count = (data.Length - 4) / 4;
|
|
|
|
|
var slots = new EncounterSlot1[count];
|
|
|
|
|
for (int i = 0; i < slots.Length; i++)
|
2019-09-13 06:20:52 +00:00
|
|
|
|
{
|
2020-08-30 17:23:22 +00:00
|
|
|
|
int offset = 4 + (4 * i);
|
|
|
|
|
int species = data[offset + 0];
|
|
|
|
|
int slotNum = data[offset + 1];
|
|
|
|
|
int min = data[offset + 2];
|
|
|
|
|
int max = data[offset + 3];
|
2020-08-30 18:08:21 +00:00
|
|
|
|
slots[i] = new EncounterSlot1(this, species, min, max, slotNum);
|
2019-09-13 06:20:52 +00:00
|
|
|
|
}
|
2020-08-30 17:23:22 +00:00
|
|
|
|
Slots = slots;
|
2020-07-19 18:32:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
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-12-29 08:37:59 +00:00
|
|
|
|
int rate = pkm is PK1 {Gen1_NotTradeback: true} pk1 ? pk1.Catch_Rate : -1;
|
2020-08-21 23:35:49 +00:00
|
|
|
|
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-30 17:23:22 +00:00
|
|
|
|
if (slot.LevelMin > evo.Level)
|
2020-08-21 23:35:49 +00:00
|
|
|
|
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
|
|
|
|
}
|