2020-08-30 17:23:22 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2022-01-03 05:35:59 +00:00
|
|
|
|
using static System.Buffers.Binary.BinaryPrimitives;
|
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.Gen7"/> encounter area
|
|
|
|
|
/// </summary>
|
2021-01-01 18:55:33 +00:00
|
|
|
|
public sealed record EncounterArea7 : EncounterArea
|
2019-09-13 06:20:52 +00:00
|
|
|
|
{
|
2021-06-30 03:58:06 +00:00
|
|
|
|
public readonly EncounterSlot7[] Slots;
|
|
|
|
|
|
|
|
|
|
protected override IReadOnlyList<EncounterSlot> Raw => Slots;
|
|
|
|
|
|
2022-02-05 01:20:56 +00:00
|
|
|
|
public static EncounterArea7[] GetAreas(BinLinkerAccessor input, GameVersion game)
|
2020-08-30 17:23:22 +00:00
|
|
|
|
{
|
|
|
|
|
var result = new EncounterArea7[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 EncounterArea7(input[i], game);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-03 05:35:59 +00:00
|
|
|
|
private EncounterArea7(ReadOnlySpan<byte> data, GameVersion game) : base(game)
|
2020-08-30 17:23:22 +00:00
|
|
|
|
{
|
|
|
|
|
Location = data[0] | (data[1] << 8);
|
|
|
|
|
Type = (SlotType)data[2];
|
|
|
|
|
|
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 EncounterSlot7[] ReadSlots(ReadOnlySpan<byte> data)
|
2020-08-30 17:23:22 +00:00
|
|
|
|
{
|
|
|
|
|
const int size = 4;
|
|
|
|
|
int count = (data.Length - 4) / size;
|
|
|
|
|
var slots = new EncounterSlot7[count];
|
|
|
|
|
for (int i = 0; i < slots.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
int offset = 4 + (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 EncounterSlot7 ReadSlot(ReadOnlySpan<byte> entry)
|
|
|
|
|
{
|
2022-03-07 07:25:47 +00:00
|
|
|
|
ushort species = ReadUInt16LittleEndian(entry);
|
|
|
|
|
byte form = (byte)(species >> 11);
|
|
|
|
|
species &= 0x3FF;
|
|
|
|
|
byte min = entry[2];
|
|
|
|
|
byte max = entry[3];
|
2022-01-03 05:35:59 +00:00
|
|
|
|
return new EncounterSlot7(this, species, form, min, max);
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-08 01:29:36 +00:00
|
|
|
|
public override IEnumerable<EncounterSlot> GetMatchingSlots(PKM pkm, EvoCriteria[] chain)
|
2019-09-13 06:20:52 +00:00
|
|
|
|
{
|
2020-08-21 23:35:49 +00:00
|
|
|
|
foreach (var slot in Slots)
|
2019-09-13 06:20:52 +00:00
|
|
|
|
{
|
2020-08-21 23:35:49 +00:00
|
|
|
|
foreach (var evo in chain)
|
2019-09-13 06:20:52 +00:00
|
|
|
|
{
|
2020-08-21 23:35:49 +00:00
|
|
|
|
if (slot.Species != evo.Species)
|
|
|
|
|
continue;
|
2019-09-13 06:20:52 +00:00
|
|
|
|
|
2020-08-21 23:35:49 +00:00
|
|
|
|
if (!slot.IsLevelWithinRange(pkm.Met_Level))
|
|
|
|
|
break;
|
2019-09-13 06:20:52 +00:00
|
|
|
|
|
2021-09-07 22:35:36 +00:00
|
|
|
|
if (slot.Form != evo.Form && slot.Species is not ((int)Species.Furfrou or (int)Species.Oricorio))
|
2020-08-21 23:35:49 +00:00
|
|
|
|
{
|
2021-08-01 05:41:52 +00:00
|
|
|
|
if (!slot.IsRandomUnspecificForm) // Minior, etc
|
2020-08-21 23:35:49 +00:00
|
|
|
|
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-08-21 23:35:49 +00:00
|
|
|
|
}
|