2022-06-29 07:01:14 +00:00
|
|
|
using System;
|
2022-01-03 05:35:59 +00:00
|
|
|
using System.Collections.Generic;
|
2022-06-29 07:01:14 +00:00
|
|
|
using static System.Buffers.Binary.BinaryPrimitives;
|
2019-09-13 06:20:52 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
namespace PKHeX.Core;
|
|
|
|
|
|
|
|
/// <inheritdoc cref="EncounterArea" />
|
|
|
|
/// <summary>
|
|
|
|
/// <see cref="GameVersion.GG"/> encounter area
|
|
|
|
/// </summary>
|
|
|
|
public sealed record EncounterArea7b : EncounterArea
|
2019-09-13 06:20:52 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
public readonly EncounterSlot7b[] Slots;
|
2021-06-30 03:58:06 +00:00
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
protected override IReadOnlyList<EncounterSlot7b> Raw => Slots;
|
2021-06-30 03:58:06 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public static EncounterArea7b[] GetAreas(BinLinkerAccessor input, GameVersion game)
|
|
|
|
{
|
|
|
|
var result = new EncounterArea7b[input.Length];
|
|
|
|
for (int i = 0; i < result.Length; i++)
|
|
|
|
result[i] = new EncounterArea7b(input[i], game);
|
|
|
|
return result;
|
|
|
|
}
|
2020-08-30 17:23:22 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private EncounterArea7b(ReadOnlySpan<byte> data, GameVersion game) : base(game)
|
|
|
|
{
|
2022-06-29 07:01:14 +00:00
|
|
|
Location = ReadInt16LittleEndian(data);
|
2022-06-18 18:04:24 +00:00
|
|
|
Slots = ReadSlots(data);
|
|
|
|
}
|
2020-08-30 17:23:22 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private EncounterSlot7b[] ReadSlots(ReadOnlySpan<byte> data)
|
|
|
|
{
|
|
|
|
const int size = 4;
|
|
|
|
int count = (data.Length - 2) / size;
|
|
|
|
var slots = new EncounterSlot7b[count];
|
|
|
|
for (int i = 0; i < slots.Length; i++)
|
2020-08-30 17:23:22 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
int offset = 2 + (size * i);
|
|
|
|
var entry = data.Slice(offset, size);
|
|
|
|
slots[i] = ReadSlot(entry);
|
2020-08-30 17:23:22 +00:00
|
|
|
}
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
return slots;
|
|
|
|
}
|
|
|
|
|
|
|
|
private EncounterSlot7b ReadSlot(ReadOnlySpan<byte> entry)
|
|
|
|
{
|
2022-08-27 06:43:36 +00:00
|
|
|
ushort species = entry[0]; // always < 255; only original 151
|
2022-06-18 18:04:24 +00:00
|
|
|
// form is always 0
|
|
|
|
byte min = entry[2];
|
|
|
|
byte max = entry[3];
|
|
|
|
return new EncounterSlot7b(this, species, min, max);
|
|
|
|
}
|
2022-01-03 05:35:59 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private const int CatchComboBonus = 1;
|
2019-09-13 06:20:52 +00:00
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
public override IEnumerable<EncounterSlot7b> GetMatchingSlots(PKM pk, EvoCriteria[] chain)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
foreach (var slot in Slots)
|
2019-09-13 06:20:52 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
foreach (var evo in chain)
|
2020-08-21 23:35:49 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (slot.Species != evo.Species)
|
|
|
|
continue;
|
2019-09-13 06:20:52 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
var met = pk.Met_Level;
|
|
|
|
if (!slot.IsLevelWithinRange(met, 0, CatchComboBonus))
|
|
|
|
break;
|
|
|
|
if (slot.Form != evo.Form)
|
2020-08-21 23:35:49 +00:00
|
|
|
break;
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
yield return slot;
|
|
|
|
break;
|
2020-08-21 23:35:49 +00:00
|
|
|
}
|
2019-09-13 06:20:52 +00:00
|
|
|
}
|
|
|
|
}
|
2020-04-13 02:41:03 +00:00
|
|
|
}
|