2020-12-29 05:12:46 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using static PKHeX.Core.GameVersion;
|
|
|
|
|
|
|
|
|
|
namespace PKHeX.Core
|
|
|
|
|
{
|
2021-06-06 18:56:54 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Cached copies of Met Location lists
|
|
|
|
|
/// </summary>
|
2020-12-29 05:12:46 +00:00
|
|
|
|
public sealed class MetDataSource
|
|
|
|
|
{
|
|
|
|
|
private readonly List<ComboItem> MetGen2;
|
|
|
|
|
private readonly List<ComboItem> MetGen3;
|
|
|
|
|
private readonly List<ComboItem> MetGen3CXD;
|
|
|
|
|
private readonly List<ComboItem> MetGen4;
|
|
|
|
|
private readonly List<ComboItem> MetGen5;
|
|
|
|
|
private readonly List<ComboItem> MetGen6;
|
|
|
|
|
private readonly List<ComboItem> MetGen7;
|
|
|
|
|
private readonly List<ComboItem> MetGen7GG;
|
|
|
|
|
private readonly List<ComboItem> MetGen8;
|
2022-02-05 01:35:15 +00:00
|
|
|
|
private readonly List<ComboItem> MetGen8a;
|
2021-11-20 02:23:49 +00:00
|
|
|
|
private readonly List<ComboItem> MetGen8b;
|
2020-12-29 05:12:46 +00:00
|
|
|
|
|
2021-05-12 06:32:29 +00:00
|
|
|
|
private IReadOnlyList<ComboItem>? MetGen4Transfer;
|
|
|
|
|
private IReadOnlyList<ComboItem>? MetGen5Transfer;
|
|
|
|
|
|
2020-12-29 05:12:46 +00:00
|
|
|
|
public MetDataSource(GameStrings s)
|
|
|
|
|
{
|
|
|
|
|
MetGen2 = CreateGen2(s);
|
|
|
|
|
MetGen3 = CreateGen3(s);
|
|
|
|
|
MetGen3CXD = CreateGen3CXD(s);
|
|
|
|
|
MetGen4 = CreateGen4(s);
|
|
|
|
|
MetGen5 = CreateGen5(s);
|
|
|
|
|
MetGen6 = CreateGen6(s);
|
|
|
|
|
MetGen7 = CreateGen7(s);
|
|
|
|
|
MetGen7GG = CreateGen7GG(s);
|
|
|
|
|
MetGen8 = CreateGen8(s);
|
2022-02-05 01:35:15 +00:00
|
|
|
|
MetGen8a = CreateGen8a(s);
|
2021-11-20 02:23:49 +00:00
|
|
|
|
MetGen8b = CreateGen8b(s);
|
2020-12-29 05:12:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static List<ComboItem> CreateGen2(GameStrings s)
|
|
|
|
|
{
|
2021-05-07 06:26:38 +00:00
|
|
|
|
var locations = Util.GetCBList(s.metGSC_00000.AsSpan(0, 0x5F));
|
|
|
|
|
Util.AddCBWithOffset(locations, s.metGSC_00000.AsSpan(0x7E, 2), 0x7E);
|
2020-12-29 05:12:46 +00:00
|
|
|
|
return locations;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static List<ComboItem> CreateGen3(GameStrings s)
|
|
|
|
|
{
|
2021-05-07 06:26:38 +00:00
|
|
|
|
var locations = Util.GetCBList(s.metRSEFRLG_00000.AsSpan(0, 213));
|
|
|
|
|
Util.AddCBWithOffset(locations, s.metRSEFRLG_00000.AsSpan(253, 3), 253);
|
2020-12-29 05:12:46 +00:00
|
|
|
|
return locations;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static List<ComboItem> CreateGen3CXD(GameStrings s)
|
|
|
|
|
{
|
2021-05-07 06:26:38 +00:00
|
|
|
|
var list = Util.GetCBList(s.metCXD_00000);
|
|
|
|
|
list.RemoveAll(z => z.Text.Length == 0);
|
|
|
|
|
return list;
|
2020-12-29 05:12:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static List<ComboItem> CreateGen4(GameStrings s)
|
|
|
|
|
{
|
|
|
|
|
var locations = Util.GetCBList(s.metHGSS_00000, 0);
|
|
|
|
|
Util.AddCBWithOffset(locations, s.metHGSS_02000, 2000, Locations.Daycare4);
|
|
|
|
|
Util.AddCBWithOffset(locations, s.metHGSS_02000, 2000, Locations.LinkTrade4);
|
|
|
|
|
Util.AddCBWithOffset(locations, s.metHGSS_03000, 3000, Locations.Ranger4);
|
|
|
|
|
Util.AddCBWithOffset(locations, s.metHGSS_00000, 0000, Legal.Met_HGSS_0);
|
|
|
|
|
Util.AddCBWithOffset(locations, s.metHGSS_02000, 2000, Legal.Met_HGSS_2);
|
|
|
|
|
Util.AddCBWithOffset(locations, s.metHGSS_03000, 3000, Legal.Met_HGSS_3);
|
|
|
|
|
return locations;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-12 06:32:29 +00:00
|
|
|
|
private IReadOnlyList<ComboItem> CreateGen4Transfer()
|
|
|
|
|
{
|
|
|
|
|
// Pal Park to front
|
|
|
|
|
var met = MetGen4.ToArray();
|
|
|
|
|
var index = Array.FindIndex(met, z => z.Value == Locations.Transfer3);
|
|
|
|
|
var pal = met[index];
|
|
|
|
|
Array.Copy(met, 0, met, 1, index);
|
|
|
|
|
met[0] = pal;
|
|
|
|
|
return met;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-29 05:12:46 +00:00
|
|
|
|
private static List<ComboItem> CreateGen5(GameStrings s)
|
|
|
|
|
{
|
|
|
|
|
var locations = Util.GetCBList(s.metBW2_00000, 0);
|
2021-11-28 22:32:05 +00:00
|
|
|
|
Util.AddCBWithOffset(locations, s.metBW2_60000, 60000, Locations.Daycare5);
|
|
|
|
|
Util.AddCBWithOffset(locations, s.metBW2_30000, 30000, Locations.LinkTrade5);
|
2020-12-29 05:12:46 +00:00
|
|
|
|
Util.AddCBWithOffset(locations, s.metBW2_00000, 00000, Legal.Met_BW2_0);
|
2021-11-28 22:32:05 +00:00
|
|
|
|
Util.AddCBWithOffset(locations, s.metBW2_30000, 30000, Legal.Met_BW2_3);
|
|
|
|
|
Util.AddCBWithOffset(locations, s.metBW2_40000, 40000, Legal.Met_BW2_4);
|
|
|
|
|
Util.AddCBWithOffset(locations, s.metBW2_60000, 60000, Legal.Met_BW2_6);
|
2020-12-29 05:12:46 +00:00
|
|
|
|
return locations;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-12 06:32:29 +00:00
|
|
|
|
private IReadOnlyList<ComboItem> CreateGen5Transfer()
|
|
|
|
|
{
|
|
|
|
|
// PokéTransfer to front
|
|
|
|
|
var met = MetGen5.ToArray();
|
|
|
|
|
var index = Array.FindIndex(met, z => z.Value == Locations.Transfer4);
|
|
|
|
|
var xfr = met[index];
|
|
|
|
|
Array.Copy(met, 0, met, 1, index);
|
|
|
|
|
met[0] = xfr;
|
|
|
|
|
return met;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-29 05:12:46 +00:00
|
|
|
|
private static List<ComboItem> CreateGen6(GameStrings s)
|
|
|
|
|
{
|
|
|
|
|
var locations = Util.GetCBList(s.metXY_00000, 0);
|
2021-11-28 22:32:05 +00:00
|
|
|
|
Util.AddCBWithOffset(locations, s.metXY_60000, 60000, Locations.Daycare5);
|
|
|
|
|
Util.AddCBWithOffset(locations, s.metXY_30000, 30000, Locations.LinkTrade6);
|
2020-12-29 05:12:46 +00:00
|
|
|
|
Util.AddCBWithOffset(locations, s.metXY_00000, 00000, Legal.Met_XY_0);
|
2021-11-28 22:32:05 +00:00
|
|
|
|
Util.AddCBWithOffset(locations, s.metXY_30000, 30000, Legal.Met_XY_3);
|
|
|
|
|
Util.AddCBWithOffset(locations, s.metXY_40000, 40000, Legal.Met_XY_4);
|
|
|
|
|
Util.AddCBWithOffset(locations, s.metXY_60000, 60000, Legal.Met_XY_6);
|
2020-12-29 05:12:46 +00:00
|
|
|
|
return locations;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static List<ComboItem> CreateGen7(GameStrings s)
|
|
|
|
|
{
|
|
|
|
|
var locations = Util.GetCBList(s.metSM_00000, 0);
|
2021-11-28 22:32:05 +00:00
|
|
|
|
Util.AddCBWithOffset(locations, s.metSM_60000, 60000, Locations.Daycare5);
|
|
|
|
|
Util.AddCBWithOffset(locations, s.metSM_30000, 30000, Locations.LinkTrade6);
|
2020-12-29 05:12:46 +00:00
|
|
|
|
Util.AddCBWithOffset(locations, s.metSM_00000, 00000, Legal.Met_SM_0);
|
2021-11-28 22:32:05 +00:00
|
|
|
|
Util.AddCBWithOffset(locations, s.metSM_30000, 30000, Legal.Met_SM_3);
|
|
|
|
|
Util.AddCBWithOffset(locations, s.metSM_40000, 40000, Legal.Met_SM_4);
|
|
|
|
|
Util.AddCBWithOffset(locations, s.metSM_60000, 60000, Legal.Met_SM_6);
|
2020-12-29 05:12:46 +00:00
|
|
|
|
return locations;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static List<ComboItem> CreateGen7GG(GameStrings s)
|
|
|
|
|
{
|
|
|
|
|
var locations = Util.GetCBList(s.metGG_00000, 0);
|
2021-11-28 22:32:05 +00:00
|
|
|
|
Util.AddCBWithOffset(locations, s.metGG_60000, 60000, Locations.Daycare5);
|
|
|
|
|
Util.AddCBWithOffset(locations, s.metGG_30000, 30000, Locations.LinkTrade6);
|
2020-12-29 05:12:46 +00:00
|
|
|
|
Util.AddCBWithOffset(locations, s.metGG_00000, 00000, Legal.Met_GG_0);
|
2021-11-28 22:32:05 +00:00
|
|
|
|
Util.AddCBWithOffset(locations, s.metGG_30000, 30000, Legal.Met_GG_3);
|
|
|
|
|
Util.AddCBWithOffset(locations, s.metGG_40000, 40000, Legal.Met_GG_4);
|
|
|
|
|
Util.AddCBWithOffset(locations, s.metGG_60000, 60000, Legal.Met_GG_6);
|
2020-12-29 05:12:46 +00:00
|
|
|
|
return locations;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static List<ComboItem> CreateGen8(GameStrings s)
|
|
|
|
|
{
|
|
|
|
|
var locations = Util.GetCBList(s.metSWSH_00000, 0);
|
2021-11-28 22:32:05 +00:00
|
|
|
|
Util.AddCBWithOffset(locations, s.metSWSH_60000, 60000, Locations.Daycare5);
|
|
|
|
|
Util.AddCBWithOffset(locations, s.metSWSH_30000, 30000, Locations.LinkTrade6);
|
2020-12-29 05:12:46 +00:00
|
|
|
|
Util.AddCBWithOffset(locations, s.metSWSH_00000, 00000, Legal.Met_SWSH_0);
|
2021-11-28 22:32:05 +00:00
|
|
|
|
Util.AddCBWithOffset(locations, s.metSWSH_30000, 30000, Legal.Met_SWSH_3);
|
|
|
|
|
Util.AddCBWithOffset(locations, s.metSWSH_40000, 40000, Legal.Met_SWSH_4);
|
|
|
|
|
Util.AddCBWithOffset(locations, s.metSWSH_60000, 60000, Legal.Met_SWSH_6);
|
2020-12-29 05:12:46 +00:00
|
|
|
|
return locations;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-05 01:35:15 +00:00
|
|
|
|
private static List<ComboItem> CreateGen8a(GameStrings s)
|
|
|
|
|
{
|
|
|
|
|
var locations = Util.GetCBList(s.metLA_00000, 0);
|
|
|
|
|
Util.AddCBWithOffset(locations, s.metLA_30000, 30000, Locations.LinkTrade6);
|
|
|
|
|
Util.AddCBWithOffset(locations, s.metLA_00000, 00000, Legal.Met_LA_0);
|
|
|
|
|
Util.AddCBWithOffset(locations, s.metLA_30000, 30000, Legal.Met_LA_3);
|
|
|
|
|
Util.AddCBWithOffset(locations, s.metLA_40000, 40000, Legal.Met_LA_4);
|
|
|
|
|
Util.AddCBWithOffset(locations, s.metLA_60000, 60000, Legal.Met_LA_6);
|
|
|
|
|
return locations;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-20 02:23:49 +00:00
|
|
|
|
private static List<ComboItem> CreateGen8b(GameStrings s)
|
|
|
|
|
{
|
|
|
|
|
// Manually add invalid (-1) location from SWSH as ID 65535
|
2021-11-28 22:32:05 +00:00
|
|
|
|
var locations = new List<ComboItem> { new(s.metSWSH_00000[0], unchecked((ushort)Locations.Default8bNone)) };
|
2021-11-20 02:23:49 +00:00
|
|
|
|
Util.AddCBWithOffset(locations, s.metBDSP_60000, 60000, Locations.Daycare5);
|
|
|
|
|
Util.AddCBWithOffset(locations, s.metBDSP_30000, 30000, Locations.LinkTrade6);
|
|
|
|
|
Util.AddCBWithOffset(locations, s.metBDSP_00000, 00000, Legal.Met_BS_0);
|
|
|
|
|
Util.AddCBWithOffset(locations, s.metBDSP_30000, 30000, Legal.Met_BS_3);
|
|
|
|
|
Util.AddCBWithOffset(locations, s.metBDSP_40000, 40000, Legal.Met_BS_4);
|
|
|
|
|
Util.AddCBWithOffset(locations, s.metBDSP_60000, 60000, Legal.Met_BS_6);
|
|
|
|
|
return locations;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-29 05:12:46 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Fetches a Met Location list for a <see cref="version"/> that has been transferred away from and overwritten.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="version">Origin version</param>
|
|
|
|
|
/// <param name="currentGen">Current save file generation</param>
|
|
|
|
|
/// <param name="egg">True if an egg location list, false if a regular met location list</param>
|
|
|
|
|
/// <returns>Met location list</returns>
|
|
|
|
|
public IReadOnlyList<ComboItem> GetLocationList(GameVersion version, int currentGen, bool egg = false)
|
|
|
|
|
{
|
|
|
|
|
if (currentGen == 2)
|
|
|
|
|
return MetGen2;
|
|
|
|
|
|
|
|
|
|
if (egg && version < W && currentGen >= 5)
|
|
|
|
|
return MetGen4;
|
|
|
|
|
|
|
|
|
|
return version switch
|
|
|
|
|
{
|
|
|
|
|
CXD when currentGen == 3 => MetGen3CXD,
|
2021-05-29 22:31:47 +00:00
|
|
|
|
R or S when currentGen == 3 => Partition1(MetGen3, z => z <= 87), // Ferry
|
2020-12-29 05:12:46 +00:00
|
|
|
|
E when currentGen == 3 => Partition1(MetGen3, z => z is <= 87 or >= 197 and <= 212), // Trainer Hill
|
|
|
|
|
FR or LG when currentGen == 3 => Partition1(MetGen3, z => z is > 87 and < 197), // Celadon Dept.
|
2021-05-29 22:31:47 +00:00
|
|
|
|
D or P when currentGen == 4 => Partition2(MetGen4, z => z <= 111, 4), // Battle Park
|
|
|
|
|
Pt when currentGen == 4 => Partition2(MetGen4, z => z <= 125, 4), // Rock Peak Ruins
|
2020-12-29 05:12:46 +00:00
|
|
|
|
HG or SS when currentGen == 4 => Partition2(MetGen4, z => z is > 125 and < 234, 4), // Celadon Dept.
|
|
|
|
|
|
|
|
|
|
B or W => MetGen5,
|
2021-05-29 22:31:47 +00:00
|
|
|
|
B2 or W2 => Partition2(MetGen5, z => z <= 116), // Abyssal Ruins
|
|
|
|
|
X or Y => Partition2(MetGen6, z => z <= 168), // Unknown Dungeon
|
2020-12-29 05:12:46 +00:00
|
|
|
|
OR or AS => Partition2(MetGen6, z => z is > 168 and <= 354), // Secret Base
|
2021-05-29 22:31:47 +00:00
|
|
|
|
SN or MN => Partition2(MetGen7, z => z < 200), // Outer Cape
|
2020-12-29 05:12:46 +00:00
|
|
|
|
US or UM
|
|
|
|
|
or RD or BU or GN or YW
|
|
|
|
|
or GD or SV or C => Partition2(MetGen7, z => z < 234), // Dividing Peak Tunnel
|
|
|
|
|
GP or GE or GO => Partition2(MetGen7GG, z => z <= 54), // Pokémon League
|
|
|
|
|
SW or SH => Partition2(MetGen8, z => z < 400),
|
2021-11-20 02:23:49 +00:00
|
|
|
|
BD or SP => Partition2(MetGen8b, z => z < 628),
|
2022-02-05 01:35:15 +00:00
|
|
|
|
PLA => Partition2(MetGen8a, z => z < 512),
|
2020-12-29 05:12:46 +00:00
|
|
|
|
_ => GetLocationListModified(version, currentGen),
|
|
|
|
|
};
|
|
|
|
|
|
2021-05-10 05:48:24 +00:00
|
|
|
|
static IReadOnlyList<ComboItem> Partition1(IReadOnlyList<ComboItem> list, Func<int, bool> criteria)
|
2020-12-29 05:12:46 +00:00
|
|
|
|
{
|
2021-05-10 05:48:24 +00:00
|
|
|
|
var result = new ComboItem[list.Count];
|
|
|
|
|
return GetOrderedList(list, result, criteria);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static IReadOnlyList<ComboItem> GetOrderedList(IReadOnlyList<ComboItem> list, ComboItem[] result, Func<int, bool> criteria, int start = 0)
|
|
|
|
|
{
|
|
|
|
|
// store values that match criteria at the next available position of the array
|
|
|
|
|
// store non-matches starting at the end. reverse before returning
|
|
|
|
|
int end = list.Count - 1;
|
2021-05-12 06:25:36 +00:00
|
|
|
|
for (var index = start; index < list.Count; index++)
|
2021-05-10 05:48:24 +00:00
|
|
|
|
{
|
2021-05-12 06:25:36 +00:00
|
|
|
|
var item = list[index];
|
2021-05-10 05:48:24 +00:00
|
|
|
|
if (criteria(item.Value))
|
|
|
|
|
result[start++] = item;
|
|
|
|
|
else
|
|
|
|
|
result[end--] = item;
|
|
|
|
|
}
|
|
|
|
|
// since the non-matches are reversed in order, we swap them back since we know where they end up at.
|
|
|
|
|
Array.Reverse(result, start, list.Count - start);
|
|
|
|
|
return result;
|
2020-12-29 05:12:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static IReadOnlyList<ComboItem> Partition2(IReadOnlyList<ComboItem> list, Func<int, bool> criteria, int keepFirst = 3)
|
|
|
|
|
{
|
2021-05-10 05:48:24 +00:00
|
|
|
|
var result = new ComboItem[list.Count];
|
|
|
|
|
for (int i = 0; i < keepFirst; i++)
|
|
|
|
|
result[i] = list[i];
|
|
|
|
|
return GetOrderedList(list, result, criteria, keepFirst);
|
2020-12-29 05:12:46 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Fetches a Met Location list for a <see cref="version"/> that has been transferred away from and overwritten.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="version">Origin version</param>
|
|
|
|
|
/// <param name="currentGen">Current save file generation</param>
|
|
|
|
|
/// <returns>Met location list</returns>
|
2021-05-12 06:32:29 +00:00
|
|
|
|
private IReadOnlyList<ComboItem> GetLocationListModified(GameVersion version, int currentGen) => version switch
|
2020-12-29 05:12:46 +00:00
|
|
|
|
{
|
2021-05-12 06:32:29 +00:00
|
|
|
|
<= CXD when currentGen == 4 => MetGen4Transfer ??= CreateGen4Transfer(),
|
|
|
|
|
< X when currentGen >= 5 => MetGen5Transfer ??= CreateGen5Transfer(),
|
2021-08-20 20:49:20 +00:00
|
|
|
|
_ => Array.Empty<ComboItem>(),
|
2021-05-12 06:32:29 +00:00
|
|
|
|
};
|
2020-12-29 05:12:46 +00:00
|
|
|
|
}
|
|
|
|
|
}
|