mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-26 22:10:21 +00:00
Misc updates
reduce some allocs, clearer names/enum usage
This commit is contained in:
parent
1430460573
commit
d5a8d29088
7 changed files with 72 additions and 64 deletions
|
@ -261,7 +261,7 @@ namespace PKHeX.Core
|
|||
return m;
|
||||
|
||||
var encounter = legal.GetSuggestedMetInfo();
|
||||
if (encounter?.Relearn.Length > 0)
|
||||
if (encounter.Relearn.Length > 0)
|
||||
m = encounter.Relearn;
|
||||
|
||||
return m;
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace PKHeX.Core
|
|||
public int Location { get; set; } = 30011;
|
||||
public int Ability { get; set; } = 1;
|
||||
public int Ball { get; set; } = 4; // Pokéball
|
||||
public int[] RelearnMoves { get; set; } = new int[4];
|
||||
public int[] RelearnMoves { get; set; } = Array.Empty<int>();
|
||||
public bool OT { get; set; } = true; // Receiver is OT?
|
||||
|
||||
public bool EggEncounter => false;
|
||||
|
@ -67,7 +67,7 @@ namespace PKHeX.Core
|
|||
pk.OT_Friendship = pk.PersonalInfo.BaseFriendship;
|
||||
pk.SetRandomIVs(flawless: 3);
|
||||
pk.RefreshAbility(Ability >> 1);
|
||||
if (RelearnMoves != null)
|
||||
if (RelearnMoves.Length > 0)
|
||||
pk.RelearnMoves = RelearnMoves;
|
||||
if (RibbonClassic)
|
||||
pk.RibbonClassic = true;
|
||||
|
|
|
@ -856,12 +856,13 @@ namespace PKHeX.Core
|
|||
|
||||
private static readonly int[] G2 = {2};
|
||||
private static readonly int[] G12 = {1, 2};
|
||||
private static readonly int[] G21 = {2, 1};
|
||||
|
||||
private static int[] GetGenMovesCheckOrderGB(PKM pkm, int originalGeneration)
|
||||
{
|
||||
if (originalGeneration == 2)
|
||||
return pkm.Korean ? G2 : G12;
|
||||
return new[] {1, 2}; // RBY
|
||||
return pkm.Korean ? G2 : G21;
|
||||
return G12; // RBY
|
||||
}
|
||||
|
||||
private static int[] GetGenMovesOrder(int start, int end)
|
||||
|
|
|
@ -11,6 +11,8 @@ namespace PKHeX.Core
|
|||
/// </summary>
|
||||
public static class VerifyRelearnMoves
|
||||
{
|
||||
private static readonly int[] RelearnEmpty = new int[4];
|
||||
|
||||
public static CheckResult[] VerifyRelearn(PKM pkm, LegalInfo info)
|
||||
{
|
||||
if (info.Generation < 6 || pkm.VC1)
|
||||
|
@ -18,7 +20,7 @@ namespace PKHeX.Core
|
|||
|
||||
switch (info.EncounterMatch)
|
||||
{
|
||||
case EncounterLink l:
|
||||
case EncounterLink l when l.RelearnMoves.Length > 0:
|
||||
return VerifyRelearnSpecifiedMoveset(pkm, info, l.RelearnMoves);
|
||||
case MysteryGift g:
|
||||
return VerifyRelearnSpecifiedMoveset(pkm, info, g.RelearnMoves);
|
||||
|
@ -50,51 +52,51 @@ namespace PKHeX.Core
|
|||
|
||||
private static CheckResult[] VerifyRelearnDexNav(PKM pkm, LegalInfo info)
|
||||
{
|
||||
CheckResult[] res = new CheckResult[4];
|
||||
var result = new CheckResult[4];
|
||||
int[] RelearnMoves = pkm.RelearnMoves;
|
||||
|
||||
// DexNav Pokémon can have 1 random egg move as a relearn move.
|
||||
res[0] = !Legal.GetValidRelearn(pkm, Legal.GetBaseEggSpecies(pkm), true).Contains(RelearnMoves[0])
|
||||
result[0] = !Legal.GetValidRelearn(pkm, Legal.GetBaseEggSpecies(pkm), true).Contains(RelearnMoves[0])
|
||||
? new CheckResult(Severity.Invalid, LMoveRelearnDexNav, CheckIdentifier.RelearnMove)
|
||||
: new CheckResult(CheckIdentifier.RelearnMove);
|
||||
|
||||
// All other relearn moves must be empty.
|
||||
for (int i = 1; i < 4; i++)
|
||||
{
|
||||
res[i] = RelearnMoves[i] != 0
|
||||
result[i] = RelearnMoves[i] != 0
|
||||
? new CheckResult(Severity.Invalid, LMoveRelearnNone, CheckIdentifier.RelearnMove)
|
||||
: new CheckResult(CheckIdentifier.RelearnMove);
|
||||
}
|
||||
|
||||
// Update the relearn base moves if the first relearn move is okay.
|
||||
info.RelearnBase = res[0].Valid
|
||||
info.RelearnBase = result[0].Valid
|
||||
? RelearnMoves
|
||||
: new int[4];
|
||||
: RelearnEmpty;
|
||||
|
||||
return res;
|
||||
return result;
|
||||
}
|
||||
|
||||
private static CheckResult[] VerifyRelearnNone(PKM pkm, LegalInfo info)
|
||||
{
|
||||
CheckResult[] res = new CheckResult[4];
|
||||
var result = new CheckResult[4];
|
||||
int[] RelearnMoves = pkm.RelearnMoves;
|
||||
|
||||
// No relearn moves should be present.
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
res[i] = RelearnMoves[i] != 0
|
||||
result[i] = RelearnMoves[i] != 0
|
||||
? new CheckResult(Severity.Invalid, LMoveRelearnNone, CheckIdentifier.RelearnMove)
|
||||
: new CheckResult(CheckIdentifier.RelearnMove);
|
||||
}
|
||||
|
||||
info.RelearnBase = new int[4];
|
||||
return res;
|
||||
info.RelearnBase = RelearnEmpty;
|
||||
return result;
|
||||
}
|
||||
|
||||
private static CheckResult[] VerifyRelearnEggBase(PKM pkm, LegalInfo info, EncounterEgg e)
|
||||
{
|
||||
int[] RelearnMoves = pkm.RelearnMoves;
|
||||
CheckResult[] res = new CheckResult[4];
|
||||
var result = new CheckResult[4];
|
||||
// Level up moves cannot be inherited if Ditto is the parent
|
||||
// that means genderless species and male only species except Nidoran and Volbeat (they breed with female nidoran and illumise) could not have level up moves as an egg
|
||||
bool inheritLvlMoves = Legal.GetCanInheritMoves(e.Species);
|
||||
|
@ -108,7 +110,7 @@ namespace PKHeX.Core
|
|||
int reqBase = GetRequiredBaseMoves(RelearnMoves, baseMoves, baseCt, inheritMoves);
|
||||
|
||||
// Check if the required amount of Base Egg Moves are present.
|
||||
FlagBaseEggMoves(res, reqBase, baseMoves, RelearnMoves);
|
||||
FlagBaseEggMoves(result, reqBase, baseMoves, RelearnMoves);
|
||||
|
||||
// Non-Base moves that can magically appear in the regular movepool
|
||||
if (Legal.LightBall.Contains(pkm.Species))
|
||||
|
@ -121,51 +123,51 @@ namespace PKHeX.Core
|
|||
|
||||
// Inherited moves appear after the required base moves.
|
||||
// If the pkm is capable of split-species breeding and any inherited move is from the other split scenario, flag accordingly.
|
||||
bool splitInvalid = FlagInvalidInheritedMoves(res, reqBase, RelearnMoves, inheritMoves, splitMoves);
|
||||
bool splitInvalid = FlagInvalidInheritedMoves(result, reqBase, RelearnMoves, inheritMoves, splitMoves);
|
||||
if (splitInvalid)
|
||||
FlagSplitbreedMoves(res, reqBase, e, pkm);
|
||||
FlagSplitbreedMoves(result, reqBase, e, pkm);
|
||||
|
||||
info.RelearnBase = baseMoves;
|
||||
return res;
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void FlagBaseEggMoves(CheckResult[] res, int required, IReadOnlyList<int> baseMoves, IReadOnlyList<int> RelearnMoves)
|
||||
private static void FlagBaseEggMoves(CheckResult[] result, int required, IReadOnlyList<int> baseMoves, IReadOnlyList<int> RelearnMoves)
|
||||
{
|
||||
for (int i = 0; i < required; i++)
|
||||
{
|
||||
if (!baseMoves.Contains(RelearnMoves[i]))
|
||||
{
|
||||
FlagRelearnMovesMissing(res, required, baseMoves, i);
|
||||
FlagRelearnMovesMissing(result, required, baseMoves, i);
|
||||
return;
|
||||
}
|
||||
res[i] = new CheckResult(Severity.Valid, LMoveRelearnEgg, CheckIdentifier.RelearnMove);
|
||||
result[i] = new CheckResult(Severity.Valid, LMoveRelearnEgg, CheckIdentifier.RelearnMove);
|
||||
}
|
||||
}
|
||||
|
||||
private static void FlagRelearnMovesMissing(CheckResult[] res, int required, IReadOnlyList<int> baseMoves, int start)
|
||||
private static void FlagRelearnMovesMissing(CheckResult[] result, int required, IReadOnlyList<int> baseMoves, int start)
|
||||
{
|
||||
for (int z = start; z < required; z++)
|
||||
res[z] = new CheckResult(Severity.Invalid, LMoveRelearnEggMissing, CheckIdentifier.RelearnMove);
|
||||
result[z] = new CheckResult(Severity.Invalid, LMoveRelearnEggMissing, CheckIdentifier.RelearnMove);
|
||||
|
||||
// provide the list of suggested base moves for the last required slot
|
||||
string em = string.Join(", ", GetMoveNames(baseMoves));
|
||||
res[required - 1].Comment += string.Format(Environment.NewLine + LMoveRelearnFExpect_0, em);
|
||||
result[required - 1].Comment += string.Format(Environment.NewLine + LMoveRelearnFExpect_0, em);
|
||||
}
|
||||
|
||||
private static bool FlagInvalidInheritedMoves(CheckResult[] res, int required, IReadOnlyList<int> RelearnMoves, IReadOnlyList<int> inheritMoves, IReadOnlyList<int> splitMoves)
|
||||
private static bool FlagInvalidInheritedMoves(CheckResult[] result, int required, IReadOnlyList<int> RelearnMoves, IReadOnlyList<int> inheritMoves, IReadOnlyList<int> splitMoves)
|
||||
{
|
||||
bool splitInvalid = false;
|
||||
bool isSplit = splitMoves.Count > 0;
|
||||
for (int i = required; i < 4; i++)
|
||||
{
|
||||
if (RelearnMoves[i] == 0) // empty
|
||||
res[i] = new CheckResult(Severity.Valid, LMoveSourceEmpty, CheckIdentifier.RelearnMove);
|
||||
result[i] = new CheckResult(Severity.Valid, LMoveSourceEmpty, CheckIdentifier.RelearnMove);
|
||||
else if (inheritMoves.Contains(RelearnMoves[i])) // inherited
|
||||
res[i] = new CheckResult(Severity.Valid, LMoveSourceRelearn, CheckIdentifier.RelearnMove);
|
||||
result[i] = new CheckResult(Severity.Valid, LMoveSourceRelearn, CheckIdentifier.RelearnMove);
|
||||
else if (isSplit && splitMoves.Contains(RelearnMoves[i])) // inherited
|
||||
splitInvalid = true;
|
||||
else // not inheritable, flag
|
||||
res[i] = new CheckResult(Severity.Invalid, LMoveRelearnInvalid, CheckIdentifier.RelearnMove);
|
||||
result[i] = new CheckResult(Severity.Invalid, LMoveRelearnInvalid, CheckIdentifier.RelearnMove);
|
||||
}
|
||||
|
||||
return splitInvalid;
|
||||
|
|
|
@ -102,7 +102,7 @@ namespace PKHeX.Core
|
|||
{
|
||||
pk.Version = (int)GetRandomVersion(Version);
|
||||
}
|
||||
int lang = GetSafeLanguage(SAV.Language, Language);
|
||||
int lang = (int)GetSafeLanguage((LanguageID)SAV.Language, (LanguageID)Language);
|
||||
bool hatchedEgg = IsEgg && SAV.Generation != 3;
|
||||
if (hatchedEgg) // ugly workaround for character table interactions
|
||||
{
|
||||
|
@ -182,12 +182,12 @@ namespace PKHeX.Core
|
|||
return pk;
|
||||
}
|
||||
|
||||
private static int GetSafeLanguage(int hatchLang, int supplied)
|
||||
private static LanguageID GetSafeLanguage(LanguageID hatchLang, LanguageID supplied)
|
||||
{
|
||||
if (supplied >= 1)
|
||||
if (supplied >= LanguageID.Japanese)
|
||||
return supplied;
|
||||
if (hatchLang < 0 || hatchLang > 8) // ko
|
||||
return 2;
|
||||
if (hatchLang < LanguageID.Hacked || hatchLang > LanguageID.Korean) // ko
|
||||
return LanguageID.English;
|
||||
return hatchLang;
|
||||
}
|
||||
|
||||
|
|
|
@ -981,7 +981,6 @@ namespace PKHeX.WinForms.Controls
|
|||
B_CGearSkin.Enabled = sav.Generation == 5;
|
||||
B_OpenPokeBeans.Enabled = B_CellsStickers.Enabled = B_FestivalPlaza.Enabled = sav is SAV7;
|
||||
|
||||
B_OpenTrainerInfo.Enabled = B_OpenItemPouch.Enabled = (sav.HasParty && !(SAV is SAV4BR)) || SAV is SAV7b; // Box RS & Battle Revolution
|
||||
B_OpenTrainerInfo.Enabled = B_OpenItemPouch.Enabled = (sav.HasParty && !(SAV is SAV4BR)) || SAV is SAV7b; // Box RS & Battle Revolution
|
||||
B_OpenMiscEditor.Enabled = sav is SAV3 || sav is SAV4 || sav is SAV5;
|
||||
B_Roamer.Enabled = sav is SAV3;
|
||||
|
|
|
@ -135,12 +135,15 @@ namespace PKHeX.WinForms
|
|||
SaveDetection.CustomBackupPaths.Clear();
|
||||
try
|
||||
{
|
||||
// cybergadget paths
|
||||
string pathCache = CyberGadgetUtil.GetCacheFolder();
|
||||
if (Directory.Exists(pathCache))
|
||||
SaveDetection.CustomBackupPaths.Add(Path.Combine(pathCache));
|
||||
string pathTemp = CyberGadgetUtil.GetTempFolder();
|
||||
if (Directory.Exists(pathTemp))
|
||||
SaveDetection.CustomBackupPaths.Add(Path.Combine(pathTemp));
|
||||
|
||||
// custom user paths
|
||||
if (File.Exists(SAVPaths))
|
||||
SaveDetection.CustomBackupPaths.AddRange(File.ReadAllLines(SAVPaths).Where(Directory.Exists));
|
||||
}
|
||||
|
@ -832,7 +835,7 @@ namespace PKHeX.WinForms
|
|||
private static bool SanityCheckSAV(ref SaveFile sav)
|
||||
{
|
||||
var gb = ParseSettings.InitFromSaveFileData(sav);
|
||||
if (sav.Generation == 1 && gb)
|
||||
if (sav is SAV1 && gb) // tradeback toggle
|
||||
{
|
||||
var drTradeback = WinFormsUtil.Prompt(MessageBoxButtons.YesNoCancel,
|
||||
MsgLegalityAllowTradebacks,
|
||||
|
@ -843,35 +846,38 @@ namespace PKHeX.WinForms
|
|||
return true;
|
||||
}
|
||||
|
||||
if (sav.Generation == 3 && (sav.IndeterminateGame || ModifierKeys == Keys.Control))
|
||||
if (sav is SAV3 s3)
|
||||
{
|
||||
WinFormsUtil.Alert(string.Format(MsgFileLoadVersionDetect, sav.Generation), MsgFileLoadVersionSelect);
|
||||
var g = new[] { GameVersion.R, GameVersion.S, GameVersion.E, GameVersion.FR, GameVersion.LG };
|
||||
var games = g.Select(z => GameInfo.VersionDataSource.First(v => v.Value == (int)z));
|
||||
var dialog = new SAV_GameSelect(games);
|
||||
dialog.ShowDialog();
|
||||
if (s3.IndeterminateGame || ModifierKeys == Keys.Control)
|
||||
{
|
||||
WinFormsUtil.Alert(string.Format(MsgFileLoadVersionDetect, sav.Generation), MsgFileLoadVersionSelect);
|
||||
var g = new[] { GameVersion.R, GameVersion.S, GameVersion.E, GameVersion.FR, GameVersion.LG };
|
||||
var games = g.Select(z => GameInfo.VersionDataSource.First(v => v.Value == (int)z));
|
||||
var dialog = new SAV_GameSelect(games);
|
||||
dialog.ShowDialog();
|
||||
|
||||
sav = SaveUtil.GetG3SaveOverride(sav, dialog.Result);
|
||||
if (sav == null)
|
||||
return false;
|
||||
if (sav.Version == GameVersion.FRLG)
|
||||
sav.Personal = dialog.Result == GameVersion.FR ? PersonalTable.FR : PersonalTable.LG;
|
||||
}
|
||||
else if (sav.Version == GameVersion.FRLG) // IndeterminateSubVersion
|
||||
{
|
||||
string fr = GameInfo.GetVersionName(GameVersion.FR);
|
||||
string lg = GameInfo.GetVersionName(GameVersion.LG);
|
||||
string dual = "{0}/{1} " + MsgFileLoadSaveDetected;
|
||||
WinFormsUtil.Alert(string.Format(dual, fr, lg), MsgFileLoadSaveSelectVersion);
|
||||
var g = new[] {GameVersion.FR, GameVersion.LG};
|
||||
var games = g.Select(z => GameInfo.VersionDataSource.First(v => v.Value == (int) z));
|
||||
var dialog = new SAV_GameSelect(games);
|
||||
dialog.ShowDialog();
|
||||
sav = SaveUtil.GetG3SaveOverride(sav, dialog.Result);
|
||||
if (sav == null)
|
||||
return false;
|
||||
if (sav.Version == GameVersion.FRLG)
|
||||
sav.Personal = dialog.Result == GameVersion.FR ? PersonalTable.FR : PersonalTable.LG;
|
||||
}
|
||||
else if (sav.Version == GameVersion.FRLG) // IndeterminateSubVersion
|
||||
{
|
||||
string fr = GameInfo.GetVersionName(GameVersion.FR);
|
||||
string lg = GameInfo.GetVersionName(GameVersion.LG);
|
||||
string dual = "{0}/{1} " + MsgFileLoadSaveDetected;
|
||||
WinFormsUtil.Alert(string.Format(dual, fr, lg), MsgFileLoadSaveSelectVersion);
|
||||
var g = new[] { GameVersion.FR, GameVersion.LG };
|
||||
var games = g.Select(z => GameInfo.VersionDataSource.First(v => v.Value == (int)z));
|
||||
var dialog = new SAV_GameSelect(games);
|
||||
dialog.ShowDialog();
|
||||
|
||||
var pt = SaveUtil.GetG3Personal(dialog.Result);
|
||||
if (pt == null)
|
||||
return false;
|
||||
sav.Personal = pt;
|
||||
var pt = SaveUtil.GetG3Personal(dialog.Result);
|
||||
if (pt == null)
|
||||
return false;
|
||||
sav.Personal = pt;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
Loading…
Reference in a new issue