2020-11-14 20:51:24 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2020-11-11 06:10:53 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace PKHeX.Core
|
|
|
|
|
{
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <see cref="GameVersion.GO"/> encounter area for direct-to-HOME transfers.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public sealed class EncounterArea8g : EncounterArea
|
|
|
|
|
{
|
2020-11-14 20:51:24 +00:00
|
|
|
|
public int Species { get; }
|
|
|
|
|
public int Form { get; }
|
2020-11-11 06:10:53 +00:00
|
|
|
|
|
2020-11-14 20:51:24 +00:00
|
|
|
|
private EncounterArea8g(int species, int form) : base(GameVersion.GO)
|
2020-11-11 06:10:53 +00:00
|
|
|
|
{
|
2020-11-14 20:51:24 +00:00
|
|
|
|
Species = species;
|
|
|
|
|
Form = form;
|
|
|
|
|
Location = Locations.GO8;
|
2020-11-11 06:10:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-11-14 20:55:30 +00:00
|
|
|
|
internal static EncounterArea8g[] GetArea(byte[][] data)
|
2020-11-11 06:10:53 +00:00
|
|
|
|
{
|
2020-11-14 20:55:30 +00:00
|
|
|
|
var areas = new EncounterArea8g[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-11 06:10:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-11-14 20:51:24 +00:00
|
|
|
|
private const int entrySize = (2 * sizeof(int)) + 2;
|
|
|
|
|
|
|
|
|
|
private static EncounterArea8g GetArea(byte[] data)
|
2020-11-11 06:10:53 +00:00
|
|
|
|
{
|
2020-11-14 20:51:24 +00:00
|
|
|
|
var sf = BitConverter.ToInt16(data, 0);
|
|
|
|
|
int species = sf & 0x7FF;
|
|
|
|
|
int form = sf >> 11;
|
2020-11-11 06:10:53 +00:00
|
|
|
|
|
2020-11-14 20:51:24 +00:00
|
|
|
|
var group = GetGroup(species, form);
|
2020-11-11 06:10:53 +00:00
|
|
|
|
|
2020-11-14 20:51:24 +00:00
|
|
|
|
var result = new EncounterSlot8GO[(data.Length - 2) / entrySize];
|
|
|
|
|
var area = new EncounterArea8g(species, form) {Slots = result};
|
|
|
|
|
for (int i = 0; i < result.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
var offset = (i * entrySize) + 2;
|
|
|
|
|
result[i] = ReadSlot(data, offset, area, species, form, group);
|
2020-11-11 06:10:53 +00:00
|
|
|
|
}
|
2020-11-14 20:51:24 +00:00
|
|
|
|
|
|
|
|
|
return area;
|
2020-11-11 06:10:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-11-14 20:51:24 +00:00
|
|
|
|
private static EncounterSlot8GO ReadSlot(byte[] data, int offset, EncounterArea8g area, int species, int form, GameVersion group)
|
2020-11-11 06:10:53 +00:00
|
|
|
|
{
|
2020-11-14 20:51:24 +00:00
|
|
|
|
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];
|
|
|
|
|
return new EncounterSlot8GO(area, species, form, group, type, shiny, start, end);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static GameVersion GetGroup(int species, int form)
|
|
|
|
|
{
|
|
|
|
|
var pt8 = PersonalTable.SWSH;
|
|
|
|
|
var ptGG = PersonalTable.GG;
|
|
|
|
|
|
|
|
|
|
var pi8 = (PersonalInfoSWSH)pt8[species];
|
|
|
|
|
if (pi8.IsPresentInGame)
|
|
|
|
|
{
|
|
|
|
|
bool lgpe = (species <= 151 || species == 808 || species == 809) && (form == 0 || ptGG[species].HasForme(form));
|
|
|
|
|
return lgpe ? GameVersion.GG : GameVersion.SWSH;
|
|
|
|
|
}
|
|
|
|
|
if (species <= Legal.MaxSpeciesID_7_USUM)
|
|
|
|
|
{
|
|
|
|
|
bool lgpe = species <= 151 && (form == 0 || ptGG[species].HasForme(form));
|
|
|
|
|
return lgpe ? GameVersion.GG : GameVersion.USUM;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(species));
|
2020-11-11 06:10:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override IEnumerable<EncounterSlot> GetMatchingSlots(PKM pkm, IReadOnlyList<EvoCriteria> chain)
|
|
|
|
|
{
|
|
|
|
|
if (pkm.TSV == 0) // HOME doesn't assign TSV=0 to accounts.
|
|
|
|
|
yield break;
|
|
|
|
|
|
2020-11-14 20:51:24 +00:00
|
|
|
|
bool exists = chain.Any(z => z.Species == Species && z.Form == Form);
|
|
|
|
|
if (!exists)
|
|
|
|
|
yield break;
|
2020-11-11 06:10:53 +00:00
|
|
|
|
|
2020-11-14 20:51:24 +00:00
|
|
|
|
var ball = (Ball)pkm.Ball;
|
2020-11-16 02:12:58 +00:00
|
|
|
|
var stamp = EncounterSlot8GO.GetTimeStamp(pkm.Met_Year + 2000, pkm.Met_Month, pkm.Met_Day);
|
2020-11-14 20:51:24 +00:00
|
|
|
|
foreach (var s in Slots)
|
|
|
|
|
{
|
|
|
|
|
var slot = (EncounterSlot8GO)s;
|
|
|
|
|
if (!slot.IsLevelWithinRange(pkm.Met_Level))
|
|
|
|
|
continue;
|
|
|
|
|
if (!slot.IsBallValid(ball))
|
|
|
|
|
continue;
|
|
|
|
|
if (!slot.Shiny.IsValid(pkm))
|
|
|
|
|
continue;
|
2020-11-15 16:31:48 +00:00
|
|
|
|
if (!slot.IsWithinStartEnd(stamp))
|
|
|
|
|
continue;
|
|
|
|
|
|
2020-11-14 20:51:24 +00:00
|
|
|
|
yield return slot;
|
2020-11-11 06:10:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|