2020-11-14 12:51:24 -08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2020-08-30 10:23:22 -07:00
|
|
|
|
using System.Linq;
|
2019-09-12 23:20:52 -07:00
|
|
|
|
|
|
|
|
|
namespace PKHeX.Core
|
|
|
|
|
{
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <see cref="GameVersion.GO"/> encounter area for <see cref="GameVersion.GG"/>
|
|
|
|
|
/// </summary>
|
2020-08-30 10:23:22 -07:00
|
|
|
|
public sealed class EncounterArea7g : EncounterArea
|
2019-09-12 23:20:52 -07:00
|
|
|
|
{
|
2020-11-14 12:51:24 -08:00
|
|
|
|
public int Species { get; }
|
|
|
|
|
public int Form { get; }
|
2020-08-30 11:08:21 -07:00
|
|
|
|
|
2020-11-14 12:51:24 -08:00
|
|
|
|
private EncounterArea7g(int species, int form) : base(GameVersion.GO)
|
2020-08-30 10:23:22 -07:00
|
|
|
|
{
|
2020-11-14 12:51:24 -08:00
|
|
|
|
Species = species;
|
|
|
|
|
Form = form;
|
|
|
|
|
Location = 50;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-14 12:55:30 -08:00
|
|
|
|
internal static EncounterArea7g[] GetArea(byte[][] data)
|
2020-11-14 12:51:24 -08:00
|
|
|
|
{
|
2020-11-14 12:55:30 -08:00
|
|
|
|
var areas = new EncounterArea7g[data.Length];
|
2020-11-14 12:51:24 -08:00
|
|
|
|
for (int i = 0; i < areas.Length; i++)
|
2020-11-14 12:55:30 -08:00
|
|
|
|
areas[i] = GetArea(data[i]);
|
2020-11-14 12:51:24 -08:00
|
|
|
|
return areas;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private const int entrySize = 2;
|
|
|
|
|
|
|
|
|
|
private static EncounterArea7g GetArea(byte[] data)
|
|
|
|
|
{
|
|
|
|
|
var sf = BitConverter.ToInt16(data, 0);
|
|
|
|
|
int species = sf & 0x7FF;
|
|
|
|
|
int form = sf >> 11;
|
|
|
|
|
|
|
|
|
|
// Files are padded to be multiples of 4 bytes. The last entry might actually be padding.
|
|
|
|
|
// Since we aren't saving a count up-front, just check if the last entry is valid.
|
|
|
|
|
int count = (data.Length - 2) / entrySize;
|
|
|
|
|
if (data[data.Length - 1] == 0) // type of "None" is not valid
|
|
|
|
|
count--;
|
2020-08-30 10:23:22 -07:00
|
|
|
|
|
2020-11-14 12:51:24 -08:00
|
|
|
|
var result = new EncounterSlot7GO[count];
|
|
|
|
|
var area = new EncounterArea7g(species, form) {Slots = result};
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < result.Length; i++)
|
2020-08-30 10:23:22 -07:00
|
|
|
|
{
|
2020-11-14 12:51:24 -08:00
|
|
|
|
var offset = (i * entrySize) + 2;
|
|
|
|
|
var shiny = (Shiny)data[offset];
|
|
|
|
|
var type = (PogoType)data[offset + 1];
|
|
|
|
|
result[i] = new EncounterSlot7GO(area, species, form, shiny, type);
|
2020-11-12 20:41:01 -08:00
|
|
|
|
}
|
2020-08-30 10:23:22 -07:00
|
|
|
|
|
2020-11-14 12:51:24 -08:00
|
|
|
|
return area;
|
2020-08-30 10:23:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-21 16:35:49 -07:00
|
|
|
|
public override IEnumerable<EncounterSlot> GetMatchingSlots(PKM pkm, IReadOnlyList<EvoCriteria> chain)
|
2019-09-12 23:20:52 -07:00
|
|
|
|
{
|
2020-11-14 12:51:24 -08:00
|
|
|
|
bool exists = chain.Any(z => z.Species == Species && z.Form == Form);
|
|
|
|
|
if (!exists)
|
|
|
|
|
yield break;
|
2020-08-21 16:35:49 -07:00
|
|
|
|
|
2020-11-14 12:51:24 -08:00
|
|
|
|
foreach (var s in Slots)
|
|
|
|
|
{
|
|
|
|
|
var slot = (EncounterSlot7GO)s;
|
|
|
|
|
if (!slot.IsLevelWithinRange(pkm.Met_Level))
|
|
|
|
|
continue;
|
|
|
|
|
if (!slot.Shiny.IsValid(pkm))
|
|
|
|
|
continue;
|
|
|
|
|
yield return slot;
|
2019-09-12 23:20:52 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-11-10 22:10:53 -08:00
|
|
|
|
}
|