diff --git a/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible8a.cs b/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible8a.cs index 3ed406f61..c628e13ac 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible8a.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible8a.cs @@ -54,7 +54,7 @@ public bool MoveNext() case YieldState.EventLocal: if (TryGetNext(EncounterEvent.EGDB_G8A)) return true; - Index = 0; State = YieldState.Static; goto case YieldState.Static; + Index = 0; goto case YieldState.StaticStart; case YieldState.StaticStart: if (!Flags.HasFlag(EncounterTypeGroup.Static)) diff --git a/PKHeX.Core/Legality/RNG/ClassicEra/Gen3/CommonEvent3.cs b/PKHeX.Core/Legality/RNG/ClassicEra/Gen3/CommonEvent3.cs index 8059470f9..f937d934b 100644 --- a/PKHeX.Core/Legality/RNG/ClassicEra/Gen3/CommonEvent3.cs +++ b/PKHeX.Core/Legality/RNG/ClassicEra/Gen3/CommonEvent3.cs @@ -231,7 +231,7 @@ public static uint GetRandomRestrictedGenderBit0(uint seed, byte gender5) while (true) { var u16 = seed & 0xFFFF; - var rand5 = LCRNG.Next5(seed) >> 16; + var rand5 = LCRNG.Next5(u16) >> 16; if (GetGenderBit0(rand5) == gender5) return u16; seed = LCRNG.Next(seed); diff --git a/PKHeX.Core/Legality/RNG/Methods/Gen8/RaidRNG.cs b/PKHeX.Core/Legality/RNG/Methods/Gen8/RaidRNG.cs index 29d18fd87..4b5accb67 100644 --- a/PKHeX.Core/Legality/RNG/Methods/Gen8/RaidRNG.cs +++ b/PKHeX.Core/Legality/RNG/Methods/Gen8/RaidRNG.cs @@ -167,7 +167,7 @@ public static bool TryApply(PK8 pk, ulong seed, Span ivs, in GenerateParam8 ForceShinyState(false, ref pid, trID, 0); isShiny = false; } - if (isShiny != criteria.Shiny.IsShiny()) + if (param.Shiny is Shiny.Random && isShiny != criteria.Shiny.IsShiny()) return false; if (isShiny) diff --git a/PKHeX.Core/Legality/RNG/Methods/Gen9/Encounter9RNG.cs b/PKHeX.Core/Legality/RNG/Methods/Gen9/Encounter9RNG.cs index 58bee6f85..3dc8b1585 100644 --- a/PKHeX.Core/Legality/RNG/Methods/Gen9/Encounter9RNG.cs +++ b/PKHeX.Core/Legality/RNG/Methods/Gen9/Encounter9RNG.cs @@ -40,7 +40,7 @@ public static bool TryApply64(this TEnc enc, PK9 pk, in ulong init, in Gen for (int ctr = 0; ctr < maxCtr; ctr++) { ulong seed = rand.Next(); // fake cryptosecure - if (!GenerateData(pk, param, criteria, seed)) + if (!GenerateData(pk, param, criteria, seed, param.IVs.IsSpecified)) continue; var type = Tera9RNG.GetTeraType(seed, enc.TeraType, enc.Species, enc.Form); @@ -60,7 +60,7 @@ public static bool GenerateData(PK9 pk, in GenerateParam9 enc, EncounterCriteria pk.EncryptionConstant = (uint)rand.NextInt(uint.MaxValue); pk.PID = GetAdaptedPID(ref rand, pk, enc); - if (criteria.Shiny.IsShiny() != pk.IsShiny) + if (enc.Shiny is Shiny.Random && criteria.Shiny.IsShiny() != pk.IsShiny) return false; const int UNSET = -1; @@ -120,16 +120,11 @@ public static bool GenerateData(PK9 pk, in GenerateParam9 enc, EncounterCriteria var nature = enc.Nature != Nature.Random ? enc.Nature : enc.Species == (int)Species.Toxtricity ? ToxtricityUtil.GetRandomNature(ref rand, pk.Form) : (Nature)rand.NextInt(25); - pk.Nature = pk.StatNature = nature; // Compromise on Nature -- some are fixed, some are random. If the request wants a specific nature, just mint it. - var requestNature = criteria.GetNature(); - if (criteria.Nature != Nature.Random && nature != requestNature) - { - if (!requestNature.IsMint()) - return false; - pk.StatNature = requestNature; - } + if (criteria.IsSpecifiedNature() && !criteria.IsSatisfiedNature(nature)) + return false; + pk.Nature = pk.StatNature = nature; pk.HeightScalar = enc.Height != 0 ? enc.Height : (byte)(rand.NextInt(0x81) + rand.NextInt(0x80)); pk.WeightScalar = enc.Weight != 0 ? enc.Weight : (byte)(rand.NextInt(0x81) + rand.NextInt(0x80)); @@ -302,7 +297,7 @@ private static uint GetAdaptedPID(ref Xoroshiro128Plus rand, PKM pk, in Generate return pid; } - public static byte GetGender(in int ratio, in ulong rand100) => ratio switch + public static byte GetGender(in byte ratio, in ulong rand100) => ratio switch { 0x1F => rand100 < 12 ? (byte)1 : (byte)0, // 12.5% 0x3F => rand100 < 25 ? (byte)1 : (byte)0, // 25% diff --git a/PKHeX.Core/Legality/Verifiers/Ball/BallVerifier.cs b/PKHeX.Core/Legality/Verifiers/Ball/BallVerifier.cs index 84c4e5f3b..a3fada2ce 100644 --- a/PKHeX.Core/Legality/Verifiers/Ball/BallVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/Ball/BallVerifier.cs @@ -24,7 +24,7 @@ public override void Verify(LegalityAnalysis data) { // Trading from PLA origin -> SW/SH will replace the Legends: Arceus ball with a regular Poké Ball // Enamorus is a special case where the ball is not replaced with a Poké Ball (it's a Cherish Ball) - PK8 when enc.Version == GameVersion.PLA && enc is not IFixedBall { FixedBall: (>0 and < Strange) } => Poke, + PK8 when enc.Version == GameVersion.PLA && enc is not IFixedBall { FixedBall: (> 0 and < Strange) } => Poke, // No replacement done. _ => NoBallReplace, diff --git a/PKHeX.Core/Legality/Verifiers/HistoryVerifier.cs b/PKHeX.Core/Legality/Verifiers/HistoryVerifier.cs index 5b315576e..80db436c6 100644 --- a/PKHeX.Core/Legality/Verifiers/HistoryVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/HistoryVerifier.cs @@ -125,12 +125,12 @@ private void VerifyOTMisc(LegalityAnalysis data, bool neverOT) VerifyOTFriendship(data, neverOT, Info.Generation, pk); } - private void VerifyOTFriendship(LegalityAnalysis data, bool neverOT, int origin, PKM pk) + private void VerifyOTFriendship(LegalityAnalysis data, bool neverOT, byte generation, PKM pk) { - if (origin < 0) + if (generation == 0) // other things are invalid, don't bother checking return; - if (origin <= 2) + if (generation <= 2) { VerifyOTFriendshipVC12(data, pk); return; diff --git a/PKHeX.Core/PKM/HOME/GameDataPB7.cs b/PKHeX.Core/PKM/HOME/GameDataPB7.cs index 6363c0ce1..504be01b1 100644 --- a/PKHeX.Core/PKM/HOME/GameDataPB7.cs +++ b/PKHeX.Core/PKM/HOME/GameDataPB7.cs @@ -52,7 +52,7 @@ public sealed class GameDataPB7 : HomeOptional1, IGameDataSide, IScaledSize public byte FieldEventFatigue2 { get => Data[0x28]; set => Data[0x28] = value; } public byte Fullness { get => Data[0x29]; set => Data[0x29] = value; } public byte Rank { get => Data[0x2A]; set => Data[0x2A] = value; } - public int OriginalTrainerAffection { get => Data[0x2B]; set => Data[0x2B] = (byte)value; } + public byte OriginalTrainerAffection { get => Data[0x2B]; set => Data[0x2B] = (byte)value; } public byte OriginalTrainerMemoryIntensity { get => Data[0x2C]; set => Data[0x2C] = value; } public byte OriginalTrainerMemory { get => Data[0x2D]; set => Data[0x2D] = value; } public ushort OriginalTrainerMemoryVariable { get => ReadUInt16LittleEndian(Data[0x2E..]); set => WriteUInt16LittleEndian(Data[0x2E..], value); } diff --git a/PKHeX.Core/PKM/Interfaces/IObedienceLevel.cs b/PKHeX.Core/PKM/Interfaces/IObedienceLevel.cs index 4a4a1f185..1cc69f107 100644 --- a/PKHeX.Core/PKM/Interfaces/IObedienceLevel.cs +++ b/PKHeX.Core/PKM/Interfaces/IObedienceLevel.cs @@ -16,13 +16,13 @@ public static class ObedienceExtensions /// /// Suggests the for the entity. /// - public static byte GetSuggestedObedienceLevel(this IObedienceLevelReadOnly _, PKM entity, int originalMet) + public static byte GetSuggestedObedienceLevel(this IObedienceLevelReadOnly _, PKM entity, byte originalMet) { if (entity.Species is (int)Species.Koraidon or (int)Species.Miraidon && entity is PK9 { FormArgument: not 0 }) return 0; // Box Legend ride-able is default 0. Everything else is met level! if (entity.Version is not (GameVersion.SL or GameVersion.VL)) return entity.CurrentLevel; // foreign, play it safe. // Can just assume min-level - return (byte)originalMet; + return originalMet; } } diff --git a/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs b/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs index 515029913..1bc43fc92 100644 --- a/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs +++ b/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs @@ -2134,8 +2134,11 @@ private void L_Obedience_Click(object sender, EventArgs e) { if (Entity is not IObedienceLevel l) return; + var met = Util.ToInt32(TB_MetLevel.Text); - var suggest = l.GetSuggestedObedienceLevel(Entity, met); + var metLevel = (byte)Math.Clamp(0, 100, met); + var suggest = l.GetSuggestedObedienceLevel(Entity, metLevel); + var current = Util.ToInt32(TB_ObedienceLevel.Text); if (suggest != current) TB_ObedienceLevel.Text = suggest.ToString();