Remove some unnecessary null checks

This commit is contained in:
Kurt 2020-04-12 13:20:40 -07:00
parent 30d21e4532
commit 0ada4cbd77
8 changed files with 16 additions and 13 deletions

View file

@ -442,7 +442,7 @@ namespace PKHeX.Core
/// </summary> /// </summary>
public IReadOnlyList<int> GetSuggestedRelearn() public IReadOnlyList<int> GetSuggestedRelearn()
{ {
if (Info?.RelearnBase == null || Info.Generation < 6) if (Info.RelearnBase.Count == 0 || Info.Generation < 6)
return new int[4]; return new int[4];
if (!EncounterMatch.EggEncounter) if (!EncounterMatch.EggEncounter)

View file

@ -307,11 +307,11 @@ namespace PKHeX.Core
{ {
if (Level > pkm.CurrentLevel) // minimum required level if (Level > pkm.CurrentLevel) // minimum required level
return false; return false;
if (pkm.Format != 1 || !pkm.Gen1_NotTradeback) if (!(pkm is PK1 pk1)|| !pkm.Gen1_NotTradeback)
return true; return true;
// Even if the in game trade uses the tables with source pokemon allowing generation 2 games, the traded pokemon could be a non-tradeback pokemon // Even if the in game trade uses the tables with source pokemon allowing generation 2 games, the traded pokemon could be a non-tradeback pokemon
var rate = (pkm as PK1)?.Catch_Rate; var rate = pk1.Catch_Rate;
if (this is EncounterTradeCatchRate r) if (this is EncounterTradeCatchRate r)
{ {
if (rate != r.Catch_Rate) if (rate != r.Catch_Rate)

View file

@ -1,4 +1,5 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using static PKHeX.Core.Legal; using static PKHeX.Core.Legal;
@ -50,7 +51,7 @@ namespace PKHeX.Core
return GetValidEncounterTradesVC(pkm, p, gameSource); return GetValidEncounterTradesVC(pkm, p, gameSource);
var table = GetEncounterTradeTable(pkm); var table = GetEncounterTradeTable(pkm);
return table?.Where(f => p.Any(r => r.Species == f.Species)) ?? Enumerable.Empty<EncounterTrade>(); return table.Where(f => p.Any(r => r.Species == f.Species));
} }
private static IEnumerable<EncounterTrade> GetPossibleVC(IReadOnlyList<DexLevel> p, GameVersion gameSource = GameVersion.Any) private static IEnumerable<EncounterTrade> GetPossibleVC(IReadOnlyList<DexLevel> p, GameVersion gameSource = GameVersion.Any)
@ -59,13 +60,13 @@ namespace PKHeX.Core
return table.Where(f => p.Any(r => r.Species == f.Species)); return table.Where(f => p.Any(r => r.Species == f.Species));
} }
private static IEnumerable<EncounterTrade>? GetEncounterTradeTableVC(GameVersion gameSource) private static IEnumerable<EncounterTrade> GetEncounterTradeTableVC(GameVersion gameSource)
{ {
if (GameVersion.RBY.Contains(gameSource)) if (GameVersion.RBY.Contains(gameSource))
return !ParseSettings.AllowGen1Tradeback ? Encounters1.TradeGift_RBY_NoTradeback : Encounters1.TradeGift_RBY_Tradeback; return !ParseSettings.AllowGen1Tradeback ? Encounters1.TradeGift_RBY_NoTradeback : Encounters1.TradeGift_RBY_Tradeback;
if (GameVersion.GSC.Contains(gameSource)) if (GameVersion.GSC.Contains(gameSource))
return Encounters2.TradeGift_GSC; return Encounters2.TradeGift_GSC;
return null; return Array.Empty<EncounterTrade>();
} }
private static IEnumerable<EncounterTrade>? GetEncounterTradeTable(PKM pkm) private static IEnumerable<EncounterTrade>? GetEncounterTradeTable(PKM pkm)
@ -78,7 +79,7 @@ namespace PKHeX.Core
6 => (pkm.XY ? Encounters6.TradeGift_XY : Encounters6.TradeGift_AO), 6 => (pkm.XY ? Encounters6.TradeGift_XY : Encounters6.TradeGift_AO),
7 => (pkm.GG ? Encounters7b.TradeGift_GG : pkm.SM ? Encounters7.TradeGift_SM : Encounters7.TradeGift_USUM), 7 => (pkm.GG ? Encounters7b.TradeGift_GG : pkm.SM ? Encounters7.TradeGift_SM : Encounters7.TradeGift_USUM),
8 => Encounters8.TradeGift_SWSH, 8 => Encounters8.TradeGift_SWSH,
_ => null, _ => Array.Empty<EncounterTrade>(),
}; };
} }

View file

@ -125,7 +125,7 @@ namespace PKHeX.Core
CheckResult GetWasNotTradeback() CheckResult GetWasNotTradeback()
{ {
if ((e as EncounterStatic)?.Version == GameVersion.Stadium || e is EncounterTradeCatchRate) if ((e is EncounterStatic s && s.Version == GameVersion.Stadium) || e is EncounterTradeCatchRate)
return GetValid(LG1CatchRateMatchPrevious); // Encounters detected by the catch rate, cant be invalid if match this encounters return GetValid(LG1CatchRateMatchPrevious); // Encounters detected by the catch rate, cant be invalid if match this encounters
if ((pk1.Species == 149 && catch_rate == PersonalTable.Y[149].CatchRate) || (GBRestrictions.Species_NotAvailable_CatchRate.Contains(pk1.Species) && catch_rate == PersonalTable.RB[pk1.Species].CatchRate)) if ((pk1.Species == 149 && catch_rate == PersonalTable.Y[149].CatchRate) || (GBRestrictions.Species_NotAvailable_CatchRate.Contains(pk1.Species) && catch_rate == PersonalTable.RB[pk1.Species].CatchRate))
return GetInvalid(LG1CatchRateEvo); return GetInvalid(LG1CatchRateEvo);

View file

@ -94,7 +94,7 @@ namespace PKHeX.Core.Searching
public static IEnumerable<PKM> FilterByBatchInstruction(IEnumerable<PKM> res, IList<string> BatchInstructions) public static IEnumerable<PKM> FilterByBatchInstruction(IEnumerable<PKM> res, IList<string> BatchInstructions)
{ {
if (BatchInstructions?.All(string.IsNullOrWhiteSpace) != false) if (BatchInstructions.All(string.IsNullOrWhiteSpace))
return res; // none specified; return res; // none specified;
var lines = BatchInstructions.Where(z => !string.IsNullOrWhiteSpace(z)); var lines = BatchInstructions.Where(z => !string.IsNullOrWhiteSpace(z));

View file

@ -530,7 +530,7 @@ namespace PKHeX.Core
} }
set set
{ {
if (value?.Length != SpawnFlagCount) if (value.Length != SpawnFlagCount)
return; return;
for (int i = 0; i < value.Length; i++) for (int i = 0; i < value.Length; i++)
SetFlag(Offsets.ObjectSpawnFlags + i >> 3, i & 7, value[i]); SetFlag(Offsets.ObjectSpawnFlags + i >> 3, i & 7, value[i]);

View file

@ -462,7 +462,9 @@ namespace PKHeX.Core
{ {
var data = File.ReadAllBytes(path); var data = File.ReadAllBytes(path);
var sav = GetVariantSAV(data); var sav = GetVariantSAV(data);
sav?.SetFileInfo(path); if (sav == null)
return null;
sav.SetFileInfo(path);
return sav; return sav;
} }

View file

@ -21,7 +21,7 @@ namespace PKHeX.WinForms
components.Dispose(); components.Dispose();
} }
base.Dispose(disposing); base.Dispose(disposing);
qr?.Dispose(); qr.Dispose();
} }
#region Windows Form Designer generated code #region Windows Form Designer generated code