2022-01-03 05:35:59 +00:00
|
|
|
|
using System;
|
|
|
|
|
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
|
|
|
|
|
2022-02-05 01:20:56 +00:00
|
|
|
|
public static EncounterArea1[] GetAreas(BinLinkerAccessor 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];
|
2022-02-05 01:20:56 +00:00
|
|
|
|
for (int i = 0; i < result.Length; i++)
|
2020-08-30 17:23:22 +00:00
|
|
|
|
result[i] = new EncounterArea1(input[i], game);
|
|
|
|
|
return result;
|
2019-09-13 06:20:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-03 05:35:59 +00:00
|
|
|
|
private EncounterArea1(ReadOnlySpan<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
|
|
|
|
|
2022-03-07 06:47:03 +00:00
|
|
|
|
var next = data[4..];
|
|
|
|
|
int count = next.Length / 4;
|
2020-08-30 17:23:22 +00:00
|
|
|
|
var slots = new EncounterSlot1[count];
|
|
|
|
|
for (int i = 0; i < slots.Length; i++)
|
2019-09-13 06:20:52 +00:00
|
|
|
|
{
|
2022-03-07 06:47:03 +00:00
|
|
|
|
const int size = 4;
|
2022-03-11 02:04:39 +00:00
|
|
|
|
var entry = next.Slice(i * size, size);
|
2022-03-07 07:25:47 +00:00
|
|
|
|
byte max = entry[3];
|
|
|
|
|
byte min = entry[2];
|
2022-03-07 06:47:03 +00:00
|
|
|
|
byte slotNum = entry[1];
|
2022-03-07 07:25:47 +00:00
|
|
|
|
byte species = entry[0];
|
2022-03-07 06:47:03 +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
|
|
|
|
{
|
2021-08-20 22:59:54 +00:00
|
|
|
|
int rate = pkm is PK1 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
|
|
|
|
|
2022-04-24 04:33:17 +00:00
|
|
|
|
if (slot.LevelMin > evo.LevelMax)
|
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;
|
2022-01-02 23:03:04 +00:00
|
|
|
|
if (expect != rate && !(ParseSettings.AllowGen1Tradeback && GBRestrictions.IsTradebackCatchRate(rate)))
|
2020-08-21 23:35:49 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
yield return slot;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-09-13 06:20:52 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-07-19 18:32:40 +00:00
|
|
|
|
}
|