2020-11-07 20:25:15 +00:00
using System.Collections.Generic ;
2017-05-28 04:17:53 +00:00
namespace PKHeX.Core
{
2017-10-24 06:12:58 +00:00
/// <summary>
/// Calculated Information storage with properties useful for parsing the legality of the input <see cref="PKM"/>.
/// </summary>
2020-12-24 23:23:38 +00:00
public sealed class LegalInfo : IGeneration
2017-05-28 04:17:53 +00:00
{
/// <summary>The <see cref="PKM"/> object used for comparisons.</summary>
private readonly PKM pkm ;
2017-09-04 02:51:29 +00:00
/// <summary>The generation of games the <see cref="PKM"/> originated from.</summary>
2021-08-06 22:35:49 +00:00
public int Generation { get ; private set ; }
2017-05-28 04:17:53 +00:00
2017-09-04 02:51:29 +00:00
/// <summary>The Game the <see cref="PKM"/> originated from.</summary>
2021-08-06 22:35:49 +00:00
public GameVersion Game { get ; private set ; }
2017-05-28 23:56:51 +00:00
2017-05-28 04:17:53 +00:00
/// <summary>The matched Encounter details for the <see cref="PKM"/>. </summary>
public IEncounterable EncounterMatch
{
get = > _match ;
set
{
2020-12-24 04:40:59 +00:00
if ( ! ReferenceEquals ( _match , EncounterInvalid . Default ) & & ( value . LevelMin ! = _match . LevelMin | | value . Species ! = _match . Species ) )
2018-06-20 00:14:22 +00:00
_evochains = null ; // clear if evo chain has the potential to be different
2017-05-28 04:17:53 +00:00
_match = value ;
Parse . Clear ( ) ;
}
}
2018-08-03 03:11:42 +00:00
2019-12-09 23:48:54 +00:00
/// <summary>
/// Original encounter data for the <see cref="pkm"/>.
/// </summary>
/// <remarks>
/// Generation 1/2 <see cref="pkm"/> that are transferred forward to Generation 7 are restricted to new encounter details.
/// By retaining their original match, more information can be provided by the parse.
/// </remarks>
public IEncounterable EncounterOriginal = > EncounterOriginalGB ? ? EncounterMatch ;
internal IEncounterable ? EncounterOriginalGB ;
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
private IEncounterable _match = EncounterInvalid . Default ;
2017-09-04 02:51:29 +00:00
/// <summary>Top level Legality Check result list for the <see cref="EncounterMatch"/>.</summary>
2021-08-06 00:16:13 +00:00
internal readonly List < CheckResult > Parse ;
2017-05-28 04:17:53 +00:00
2021-03-31 03:27:40 +00:00
public readonly CheckResult [ ] Relearn = new CheckResult [ 4 ] ;
2019-02-22 04:41:04 +00:00
public CheckMoveResult [ ] Moves { get ; internal set ; } = new CheckMoveResult [ 4 ] ;
2017-05-28 04:17:53 +00:00
2020-12-22 01:17:56 +00:00
private static readonly ValidEncounterMoves NONE = new ( ) ;
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
public ValidEncounterMoves EncounterMoves { get ; internal set ; } = NONE ;
2021-01-02 22:47:39 +00:00
public IReadOnlyList < EvoCriteria > [ ] EvoChainsAllGens = > _evochains ? ? = EvolutionChain . GetEvolutionChainsAllGens ( pkm , EncounterMatch ) ;
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
private IReadOnlyList < EvoCriteria > [ ] ? _evochains ;
2017-09-04 02:51:29 +00:00
/// <summary><see cref="RNG"/> related information that generated the <see cref="PKM.PID"/>/<see cref="PKM.IVs"/> value(s).</summary>
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
public PIDIV PIDIV
{
get = > _pidiv ;
internal set
{
_pidiv = value ;
PIDParsed = true ;
}
}
public bool PIDParsed { get ; private set ; }
private PIDIV _pidiv = PIDIV . None ;
2017-07-29 18:54:52 +00:00
2017-09-04 02:51:29 +00:00
/// <summary>Indicates whether or not the <see cref="PIDIV"/> can originate from the <see cref="EncounterMatch"/>.</summary>
2017-11-29 05:30:53 +00:00
/// <remarks>This boolean is true until all valid <see cref="PIDIV"/> encounters are tested, after which it is false.</remarks>
2019-02-22 04:41:04 +00:00
public bool PIDIVMatches { get ; internal set ; } = true ;
2017-05-28 04:17:53 +00:00
2017-11-29 05:30:53 +00:00
/// <summary>Indicates whether or not the <see cref="PIDIV"/> can originate from the <see cref="EncounterMatch"/> with explicit <see cref="RNG"/> <see cref="Frame"/> matching.</summary>
/// <remarks>This boolean is true until all valid <see cref="Frame"/> entries are tested for all possible <see cref="EncounterSlot"/> matches, after which it is false.</remarks>
2019-02-22 04:41:04 +00:00
public bool FrameMatches { get ; internal set ; } = true ;
2017-11-29 05:30:53 +00:00
2021-08-06 00:16:13 +00:00
public LegalInfo ( PKM pk , List < CheckResult > parse )
2017-05-28 23:56:51 +00:00
{
pkm = pk ;
2021-08-06 00:16:13 +00:00
Parse = parse ;
2021-08-06 22:35:49 +00:00
StoreMetadata ( ( GameVersion ) pk . Version , pkm . Generation ) ;
}
2017-09-04 02:51:29 +00:00
2021-08-06 22:35:49 +00:00
internal void StoreMetadata ( GameVersion game , int gen )
{
// We can call this method at the start for any Gen3+ encounter iteration.
// We need to call this for each Gen1/2 encounter as Version is not stored for those origins.
Game = game ;
Generation = gen ;
2017-05-28 23:56:51 +00:00
}
2017-05-28 04:17:53 +00:00
}
}