mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-10 06:34:19 +00:00
Minor clean
Slap on interface for EntreeSlot
De-magic some 💯 numbers to indicate what they're doing
Improve perf of move-match-relearn check
Add an "else" as valid is never both values (history verifier)
This commit is contained in:
parent
a0bdb1a40e
commit
9793e9f1a0
9 changed files with 64 additions and 38 deletions
|
@ -37,14 +37,15 @@ namespace PKHeX.Core
|
|||
{
|
||||
if (pk is not PK8 pk8)
|
||||
return;
|
||||
var permit = pk8.PersonalInfo.TMHM;
|
||||
var permit = pk8.PersonalInfo.TMHM.AsSpan(PersonalInfoSWSH.CountTM);
|
||||
var moveIDs = Legal.TMHM_SWSH.AsSpan(PersonalInfoSWSH.CountTM);
|
||||
foreach (var m in moves)
|
||||
{
|
||||
var index = Array.IndexOf(Legal.TMHM_SWSH, m, 100);
|
||||
if (index < 100)
|
||||
var index = moveIDs.IndexOf(m);
|
||||
if (index == -1)
|
||||
continue;
|
||||
if (permit[index])
|
||||
pk8.SetMoveRecordFlag(index - 100, true);
|
||||
pk8.SetMoveRecordFlag(index, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,11 +57,11 @@ namespace PKHeX.Core
|
|||
{
|
||||
if (pk is not PK8 pk8)
|
||||
return;
|
||||
var permit = pk8.PersonalInfo.TMHM;
|
||||
for (int i = 100; i < permit.Length; i++)
|
||||
var permit = pk8.PersonalInfo.TMHM.AsSpan(PersonalInfoSWSH.CountTM); // tm[100], tr[100]
|
||||
for (int i = 0; i < permit.Length; i++)
|
||||
{
|
||||
if (permit[i])
|
||||
pk8.SetMoveRecordFlag(i - 100, true);
|
||||
pk8.SetMoveRecordFlag(i, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -126,8 +126,8 @@ namespace PKHeX.Core
|
|||
public static bool CanHatchAsEgg(int species, int form, GameVersion game)
|
||||
{
|
||||
// Sanity check form for origin
|
||||
var gameInfo = GameData.GetPersonal(game);
|
||||
var entry = gameInfo.GetFormEntry(species, form);
|
||||
var pt = GameData.GetPersonal(game);
|
||||
var entry = pt.GetFormEntry(species, form);
|
||||
return form < entry.FormCount || (species == (int)Rotom && form <= 5);
|
||||
}
|
||||
|
||||
|
|
|
@ -233,7 +233,7 @@ namespace PKHeX.Core
|
|||
{
|
||||
if (GameVersion.SWSH.Contains(ver))
|
||||
{
|
||||
for (int i = 0; i < 100; i++)
|
||||
for (int i = 0; i < PersonalInfoSWSH.CountTM; i++)
|
||||
{
|
||||
if (Legal.TMHM_SWSH[i] != move)
|
||||
continue;
|
||||
|
@ -250,11 +250,13 @@ namespace PKHeX.Core
|
|||
{
|
||||
if (GameVersion.SWSH.Contains(ver))
|
||||
{
|
||||
for (int i = 0; i < 100; i++)
|
||||
for (int i = 0; i < PersonalInfoSWSH.CountTR; i++)
|
||||
{
|
||||
if (Legal.TMHM_SWSH[i + 100] != move)
|
||||
var index = i + PersonalInfoSWSH.CountTM;
|
||||
if (Legal.TMHM_SWSH[index] != move)
|
||||
continue;
|
||||
if (!PersonalTable.SWSH.GetFormEntry(species, form).TMHM[i + 100])
|
||||
var pi = PersonalTable.SWSH.GetFormEntry(species, form);
|
||||
if (!pi.TMHM[index])
|
||||
break;
|
||||
if (allowBit)
|
||||
return GameVersion.SWSH;
|
||||
|
@ -451,7 +453,7 @@ namespace PKHeX.Core
|
|||
return;
|
||||
var pi = PersonalTable.SWSH.GetFormEntry(species, form);
|
||||
var tmhm = pi.TMHM;
|
||||
for (int i = 0; i < 100; i++)
|
||||
for (int i = 0; i < PersonalInfoSWSH.CountTM; i++)
|
||||
{
|
||||
if (!tmhm[i])
|
||||
continue;
|
||||
|
@ -464,9 +466,10 @@ namespace PKHeX.Core
|
|||
var pi = PersonalTable.SWSH.GetFormEntry(species, form);
|
||||
var tmhm = pi.TMHM;
|
||||
var pk8 = (PK8)pkm;
|
||||
for (int i = 0; i < 100; i++)
|
||||
for (int i = 0; i < PersonalInfoSWSH.CountTR; i++)
|
||||
{
|
||||
if (!tmhm[i + 100])
|
||||
var index = i + PersonalInfoSWSH.CountTM;
|
||||
if (!tmhm[index])
|
||||
continue;
|
||||
if (!pk8.GetMoveRecordFlag(i))
|
||||
{
|
||||
|
@ -481,7 +484,7 @@ namespace PKHeX.Core
|
|||
continue;
|
||||
}
|
||||
}
|
||||
r.Add(Legal.TMHM_SWSH[i + 100]);
|
||||
r.Add(Legal.TMHM_SWSH[index]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -489,11 +492,12 @@ namespace PKHeX.Core
|
|||
{
|
||||
var pi = PersonalTable.SWSH.GetFormEntry(species, form);
|
||||
var tmhm = pi.TMHM;
|
||||
for (int i = 0; i < 100; i++)
|
||||
for (int i = 0; i < PersonalInfoSWSH.CountTM; i++)
|
||||
{
|
||||
if (!tmhm[i + 100])
|
||||
var index = i + PersonalInfoSWSH.CountTM;
|
||||
if (!tmhm[index])
|
||||
continue;
|
||||
yield return Legal.TMHM_SWSH[i + 100];
|
||||
yield return Legal.TMHM_SWSH[index];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -163,7 +163,7 @@ namespace PKHeX.Core
|
|||
var valid = t.GetValidity();
|
||||
if (valid == GeoValid.CountryAfterPreviousEmpty)
|
||||
data.AddLine(GetInvalid(LegalityCheckStrings.LGeoBadOrder));
|
||||
if (valid == GeoValid.RegionWithoutCountry)
|
||||
else if (valid == GeoValid.RegionWithoutCountry)
|
||||
data.AddLine(GetInvalid(LegalityCheckStrings.LGeoNoRegion));
|
||||
if (t.Geo1_Country != 0 && pkm.IsUntraded) // traded
|
||||
data.AddLine(GetInvalid(LegalityCheckStrings.LGeoNoCountryHT));
|
||||
|
|
|
@ -54,7 +54,7 @@ namespace PKHeX.Core
|
|||
// {0} studied about how to use {2} in a Box, thinking about {1}. {4} that {3}.
|
||||
// {0} practiced its cool pose for the move {2} in a Box, wishing to be praised by {1}. {4} that {3}.
|
||||
case 80 or 81 when !CanKnowMove(pkm, memory, gen, info):
|
||||
return Get(string.Format(LMemoryArgBadMove, memory.Handler), gen == 8 ? Severity.Fishy : Severity.Invalid);
|
||||
return Get(string.Format(LMemoryArgBadMove, memory.Handler), Severity.Invalid);
|
||||
|
||||
// Species
|
||||
// {0} had a great chat about {1} with the {2} that it was in a Box with. {4} that {3}.
|
||||
|
|
|
@ -63,13 +63,14 @@ namespace PKHeX.Core
|
|||
if (pkm.Format >= 6)
|
||||
VerifyFullness(data, pkm);
|
||||
|
||||
if (data.EncounterMatch is WC8 { IsHOMEGift: true } w)
|
||||
var enc = data.EncounterMatch;
|
||||
if (enc is WC8 { IsHOMEGift: true } w)
|
||||
{
|
||||
var date = new DateTime(pkm.Met_Year + 2000, pkm.Met_Month, pkm.Met_Day);
|
||||
if (!EncountersHOME.IsValidDateWC8(w.CardID, date))
|
||||
data.AddLine(GetInvalid(LDateOutsideDistributionWindow));
|
||||
}
|
||||
else if (data.EncounterMatch is IOverworldCorrelation8 z)
|
||||
else if (enc is IOverworldCorrelation8 z)
|
||||
{
|
||||
var match = z.IsOverworldCorrelationCorrect(pkm);
|
||||
var req = z.GetRequirement(pkm);
|
||||
|
@ -246,7 +247,7 @@ namespace PKHeX.Core
|
|||
if (pkm.OT_Friendship > HatchCycles)
|
||||
data.AddLine(GetInvalid(LEggHatchCycles, Egg));
|
||||
|
||||
if (pkm.Format >= 6 && enc is EncounterEgg && !pkm.Moves.SequenceEqual(pkm.RelearnMoves))
|
||||
if (pkm.Format >= 6 && enc is EncounterEgg && !MovesMatchRelearn(pkm))
|
||||
{
|
||||
var moves = string.Join(", ", ParseSettings.GetMoveNames(pkm.Moves));
|
||||
var msg = string.Format(LMoveFExpect_0, moves);
|
||||
|
@ -262,6 +263,19 @@ namespace PKHeX.Core
|
|||
}
|
||||
}
|
||||
|
||||
private static bool MovesMatchRelearn(PKM pkm)
|
||||
{
|
||||
if (pkm.Move1 != pkm.RelearnMove1)
|
||||
return false;
|
||||
if (pkm.Move2 != pkm.RelearnMove2)
|
||||
return false;
|
||||
if (pkm.Move3 != pkm.RelearnMove3)
|
||||
return false;
|
||||
if (pkm.Move4 != pkm.RelearnMove4)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void VerifyFatefulMysteryGift(LegalityAnalysis data, MysteryGift g)
|
||||
{
|
||||
var pkm = data.pkm;
|
||||
|
@ -394,7 +408,7 @@ namespace PKHeX.Core
|
|||
// ReSharper disable once CompareOfFloatsByEqualityOperator -- THESE MUST MATCH EXACTLY
|
||||
if (!IsCloseEnough(pb7.WeightAbsolute, pb7.CalcWeightAbsolute))
|
||||
data.AddLine(GetInvalid(LStatIncorrectWeight, Encounter));
|
||||
if (pb7.Stat_CP != pb7.CalcCP && !IsStarter(pb7))
|
||||
if (pb7.Stat_CP != pb7.CalcCP && !IsStarterLGPE(pb7))
|
||||
data.AddLine(GetInvalid(LStatIncorrectCP, Encounter));
|
||||
}
|
||||
|
||||
|
@ -405,7 +419,12 @@ namespace PKHeX.Core
|
|||
return Math.Abs(ia - ib) <= 7;
|
||||
}
|
||||
|
||||
private static bool IsStarter(PKM pb7) => (pb7.Species == (int)Species.Pikachu && pb7.Form == 8) || (pb7.Species == (int)Species.Eevee && pb7.Form == 1);
|
||||
private static bool IsStarterLGPE(ISpeciesForm pk) => pk.Species switch
|
||||
{
|
||||
(int)Species.Pikachu when pk.Form == 8 => true,
|
||||
(int)Species.Eevee when pk.Form == 1 => true,
|
||||
_ => false,
|
||||
};
|
||||
|
||||
private void VerifySWSHStats(LegalityAnalysis data, PK8 pk8)
|
||||
{
|
||||
|
@ -454,7 +473,7 @@ namespace PKHeX.Core
|
|||
}
|
||||
|
||||
PersonalInfo? pi = null;
|
||||
for (int i = 0; i < 100; i++)
|
||||
for (int i = 0; i < PersonalInfoSWSH.CountTR; i++)
|
||||
{
|
||||
if (!pk8.GetMoveRecordFlag(i))
|
||||
continue;
|
||||
|
@ -472,7 +491,7 @@ namespace PKHeX.Core
|
|||
continue;
|
||||
}
|
||||
|
||||
data.AddLine(GetInvalid(string.Format(LMoveSourceTR, ParseSettings.MoveStrings[Legal.TMHM_SWSH[i + 100]])));
|
||||
data.AddLine(GetInvalid(string.Format(LMoveSourceTR, ParseSettings.MoveStrings[Legal.TMHM_SWSH[i + PersonalInfoSWSH.CountTM]])));
|
||||
}
|
||||
|
||||
// weight/height scalars can be legally 0 (1:65536) so don't bother checking
|
||||
|
@ -481,7 +500,7 @@ namespace PKHeX.Core
|
|||
private static bool CanLearnTR(int species, int form, int tr)
|
||||
{
|
||||
var pi = PersonalTable.SWSH.GetFormEntry(species, form);
|
||||
return pi.TMHM[tr + 100];
|
||||
return pi.TMHM[tr + PersonalInfoSWSH.CountTM];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,14 +9,16 @@ namespace PKHeX.Core
|
|||
public sealed class PersonalInfoSWSH : PersonalInfo
|
||||
{
|
||||
public const int SIZE = 0xB0;
|
||||
public const int CountTM = 100;
|
||||
public const int CountTR = 100;
|
||||
|
||||
public PersonalInfoSWSH(byte[] data) : base(data)
|
||||
{
|
||||
TMHM = new bool[200];
|
||||
for (var i = 0; i < 100; i++)
|
||||
for (var i = 0; i < CountTR; i++)
|
||||
{
|
||||
TMHM[i] = FlagUtil.GetFlag(Data, 0x28 + (i >> 3), i);
|
||||
TMHM[i + 100] = FlagUtil.GetFlag(Data, 0x3C + (i >> 3), i);
|
||||
TMHM[i] = FlagUtil.GetFlag(Data, 0x28 + (i >> 3), i);
|
||||
TMHM[i + CountTM] = FlagUtil.GetFlag(Data, 0x3C + (i >> 3), i);
|
||||
}
|
||||
|
||||
// 0x38-0x3B type tutors, but only 8 bits are valid flags.
|
||||
|
@ -37,10 +39,10 @@ namespace PKHeX.Core
|
|||
|
||||
public override byte[] Write()
|
||||
{
|
||||
for (var i = 0; i < 100; i++)
|
||||
for (var i = 0; i < CountTR; i++)
|
||||
{
|
||||
FlagUtil.SetFlag(Data, 0x28 + (i >> 3), i, TMHM[i]);
|
||||
FlagUtil.SetFlag(Data, 0x3C + (i >> 3), i, TMHM[i + 100]);
|
||||
FlagUtil.SetFlag(Data, 0x3C + (i >> 3), i, TMHM[i + CountTM]);
|
||||
}
|
||||
for (int i = 0; i < TypeTutors.Length; i++)
|
||||
FlagUtil.SetFlag(Data, 0x38, i, TypeTutors[i]);
|
||||
|
|
|
@ -5,7 +5,7 @@ namespace PKHeX.Core
|
|||
/// <summary>
|
||||
/// Generation 5 <see cref="EntreeForest"/> slot
|
||||
/// </summary>
|
||||
public sealed class EntreeSlot
|
||||
public sealed class EntreeSlot : ISpeciesForm
|
||||
{
|
||||
/// <summary>
|
||||
/// <see cref="PKM.Species"/> index
|
||||
|
|
|
@ -37,13 +37,13 @@ namespace PKHeX.WinForms
|
|||
|
||||
private void LoadRecords()
|
||||
{
|
||||
for (int i = 0; i < 100; i++)
|
||||
for (int i = 0; i < PersonalInfoSWSH.CountTR; i++)
|
||||
CLB_Flags.SetItemChecked(i, pkm.GetMoveRecordFlag(i));
|
||||
}
|
||||
|
||||
private void Save()
|
||||
{
|
||||
for (int i = 0; i < 100; i++)
|
||||
for (int i = 0; i < PersonalInfoSWSH.CountTR; i++)
|
||||
pkm.SetMoveRecordFlag(i, CLB_Flags.GetItemChecked(i));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue