mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-05-09 04:24:36 -05:00
Reduce linq usage
reuse variables instead of re-fetching (pkm.Species) add overload for HashSet<int> contains vs ICollection merge BattleOnly to one hashset
This commit is contained in:
parent
e5ac193e8e
commit
bc6c361746
|
|
@ -674,6 +674,8 @@ private static void MarkG5Slots(ref EncounterArea[] Areas)
|
|||
new EncounterTrade { Species = 424, Level = 40, Ability = 2, TID = 17074, SID = 00001, OTGender = 1, Gender = 0, IVs = new[] {20,20,20,31,20,20}, Nature = Nature.Jolly, }, // Ambipom
|
||||
new EncounterTrade { Species = 065, Level = 40, Ability = 1, TID = 17074, SID = 00001, OTGender = 1, Gender = 0, IVs = new[] {20,20,20,31,20,20}, Nature = Nature.Timid, }, // Alakazam
|
||||
};
|
||||
|
||||
internal const int YancyCurtisTID = 10303;
|
||||
internal static readonly EncounterTrade[] TradeGift_B2W2_YancyCurtis =
|
||||
{
|
||||
// player is male
|
||||
|
|
|
|||
|
|
@ -139,7 +139,7 @@ public static partial class Legal
|
|||
internal static readonly ushort[] HeldItems_SM = new ushort[1].Concat(Pouch_Items_SM).Concat(Pouch_Berries_SM).Concat(Pouch_Medicine_SM).Concat(Pouch_ZCrystalHeld_SM).ToArray();
|
||||
internal static readonly ushort[] HeldItems_USUM = new ushort[1].Concat(Pouch_Items_SM).Concat(Pouch_Berries_SM).Concat(Pouch_Medicine_SM).Concat(Pouch_ZCrystalHeld_USUM).Concat(Pouch_Roto_USUM).ToArray();
|
||||
|
||||
private static readonly HashSet<int> WildPokeballs7 = new HashSet<int> {
|
||||
internal static readonly HashSet<int> WildPokeballs7 = new HashSet<int> {
|
||||
0x01, 0x02, 0x03, 0x04, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
|
||||
0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, // Johto Balls
|
||||
0x1A, // Beast
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using static PKHeX.Core.LegalityCheckStrings;
|
||||
|
||||
namespace PKHeX.Core
|
||||
|
|
@ -106,7 +105,8 @@ private CheckResult VerifyBallInherited(LegalityAnalysis data)
|
|||
private CheckResult VerifyBallEggGen6(LegalityAnalysis data)
|
||||
{
|
||||
var pkm = data.pkm;
|
||||
if (pkm.Gender == 2 || Legal.BreedMaleOnly.Contains(data.EncounterMatch.Species)) // Genderless
|
||||
int species = data.EncounterMatch.Species;
|
||||
if (pkm.Gender == 2 || Legal.BreedMaleOnly.Contains(species)) // Genderless
|
||||
return VerifyBallEquals(data, 4); // Must be Pokéball as ball can only pass via mother (not Ditto!)
|
||||
|
||||
int ball = pkm.Ball;
|
||||
|
|
@ -114,7 +114,6 @@ private CheckResult VerifyBallEggGen6(LegalityAnalysis data)
|
|||
if (ball >= 26)
|
||||
return GetInvalid(V126);
|
||||
|
||||
int species = data.EncounterMatch.Species;
|
||||
if (ball == 0x05) // Safari Ball
|
||||
{
|
||||
if (!Legal.Inherit_Safari.Contains(species))
|
||||
|
|
@ -141,7 +140,7 @@ private CheckResult VerifyBallEggGen6(LegalityAnalysis data)
|
|||
}
|
||||
if (ball == 0x19) // Dream Ball
|
||||
{
|
||||
if (pkm.AbilityNumber == 4 && Legal.Ban_DreamHidden.Contains(pkm.Species))
|
||||
if (pkm.AbilityNumber == 4 && Legal.Ban_DreamHidden.Contains(species))
|
||||
return GetInvalid(V122);
|
||||
if (Legal.Inherit_Dream.Contains(species))
|
||||
return GetValid(V123);
|
||||
|
|
@ -149,13 +148,13 @@ private CheckResult VerifyBallEggGen6(LegalityAnalysis data)
|
|||
}
|
||||
if (0x0D <= ball && ball <= 0x0F) // Dusk Heal Quick
|
||||
{
|
||||
if (!Legal.Ban_Gen4Ball_6.Contains(pkm.Species))
|
||||
if (!Legal.Ban_Gen4Ball_6.Contains(species))
|
||||
return GetValid(V123);
|
||||
return GetInvalid(V121);
|
||||
}
|
||||
if (0x02 <= ball && ball <= 0x0C) // Don't worry, Ball # 0x05 was already checked.
|
||||
{
|
||||
if (Legal.Ban_Gen3Ball.Contains(pkm.Species))
|
||||
if (Legal.Ban_Gen3Ball.Contains(species))
|
||||
return GetInvalid(V121);
|
||||
if (pkm.AbilityNumber == 4 && Legal.Ban_Gen3BallHidden.Contains(pkm.SpecForm))
|
||||
return GetInvalid(V122);
|
||||
|
|
@ -163,9 +162,9 @@ private CheckResult VerifyBallEggGen6(LegalityAnalysis data)
|
|||
|
||||
}
|
||||
|
||||
if (pkm.Species > 650 && pkm.Species != 700) // Sylveon
|
||||
if (species > 650 && species != 700) // Sylveon
|
||||
{
|
||||
if (Legal.GetWildBalls(pkm).Contains(pkm.Ball))
|
||||
if (Legal.WildPokeballs6.Contains(pkm.Ball))
|
||||
return GetValid(V123);
|
||||
return GetInvalid(V121);
|
||||
}
|
||||
|
|
@ -175,12 +174,12 @@ private CheckResult VerifyBallEggGen6(LegalityAnalysis data)
|
|||
private CheckResult VerifyBallEggGen7(LegalityAnalysis data)
|
||||
{
|
||||
var pkm = data.pkm;
|
||||
if (722 <= pkm.Species && pkm.Species <= 730) // G7 Starters
|
||||
int species = data.EncounterMatch.Species;
|
||||
if (722 <= species && species <= 730) // G7 Starters
|
||||
return VerifyBallEquals(data, 4);
|
||||
|
||||
int ball = pkm.Ball;
|
||||
|
||||
int species = data.EncounterMatch.Species;
|
||||
if (ball == 0x05) // Safari Ball
|
||||
{
|
||||
if (!(Legal.Inherit_Safari.Contains(species) || Legal.Inherit_SafariMale.Contains(species)))
|
||||
|
|
@ -235,8 +234,8 @@ private CheckResult VerifyBallEggGen7(LegalityAnalysis data)
|
|||
// next statement catches all new alolans
|
||||
}
|
||||
|
||||
if (pkm.Species > 721)
|
||||
return VerifyBallEquals(data, Legal.GetWildBalls(pkm));
|
||||
if (species > 721)
|
||||
return VerifyBallEquals(data, Legal.WildPokeballs7);
|
||||
|
||||
if (ball >= 27)
|
||||
return GetInvalid(V126);
|
||||
|
|
@ -245,6 +244,7 @@ private CheckResult VerifyBallEggGen7(LegalityAnalysis data)
|
|||
}
|
||||
|
||||
private CheckResult VerifyBallEquals(LegalityAnalysis data, int ball) => GetResult(ball == data.pkm.Ball);
|
||||
private CheckResult VerifyBallEquals(LegalityAnalysis data, HashSet<int> balls) => GetResult(balls.Contains(data.pkm.Ball));
|
||||
private CheckResult VerifyBallEquals(LegalityAnalysis data, ICollection<int> balls) => GetResult(balls.Contains(data.pkm.Ball));
|
||||
private CheckResult GetResult(bool valid)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -13,16 +13,16 @@ public override void Verify(LegalityAnalysis data)
|
|||
var evs = pkm.EVs;
|
||||
int sum = pkm.EVTotal;
|
||||
if (sum > 0 && pkm.IsEgg)
|
||||
data.AddLine(GetInvalid(V22, CheckIdentifier.EVs));
|
||||
data.AddLine(GetInvalid(V22));
|
||||
if (pkm.Format >= 3 && sum > 510)
|
||||
data.AddLine(GetInvalid(V25, CheckIdentifier.EVs));
|
||||
data.AddLine(GetInvalid(V25));
|
||||
if (pkm.Format >= 6 && evs.Any(ev => ev > 252))
|
||||
data.AddLine(GetInvalid(V26, CheckIdentifier.EVs));
|
||||
data.AddLine(GetInvalid(V26));
|
||||
if (pkm.Format == 4 && pkm.Gen4 && EncounterMatch.LevelMin == 100)
|
||||
{
|
||||
// Cannot EV train at level 100 -- Certain events are distributed at level 100.
|
||||
if (evs.Any(ev => ev > 100)) // EVs can only be increased by vitamins to a max of 100.
|
||||
data.AddLine(GetInvalid(V367, CheckIdentifier.EVs));
|
||||
data.AddLine(GetInvalid(V367));
|
||||
}
|
||||
else if (pkm.Format < 5)
|
||||
{
|
||||
|
|
@ -32,7 +32,7 @@ public override void Verify(LegalityAnalysis data)
|
|||
|
||||
const int maxEV = 100; // Vitamin Max
|
||||
if (PKX.GetEXP(EncounterMatch.LevelMin, pkm.Species) == pkm.EXP && evs.Any(ev => ev > maxEV))
|
||||
data.AddLine(GetInvalid(string.Format(V418, maxEV), CheckIdentifier.EVs));
|
||||
data.AddLine(GetInvalid(string.Format(V418, maxEV)));
|
||||
}
|
||||
|
||||
// Only one of the following can be true: 0, 508, and x%6!=0
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using static PKHeX.Core.LegalityCheckStrings;
|
||||
|
||||
namespace PKHeX.Core
|
||||
|
|
@ -164,7 +163,7 @@ bool IsValidPikachuCap()
|
|||
return GetInvalid(V317);
|
||||
}
|
||||
|
||||
if (pkm.AltForm != 0 && BattleOnly.Any(arr => arr.Contains(pkm.Species)))
|
||||
if (pkm.AltForm != 0 && BattleOnly.Contains(pkm.Species))
|
||||
return GetInvalid(V310);
|
||||
|
||||
return VALID;
|
||||
|
|
@ -197,7 +196,14 @@ private static int GetGenesectFormFromHeldItem(int item)
|
|||
return 0;
|
||||
}
|
||||
|
||||
private static readonly HashSet<int>[] BattleOnly = {Legal.BattleForms, Legal.BattleMegas, Legal.BattlePrimals};
|
||||
static FormVerifier()
|
||||
{
|
||||
BattleOnly = new HashSet<int>();
|
||||
BattleOnly.UnionWith(Legal.BattleForms);
|
||||
BattleOnly.UnionWith(Legal.BattleMegas);
|
||||
BattleOnly.UnionWith(Legal.BattlePrimals);
|
||||
}
|
||||
private static readonly HashSet<int> BattleOnly;
|
||||
|
||||
private static readonly HashSet<int> SafariFloette = new HashSet<int> {0, 1, 3}; // 0/1/3 - RBY
|
||||
private void VerifyFormFriendSafari(LegalityAnalysis data)
|
||||
|
|
|
|||
|
|
@ -53,23 +53,18 @@ private void VerifyMiscG1Types(LegalityAnalysis data, PK1 pk1)
|
|||
{
|
||||
var Type_A = pk1.Type_A;
|
||||
var Type_B = pk1.Type_B;
|
||||
if (pk1.Species == 137)
|
||||
if (pk1.Species == 137) // Porygon
|
||||
{
|
||||
// Porygon can have any type combination of any generation 1 species because of the move Conversion,
|
||||
// that change Porygon type to match the oponent types
|
||||
var Type_A_Match = Legal.Types_Gen1.Any(t => t == Type_A);
|
||||
var Type_B_Match = Legal.Types_Gen1.Any(t => t == Type_B);
|
||||
if (!Type_A_Match)
|
||||
// Can have any type combination of any species by using Conversion.
|
||||
if (!Legal.Types_Gen1.Contains(Type_A))
|
||||
data.AddLine(GetInvalid(V386));
|
||||
if (!Type_B_Match)
|
||||
else if (!Legal.Types_Gen1.Contains(Type_B))
|
||||
data.AddLine(GetInvalid(V387));
|
||||
if (Type_A_Match && Type_B_Match)
|
||||
else // Both match a type, ensure a gen1 species has this combo
|
||||
{
|
||||
var TypesAB_Match = PersonalTable.RB.IsValidTypeCombination(Type_A, Type_B);
|
||||
if (TypesAB_Match)
|
||||
data.AddLine(GetValid(V391));
|
||||
else
|
||||
data.AddLine(GetInvalid(V388));
|
||||
var result = TypesAB_Match ? GetValid(V391) : GetInvalid(V388);
|
||||
data.AddLine(result);
|
||||
}
|
||||
}
|
||||
else // Types must match species types
|
||||
|
|
@ -91,7 +86,7 @@ private void VerifyMiscG1CatchRate(LegalityAnalysis data, PK1 pk1)
|
|||
{
|
||||
case TradebackType.Any:
|
||||
case TradebackType.WasTradeback:
|
||||
if (catch_rate == 0 || Legal.HeldItems_GSC.Any(h => h == catch_rate))
|
||||
if (catch_rate == 0 || Legal.HeldItems_GSC.Contains((ushort)catch_rate))
|
||||
data.AddLine(GetValid(V394));
|
||||
else if (pk1.TradebackStatus == TradebackType.WasTradeback)
|
||||
data.AddLine(GetInvalid(V395));
|
||||
|
|
@ -111,7 +106,7 @@ private void VerifyMiscG1CatchRate(LegalityAnalysis data, PK1 pk1)
|
|||
break;
|
||||
}
|
||||
}
|
||||
private void VerifyMiscFatefulEncounter(LegalityAnalysis data)
|
||||
private static void VerifyMiscFatefulEncounter(LegalityAnalysis data)
|
||||
{
|
||||
var pkm = data.pkm;
|
||||
var EncounterMatch = data.EncounterMatch;
|
||||
|
|
@ -147,7 +142,7 @@ private void VerifyMiscFatefulEncounter(LegalityAnalysis data)
|
|||
if (pkm.FatefulEncounter)
|
||||
data.AddLine(GetInvalid(V325, CheckIdentifier.Fateful));
|
||||
}
|
||||
private void VerifyMiscEggCommon(LegalityAnalysis data)
|
||||
private static void VerifyMiscEggCommon(LegalityAnalysis data)
|
||||
{
|
||||
var pkm = data.pkm;
|
||||
if (pkm.Move1_PPUps > 0 || pkm.Move2_PPUps > 0 || pkm.Move3_PPUps > 0 || pkm.Move4_PPUps > 0)
|
||||
|
|
@ -170,7 +165,7 @@ private void VerifyMiscEggCommon(LegalityAnalysis data)
|
|||
data.AddLine(GetInvalid(msg, CheckIdentifier.Egg));
|
||||
}
|
||||
}
|
||||
private void VerifyFatefulMysteryGift(LegalityAnalysis data, MysteryGift g)
|
||||
private static void VerifyFatefulMysteryGift(LegalityAnalysis data, MysteryGift g)
|
||||
{
|
||||
var pkm = data.pkm;
|
||||
if (g is PGF p && p.IsShiny)
|
||||
|
|
@ -181,18 +176,18 @@ private void VerifyFatefulMysteryGift(LegalityAnalysis data, MysteryGift g)
|
|||
data.AddLine(GetInvalid(V411, CheckIdentifier.PID));
|
||||
}
|
||||
|
||||
if (pkm.FatefulEncounter)
|
||||
data.AddLine(GetValid(V321, CheckIdentifier.Fateful));
|
||||
else
|
||||
data.AddLine(GetInvalid(V322, CheckIdentifier.Fateful));
|
||||
var result = pkm.FatefulEncounter
|
||||
? GetValid(V321, CheckIdentifier.Fateful)
|
||||
: GetInvalid(V322, CheckIdentifier.Fateful);
|
||||
data.AddLine(result);
|
||||
}
|
||||
private void VerifyWC3Shiny(LegalityAnalysis data, WC3 g3)
|
||||
private static void VerifyWC3Shiny(LegalityAnalysis data, WC3 g3)
|
||||
{
|
||||
// check for shiny locked gifts
|
||||
if (!g3.Shiny.IsValid(data.pkm))
|
||||
data.AddLine(GetInvalid(V409, CheckIdentifier.Fateful));
|
||||
}
|
||||
private void VerifyFatefulIngameActive(LegalityAnalysis data)
|
||||
private static void VerifyFatefulIngameActive(LegalityAnalysis data)
|
||||
{
|
||||
var pkm = data.pkm;
|
||||
if (pkm.Version == 15 && pkm is XK3 xk3 && data.Info.WasXD)
|
||||
|
|
@ -204,10 +199,10 @@ private void VerifyFatefulIngameActive(LegalityAnalysis data)
|
|||
return; // fateful is set when transferred away
|
||||
}
|
||||
|
||||
if (pkm.FatefulEncounter)
|
||||
data.AddLine(GetValid(V323, CheckIdentifier.Fateful));
|
||||
else
|
||||
data.AddLine(GetInvalid(V324, CheckIdentifier.Fateful));
|
||||
var result = pkm.FatefulEncounter
|
||||
? GetValid(V323, CheckIdentifier.Fateful)
|
||||
: GetInvalid(V324, CheckIdentifier.Fateful);
|
||||
data.AddLine(result);
|
||||
}
|
||||
|
||||
public void VerifyVersionEvolution(LegalityAnalysis data)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
using System.Linq;
|
||||
using static PKHeX.Core.LegalityCheckStrings;
|
||||
using static PKHeX.Core.LegalityCheckStrings;
|
||||
|
||||
namespace PKHeX.Core
|
||||
{
|
||||
|
|
@ -25,7 +24,7 @@ public override void Verify(LegalityAnalysis data)
|
|||
if (!checksRequired)
|
||||
return;
|
||||
|
||||
if (pkm.IVs.Any(iv => iv != 30))
|
||||
if (pkm.IVTotal != 30*6)
|
||||
data.AddLine(GetInvalid(V218, CheckIdentifier.IVs));
|
||||
if (!VerifyNsPKMOTValid(pkm))
|
||||
data.AddLine(GetInvalid(V219, CheckIdentifier.Trainer));
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using static PKHeX.Core.LegalityCheckStrings;
|
||||
|
||||
namespace PKHeX.Core
|
||||
|
|
@ -310,7 +309,7 @@ private void VerifyTrade5(LegalityAnalysis data)
|
|||
}
|
||||
else // B2W2
|
||||
{
|
||||
if (Encounters5.TradeGift_B2W2_YancyCurtis.Contains(EncounterMatch))
|
||||
if (EncounterMatch is EncounterTrade t && t.TID == Encounters5.YancyCurtisTID)
|
||||
VerifyTradeOTOnly(data, pkm.OT_Gender == 0 ? Encounters5.TradeOT_B2W2_M : Encounters5.TradeOT_B2W2_F);
|
||||
else
|
||||
VerifyTradeTable(data, Encounters5.TradeB2W2, Encounters5.TradeGift_B2W2);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
using System.Linq;
|
||||
using static PKHeX.Core.LegalityCheckStrings;
|
||||
using static PKHeX.Core.LegalityCheckStrings;
|
||||
|
||||
namespace PKHeX.Core
|
||||
{
|
||||
|
|
@ -39,7 +38,7 @@ public override void Verify(LegalityAnalysis data)
|
|||
data.AddLine(Get(V36, Severity.Fishy));
|
||||
else if (pkm.SID == 0)
|
||||
data.AddLine(Get(V37, Severity.Fishy));
|
||||
else if (pkm.TID == 12345 && pkm.SID == 54321 || SuspiciousOTNames.Any(z => ot.StartsWith(z)))
|
||||
else if (pkm.TID == 12345 && pkm.SID == 54321 || IsOTNameSuspicious(ot))
|
||||
data.AddLine(Get(V417, Severity.Fishy));
|
||||
|
||||
if (pkm.VC)
|
||||
|
|
@ -60,7 +59,7 @@ public void VerifyOTG1(LegalityAnalysis data)
|
|||
|
||||
VerifyG1OTWithinBounds(data, tr);
|
||||
if (data.EncounterOriginal is EncounterStatic s && (s.Version == GameVersion.Stadium || s.Version == GameVersion.Stadium2))
|
||||
VerifyG1OTStadium(data, tr);
|
||||
data.AddLine(VerifyG1OTStadium(data, tr));
|
||||
|
||||
if (pkm.Species == 151)
|
||||
{
|
||||
|
|
@ -95,15 +94,12 @@ private void VerifyG1OTWithinBounds(LegalityAnalysis data, string str)
|
|||
data.AddLine(GetInvalid(V421));
|
||||
}
|
||||
}
|
||||
private void VerifyG1OTStadium(LegalityAnalysis data, string tr)
|
||||
private CheckResult VerifyG1OTStadium(LegalityAnalysis data, string tr)
|
||||
{
|
||||
var pkm = data.pkm;
|
||||
bool jp = pkm.Japanese;
|
||||
bool valid = GetIsStadiumOTIDValid(data, jp, tr);
|
||||
if (!valid)
|
||||
data.AddLine(GetInvalid(V402));
|
||||
else
|
||||
data.AddLine(GetValid(jp ? V404 : V403));
|
||||
return valid ? GetValid(jp ? V404 : V403) : GetInvalid(V402);
|
||||
}
|
||||
private bool GetIsStadiumOTIDValid(LegalityAnalysis data, bool jp, string tr)
|
||||
{
|
||||
|
|
@ -112,5 +108,13 @@ private bool GetIsStadiumOTIDValid(LegalityAnalysis data, bool jp, string tr)
|
|||
return tr == "スタジアム" && pkm.TID == 1999;
|
||||
return tr == (data.Info.Generation == 1 ? "STADIUM" : "Stadium") && pkm.TID == 2000;
|
||||
}
|
||||
|
||||
private bool IsOTNameSuspicious(string name)
|
||||
{
|
||||
foreach (var ot in SuspiciousOTNames)
|
||||
if (name.StartsWith(ot))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user