diff --git a/PKHeX.Core/Legality/Areas/EncounterArea.cs b/PKHeX.Core/Legality/Areas/EncounterArea.cs index 1e11e17f6..37bb58ad3 100644 --- a/PKHeX.Core/Legality/Areas/EncounterArea.cs +++ b/PKHeX.Core/Legality/Areas/EncounterArea.cs @@ -216,7 +216,7 @@ private static List GetAreas2_F(byte[] data, ref int ofs) s.Species = dl[index + j].Species; s.LevelMin = s.LevelMax = dl[index + j].Level; s.Type = slots[i - 1].Type; // special slots are never first in a set, so copy previous type - s.Time = j == 0 ? EncounterTime.MorningDay : EncounterTime.Night; + s.Time = j == 0 ? EncounterTime.Morning | EncounterTime.Day : EncounterTime.Night; } } area.Slots = slots; diff --git a/PKHeX.Core/Legality/Encounters/Generator/EncounterSlotGenerator.cs b/PKHeX.Core/Legality/Encounters/Generator/EncounterSlotGenerator.cs index 518852ab4..b4e66e796 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/EncounterSlotGenerator.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/EncounterSlotGenerator.cs @@ -328,8 +328,8 @@ private static IEnumerable GetFilteredSlots12(PKM pkm, int gen, G return slots; case 2: - if (pkm is PK2 pk2 && pk2.Met_Day != 0) - return slots.Where(slot => ((EncounterSlot1)slot).Time.Contains(pk2.Met_Day)); + if (pkm is PK2 pk2 && pk2.Met_TimeOfDay != 0) + return slots.Where(slot => ((EncounterSlot1)slot).Time.Contains(pk2.Met_TimeOfDay)); return slots; default: diff --git a/PKHeX.Core/Legality/Enums/EncounterTime.cs b/PKHeX.Core/Legality/Enums/EncounterTime.cs index 45a56219f..b2ef3e19c 100644 --- a/PKHeX.Core/Legality/Enums/EncounterTime.cs +++ b/PKHeX.Core/Legality/Enums/EncounterTime.cs @@ -1,32 +1,30 @@ -namespace PKHeX.Core +using System; + +namespace PKHeX.Core { /// /// Generation 2 Time of Encounter enum /// + [Flags] internal enum EncounterTime { - Any = -1, - MorningDay = -2, - Morning = 1, - Day = 2, - Night = 3 + Any = 0, + Morning = 1 << 1, + Day = 1 << 2, + Night = 1 << 3, } internal static class EncounterTimeExtension { - internal static bool Contains(this EncounterTime t1, int t2) => t1.Contains((EncounterTime)t2); - private static bool Contains(this EncounterTime t1, EncounterTime t2) + internal static bool Contains(this EncounterTime t1, int t2) => t1.HasFlag((EncounterTime)(1 << t2)); + internal static int RandomValidTime(this EncounterTime t1) { - if (t1 == t2 || t1 == EncounterTime.Any || t2 == EncounterTime.Any) - return true; - - if (t1 == EncounterTime.MorningDay) - return t2 == EncounterTime.Morning || t2 == EncounterTime.Day; - - if (t2 == EncounterTime.MorningDay) - return t1 == EncounterTime.Morning || t1 == EncounterTime.Day; - - return false; + int val = Util.Rand.Next(1, 4); + if (t1 == EncounterTime.Any) + return val; + while (!t1.Contains(val)) + val = Util.Rand.Next(1, 4); + return val; } } } \ No newline at end of file