mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-27 06:20:25 +00:00
Remove some unnecessary null checks
This commit is contained in:
parent
30d21e4532
commit
0ada4cbd77
8 changed files with 16 additions and 13 deletions
|
@ -442,7 +442,7 @@ namespace PKHeX.Core
|
|||
/// </summary>
|
||||
public IReadOnlyList<int> GetSuggestedRelearn()
|
||||
{
|
||||
if (Info?.RelearnBase == null || Info.Generation < 6)
|
||||
if (Info.RelearnBase.Count == 0 || Info.Generation < 6)
|
||||
return new int[4];
|
||||
|
||||
if (!EncounterMatch.EggEncounter)
|
||||
|
|
|
@ -307,11 +307,11 @@ namespace PKHeX.Core
|
|||
{
|
||||
if (Level > pkm.CurrentLevel) // minimum required level
|
||||
return false;
|
||||
if (pkm.Format != 1 || !pkm.Gen1_NotTradeback)
|
||||
if (!(pkm is PK1 pk1)|| !pkm.Gen1_NotTradeback)
|
||||
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
|
||||
var rate = (pkm as PK1)?.Catch_Rate;
|
||||
var rate = pk1.Catch_Rate;
|
||||
if (this is EncounterTradeCatchRate r)
|
||||
{
|
||||
if (rate != r.Catch_Rate)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using static PKHeX.Core.Legal;
|
||||
|
||||
|
@ -50,7 +51,7 @@ namespace PKHeX.Core
|
|||
return GetValidEncounterTradesVC(pkm, p, gameSource);
|
||||
|
||||
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)
|
||||
|
@ -59,13 +60,13 @@ namespace PKHeX.Core
|
|||
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))
|
||||
return !ParseSettings.AllowGen1Tradeback ? Encounters1.TradeGift_RBY_NoTradeback : Encounters1.TradeGift_RBY_Tradeback;
|
||||
if (GameVersion.GSC.Contains(gameSource))
|
||||
return Encounters2.TradeGift_GSC;
|
||||
return null;
|
||||
return Array.Empty<EncounterTrade>();
|
||||
}
|
||||
|
||||
private static IEnumerable<EncounterTrade>? GetEncounterTradeTable(PKM pkm)
|
||||
|
@ -78,7 +79,7 @@ namespace PKHeX.Core
|
|||
6 => (pkm.XY ? Encounters6.TradeGift_XY : Encounters6.TradeGift_AO),
|
||||
7 => (pkm.GG ? Encounters7b.TradeGift_GG : pkm.SM ? Encounters7.TradeGift_SM : Encounters7.TradeGift_USUM),
|
||||
8 => Encounters8.TradeGift_SWSH,
|
||||
_ => null,
|
||||
_ => Array.Empty<EncounterTrade>(),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -125,7 +125,7 @@ namespace PKHeX.Core
|
|||
|
||||
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
|
||||
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);
|
||||
|
|
|
@ -94,7 +94,7 @@ namespace PKHeX.Core.Searching
|
|||
|
||||
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;
|
||||
|
||||
var lines = BatchInstructions.Where(z => !string.IsNullOrWhiteSpace(z));
|
||||
|
|
|
@ -530,7 +530,7 @@ namespace PKHeX.Core
|
|||
}
|
||||
set
|
||||
{
|
||||
if (value?.Length != SpawnFlagCount)
|
||||
if (value.Length != SpawnFlagCount)
|
||||
return;
|
||||
for (int i = 0; i < value.Length; i++)
|
||||
SetFlag(Offsets.ObjectSpawnFlags + i >> 3, i & 7, value[i]);
|
||||
|
|
|
@ -462,7 +462,9 @@ namespace PKHeX.Core
|
|||
{
|
||||
var data = File.ReadAllBytes(path);
|
||||
var sav = GetVariantSAV(data);
|
||||
sav?.SetFileInfo(path);
|
||||
if (sav == null)
|
||||
return null;
|
||||
sav.SetFileInfo(path);
|
||||
return sav;
|
||||
}
|
||||
|
||||
|
|
2
PKHeX.WinForms/Misc/QR.Designer.cs
generated
2
PKHeX.WinForms/Misc/QR.Designer.cs
generated
|
@ -21,7 +21,7 @@ namespace PKHeX.WinForms
|
|||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
qr?.Dispose();
|
||||
qr.Dispose();
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
|
Loading…
Reference in a new issue