2020-11-14 20:51:24 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2020-08-30 17:23:22 +00:00
|
|
|
|
using System.Linq;
|
2019-09-13 06:20:52 +00:00
|
|
|
|
|
|
|
|
|
namespace PKHeX.Core
|
|
|
|
|
{
|
2020-12-11 04:42:30 +00:00
|
|
|
|
/// <inheritdoc cref="EncounterArea" />
|
2019-09-13 06:20:52 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// <see cref="GameVersion.GO"/> encounter area for <see cref="GameVersion.GG"/>
|
|
|
|
|
/// </summary>
|
2021-01-01 18:55:33 +00:00
|
|
|
|
public sealed record EncounterArea7g : EncounterArea, ISpeciesForm
|
2019-09-13 06:20:52 +00:00
|
|
|
|
{
|
2020-11-17 05:17:45 +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>
|
2020-11-14 20:51:24 +00:00
|
|
|
|
public int Species { get; }
|
2020-11-17 05:17:45 +00:00
|
|
|
|
/// <summary> Form of the Species </summary>
|
2020-11-14 20:51:24 +00:00
|
|
|
|
public int Form { get; }
|
2020-08-30 18:08:21 +00:00
|
|
|
|
|
2020-11-14 20:51:24 +00:00
|
|
|
|
private EncounterArea7g(int species, int form) : base(GameVersion.GO)
|
2020-08-30 17:23:22 +00:00
|
|
|
|
{
|
2020-11-14 20:51:24 +00:00
|
|
|
|
Species = species;
|
|
|
|
|
Form = form;
|
2020-11-19 05:34:40 +00:00
|
|
|
|
Location = Locations.GO7;
|
2020-11-14 20:51:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-11-14 20:55:30 +00:00
|
|
|
|
internal static EncounterArea7g[] GetArea(byte[][] data)
|
2020-11-14 20:51:24 +00:00
|
|
|
|
{
|
2020-11-14 20:55:30 +00:00
|
|
|
|
var areas = new EncounterArea7g[data.Length];
|
2020-11-14 20:51:24 +00:00
|
|
|
|
for (int i = 0; i < areas.Length; i++)
|
2020-11-14 20:55:30 +00:00
|
|
|
|
areas[i] = GetArea(data[i]);
|
2020-11-14 20:51:24 +00:00
|
|
|
|
return areas;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-16 23:32:22 +00:00
|
|
|
|
private const int entrySize = (2 * sizeof(int)) + 2;
|
2020-11-14 20:51:24 +00:00
|
|
|
|
|
|
|
|
|
private static EncounterArea7g GetArea(byte[] data)
|
|
|
|
|
{
|
|
|
|
|
var sf = BitConverter.ToInt16(data, 0);
|
|
|
|
|
int species = sf & 0x7FF;
|
|
|
|
|
int form = sf >> 11;
|
|
|
|
|
|
2020-11-16 23:32:22 +00:00
|
|
|
|
var result = new EncounterSlot7GO[(data.Length - 2) / entrySize];
|
|
|
|
|
var area = new EncounterArea7g(species, form) { Slots = result };
|
2020-11-14 20:51:24 +00:00
|
|
|
|
for (int i = 0; i < result.Length; i++)
|
2020-08-30 17:23:22 +00:00
|
|
|
|
{
|
2020-11-14 20:51:24 +00:00
|
|
|
|
var offset = (i * entrySize) + 2;
|
2020-11-16 23:32:22 +00:00
|
|
|
|
result[i] = ReadSlot(data, offset, area, species, form);
|
2020-11-13 04:41:01 +00:00
|
|
|
|
}
|
2020-08-30 17:23:22 +00:00
|
|
|
|
|
2020-11-14 20:51:24 +00:00
|
|
|
|
return area;
|
2020-08-30 17:23:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-11-16 23:32:22 +00:00
|
|
|
|
private static EncounterSlot7GO ReadSlot(byte[] data, int offset, EncounterArea7g area, int species, int form)
|
|
|
|
|
{
|
|
|
|
|
int start = BitConverter.ToInt32(data, offset);
|
|
|
|
|
int end = BitConverter.ToInt32(data, offset + 4);
|
|
|
|
|
var shiny = (Shiny)data[offset + 8];
|
|
|
|
|
var type = (PogoType)data[offset + 9];
|
2020-11-17 05:17:45 +00:00
|
|
|
|
return new EncounterSlot7GO(area, species, form, start, end, shiny, type);
|
2020-11-16 23:32:22 +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-11-16 23:32:22 +00:00
|
|
|
|
var sf = chain.FirstOrDefault(z => z.Species == Species && z.Form == Form);
|
|
|
|
|
if (sf == null)
|
2020-11-14 20:51:24 +00:00
|
|
|
|
yield break;
|
2020-08-21 23:35:49 +00:00
|
|
|
|
|
2020-11-16 23:32:22 +00:00
|
|
|
|
var stamp = EncounterSlotGO.GetTimeStamp(pkm.Met_Year + 2000, pkm.Met_Month, pkm.Met_Day);
|
|
|
|
|
var met = Math.Max(sf.MinLevel, pkm.Met_Level);
|
2020-11-14 20:51:24 +00:00
|
|
|
|
foreach (var s in Slots)
|
|
|
|
|
{
|
|
|
|
|
var slot = (EncounterSlot7GO)s;
|
2020-11-16 23:32:22 +00:00
|
|
|
|
if (!slot.IsLevelWithinRange(met))
|
2020-11-14 20:51:24 +00:00
|
|
|
|
continue;
|
2020-11-16 23:32:22 +00:00
|
|
|
|
//if (!slot.IsBallValid(ball)) -- can have any of the in-game balls due to re-capture
|
|
|
|
|
// continue;
|
2020-11-14 20:51:24 +00:00
|
|
|
|
if (!slot.Shiny.IsValid(pkm))
|
|
|
|
|
continue;
|
2020-11-16 23:32:22 +00:00
|
|
|
|
if (!slot.IsWithinStartEnd(stamp))
|
|
|
|
|
continue;
|
2020-11-17 05:17:45 +00:00
|
|
|
|
|
2020-11-14 20:51:24 +00:00
|
|
|
|
yield return slot;
|
2019-09-13 06:20:52 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-11-11 06:10:53 +00:00
|
|
|
|
}
|