2018-03-06 06:19:56 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
using static PKHeX.Core.EncountersWC3;
|
|
|
|
|
|
|
|
|
|
namespace PKHeX.Core
|
|
|
|
|
{
|
|
|
|
|
public static class EncounterEvent
|
|
|
|
|
{
|
|
|
|
|
/// <summary>Event Database for Generation 3</summary>
|
2020-11-12 05:01:41 +00:00
|
|
|
|
public static IReadOnlyList<WC3> MGDB_G3 { get; private set; } = Array.Empty<WC3>();
|
2018-03-06 06:19:56 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>Event Database for Generation 4</summary>
|
2020-11-12 05:01:41 +00:00
|
|
|
|
public static IReadOnlyList<PCD> MGDB_G4 { get; private set; } = Array.Empty<PCD>();
|
2018-03-06 06:19:56 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>Event Database for Generation 5</summary>
|
2020-11-12 05:01:41 +00:00
|
|
|
|
public static IReadOnlyList<PGF> MGDB_G5 { get; private set; } = Array.Empty<PGF>();
|
2018-03-06 06:19:56 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>Event Database for Generation 6</summary>
|
2020-11-12 05:01:41 +00:00
|
|
|
|
public static IReadOnlyList<WC6> MGDB_G6 { get; private set; } = Array.Empty<WC6>();
|
2018-03-06 06:19:56 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>Event Database for Generation 7</summary>
|
2020-11-12 05:01:41 +00:00
|
|
|
|
public static IReadOnlyList<WC7> MGDB_G7 { get; private set; } = Array.Empty<WC7>();
|
2018-03-06 06:19:56 +00:00
|
|
|
|
|
2018-11-11 21:09:04 +00:00
|
|
|
|
/// <summary>Event Database for Generation 7 <see cref="GameVersion.GG"/></summary>
|
2020-11-12 05:01:41 +00:00
|
|
|
|
public static IReadOnlyList<WB7> MGDB_G7GG { get; private set; } = Array.Empty<WB7>();
|
2018-11-11 21:09:04 +00:00
|
|
|
|
|
2019-11-16 01:34:18 +00:00
|
|
|
|
/// <summary>Event Database for Generation 8</summary>
|
2020-11-12 05:01:41 +00:00
|
|
|
|
public static IReadOnlyList<WC8> MGDB_G8 { get; private set; } = Array.Empty<WC8>();
|
2019-09-23 23:56:47 +00:00
|
|
|
|
|
2018-05-27 22:57:28 +00:00
|
|
|
|
/// <summary>Indicates if the databases are initialized.</summary>
|
2020-11-12 05:01:41 +00:00
|
|
|
|
public static bool Initialized => MGDB_G3.Count != 0;
|
2018-05-27 22:57:28 +00:00
|
|
|
|
|
2021-06-04 20:48:02 +00:00
|
|
|
|
private static PCD[] GetPCDDB(byte[] bin) => Get(bin, PCD.Size, d => new PCD(d));
|
|
|
|
|
private static PGF[] GetPGFDB(byte[] bin) => Get(bin, PGF.Size, d => new PGF(d));
|
2018-07-28 05:26:27 +00:00
|
|
|
|
|
2021-06-04 20:48:02 +00:00
|
|
|
|
private static WC6[] GetWC6DB(byte[] wc6bin, byte[] wc6full) => WC6Full.GetArray(wc6full, wc6bin);
|
|
|
|
|
private static WC7[] GetWC7DB(byte[] wc7bin, byte[] wc7full) => WC7Full.GetArray(wc7full, wc7bin);
|
2018-07-28 05:26:27 +00:00
|
|
|
|
|
2021-06-04 20:48:02 +00:00
|
|
|
|
private static WB7[] GetWB7DB(byte[] bin) => Get(bin, WB7.SizeFull, d => new WB7(d));
|
|
|
|
|
private static WC8[] GetWC8DB(byte[] bin) => Get(bin, WC8.Size, d => new WC8(d));
|
2018-07-28 05:26:27 +00:00
|
|
|
|
|
2021-06-04 20:48:02 +00:00
|
|
|
|
private static T[] Get<T>(byte[] bin, int size, Func<byte[], T> ctor)
|
|
|
|
|
{
|
|
|
|
|
var result = new T[bin.Length / size];
|
|
|
|
|
System.Diagnostics.Debug.Assert(result.Length * size == bin.Length);
|
|
|
|
|
for (int i = 0; i < result.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
var offset = i * size;
|
|
|
|
|
var slice = bin.Slice(offset, size);
|
|
|
|
|
result[i] = ctor(slice);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2019-11-16 01:34:18 +00:00
|
|
|
|
|
2018-03-06 06:19:56 +00:00
|
|
|
|
public static void RefreshMGDB(params string[] paths)
|
|
|
|
|
{
|
2021-06-04 20:48:02 +00:00
|
|
|
|
ICollection<PCD> g4 = GetPCDDB(Util.GetBinaryResource("wc4.pkl"));
|
|
|
|
|
ICollection<PGF> g5 = GetPGFDB(Util.GetBinaryResource("pgf.pkl"));
|
|
|
|
|
ICollection<WC6> g6 = GetWC6DB(Util.GetBinaryResource("wc6.pkl"), Util.GetBinaryResource("wc6full.pkl"));
|
|
|
|
|
ICollection<WC7> g7 = GetWC7DB(Util.GetBinaryResource("wc7.pkl"), Util.GetBinaryResource("wc7full.pkl"));
|
|
|
|
|
ICollection<WB7> b7 = GetWB7DB(Util.GetBinaryResource("wb7full.pkl"));
|
|
|
|
|
ICollection<WC8> g8 = GetWC8DB(Util.GetBinaryResource("wc8.pkl"));
|
2018-03-06 06:19:56 +00:00
|
|
|
|
|
2019-09-23 23:56:47 +00:00
|
|
|
|
foreach (var gift in paths.Where(Directory.Exists).SelectMany(MysteryUtil.GetGiftsFromFolder))
|
2018-03-06 06:19:56 +00:00
|
|
|
|
{
|
2021-06-04 20:48:02 +00:00
|
|
|
|
static void AddOrExpand<T>(ref ICollection<T> arr, T obj)
|
|
|
|
|
{
|
2021-06-04 20:53:02 +00:00
|
|
|
|
if (arr is HashSet<T> h)
|
|
|
|
|
h.Add(obj);
|
2021-06-04 20:48:02 +00:00
|
|
|
|
else
|
|
|
|
|
arr = new HashSet<T>(arr) {obj};
|
|
|
|
|
}
|
2019-09-23 23:56:47 +00:00
|
|
|
|
switch (gift)
|
2018-03-06 06:19:56 +00:00
|
|
|
|
{
|
2021-06-04 20:48:02 +00:00
|
|
|
|
case PCD pcd: AddOrExpand(ref g4, pcd); continue;
|
|
|
|
|
case PGF pgf: AddOrExpand(ref g5, pgf); continue;
|
|
|
|
|
case WC6 wc6: AddOrExpand(ref g6, wc6); continue;
|
|
|
|
|
case WC7 wc7: AddOrExpand(ref g7, wc7); continue;
|
|
|
|
|
case WB7 wb7: AddOrExpand(ref b7, wb7); continue;
|
|
|
|
|
case WC8 wc8: AddOrExpand(ref g8, wc8); continue;
|
2018-03-06 06:19:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-04 20:48:02 +00:00
|
|
|
|
static T[] SetArray<T>(ICollection<T> arr)
|
|
|
|
|
{
|
|
|
|
|
if (arr is T[] x)
|
|
|
|
|
return x;
|
2021-06-04 20:53:02 +00:00
|
|
|
|
|
|
|
|
|
// rather than use Linq to build an array, just do it the quick way directly.
|
2021-06-04 20:48:02 +00:00
|
|
|
|
var result = new T[arr.Count];
|
|
|
|
|
((HashSet<T>)arr).CopyTo(result, 0);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-06 06:19:56 +00:00
|
|
|
|
MGDB_G3 = Encounter_WC3; // hardcoded
|
2021-06-04 20:48:02 +00:00
|
|
|
|
MGDB_G4 = SetArray(g4);
|
|
|
|
|
MGDB_G5 = SetArray(g5);
|
|
|
|
|
MGDB_G6 = SetArray(g6);
|
|
|
|
|
MGDB_G7 = SetArray(g7);
|
|
|
|
|
MGDB_G7GG = SetArray(b7);
|
|
|
|
|
MGDB_G8 = SetArray(g8);
|
2018-03-06 06:19:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static IEnumerable<MysteryGift> GetAllEvents(bool sorted = true)
|
|
|
|
|
{
|
2020-11-12 05:01:41 +00:00
|
|
|
|
var regular = new IReadOnlyList<MysteryGift>[]
|
2018-03-06 06:19:56 +00:00
|
|
|
|
{
|
|
|
|
|
MGDB_G4,
|
|
|
|
|
MGDB_G5,
|
|
|
|
|
MGDB_G6,
|
|
|
|
|
MGDB_G7,
|
2018-11-21 20:24:41 +00:00
|
|
|
|
MGDB_G7GG,
|
2019-09-23 23:56:47 +00:00
|
|
|
|
MGDB_G8,
|
2018-03-06 06:19:56 +00:00
|
|
|
|
}.SelectMany(z => z);
|
|
|
|
|
regular = regular.Where(mg => !mg.IsItem && mg.IsPokémon && mg.Species > 0);
|
2018-09-15 23:22:07 +00:00
|
|
|
|
var result = MGDB_G3.Concat(regular);
|
2018-03-06 06:19:56 +00:00
|
|
|
|
if (sorted)
|
|
|
|
|
result = result.OrderBy(mg => mg.Species);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|