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>
|
2018-09-15 23:22:07 +00:00
|
|
|
|
public static WC3[] MGDB_G3 { get; private set; } = Array.Empty<WC3>();
|
2018-03-06 06:19:56 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>Event Database for Generation 4</summary>
|
2018-09-15 23:22:07 +00:00
|
|
|
|
public static PCD[] MGDB_G4 { get; private set; } = Array.Empty<PCD>();
|
2018-03-06 06:19:56 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>Event Database for Generation 5</summary>
|
2018-09-15 23:22:07 +00:00
|
|
|
|
public static PGF[] MGDB_G5 { get; private set; } = Array.Empty<PGF>();
|
2018-03-06 06:19:56 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>Event Database for Generation 6</summary>
|
2018-09-15 23:22:07 +00:00
|
|
|
|
public static WC6[] MGDB_G6 { get; private set; } = Array.Empty<WC6>();
|
2018-03-06 06:19:56 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>Event Database for Generation 7</summary>
|
2018-09-15 23:22:07 +00:00
|
|
|
|
public static 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>
|
2018-11-21 20:24:41 +00:00
|
|
|
|
public static 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>
|
|
|
|
|
public static 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>
|
|
|
|
|
public static bool Initialized => MGDB_G3.Length != 0;
|
|
|
|
|
|
2019-09-10 07:21:51 +00:00
|
|
|
|
private static HashSet<PCD> GetPCDDB(byte[] bin) => new HashSet<PCD>(ArrayUtil.EnumerateSplit(bin, PCD.Size).Select(d => new PCD(d)));
|
2018-07-28 05:26:27 +00:00
|
|
|
|
|
2019-09-10 07:21:51 +00:00
|
|
|
|
private static HashSet<PGF> GetPGFDB(byte[] bin) => new HashSet<PGF>(ArrayUtil.EnumerateSplit(bin, PGF.Size).Select(d => new PGF(d)));
|
2018-07-28 05:26:27 +00:00
|
|
|
|
|
2018-09-15 23:22:07 +00:00
|
|
|
|
private static HashSet<WC6> GetWC6DB(byte[] wc6bin, byte[] wc6full) => new HashSet<WC6>(
|
PKHeX.Core Nullable cleanup (#2401)
* Handle some nullable cases
Refactor MysteryGift into a second abstract class (backed by a byte array, or fake data)
Make some classes have explicit constructors instead of { } initialization
* Handle bits more obviously without null
* Make SaveFile.BAK explicitly readonly again
* merge constructor methods to have readonly fields
* Inline some properties
* More nullable handling
* Rearrange box actions
define straightforward classes to not have any null properties
* Make extrabyte reference array immutable
* Move tooltip creation to designer
* Rearrange some logic to reduce nesting
* Cache generated fonts
* Split mystery gift album purpose
* Handle more tooltips
* Disallow null setters
* Don't capture RNG object, only type enum
* Unify learnset objects
Now have readonly properties which are never null
don't new() empty learnsets (>800 Learnset objects no longer created,
total of 2400 objects since we also new() a move & level array)
optimize g1/2 reader for early abort case
* Access rewrite
Initialize blocks in a separate object, and get via that object
removes a couple hundred "might be null" warnings since blocks are now readonly getters
some block references have been relocated, but interfaces should expose all that's needed
put HoF6 controls in a groupbox, and disable
* Readonly personal data
* IVs non nullable for mystery gift
* Explicitly initialize forced encounter moves
* Make shadow objects readonly & non-null
Put murkrow fix in binary data resource, instead of on startup
* Assign dex form fetch on constructor
Fixes legality parsing edge cases
also handle cxd parse for valid; exit before exception is thrown in FrameGenerator
* Remove unnecessary null checks
* Keep empty value until init
SetPouch sets the value to an actual one during load, but whatever
* Readonly team lock data
* Readonly locks
Put locked encounters at bottom (favor unlocked)
* Mail readonly data / offset
Rearrange some call flow and pass defaults
Add fake classes for SaveDataEditor mocking
Always party size, no need to check twice in stat editor
use a fake save file as initial data for savedata editor, and for
gamedata (wow i found a usage)
constrain eventwork editor to struct variable types (uint, int, etc),
thus preventing null assignment errors
2019-10-17 01:47:31 +00:00
|
|
|
|
ArrayUtil.EnumerateSplit(wc6full, WC6Full.Size).Select(d => new WC6Full(d).Gift)
|
2019-09-10 07:21:51 +00:00
|
|
|
|
.Concat(ArrayUtil.EnumerateSplit(wc6bin, WC6.Size).Select(d => new WC6(d))));
|
2018-07-28 05:26:27 +00:00
|
|
|
|
|
2018-09-15 23:22:07 +00:00
|
|
|
|
private static HashSet<WC7> GetWC7DB(byte[] wc7bin, byte[] wc7full) => new HashSet<WC7>(
|
PKHeX.Core Nullable cleanup (#2401)
* Handle some nullable cases
Refactor MysteryGift into a second abstract class (backed by a byte array, or fake data)
Make some classes have explicit constructors instead of { } initialization
* Handle bits more obviously without null
* Make SaveFile.BAK explicitly readonly again
* merge constructor methods to have readonly fields
* Inline some properties
* More nullable handling
* Rearrange box actions
define straightforward classes to not have any null properties
* Make extrabyte reference array immutable
* Move tooltip creation to designer
* Rearrange some logic to reduce nesting
* Cache generated fonts
* Split mystery gift album purpose
* Handle more tooltips
* Disallow null setters
* Don't capture RNG object, only type enum
* Unify learnset objects
Now have readonly properties which are never null
don't new() empty learnsets (>800 Learnset objects no longer created,
total of 2400 objects since we also new() a move & level array)
optimize g1/2 reader for early abort case
* Access rewrite
Initialize blocks in a separate object, and get via that object
removes a couple hundred "might be null" warnings since blocks are now readonly getters
some block references have been relocated, but interfaces should expose all that's needed
put HoF6 controls in a groupbox, and disable
* Readonly personal data
* IVs non nullable for mystery gift
* Explicitly initialize forced encounter moves
* Make shadow objects readonly & non-null
Put murkrow fix in binary data resource, instead of on startup
* Assign dex form fetch on constructor
Fixes legality parsing edge cases
also handle cxd parse for valid; exit before exception is thrown in FrameGenerator
* Remove unnecessary null checks
* Keep empty value until init
SetPouch sets the value to an actual one during load, but whatever
* Readonly team lock data
* Readonly locks
Put locked encounters at bottom (favor unlocked)
* Mail readonly data / offset
Rearrange some call flow and pass defaults
Add fake classes for SaveDataEditor mocking
Always party size, no need to check twice in stat editor
use a fake save file as initial data for savedata editor, and for
gamedata (wow i found a usage)
constrain eventwork editor to struct variable types (uint, int, etc),
thus preventing null assignment errors
2019-10-17 01:47:31 +00:00
|
|
|
|
ArrayUtil.EnumerateSplit(wc7full, WC7Full.Size).Select(d => new WC7Full(d).Gift)
|
2019-09-10 07:21:51 +00:00
|
|
|
|
.Concat(ArrayUtil.EnumerateSplit(wc7bin, WC7.Size).Select(d => new WC7(d))));
|
2018-03-06 06:19:56 +00:00
|
|
|
|
|
2019-09-10 07:21:51 +00:00
|
|
|
|
private static HashSet<WB7> GetWB7DB(byte[] wc7full) => new HashSet<WB7>(ArrayUtil.EnumerateSplit(wc7full, WB7.SizeFull).Select(d => new WB7(d)));
|
2018-11-11 21:09:04 +00:00
|
|
|
|
|
2019-11-16 01:34:18 +00:00
|
|
|
|
private static HashSet<WC8> GetWC8DB(byte[] wc8bin) =>
|
|
|
|
|
new HashSet<WC8>(ArrayUtil.EnumerateSplit(wc8bin, WC8.Size).Select(d => new WC8(d)));
|
|
|
|
|
|
2018-03-06 06:19:56 +00:00
|
|
|
|
public static void RefreshMGDB(params string[] paths)
|
|
|
|
|
{
|
|
|
|
|
var g4 = GetPCDDB(Util.GetBinaryResource("wc4.pkl"));
|
|
|
|
|
var g5 = GetPGFDB(Util.GetBinaryResource("pgf.pkl"));
|
|
|
|
|
var g6 = GetWC6DB(Util.GetBinaryResource("wc6.pkl"), Util.GetBinaryResource("wc6full.pkl"));
|
|
|
|
|
var g7 = GetWC7DB(Util.GetBinaryResource("wc7.pkl"), Util.GetBinaryResource("wc7full.pkl"));
|
2018-11-21 20:24:41 +00:00
|
|
|
|
var b7 = GetWB7DB(Util.GetBinaryResource("wb7full.pkl"));
|
2019-11-16 01:34:18 +00:00
|
|
|
|
var 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
|
|
|
|
{
|
2019-09-23 23:56:47 +00:00
|
|
|
|
switch (gift)
|
2018-03-06 06:19:56 +00:00
|
|
|
|
{
|
2019-09-23 23:56:47 +00:00
|
|
|
|
case PCD pcd: g4.Add(pcd); continue;
|
|
|
|
|
case PGF pgf: g5.Add(pgf); continue;
|
|
|
|
|
case WC6 wc6: g6.Add(wc6); continue;
|
|
|
|
|
case WC7 wc7: g7.Add(wc7); continue;
|
|
|
|
|
case WB7 wb7: b7.Add(wb7); continue;
|
2019-11-16 01:34:18 +00:00
|
|
|
|
case WC8 wc8: g8.Add(wc8); continue;
|
2018-03-06 06:19:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MGDB_G3 = Encounter_WC3; // hardcoded
|
|
|
|
|
MGDB_G4 = g4.ToArray();
|
|
|
|
|
MGDB_G5 = g5.ToArray();
|
|
|
|
|
MGDB_G6 = g6.ToArray();
|
|
|
|
|
MGDB_G7 = g7.ToArray();
|
2018-11-21 20:24:41 +00:00
|
|
|
|
MGDB_G7GG = b7.ToArray();
|
2019-11-16 01:34:18 +00:00
|
|
|
|
MGDB_G8 = g8.ToArray();
|
2018-03-06 06:19:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static IEnumerable<MysteryGift> GetAllEvents(bool sorted = true)
|
|
|
|
|
{
|
2018-09-15 23:22:07 +00:00
|
|
|
|
var regular = new 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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|