2022-08-27 06:43:36 +00:00
|
|
|
using System;
|
2020-11-14 20:51:24 +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.GO"/> encounter area for <see cref="GameVersion.GG"/>
|
|
|
|
/// </summary>
|
|
|
|
public sealed record EncounterArea7g : EncounterArea, ISpeciesForm
|
2019-09-13 06:20:52 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary> Species for the area </summary>
|
|
|
|
/// <remarks> Due to how the encounter data is packaged by PKHeX, each species-form is grouped together. </remarks>
|
2022-08-27 06:43:36 +00:00
|
|
|
public ushort Species { get; }
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary> Form of the Species </summary>
|
2022-08-27 06:43:36 +00:00
|
|
|
public byte Form { get; }
|
2022-06-18 18:04:24 +00:00
|
|
|
public readonly EncounterSlot7GO[] Slots;
|
|
|
|
|
|
|
|
protected override IReadOnlyList<EncounterSlot> Raw => Slots;
|
|
|
|
|
|
|
|
private EncounterArea7g(ushort species, byte form, EncounterSlot7GO[] slots) : base(GameVersion.GO)
|
2019-09-13 06:20:52 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
Species = species;
|
|
|
|
Form = form;
|
|
|
|
Location = Locations.GO7;
|
|
|
|
Slots = slots;
|
|
|
|
}
|
2020-08-30 18:08:21 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
internal static EncounterArea7g[] GetArea(BinLinkerAccessor data)
|
|
|
|
{
|
|
|
|
var areas = new EncounterArea7g[data.Length];
|
|
|
|
for (int i = 0; i < areas.Length; i++)
|
|
|
|
areas[i] = GetArea(data[i]);
|
|
|
|
return areas;
|
|
|
|
}
|
2021-06-30 03:58:06 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private const int meta = 4;
|
|
|
|
private const int entrySize = (2 * sizeof(int)) + 2;
|
2020-11-14 20:51:24 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private static EncounterArea7g GetArea(ReadOnlySpan<byte> data)
|
|
|
|
{
|
|
|
|
var species = ReadUInt16LittleEndian(data);
|
|
|
|
var form = data[2];
|
|
|
|
//var import = (EntityFormatDetected)data[3];
|
|
|
|
|
|
|
|
data = data[meta..];
|
|
|
|
var result = new EncounterSlot7GO[data.Length / entrySize];
|
|
|
|
var area = new EncounterArea7g(species, form, result);
|
|
|
|
for (int i = 0; i < result.Length; i++)
|
2020-11-14 20:51:24 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
var offset = i * entrySize;
|
|
|
|
var entry = data.Slice(offset, entrySize);
|
|
|
|
result[i] = ReadSlot(entry, area, species, form);
|
2020-11-14 20:51:24 +00:00
|
|
|
}
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
return area;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static EncounterSlot7GO ReadSlot(ReadOnlySpan<byte> entry, EncounterArea7g area, ushort species, byte form)
|
|
|
|
{
|
|
|
|
int start = ReadInt32LittleEndian(entry);
|
|
|
|
int end = ReadInt32LittleEndian(entry[4..]);
|
|
|
|
var sg = entry[8];
|
|
|
|
var shiny = (Shiny)(sg & 0x3F);
|
|
|
|
var gender = (Gender)(sg >> 6);
|
|
|
|
var type = (PogoType)entry[9];
|
|
|
|
return new EncounterSlot7GO(area, species, form, start, end, shiny, gender, type);
|
|
|
|
}
|
2020-11-14 20:51:24 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public override IEnumerable<EncounterSlot> GetMatchingSlots(PKM pk, EvoCriteria[] chain)
|
|
|
|
{
|
|
|
|
// Find the first chain that has slots defined.
|
|
|
|
// Since it is possible to evolve before transferring, we only need the highest evolution species possible.
|
|
|
|
// PoGoEncTool has already extrapolated the evolutions to separate encounters!
|
|
|
|
var sf = Array.Find(chain, z => z.Species == Species && z.Form == Form);
|
|
|
|
if (sf == default)
|
|
|
|
yield break;
|
2020-08-30 17:23:22 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
var stamp = EncounterSlotGO.GetTimeStamp(pk.Met_Year + 2000, pk.Met_Month, pk.Met_Day);
|
|
|
|
var met = Math.Max(sf.LevelMin, pk.Met_Level);
|
|
|
|
EncounterSlot7GO? deferredIV = null;
|
2020-08-30 17:23:22 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
foreach (var slot in Slots)
|
2020-11-16 23:32:22 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (!slot.IsLevelWithinRange(met))
|
|
|
|
continue;
|
|
|
|
//if (!slot.IsBallValid(ball)) -- can have any of the in-game balls due to re-capture
|
|
|
|
// continue;
|
|
|
|
if (!slot.Shiny.IsValid(pk))
|
|
|
|
continue;
|
|
|
|
//if (slot.Gender != Gender.Random && (int) slot.Gender != pk.Gender)
|
|
|
|
// continue;
|
|
|
|
if (!slot.IsWithinStartEnd(stamp))
|
|
|
|
continue;
|
2020-11-16 23:32:22 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (!slot.GetIVsValid(pk))
|
2020-11-14 20:51:24 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
deferredIV ??= slot;
|
|
|
|
continue;
|
2019-09-13 06:20:52 +00:00
|
|
|
}
|
2021-02-05 22:20:43 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
yield return slot;
|
2019-09-13 06:20:52 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
if (deferredIV != null)
|
|
|
|
yield return deferredIV;
|
2019-09-13 06:20:52 +00:00
|
|
|
}
|
2020-11-11 06:10:53 +00:00
|
|
|
}
|