mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-23 12:33:06 +00:00
Misc changes
remove multiple iteration of ienumerable, reduce nesting
This commit is contained in:
parent
89e32b24f0
commit
f014f5ed1c
2 changed files with 40 additions and 37 deletions
|
@ -2215,8 +2215,7 @@ namespace PKHeX.Core
|
||||||
{
|
{
|
||||||
var SpecialMoves = (EncounterMatch as MysteryGift)?.Moves ??
|
var SpecialMoves = (EncounterMatch as MysteryGift)?.Moves ??
|
||||||
(EncounterMatch as EncounterStatic)?.Moves ??
|
(EncounterMatch as EncounterStatic)?.Moves ??
|
||||||
(EncounterMatch as EncounterTrade)?.Moves ??
|
(EncounterMatch as EncounterTrade)?.Moves;
|
||||||
null;
|
|
||||||
var allowinherited = SpecialMoves == null;
|
var allowinherited = SpecialMoves == null;
|
||||||
res = verifyMovesIsEggPreRelearn(Moves, SpecialMoves ?? new int[0], allowinherited);
|
res = verifyMovesIsEggPreRelearn(Moves, SpecialMoves ?? new int[0], allowinherited);
|
||||||
}
|
}
|
||||||
|
@ -2300,7 +2299,7 @@ namespace PKHeX.Core
|
||||||
private CheckResult[] verifyMovesIsEggPreRelearn(int[] Moves, int[] SpecialMoves, bool allowinherited)
|
private CheckResult[] verifyMovesIsEggPreRelearn(int[] Moves, int[] SpecialMoves, bool allowinherited)
|
||||||
{
|
{
|
||||||
CheckResult[] res = new CheckResult[4];
|
CheckResult[] res = new CheckResult[4];
|
||||||
var ValidSpecialMoves = SpecialMoves.Where(m => m > 0);
|
var ValidSpecialMoves = SpecialMoves.Where(m => m != 0).ToList();
|
||||||
// Some games can have different egg movepools. Have to check all situations.
|
// Some games can have different egg movepools. Have to check all situations.
|
||||||
GameVersion[] Games = getBaseMovesIsEggGames();
|
GameVersion[] Games = getBaseMovesIsEggGames();
|
||||||
int splitctr = Legal.getSplitBreedGeneration(pkm).Contains(pkm.Species) ? 1 : 0;
|
int splitctr = Legal.getSplitBreedGeneration(pkm).Contains(pkm.Species) ? 1 : 0;
|
||||||
|
@ -2309,12 +2308,12 @@ namespace PKHeX.Core
|
||||||
for (int i = 0; i <= splitctr; i++)
|
for (int i = 0; i <= splitctr; i++)
|
||||||
{
|
{
|
||||||
var baseEggMoves = Legal.getBaseEggMoves(pkm, i, ver, pkm.GenNumber < 4 ? 5 : 1)?.ToList() ?? new List<int>();
|
var baseEggMoves = Legal.getBaseEggMoves(pkm, i, ver, pkm.GenNumber < 4 ? 5 : 1)?.ToList() ?? new List<int>();
|
||||||
var InheritedLvlMoves = Legal.getBaseEggMoves(pkm, i, ver, 100) ?? new List<int>();
|
var InheritedLvlMoves = Legal.getBaseEggMoves(pkm, i, ver, 100)?.ToList() ?? new List<int>();
|
||||||
var EggMoves = Legal.getEggMoves(pkm, ver)?.ToList() ?? new List<int>();
|
var EggMoves = Legal.getEggMoves(pkm, ver)?.ToList() ?? new List<int>();
|
||||||
var InheritedTutorMoves = (ver == GameVersion.C) ? Legal.getTutorMoves(pkm, pkm.Species, pkm.AltForm, false, 2) : new int[0];
|
var InheritedTutorMoves = ver == GameVersion.C ? Legal.getTutorMoves(pkm, pkm.Species, pkm.AltForm, false, 2)?.ToList() : new List<int>();
|
||||||
// Only TM Hm moves from the source game of the egg, not any other games from the same generation
|
// Only TM Hm moves from the source game of the egg, not any other games from the same generation
|
||||||
var InheritedTMHMMoves = Legal.getTMHM(pkm, pkm.Species, pkm.AltForm, pkm.GenNumber, ver, false);
|
var InheritedTMHMMoves = Legal.getTMHM(pkm, pkm.Species, pkm.AltForm, pkm.GenNumber, ver, false)?.ToList();
|
||||||
InheritedLvlMoves = InheritedLvlMoves.Except(baseEggMoves);
|
InheritedLvlMoves.RemoveAll(x => baseEggMoves.Contains(x));
|
||||||
|
|
||||||
if (pkm.Format > 2 || SpecialMoves.Any())
|
if (pkm.Format > 2 || SpecialMoves.Any())
|
||||||
{
|
{
|
||||||
|
@ -2324,15 +2323,15 @@ namespace PKHeX.Core
|
||||||
if (res.All(r => r.Valid)) // moves is satisfactory
|
if (res.All(r => r.Valid)) // moves is satisfactory
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
if(pkm.Format == 2)
|
if (pkm.Format != 2)
|
||||||
{
|
continue;
|
||||||
|
|
||||||
// For gen 2 if does not match special egg check for normal egg too
|
// For gen 2 if does not match special egg check for normal egg too
|
||||||
res = verifyPreRelearnEggBase(Moves, baseEggMoves, EggMoves, InheritedLvlMoves, InheritedTMHMMoves, InheritedTutorMoves, new List<int>(), true, ver);
|
res = verifyPreRelearnEggBase(Moves, baseEggMoves, EggMoves, InheritedLvlMoves, InheritedTMHMMoves, InheritedTutorMoves, new List<int>(), true, ver);
|
||||||
if (res.All(r => r.Valid)) // moves is satisfactory
|
if (res.All(r => r.Valid)) // moves are satisfactory
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
private CheckResult[] verifyMovesWasEggPreRelearn(int[] Moves, List<int>[] validLevelMoves, List<int>[] validTMHM, List<int>[] validTutor)
|
private CheckResult[] verifyMovesWasEggPreRelearn(int[] Moves, List<int>[] validLevelMoves, List<int>[] validTMHM, List<int>[] validTutor)
|
||||||
|
@ -2827,7 +2826,7 @@ namespace PKHeX.Core
|
||||||
|
|
||||||
/* Similar to verifyRelearnEgg but in pre relearn generation is the moves what should match the expected order
|
/* Similar to verifyRelearnEgg but in pre relearn generation is the moves what should match the expected order
|
||||||
but only if the pokemon is inside an egg */
|
but only if the pokemon is inside an egg */
|
||||||
private CheckResult[] verifyPreRelearnEggBase(int[] Moves, List<int> baseMoves, List<int> eggmoves, IEnumerable<int> lvlmoves, IEnumerable<int> tmhmmoves, IEnumerable<int> tutormoves, IEnumerable<int> specialmoves, bool AllowInherited, GameVersion ver)
|
private CheckResult[] verifyPreRelearnEggBase(int[] Moves, List<int> baseMoves, List<int> eggmoves, List<int> lvlmoves, List<int> tmhmmoves, List<int> tutormoves, List<int> specialmoves, bool AllowInherited, GameVersion ver)
|
||||||
{
|
{
|
||||||
CheckResult[] res = new CheckResult[4];
|
CheckResult[] res = new CheckResult[4];
|
||||||
|
|
||||||
|
@ -2867,14 +2866,14 @@ namespace PKHeX.Core
|
||||||
moveoffset += reqBase;
|
moveoffset += reqBase;
|
||||||
|
|
||||||
// Check also if the required amount of Special Egg Moves are present, ir are after base moves
|
// Check also if the required amount of Special Egg Moves are present, ir are after base moves
|
||||||
for (int i = moveoffset; i < moveoffset + specialmoves.Count(); i++)
|
for (int i = moveoffset; i < moveoffset + specialmoves.Count; i++)
|
||||||
{
|
{
|
||||||
if (specialmoves.Contains(Moves[i]))
|
if (specialmoves.Contains(Moves[i]))
|
||||||
res[i] = new CheckResult(Severity.Valid, V333, CheckIdentifier.Move);
|
res[i] = new CheckResult(Severity.Valid, V333, CheckIdentifier.Move);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// mark remaining special egg moves missing
|
// mark remaining special egg moves missing
|
||||||
for (int z = i; z < moveoffset + specialmoves.Count(); z++)
|
for (int z = i; z < moveoffset + specialmoves.Count; z++)
|
||||||
res[z] = new CheckResult(Severity.Invalid, V342, CheckIdentifier.Move);
|
res[z] = new CheckResult(Severity.Invalid, V342, CheckIdentifier.Move);
|
||||||
|
|
||||||
// provide the list of suggested base moves and specia moves for the last required slot
|
// provide the list of suggested base moves and specia moves for the last required slot
|
||||||
|
@ -2894,7 +2893,7 @@ namespace PKHeX.Core
|
||||||
|
|
||||||
// Inherited moves appear after the required base moves.
|
// Inherited moves appear after the required base moves.
|
||||||
var AllowInheritedSeverity = AllowInherited ? Severity.Valid : Severity.Invalid;
|
var AllowInheritedSeverity = AllowInherited ? Severity.Valid : Severity.Invalid;
|
||||||
for (int i = reqBase + specialmoves.Count(); i < 4; i++)
|
for (int i = reqBase + specialmoves.Count; i < 4; i++)
|
||||||
{
|
{
|
||||||
if (Moves[i] == 0) // empty
|
if (Moves[i] == 0) // empty
|
||||||
res[i] = new CheckResult(Severity.Valid, V167, CheckIdentifier.Move);
|
res[i] = new CheckResult(Severity.Valid, V167, CheckIdentifier.Move);
|
||||||
|
|
|
@ -828,32 +828,36 @@ namespace PKHeX.Core
|
||||||
internal static EncounterSlot[] getValidWildEncounters(PKM pkm, GameVersion gameSource = GameVersion.Any)
|
internal static EncounterSlot[] getValidWildEncounters(PKM pkm, GameVersion gameSource = GameVersion.Any)
|
||||||
{
|
{
|
||||||
if (gameSource == GameVersion.Any)
|
if (gameSource == GameVersion.Any)
|
||||||
gameSource = (GameVersion)pkm.Version;
|
gameSource = (GameVersion) pkm.Version;
|
||||||
|
|
||||||
List<EncounterSlot> s = new List<EncounterSlot>();
|
List<EncounterSlot> s = new List<EncounterSlot>();
|
||||||
|
|
||||||
foreach (var area in getEncounterAreas(pkm, gameSource))
|
foreach (var area in getEncounterAreas(pkm, gameSource))
|
||||||
s.AddRange(getValidEncounterSlots(pkm, area, DexNav: pkm.AO));
|
s.AddRange(getValidEncounterSlots(pkm, area, DexNav: pkm.AO));
|
||||||
|
|
||||||
if(s.Count() > 1 && 3 <= pkm.GenNumber && pkm.GenNumber <= 4 && !pkm.HasOriginalMetLocation)
|
if (s.Count <= 1 || 3 > pkm.GenNumber || pkm.GenNumber > 4 || pkm.HasOriginalMetLocation)
|
||||||
{
|
return s.Any() ? s.ToArray() : null;
|
||||||
// If has original met location or there is only one possible slot does not check safari zone nor bug contest
|
|
||||||
|
// If has original met location or there is only one possible slot does not check safari zone nor BCC
|
||||||
// defer to ball legality
|
// defer to ball legality
|
||||||
var IsSafariBall = pkm.Ball == 5;
|
var IsSafariBall = pkm.Ball == 5;
|
||||||
var s_Safari = IsSafariBall ? s.Where(slot => IsSafariSlot(slot.Type)) : s.Where(slot => !IsSafariSlot(slot.Type));
|
var s_Safari = IsSafariBall
|
||||||
|
? s.Where(slot => IsSafariSlot(slot.Type)).ToList()
|
||||||
|
: s.Where(slot => !IsSafariSlot(slot.Type)).ToList();
|
||||||
if (s_Safari.Any())
|
if (s_Safari.Any())
|
||||||
// safari ball only in safari zones and non safari ball only outside safari zones
|
// safari ball only in safari zones and non safari ball only outside safari zones
|
||||||
s = s_Safari.ToList();
|
s = s_Safari.ToList();
|
||||||
|
|
||||||
if (s.Count() > 1 && pkm.GenNumber == 4)
|
if (s.Count <= 1 || pkm.GenNumber != 4)
|
||||||
{
|
return s.Any() ? s.ToArray() : null;
|
||||||
|
|
||||||
var IsSportsBall = pkm.Ball == 0x18;
|
var IsSportsBall = pkm.Ball == 0x18;
|
||||||
var s_BugContest = IsSportsBall ? s.Where(slot => slot.Type == SlotType.BugContest) : s.Where(slot => slot.Type != SlotType.BugContest);
|
var s_BugContest = IsSportsBall
|
||||||
|
? s.Where(slot => slot.Type == SlotType.BugContest).ToList()
|
||||||
|
: s.Where(slot => slot.Type != SlotType.BugContest).ToList();
|
||||||
if (s_BugContest.Any())
|
if (s_BugContest.Any())
|
||||||
// sport ball only in bug contest and non sport balls only outside bug contest
|
// sport ball only in BCC and non sport balls only outside BCC
|
||||||
return s_BugContest.ToArray();
|
return s_BugContest.ToArray();
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return s.Any() ? s.ToArray() : null;
|
return s.Any() ? s.ToArray() : null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue