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