mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-26 14:00:21 +00:00
Refactoring
de-linq some areas where direct accessing is possible (list/array)
This commit is contained in:
parent
4a63769351
commit
5bc2e6da88
12 changed files with 60 additions and 65 deletions
|
@ -77,39 +77,18 @@ namespace PKHeX.Core
|
|||
#endif
|
||||
{
|
||||
PersonalInfo = table?.GetFormeEntry(pk.Species, pk.AltForm) ?? pk.PersonalInfo;
|
||||
switch (pk.Format) // prior to storing GameVersion
|
||||
{
|
||||
case 1: ParsePK1(pk); break;
|
||||
case 2: ParsePK1(pk); break;
|
||||
}
|
||||
ParseLegality(pk);
|
||||
|
||||
if (!Parse.Any())
|
||||
switch (pk.GenNumber)
|
||||
{
|
||||
case 3: ParsePK3(pk); break;
|
||||
case 4: ParsePK4(pk); break;
|
||||
case 5: ParsePK5(pk); break;
|
||||
case 6: ParsePK6(pk); break;
|
||||
if (Parse.Count <= 0)
|
||||
return;
|
||||
|
||||
case 1: case 2:
|
||||
case 7: ParsePK7(pk); break;
|
||||
}
|
||||
|
||||
if (Parse.Count > 0)
|
||||
{
|
||||
if (Parse.Any(chk => !chk.Valid))
|
||||
Valid = false;
|
||||
else if (Info.Moves.Any(m => m.Valid != true))
|
||||
Valid = false;
|
||||
else if (Info.Relearn.Any(m => m.Valid != true))
|
||||
Valid = false;
|
||||
else
|
||||
Valid = true;
|
||||
Valid = Parse.All(chk => chk.Valid)
|
||||
&& Info.Moves.All(m => m.Valid)
|
||||
&& Info.Relearn.All(m => m.Valid);
|
||||
|
||||
if (pkm.FatefulEncounter && Info.Relearn.Any(chk => !chk.Valid) && EncounterMatch == null)
|
||||
AddLine(Severity.Indeterminate, V188, CheckIdentifier.Fateful);
|
||||
}
|
||||
}
|
||||
#if SUPPRESS
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@ -122,6 +101,24 @@ namespace PKHeX.Core
|
|||
#endif
|
||||
Parsed = true;
|
||||
}
|
||||
private void ParseLegality(PKM pk)
|
||||
{
|
||||
if (pk.Format == 1 || pk.Format == 2) // prior to storing GameVersion
|
||||
{
|
||||
ParsePK1(pk);
|
||||
return;
|
||||
}
|
||||
switch (pk.GenNumber)
|
||||
{
|
||||
case 3: ParsePK3(pk); return;
|
||||
case 4: ParsePK4(pk); return;
|
||||
case 5: ParsePK5(pk); return;
|
||||
case 6: ParsePK6(pk); return;
|
||||
|
||||
case 1: case 2:
|
||||
case 7: ParsePK7(pk); return;
|
||||
}
|
||||
}
|
||||
|
||||
private void AddLine(Severity s, string c, CheckIdentifier i)
|
||||
{
|
||||
|
@ -289,8 +286,6 @@ namespace PKHeX.Core
|
|||
VerifyConsoleRegion();
|
||||
VerifyVersionEvolution();
|
||||
}
|
||||
|
||||
// SecondaryChecked = true;
|
||||
}
|
||||
private string GetLegalityReport()
|
||||
{
|
||||
|
|
|
@ -964,7 +964,7 @@ namespace PKHeX.Core
|
|||
}
|
||||
|
||||
List<string> result = RibbonVerifier.GetIncorrectRibbons(pkm, encounterContent, Info.Generation);
|
||||
if (result.Any())
|
||||
if (result.Count != 0)
|
||||
AddLine(Severity.Invalid, string.Join(Environment.NewLine, result.Where(s => !string.IsNullOrEmpty(s))), CheckIdentifier.Ribbon);
|
||||
else
|
||||
AddLine(Severity.Valid, V602, CheckIdentifier.Ribbon);
|
||||
|
|
|
@ -400,7 +400,7 @@ namespace PKHeX.Core
|
|||
{
|
||||
List<int>[] Moves = new List<int>[evoChains.Length];
|
||||
for (int i = 1; i < evoChains.Length; i++)
|
||||
if (evoChains[i].Any())
|
||||
if (evoChains[i].Length != 0)
|
||||
Moves[i] = GetValidMoves(pkm, evoChains[i], i, minLvLG1, minLvLG2, LVL, Tutor, Machine, MoveReminder, RemoveTransferHM).ToList();
|
||||
else
|
||||
Moves[i] = new List<int>();
|
||||
|
@ -577,7 +577,7 @@ namespace PKHeX.Core
|
|||
// Return moves that the pokemon could learn after evolving
|
||||
var moves = new List<int>();
|
||||
for (int i = 1; i < evoChains.Length; i++)
|
||||
if (evoChains[i].Any())
|
||||
if (evoChains[i].Length != 0)
|
||||
moves.AddRange(GetValidPostEvolutionMoves(pkm, Species, evoChains[i], i, Version));
|
||||
if (pkm.GenNumber >= 6)
|
||||
moves.AddRange(pkm.RelearnMoves.Where(m => m != 0));
|
||||
|
@ -1502,30 +1502,30 @@ namespace PKHeX.Core
|
|||
|
||||
// Remove future gen evolutions after a few special considerations,
|
||||
// it the pokemon origin is illegal like a "gen 3" Infernape the list will be emptied, it didnt existed in gen 3 in any evolution phase
|
||||
while (CompleteEvoChain.Any() && CompleteEvoChain.First().Species > maxspeciesgen)
|
||||
while (CompleteEvoChain.Length != 0 && CompleteEvoChain[0].Species > maxspeciesgen)
|
||||
{
|
||||
// Eevee requires to level one time to be Sylveon, it can be deduced in gen 5 and before it existed with maximum one level bellow current
|
||||
if (CompleteEvoChain.First().Species == 700 && gen == 5)
|
||||
if (CompleteEvoChain[0].Species == 700 && gen == 5)
|
||||
lvl--;
|
||||
// This is a gen 3 pokemon in a gen 4 phase evolution that requieres level up and then transfered to gen 5+
|
||||
// We can deduce that it existed in gen 4 until met level,
|
||||
// but if current level is met level we can also deduce it existed in gen 3 until maximum met level -1
|
||||
if (gen == 3 && pkm.Format > 4 && lvl == pkm.CurrentLevel && CompleteEvoChain.First().Species > MaxSpeciesID_3 && CompleteEvoChain.First().RequiresLvlUp)
|
||||
if (gen == 3 && pkm.Format > 4 && lvl == pkm.CurrentLevel && CompleteEvoChain[0].Species > MaxSpeciesID_3 && CompleteEvoChain[0].RequiresLvlUp)
|
||||
lvl--;
|
||||
// The same condition for gen2 evolution of gen 1 pokemon, level of the pokemon in gen 1 games would be CurrentLevel -1 one level bellow gen 2 level
|
||||
if (gen == 1 && pkm.Format == 2 && lvl == pkm.CurrentLevel && CompleteEvoChain.First().Species > MaxSpeciesID_1 && CompleteEvoChain.First().RequiresLvlUp)
|
||||
if (gen == 1 && pkm.Format == 2 && lvl == pkm.CurrentLevel && CompleteEvoChain[0].Species > MaxSpeciesID_1 && CompleteEvoChain[0].RequiresLvlUp)
|
||||
lvl--;
|
||||
CompleteEvoChain = CompleteEvoChain.Skip(1).ToArray();
|
||||
}
|
||||
|
||||
// Alolan form evolutions, remove from gens 1-6 chains
|
||||
if (gen < 7 && pkm.Format >= 7 && CompleteEvoChain.Any() && CompleteEvoChain.First().Form > 0 && EvolveToAlolanForms.Contains(CompleteEvoChain.First().Species))
|
||||
if (gen < 7 && pkm.Format >= 7 && CompleteEvoChain.Length != 0 && CompleteEvoChain[0].Form > 0 && EvolveToAlolanForms.Contains(CompleteEvoChain[0].Species))
|
||||
CompleteEvoChain = CompleteEvoChain.Skip(1).ToArray();
|
||||
|
||||
if (!CompleteEvoChain.Any())
|
||||
if (CompleteEvoChain.Length == 0)
|
||||
continue;
|
||||
|
||||
GensEvoChains[gen] = GetEvolutionChain(pkm, Encounter, CompleteEvoChain.First().Species, lvl);
|
||||
GensEvoChains[gen] = GetEvolutionChain(pkm, Encounter, CompleteEvoChain[0].Species, lvl);
|
||||
if (gen > 2 && !pkm.HasOriginalMetLocation && gen >= pkm.GenNumber)
|
||||
//Remove previous evolutions bellow transfer level
|
||||
//For example a gen3 charizar in format 7 with current level 36 and met level 36
|
||||
|
@ -1560,12 +1560,12 @@ namespace PKHeX.Core
|
|||
|
||||
int minindex = Math.Max(0, Array.FindIndex(vs, p => p.Species == minspec));
|
||||
Array.Resize(ref vs, minindex + 1);
|
||||
var last = vs.Last();
|
||||
var last = vs[vs.Length - 1];
|
||||
if (last.MinLevel > 1) // Last entry from vs is removed, turn next entry into the wild/hatched pokemon
|
||||
{
|
||||
last.MinLevel = Encounter.LevelMin;
|
||||
last.RequiresLvlUp = false;
|
||||
var first = vs.First();
|
||||
var first = vs[0];
|
||||
if (!first.RequiresLvlUp)
|
||||
{
|
||||
if (first.MinLevel == 2)
|
||||
|
@ -1645,7 +1645,7 @@ namespace PKHeX.Core
|
|||
r.AddRange(pkm.RelearnMoves);
|
||||
|
||||
for (int gen = pkm.GenNumber; gen <= pkm.Format; gen++)
|
||||
if (vs[gen].Any())
|
||||
if (vs[gen].Length != 0)
|
||||
r.AddRange(GetValidMoves(pkm, Version, vs[gen], gen, minLvLG1: minLvLG1, minLvLG2: minLvLG2, LVL: LVL, Relearn: false, Tutor: Tutor, Machine: Machine, MoveReminder: MoveReminder, RemoveTransferHM: RemoveTransferHM));
|
||||
|
||||
return r.Distinct();
|
||||
|
@ -1653,7 +1653,7 @@ namespace PKHeX.Core
|
|||
private static IEnumerable<int> GetValidMoves(PKM pkm, GameVersion Version, DexLevel[] vs, int Generation, int minLvLG1 = 1, int minLvLG2 = 1, bool LVL = false, bool Relearn = false, bool Tutor = false, bool Machine = false, bool MoveReminder = true, bool RemoveTransferHM = true)
|
||||
{
|
||||
List<int> r = new List<int> { 0 };
|
||||
if (!vs.Any())
|
||||
if (vs.Length == 0)
|
||||
return r;
|
||||
int species = pkm.Species;
|
||||
|
||||
|
@ -1667,7 +1667,7 @@ namespace PKHeX.Core
|
|||
// In gen 3 deoxys has different forms depending on the current game, in personal info there is no alter form info
|
||||
formcount = 4;
|
||||
for (int i = 0; i < formcount; i++)
|
||||
r.AddRange(GetMoves(pkm, species, minLvLG1, minLvLG2, vs.First().Level, i, moveTutor, Version, LVL, Tutor, Machine, MoveReminder, RemoveTransferHM, Generation));
|
||||
r.AddRange(GetMoves(pkm, species, minLvLG1, minLvLG2, vs[0].Level, i, moveTutor, Version, LVL, Tutor, Machine, MoveReminder, RemoveTransferHM, Generation));
|
||||
if (Relearn) r.AddRange(pkm.RelearnMoves);
|
||||
return r.Distinct();
|
||||
}
|
||||
|
|
|
@ -1489,7 +1489,7 @@ namespace PKHeX.Core
|
|||
var vs = GetValidPreEvolutions(pkm);
|
||||
return (from area in GetEncounterSlots(pkm)
|
||||
let slots = GetValidEncounterSlots(pkm, area, vs, DexNav: pkm.AO, ignoreLevel: true).ToArray()
|
||||
where slots.Any()
|
||||
where slots.Length != 0
|
||||
select new EncounterArea
|
||||
{
|
||||
Location = area.Location,
|
||||
|
|
|
@ -322,7 +322,7 @@ namespace PKHeX.Core
|
|||
if (res[m].Valid && gen == 1)
|
||||
{
|
||||
learnInfo.Gen1Moves.Add(m);
|
||||
if (learnInfo.Gen2PreevoMoves.Any())
|
||||
if (learnInfo.Gen2PreevoMoves.Count != 0)
|
||||
learnInfo.MixedGen12NonTradeback = true;
|
||||
}
|
||||
|
||||
|
@ -368,7 +368,7 @@ namespace PKHeX.Core
|
|||
if (!learnInfo.Source.EggLevelUpSource.Contains(moves[m])) // Check if contains level-up egg moves from parents
|
||||
continue;
|
||||
|
||||
if (learnInfo.IsGen2Pkm && learnInfo.Gen1Moves.Any() && moves[m] > Legal.MaxMoveID_1)
|
||||
if (learnInfo.IsGen2Pkm && learnInfo.Gen1Moves.Count != 0 && moves[m] > Legal.MaxMoveID_1)
|
||||
{
|
||||
res[m] = new CheckMoveResult(MoveSource.InheritLevelUp, gen, Severity.Invalid, V334, CheckIdentifier.Move);
|
||||
learnInfo.MixedGen12NonTradeback = true;
|
||||
|
@ -396,7 +396,7 @@ namespace PKHeX.Core
|
|||
{
|
||||
// To learn exclusive generation 1 moves the pokemon was tradeback, but it can't be trade to generation 1
|
||||
// without removing moves above MaxMoveID_1, egg moves above MaxMoveID_1 and gen 1 moves are incompatible
|
||||
if (learnInfo.IsGen2Pkm && learnInfo.Gen1Moves.Any() && moves[m] > Legal.MaxMoveID_1)
|
||||
if (learnInfo.IsGen2Pkm && learnInfo.Gen1Moves.Count != 0 && moves[m] > Legal.MaxMoveID_1)
|
||||
{
|
||||
res[m] = new CheckMoveResult(MoveSource.EggMove, gen, Severity.Invalid, V334, CheckIdentifier.Move) { Flag = true };
|
||||
learnInfo.MixedGen12NonTradeback = true;
|
||||
|
@ -413,7 +413,7 @@ namespace PKHeX.Core
|
|||
|
||||
if (!learnInfo.Source.EggMoveSource.Contains(moves[m]))
|
||||
{
|
||||
if (learnInfo.IsGen2Pkm && learnInfo.Gen1Moves.Any() && moves[m] > Legal.MaxMoveID_1)
|
||||
if (learnInfo.IsGen2Pkm && learnInfo.Gen1Moves.Count != 0 && moves[m] > Legal.MaxMoveID_1)
|
||||
{
|
||||
res[m] = new CheckMoveResult(MoveSource.SpecialEgg, gen, Severity.Invalid, V334, CheckIdentifier.Move) { Flag = true };
|
||||
learnInfo.MixedGen12NonTradeback = true;
|
||||
|
@ -431,11 +431,11 @@ namespace PKHeX.Core
|
|||
// A pokemon could have normal egg moves and regular egg moves
|
||||
// Only if all regular egg moves are event egg moves or all event egg moves are regular egg moves
|
||||
var RegularEggMovesLearned = learnInfo.EggMovesLearned.Union(learnInfo.LevelUpEggMoves).ToList();
|
||||
if (RegularEggMovesLearned.Any() && learnInfo.EventEggMoves.Any())
|
||||
if (RegularEggMovesLearned.Count != 0 && learnInfo.EventEggMoves.Count != 0)
|
||||
{
|
||||
// Moves that are egg moves or event egg moves but not both
|
||||
var IncompatibleEggMoves = RegularEggMovesLearned.Except(learnInfo.EventEggMoves).Union(learnInfo.EventEggMoves.Except(RegularEggMovesLearned)).ToList();
|
||||
if (!IncompatibleEggMoves.Any())
|
||||
if (IncompatibleEggMoves.Count == 0)
|
||||
return;
|
||||
foreach (int m in IncompatibleEggMoves)
|
||||
{
|
||||
|
@ -448,7 +448,7 @@ namespace PKHeX.Core
|
|||
}
|
||||
}
|
||||
// If there is no incompatibility with event egg check that there is no inherited move in gift eggs and event eggs
|
||||
else if (RegularEggMovesLearned.Any() && (pkm.WasGiftEgg || pkm.WasEventEgg))
|
||||
else if (RegularEggMovesLearned.Count != 0 && (pkm.WasGiftEgg || pkm.WasEventEgg))
|
||||
{
|
||||
foreach (int m in RegularEggMovesLearned)
|
||||
{
|
||||
|
@ -474,7 +474,7 @@ namespace PKHeX.Core
|
|||
incompatible.Add(54);
|
||||
if (moves.Contains(114))
|
||||
incompatible.Add(114);
|
||||
if (incompatible.Any())
|
||||
if (incompatible.Count != 0)
|
||||
incompatible.Add(151);
|
||||
break;
|
||||
|
||||
|
|
|
@ -813,7 +813,7 @@ namespace PKHeX.Core
|
|||
Slots = grass.Concat(water).ToArray()
|
||||
};
|
||||
}
|
||||
return areas.Where(area => area.Slots.Any()).ToArray();
|
||||
return areas.Where(area => area.Slots.Length != 0).ToArray();
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets the encounter areas with <see cref="EncounterSlot"/> information from Pokémon Yellow (Generation 1) Fishing data.
|
||||
|
@ -944,7 +944,7 @@ namespace PKHeX.Core
|
|||
foreach (byte[] t in entries)
|
||||
{
|
||||
EncounterArea Area = GetArea3(t);
|
||||
if (Area.Slots.Any())
|
||||
if (Area.Slots.Length != 0)
|
||||
Areas.Add(Area);
|
||||
}
|
||||
return Areas.ToArray();
|
||||
|
|
|
@ -724,7 +724,7 @@ namespace PKHeX.Core
|
|||
dl.Last().RequiresLvlUp = false;
|
||||
return dl;
|
||||
}
|
||||
private static void UpdateMinValues(IReadOnlyCollection<DexLevel> dl, EvolutionMethod evo)
|
||||
private static void UpdateMinValues(IReadOnlyList<DexLevel> dl, EvolutionMethod evo)
|
||||
{
|
||||
var last = dl.Last();
|
||||
if (evo.Level == 0 || !evo.RequiresLevelUp) // Evolutions like elemental stones, trade, etc
|
||||
|
@ -736,7 +736,7 @@ namespace PKHeX.Core
|
|||
// Evolutions like frienship, pichu -> pikachu, eevee -> umbreon, etc
|
||||
last.MinLevel = 2;
|
||||
|
||||
var first = dl.First();
|
||||
var first = dl[0];
|
||||
if (dl.Count > 1 && !first.RequiresLvlUp)
|
||||
first.MinLevel = 2; // Raichu from Pikachu would have minimum level 1, but with Pichu included Raichu minimum level is 2
|
||||
}
|
||||
|
@ -745,7 +745,7 @@ namespace PKHeX.Core
|
|||
{
|
||||
last.MinLevel = evo.Level;
|
||||
|
||||
var first = dl.First();
|
||||
var first = dl[0];
|
||||
if (dl.Count > 1)
|
||||
{
|
||||
if (first.MinLevel < evo.Level && !first.RequiresLvlUp)
|
||||
|
|
|
@ -253,7 +253,7 @@ namespace PKHeX.Core
|
|||
if (chk != BitConverter.ToUInt16(Data, ofs + 0xFF6))
|
||||
list.Add($"Block {BlockOrder[i]:00} @ {i*SIZE_BLOCK:X5} invalid.");
|
||||
}
|
||||
return list.Any() ? string.Join(Environment.NewLine, list) : "Checksums are valid.";
|
||||
return list.Count != 0 ? string.Join(Environment.NewLine, list) : "Checksums are valid.";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -123,7 +123,7 @@ namespace PKHeX.Core
|
|||
if (SaveUtil.CRC16_CCITT(Data, c[1][0] + SBO, c[1][1] - c[1][0]) != BitConverter.ToUInt16(Data, c[1][2] + SBO))
|
||||
list.Add("Large block checksum is invalid");
|
||||
|
||||
return list.Any() ? string.Join(Environment.NewLine, list) : "Checksums are valid.";
|
||||
return list.Count != 0 ? string.Join(Environment.NewLine, list) : "Checksums are valid.";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ namespace PKHeX.Core
|
|||
}
|
||||
}
|
||||
|
||||
CurrentSlot = SaveSlots.First();
|
||||
CurrentSlot = SaveSlots[0];
|
||||
|
||||
Personal = PersonalTable.DP;
|
||||
HeldItems = Legal.HeldItems_DP;
|
||||
|
|
|
@ -625,7 +625,7 @@ namespace PKHeX.Core
|
|||
public byte[] GetBoxBinary(int box) => BoxData.Skip(box*BoxSlotCount).Take(BoxSlotCount).SelectMany(pk => pk.EncryptedBoxData).ToArray();
|
||||
public bool SetPCBinary(byte[] data)
|
||||
{
|
||||
if (LockedSlots.Any())
|
||||
if (LockedSlots.Length != 0)
|
||||
return false;
|
||||
if (data.Length != PCBinary.Length)
|
||||
return false;
|
||||
|
|
|
@ -245,7 +245,7 @@ namespace PKHeX.Core
|
|||
}
|
||||
public static List<ComboItem> GetCBList(string[] inStrings, params int[][] allowed)
|
||||
{
|
||||
if (allowed?.First() == null)
|
||||
if (allowed?[0] == null)
|
||||
allowed = new[] { Enumerable.Range(0, inStrings.Length).ToArray() };
|
||||
|
||||
return allowed.SelectMany(list => list
|
||||
|
|
Loading…
Reference in a new issue