diff --git a/PKHeX.Core/Legality/Core.cs b/PKHeX.Core/Legality/Core.cs index a5572cb35..8f4fc3f76 100644 --- a/PKHeX.Core/Legality/Core.cs +++ b/PKHeX.Core/Legality/Core.cs @@ -2229,5 +2229,16 @@ public static LanguageID GetSafeLanguage(int generation, LanguageID prefer, Game return LanguageID.English; } } + + public static int GetRandomFeeling(int memory, int max = 24) + { + var bits = MemoryFeelings[memory]; + while (true) + { + int feel = Util.Rand.Next(0, max); + if ((bits & (1 << feel)) != 0) + return feel; + } + } } } diff --git a/PKHeX.Core/MysteryGifts/WC6.cs b/PKHeX.Core/MysteryGifts/WC6.cs index 2e4841a9b..fd98a224e 100644 --- a/PKHeX.Core/MysteryGifts/WC6.cs +++ b/PKHeX.Core/MysteryGifts/WC6.cs @@ -363,14 +363,14 @@ public override PKM ConvertToPKM(ITrainerInfo SAV) pk.OT_Memory = 3; pk.OT_TextVar = 9; pk.OT_Intensity = 1; - pk.OT_Feeling = Util.Rand.Next(0, 10); // 0-9 + pk.OT_Feeling = Legal.GetRandomFeeling(pk.OT_Memory, 10); // 0-9 } else { pk.HT_Memory = 3; pk.HT_TextVar = 9; pk.HT_Intensity = 1; - pk.HT_Feeling = Util.Rand.Next(0, 10); // 0-9 + pk.HT_Feeling = Legal.GetRandomFeeling(pk.HT_Memory, 10); // 0-9 pk.HT_Friendship = pk.OT_Friendship; } pk.IsNicknamed = IsNicknamed; diff --git a/PKHeX.Core/PKM/Editing/CommonEdits.cs b/PKHeX.Core/PKM/Editing/CommonEdits.cs index 78a769a81..ef6121261 100644 --- a/PKHeX.Core/PKM/Editing/CommonEdits.cs +++ b/PKHeX.Core/PKM/Editing/CommonEdits.cs @@ -559,7 +559,7 @@ public static void SetHatchMemory6(this PKM pk) { pk.OT_Memory = 2; pk.OT_Affection = 0; - pk.OT_Feeling = Util.Rand.Next(0, 10); + Legal.GetRandomFeeling(pk.OT_Memory); pk.OT_Intensity = 1; pk.OT_TextVar = pk.XY ? 43 : 27; // riverside road : battling spot } @@ -569,7 +569,7 @@ public static void SetRandomMemory6(this PKM pk) // for lack of better randomization :) pk.OT_Memory = 63; pk.OT_Intensity = 6; - pk.OT_Feeling = 3; + Legal.GetRandomFeeling(pk.OT_Memory); } } } diff --git a/PKHeX.Core/PKM/PK5.cs b/PKHeX.Core/PKM/PK5.cs index c7e8d428c..7ec937e90 100644 --- a/PKHeX.Core/PKM/PK5.cs +++ b/PKHeX.Core/PKM/PK5.cs @@ -493,7 +493,7 @@ public PK6 ConvertToPK6() pk6.Geo1_Country = PKMConverter.Country; pk6.HT_Intensity = 1; pk6.HT_Memory = 4; - pk6.HT_Feeling = (int)(Util.Rand32() % 10); + pk6.HT_Feeling = Legal.GetRandomFeeling(pk6.HT_Memory); // When transferred, friendship gets reset. pk6.OT_Friendship = pk6.HT_Friendship = PersonalInfo.BaseFriendship; diff --git a/PKHeX.Core/PKM/PK6.cs b/PKHeX.Core/PKM/PK6.cs index b3f7753a3..d4de1d66b 100644 --- a/PKHeX.Core/PKM/PK6.cs +++ b/PKHeX.Core/PKM/PK6.cs @@ -559,7 +559,7 @@ public void TradeMemory(bool Bank) HT_Memory = 4; // Link trade to [VAR: General Location] HT_TextVar = Bank ? 0 : 9; // Somewhere (Bank) : Pokécenter (Trade) HT_Intensity = 1; - HT_Feeling = Util.Rand.Next(0, Bank ? 10 : 20); // 0-9 Bank, 0-19 Trade + HT_Feeling = Legal.GetRandomFeeling(HT_Memory, Bank ? 10 : 20); // 0-9 Bank, 0-19 Trade } // Legality Properties diff --git a/PKHeX.Core/PKM/PK7.cs b/PKHeX.Core/PKM/PK7.cs index a325dae88..4ada7f814 100644 --- a/PKHeX.Core/PKM/PK7.cs +++ b/PKHeX.Core/PKM/PK7.cs @@ -596,7 +596,7 @@ public void TradeMemory(bool Bank) HT_Memory = 4; // Link trade to [VAR: General Location] HT_TextVar = 0; // Somewhere (Bank) HT_Intensity = 1; - HT_Feeling = Util.Rand.Next(0, 10); // 0-9 Bank + HT_Feeling = Legal.GetRandomFeeling(HT_Memory, 10); // 0-9 Bank } // Legality Properties