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.GG"/> encounter area
|
|
|
|
|
/// </summary>
|
2021-01-01 18:55:33 +00:00
|
|
|
|
public sealed record EncounterArea7b : EncounterArea
|
2019-09-13 06:20:52 +00:00
|
|
|
|
{
|
2021-06-30 03:58:06 +00:00
|
|
|
|
public readonly EncounterSlot7b[] Slots;
|
|
|
|
|
|
|
|
|
|
protected override IReadOnlyList<EncounterSlot> Raw => Slots;
|
|
|
|
|
|
2020-08-30 17:23:22 +00:00
|
|
|
|
public static EncounterArea7b[] GetAreas(byte[][] input, GameVersion game)
|
|
|
|
|
{
|
|
|
|
|
var result = new EncounterArea7b[input.Length];
|
|
|
|
|
for (int i = 0; i < input.Length; i++)
|
|
|
|
|
result[i] = new EncounterArea7b(input[i], game);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-03 05:35:59 +00:00
|
|
|
|
private EncounterArea7b(ReadOnlySpan<byte> data, GameVersion game) : base(game)
|
2020-08-30 17:23:22 +00:00
|
|
|
|
{
|
|
|
|
|
Location = data[0] | (data[1] << 8);
|
2020-08-30 18:08:21 +00:00
|
|
|
|
Slots = ReadSlots(data);
|
2020-08-30 17:23:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-03 05:35:59 +00:00
|
|
|
|
private EncounterSlot7b[] ReadSlots(ReadOnlySpan<byte> data)
|
2020-08-30 17:23:22 +00:00
|
|
|
|
{
|
|
|
|
|
const int size = 4;
|
|
|
|
|
int count = (data.Length - 2) / size;
|
|
|
|
|
var slots = new EncounterSlot7b[count];
|
|
|
|
|
for (int i = 0; i < slots.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
int offset = 2 + (size * i);
|
2022-01-03 05:35:59 +00:00
|
|
|
|
var entry = data.Slice(offset, size);
|
|
|
|
|
slots[i] = ReadSlot(entry);
|
2020-08-30 17:23:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return slots;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-03 05:35:59 +00:00
|
|
|
|
private EncounterSlot7b ReadSlot(ReadOnlySpan<byte> entry)
|
|
|
|
|
{
|
|
|
|
|
int species = entry[0]; // always < 255; only original 151
|
|
|
|
|
// form is always 0
|
|
|
|
|
int min = entry[2];
|
|
|
|
|
int max = entry[3];
|
|
|
|
|
return new EncounterSlot7b(this, species, min, max);
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-13 06:20:52 +00:00
|
|
|
|
private const int CatchComboBonus = 1;
|
|
|
|
|
|
2020-08-21 23:35:49 +00:00
|
|
|
|
public override IEnumerable<EncounterSlot> GetMatchingSlots(PKM pkm, IReadOnlyList<EvoCriteria> chain)
|
2019-09-13 06:20:52 +00:00
|
|
|
|
{
|
2020-08-21 23:35:49 +00:00
|
|
|
|
foreach (var slot in Slots)
|
|
|
|
|
{
|
|
|
|
|
foreach (var evo in chain)
|
|
|
|
|
{
|
|
|
|
|
if (slot.Species != evo.Species)
|
|
|
|
|
continue;
|
2019-09-13 06:20:52 +00:00
|
|
|
|
|
2020-08-21 23:35:49 +00:00
|
|
|
|
var met = pkm.Met_Level;
|
|
|
|
|
if (!slot.IsLevelWithinRange(met, 0, CatchComboBonus))
|
|
|
|
|
break;
|
|
|
|
|
if (slot.Form != evo.Form)
|
|
|
|
|
break;
|
2019-09-13 06:20:52 +00:00
|
|
|
|
|
2020-08-21 23:35:49 +00:00
|
|
|
|
yield return slot;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-09-13 06:20:52 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-04-13 02:41:03 +00:00
|
|
|
|
}
|