Fix NullReferenceException in legality checks

This commit is contained in:
Michael Scire
2016-11-09 17:52:38 -08:00
parent 5c91e1fb5d
commit dfa92e79b7

View File

@@ -9,6 +9,12 @@ public partial class LegalityAnalysis
private PKM pkm;
private readonly List<CheckResult> Parse = new List<CheckResult>();
private enum Encounters
{
Unknown = -1,
Generic = 0
}
private object EncounterMatch;
private Type EncounterType;
private bool EncounterIsMysteryGift => EncounterType.IsSubclassOf(typeof (MysteryGift));
@@ -95,6 +101,10 @@ private void updateMoveLegality()
private void updateChecks()
{
Encounter = verifyEncounter();
// If EncounterMatch is null, nullrefexception will prevent a lot of analysis from happening at all.
EncounterMatch = EncounterMatch ?? Encounters.Unknown;
EncounterType = EncounterMatch?.GetType();
if (EncounterType == typeof (MysteryGift))
EncounterType = EncounterType.BaseType;