2023-01-22 04:02:33 +00:00
|
|
|
using System;
|
2020-08-30 17:23:22 +00:00
|
|
|
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
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
namespace PKHeX.Core;
|
|
|
|
|
|
|
|
/// <inheritdoc cref="EncounterArea" />
|
|
|
|
/// <summary>
|
|
|
|
/// <see cref="GameVersion.ORAS"/> encounter area
|
|
|
|
/// </summary>
|
|
|
|
public sealed record EncounterArea6AO : EncounterArea
|
2019-09-13 06:20:52 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
public readonly EncounterSlot6AO[] Slots;
|
2021-06-30 03:58:06 +00:00
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
protected override IReadOnlyList<EncounterSlot6AO> Raw => Slots;
|
2021-06-30 03:58:06 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public static EncounterArea6AO[] GetAreas(BinLinkerAccessor input, GameVersion game)
|
|
|
|
{
|
|
|
|
var result = new EncounterArea6AO[input.Length];
|
|
|
|
for (int i = 0; i < result.Length; i++)
|
|
|
|
result[i] = new EncounterArea6AO(input[i], game);
|
|
|
|
return result;
|
|
|
|
}
|
2020-08-30 17:23:22 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private EncounterArea6AO(ReadOnlySpan<byte> data, GameVersion game) : base(game)
|
|
|
|
{
|
|
|
|
Location = ReadInt16LittleEndian(data);
|
|
|
|
Type = (SlotType)data[2];
|
2020-08-30 17:23:22 +00:00
|
|
|
|
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 EncounterSlot6AO[] ReadSlots(ReadOnlySpan<byte> data)
|
|
|
|
{
|
|
|
|
const int size = 4;
|
|
|
|
int count = (data.Length - 4) / size;
|
|
|
|
var slots = new EncounterSlot6AO[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 = 4 + (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 EncounterSlot6AO ReadSlot(ReadOnlySpan<byte> entry)
|
|
|
|
{
|
|
|
|
ushort species = ReadUInt16LittleEndian(entry);
|
|
|
|
byte form = (byte)(species >> 11);
|
|
|
|
species &= 0x3FF;
|
|
|
|
byte min = entry[2];
|
|
|
|
byte max = entry[3];
|
|
|
|
return new EncounterSlot6AO(this, species, form, min, max);
|
|
|
|
}
|
2022-01-03 05:35:59 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private const int FluteBoostMin = 4; // White Flute decreases levels.
|
|
|
|
private const int FluteBoostMax = 4; // Black Flute increases levels.
|
|
|
|
private const int DexNavBoost = 30; // Maximum DexNav chain
|
2019-09-13 06:20:52 +00:00
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
public override IEnumerable<EncounterSlot6AO> 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)
|
2019-09-13 06:20:52 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (slot.Species != evo.Species)
|
|
|
|
continue;
|
2020-08-21 23:35:49 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
var boostMax = Type != SlotType.Rock_Smash ? DexNavBoost : FluteBoostMax;
|
|
|
|
const int boostMin = FluteBoostMin;
|
|
|
|
if (!slot.IsLevelWithinRange(pk.Met_Level, boostMin, boostMax))
|
|
|
|
break;
|
2020-08-21 23:35:49 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (slot.Form != evo.Form && !slot.IsRandomUnspecificForm)
|
2020-08-21 23:35:49 +00:00
|
|
|
break;
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
// Track some metadata about how this slot was matched.
|
|
|
|
var clone = slot with
|
|
|
|
{
|
|
|
|
WhiteFlute = evo.LevelMin < slot.LevelMin,
|
|
|
|
BlackFlute = evo.LevelMin > slot.LevelMax && evo.LevelMin <= slot.LevelMax + FluteBoostMax,
|
|
|
|
DexNav = slot.CanDexNav && (evo.LevelMin != slot.LevelMax || pk.RelearnMove1 != 0 || pk.AbilityNumber == 4),
|
|
|
|
};
|
|
|
|
yield return clone;
|
|
|
|
break;
|
2019-09-13 06:20:52 +00:00
|
|
|
}
|
2020-08-21 23:35:49 +00:00
|
|
|
}
|
2019-09-13 06:20:52 +00:00
|
|
|
}
|
2020-08-21 23:35:49 +00:00
|
|
|
}
|