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.XY"/> encounter area
|
|
|
|
|
/// </summary>
|
2021-01-01 18:55:33 +00:00
|
|
|
|
public sealed record EncounterArea6XY : EncounterArea
|
2019-09-13 06:20:52 +00:00
|
|
|
|
{
|
2021-06-30 03:58:06 +00:00
|
|
|
|
public readonly EncounterSlot6XY[] Slots;
|
|
|
|
|
|
|
|
|
|
protected override IReadOnlyList<EncounterSlot> Raw => Slots;
|
|
|
|
|
|
2022-02-05 01:20:56 +00:00
|
|
|
|
public static EncounterArea6XY[] GetAreas(BinLinkerAccessor input, GameVersion game, EncounterArea6XY safari)
|
2020-08-30 17:23:22 +00:00
|
|
|
|
{
|
2022-02-05 01:20:56 +00:00
|
|
|
|
int count = input.Length;
|
|
|
|
|
var result = new EncounterArea6XY[count + 1];
|
|
|
|
|
for (int i = 0; i < count; i++)
|
2020-08-30 17:23:22 +00:00
|
|
|
|
result[i] = new EncounterArea6XY(input[i], game);
|
2021-05-14 22:30:55 +00:00
|
|
|
|
result[^1] = safari;
|
2020-08-30 17:23:22 +00:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-21 23:18:58 +00:00
|
|
|
|
public EncounterArea6XY() : base(GameVersion.XY)
|
2020-08-30 17:23:22 +00:00
|
|
|
|
{
|
2021-02-21 23:18:58 +00:00
|
|
|
|
Location = 148; // Friend Safari
|
2020-08-30 17:23:22 +00:00
|
|
|
|
Type = SlotType.FriendSafari;
|
|
|
|
|
|
2021-02-21 23:18:58 +00:00
|
|
|
|
Slots = LoadSafariSlots();
|
2020-08-30 17:23:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-03 05:35:59 +00:00
|
|
|
|
private EncounterArea6XY(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
|
|
|
|
}
|
|
|
|
|
|
2021-02-21 23:18:58 +00:00
|
|
|
|
private EncounterSlot6XY[] LoadSafariSlots()
|
|
|
|
|
{
|
|
|
|
|
const int SpeciesFormSlots = 4;
|
|
|
|
|
|
|
|
|
|
// Single form species
|
2022-03-07 07:25:47 +00:00
|
|
|
|
Span<ushort> species = stackalloc ushort[]
|
2021-02-21 23:18:58 +00:00
|
|
|
|
{
|
|
|
|
|
002, 005, 008, 012, 014, 016, 021, 025, 027, 035,
|
|
|
|
|
038, 039, 043, 044, 046, 049, 049, 051, 056, 058,
|
|
|
|
|
061, 063, 067, 077, 082, 083, 084, 087, 089, 091,
|
|
|
|
|
095, 096, 098, 101, 105, 112, 113, 114, 125, 126,
|
|
|
|
|
127, 130, 131, 132, 133, 148, 163, 165, 168, 175,
|
|
|
|
|
178, 184, 190, 191, 194, 195, 202, 203, 205, 206,
|
|
|
|
|
209, 213, 214, 215, 215, 216, 218, 219, 221, 222,
|
|
|
|
|
224, 225, 227, 231, 235, 236, 247, 262, 267, 268,
|
|
|
|
|
274, 281, 284, 286, 290, 294, 297, 299, 302, 303,
|
|
|
|
|
303, 307, 310, 313, 314, 317, 323, 326, 328, 332,
|
|
|
|
|
336, 342, 352, 353, 356, 357, 359, 361, 363, 372,
|
|
|
|
|
375, 400, 404, 415, 417, 419, 423, 426, 437, 442,
|
|
|
|
|
444, 447, 452, 454, 459, 506, 510, 511, 513, 515,
|
|
|
|
|
517, 520, 523, 525, 527, 530, 531, 536, 538, 539,
|
|
|
|
|
541, 544, 548, 551, 556, 557, 561, 569, 572, 575,
|
|
|
|
|
578, 581, 586, 587, 596, 597, 600, 608, 611, 614,
|
|
|
|
|
618, 619, 621, 623, 624, 627, 629, 636, 651, 654,
|
|
|
|
|
657, 660, 662, 662, 668, 673, 674, 677, 682, 684,
|
|
|
|
|
686, 689, 694, 701, 702, 702, 705, 707, 708, 710,
|
2021-08-20 20:49:20 +00:00
|
|
|
|
712, 714,
|
2021-02-21 23:18:58 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var slots = new EncounterSlot6XY[species.Length + SpeciesFormSlots];
|
|
|
|
|
int i = 0;
|
|
|
|
|
for (; i < species.Length; i++)
|
|
|
|
|
slots[i] = new EncounterSlot6XY(this, species[i], 0, 30, 30);
|
|
|
|
|
|
|
|
|
|
// Floette has 3 separate forms (RBY)
|
|
|
|
|
slots[i++] = new EncounterSlot6XY(this, (int)Species.Floette, 0, 30, 30);
|
2021-02-22 00:50:03 +00:00
|
|
|
|
slots[i++] = new EncounterSlot6XY(this, (int)Species.Floette, 1, 30, 30);
|
2021-02-21 23:18:58 +00:00
|
|
|
|
slots[i++] = new EncounterSlot6XY(this, (int)Species.Floette, 3, 30, 30);
|
|
|
|
|
|
|
|
|
|
// Region Random Vivillon
|
2022-01-03 05:35:59 +00:00
|
|
|
|
slots[i] = new EncounterSlot6XY(this, (int)Species.Vivillon, EncounterSlot.FormVivillon, 30, 30);
|
2021-02-21 23:18:58 +00:00
|
|
|
|
return slots;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-03 05:35:59 +00:00
|
|
|
|
private EncounterSlot6XY[] 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 EncounterSlot6XY[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);
|
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];
|
2020-08-30 18:08:21 +00:00
|
|
|
|
slots[i] = new EncounterSlot6XY(this, species, form, min, max);
|
2020-08-30 17:23:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return slots;
|
|
|
|
|
}
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
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.IsRandomUnspecificForm && slot.Species is not ((int)Species.Burmy or (int)Species.Furfrou))
|
2020-08-21 23:35:49 +00:00
|
|
|
|
{
|
2021-09-07 22:35:36 +00:00
|
|
|
|
// Only slot that can be form-mismatched via Pressure is Flabébé
|
2020-08-21 23:35:49 +00:00
|
|
|
|
if (slot.Species != (int)Species.Flabébé)
|
|
|
|
|
break;
|
2019-09-13 06:20:52 +00:00
|
|
|
|
|
2020-08-21 23:35:49 +00:00
|
|
|
|
var maxLevel = slot.LevelMax;
|
|
|
|
|
if (!ExistsPressureSlot(evo, ref maxLevel))
|
|
|
|
|
break;
|
2019-09-13 06:20:52 +00:00
|
|
|
|
|
2020-08-21 23:35:49 +00:00
|
|
|
|
if (maxLevel != pkm.Met_Level)
|
|
|
|
|
break;
|
2019-09-13 06:20:52 +00:00
|
|
|
|
|
2021-06-30 03:58:06 +00:00
|
|
|
|
yield return slot.CreatePressureFormCopy(evo.Form);
|
2020-08-21 23:35:49 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2020-03-14 18:32:27 +00:00
|
|
|
|
|
2020-08-21 23:35:49 +00:00
|
|
|
|
yield return slot;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-03-14 18:32:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-03-07 07:25:47 +00:00
|
|
|
|
private bool ExistsPressureSlot(DexLevel evo, ref byte level)
|
2020-03-14 18:32:27 +00:00
|
|
|
|
{
|
2020-08-21 23:35:49 +00:00
|
|
|
|
bool existsForm = false;
|
|
|
|
|
foreach (var z in Slots)
|
|
|
|
|
{
|
|
|
|
|
if (z.Species != evo.Species)
|
|
|
|
|
continue;
|
|
|
|
|
if (z.Form == evo.Form)
|
|
|
|
|
continue;
|
|
|
|
|
if (z.LevelMax < level)
|
|
|
|
|
continue;
|
|
|
|
|
level = z.LevelMax;
|
|
|
|
|
existsForm = true;
|
|
|
|
|
}
|
|
|
|
|
return existsForm;
|
2019-09-13 06:20:52 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-21 23:35:49 +00:00
|
|
|
|
}
|