Condense some expressions, parameter names

Enable warnings as errors, so that future pull requests can't submit nullable warning content
This commit is contained in:
Kurt 2021-07-31 22:38:04 -07:00
parent 1bc5cb1113
commit f46bda3f75
3 changed files with 48 additions and 49 deletions

View file

@ -10,13 +10,13 @@ namespace PKHeX.Core
{
private static readonly List<EvoCriteria> NONE = new(0);
internal static IReadOnlyList<EvoCriteria>[] GetEvolutionChainsAllGens(PKM pkm, IEncounterTemplate Encounter)
internal static IReadOnlyList<EvoCriteria>[] GetEvolutionChainsAllGens(PKM pkm, IEncounterTemplate enc)
{
var CompleteEvoChain = GetEvolutionChain(pkm, Encounter, pkm.Species, pkm.CurrentLevel);
if (Encounter is EncounterInvalid || pkm.IsEgg || CompleteEvoChain.Count == 0)
return GetChainSingle(pkm, CompleteEvoChain);
var chain = GetEvolutionChain(pkm, enc, pkm.Species, pkm.CurrentLevel);
if (enc is EncounterInvalid || pkm.IsEgg || chain.Count == 0)
return GetChainSingle(pkm, chain);
return GetChainAll(pkm, Encounter, CompleteEvoChain);
return GetChainAll(pkm, enc, chain);
}
private static List<EvoCriteria>[] GetChainBase(int maxgen)
@ -27,19 +27,19 @@ namespace PKHeX.Core
return GensEvoChains;
}
private static List<EvoCriteria>[] GetChainSingle(PKM pkm, List<EvoCriteria> CompleteEvoChain)
private static List<EvoCriteria>[] GetChainSingle(PKM pkm, List<EvoCriteria> fullChain)
{
var chain = GetChainBase(Math.Max(2, pkm.Format));
chain[pkm.Format] = CompleteEvoChain;
chain[pkm.Format] = fullChain;
return chain;
}
private static List<EvoCriteria>[] GetChainAll(PKM pkm, IEncounterTemplate enc, IReadOnlyList<EvoCriteria> CompleteEvoChain)
private static List<EvoCriteria>[] GetChainAll(PKM pkm, IEncounterTemplate enc, IReadOnlyList<EvoCriteria> fullChain)
{
int maxgen = pkm is PK1 {Gen1_NotTradeback: false} ? 2 : pkm.Format;
var GensEvoChains = GetChainBase(maxgen);
var queue = new Queue<EvoCriteria>(CompleteEvoChain);
var queue = new Queue<EvoCriteria>(fullChain);
var mostEvolved = queue.Dequeue();
int lvl = pkm.CurrentLevel;
@ -143,10 +143,10 @@ namespace PKHeX.Core
_ => false
};
private static void TrimVC1Transfer(PKM pkm, IList<List<EvoCriteria>> GensEvoChains)
private static void TrimVC1Transfer(PKM pkm, IList<List<EvoCriteria>> allChains)
{
if (GensEvoChains[7].All(z => z.Species > MaxSpeciesID_1))
GensEvoChains[pkm.Format] = NONE; // needed a Gen1 species present; invalidate the chain.
if (allChains[7].All(z => z.Species > MaxSpeciesID_1))
allChains[pkm.Format] = NONE; // needed a Gen1 species present; invalidate the chain.
}
internal static int GetEvoChainSpeciesIndex(IReadOnlyList<EvoCriteria> chain, int species)
@ -159,39 +159,39 @@ namespace PKHeX.Core
return -1;
}
private static List<EvoCriteria> GetEvolutionChain(PKM pkm, IEncounterTemplate Encounter, int maxspec, int maxlevel)
private static List<EvoCriteria> GetEvolutionChain(PKM pkm, IEncounterTemplate enc, int mostEvolvedSpecies, int maxlevel)
{
var chain = GetValidPreEvolutions(pkm, minLevel: Encounter.LevelMin);
if (Encounter.Species == maxspec)
var chain = GetValidPreEvolutions(pkm, minLevel: enc.LevelMin);
if (enc.Species == mostEvolvedSpecies)
{
if (chain.Count != 1)
{
chain.RemoveAll(z => z.Species != Encounter.Species);
chain[0].MinLevel = Encounter.LevelMin;
chain.RemoveAll(z => z.Species != enc.Species);
chain[0].MinLevel = enc.LevelMin;
}
return chain;
}
// Evolution chain is in reverse order (devolution)
// Find the index of the minimum species to determine the end of the chain
int minindex = GetEvoChainSpeciesIndex(chain, Encounter.Species);
bool last = minindex < 0 || minindex == chain.Count - 1;
int minIndex = GetEvoChainSpeciesIndex(chain, enc.Species);
bool last = minIndex < 0 || minIndex == chain.Count - 1;
// If we remove a pre-evolution, update the chain if appropriate.
if (!last)
{
// Remove chain species after the encounter
int count = chain.Count;
for (int i = minindex + 1; i < count; i++)
for (int i = minIndex + 1; i < count; i++)
chain.RemoveAt(i);
if (chain.Count == 0)
return chain; // no species left in chain
CheckLastEncounterRemoval(Encounter, chain);
CheckLastEncounterRemoval(enc, chain);
}
// maxspec is used to remove future geneneration evolutions, to gather evolution chain of a pokemon in previous generations
int skip = Math.Max(0, GetEvoChainSpeciesIndex(chain, maxspec));
int skip = Math.Max(0, GetEvoChainSpeciesIndex(chain, mostEvolvedSpecies));
for (int i = 0; i < skip; i++)
chain.RemoveAt(0);

View file

@ -813,34 +813,32 @@ namespace PKHeX.Core
_ => false
};
public static bool IsCompatible3(this PIDType val, IEncounterTemplate encounter, PKM pkm)
public static bool IsCompatible3(this PIDType val, IEncounterTemplate encounter, PKM pkm) => encounter switch
{
switch (encounter)
{
case WC3 g:
if (val == g.Method)
return true;
if (val == CXDAnti && g.Shiny == Shiny.Never && g.Method == CXD)
return true;
// forced shiny eggs, when hatched, can lose their detectable correlation.
return g.IsEgg && !pkm.IsEgg && val == None && (g.Method is BACD_R_S or BACD_U_S);
case EncounterStaticShadow:
return pkm.Version == (int)GameVersion.CXD && (val is CXD or CXDAnti);
case EncounterStatic3 s:
return pkm.Version switch
{
(int)GameVersion.CXD => val is CXD or CXD_ColoStarter or CXDAnti,
(int)GameVersion.E => val == Method_1, // no roamer glitch
(int)GameVersion.FR or (int)GameVersion.LG => s.Roaming ? val.IsRoamerPIDIV(pkm) : val == Method_1, // roamer glitch
_ => s.Roaming ? val.IsRoamerPIDIV(pkm) : MethodH14.Contains(val), // RS, roamer glitch && RSBox s/w emulation => method 4 available
};
case EncounterSlot w:
if (pkm.Version == 15)
return val == PokeSpot;
return (w.Species == (int)Species.Unown ? MethodH_Unown : MethodH).Contains(val);
default:
return val == None;
}
WC3 g => IsCompatible3Mystery(val, pkm, g),
EncounterStatic3 s => IsCompatible3Static(val, pkm, s),
EncounterSlot3 w => (w.Species == (int)Species.Unown ? MethodH_Unown : MethodH).Contains(val),
EncounterStaticShadow => val is CXD or CXDAnti,
EncounterSlot3PokeSpot => val == PokeSpot,
_ => val == None
};
private static bool IsCompatible3Static(PIDType val, PKM pkm, EncounterStatic3 s) => pkm.Version switch
{
(int)GameVersion.CXD => val is CXD or CXD_ColoStarter or CXDAnti,
(int)GameVersion.E => val == Method_1, // no roamer glitch
(int)GameVersion.FR or (int) GameVersion.LG => s.Roaming ? val.IsRoamerPIDIV(pkm) : val == Method_1, // roamer glitch
_ => s.Roaming ? val.IsRoamerPIDIV(pkm) : MethodH14.Contains(val), // RS, roamer glitch && RSBox s/w emulation => method 4 available
};
private static bool IsCompatible3Mystery(PIDType val, PKM pkm, WC3 g)
{
if (val == g.Method)
return true;
if (val == CXDAnti && g.Shiny == Shiny.Never && g.Method == CXD)
return true;
// forced shiny eggs, when hatched, can lose their detectable correlation.
return g.IsEgg && !pkm.IsEgg && val == None && (g.Method is BACD_R_S or BACD_U_S);
}
private static bool IsRoamerPIDIV(this PIDType val, PKM pkm)

View file

@ -12,6 +12,7 @@
<RepositoryUrl>https://github.com/kwsch/PKHeX</RepositoryUrl>
<LangVersion>9</LangVersion>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<ItemGroup>