mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-05-11 06:05:04 -05:00
Refactor time of day check/validate
Fixes time of day flitering property reference (met_day is always 0, so it never reached)
This commit is contained in:
parent
867c705597
commit
d4e38dded0
|
|
@ -216,7 +216,7 @@ private static List<EncounterArea> 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;
|
||||
|
|
|
|||
|
|
@ -328,8 +328,8 @@ private static IEnumerable<EncounterSlot> 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:
|
||||
|
|
|
|||
|
|
@ -1,32 +1,30 @@
|
|||
namespace PKHeX.Core
|
||||
using System;
|
||||
|
||||
namespace PKHeX.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Generation 2 Time of Encounter enum
|
||||
/// </summary>
|
||||
[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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user