2022-09-23 20:36:44 +00:00
|
|
|
using System.Diagnostics;
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
namespace PKHeX.Core;
|
|
|
|
|
2022-08-21 08:39:16 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Represents an RNG seed and the conditions of which it occurs.
|
|
|
|
/// </summary>
|
2022-09-23 20:36:44 +00:00
|
|
|
[DebuggerDisplay($"{{{nameof(FrameType)},nq}}[{{{nameof(Lead)},nq}}]")]
|
2022-06-18 18:04:24 +00:00
|
|
|
public sealed class Frame
|
2017-05-14 21:42:18 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Ending seed value for the frame (prior to nature call).
|
|
|
|
/// </summary>
|
|
|
|
public readonly uint Seed;
|
|
|
|
public readonly LeadRequired Lead;
|
2017-05-15 06:21:34 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private readonly FrameType FrameType;
|
2017-05-14 21:42:18 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Starting seed for the frame (to generate the frame).
|
|
|
|
/// </summary>
|
|
|
|
public uint OriginSeed { get; set; }
|
2017-12-02 05:23:37 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary>
|
|
|
|
/// RNG Call Value for the Level Calc
|
|
|
|
/// </summary>
|
|
|
|
public uint RandLevel { get; set; }
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary>
|
|
|
|
/// RNG Call Value for the Encounter Slot Calc
|
|
|
|
/// </summary>
|
|
|
|
public uint RandESV { get; set; }
|
2017-05-15 06:21:34 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public bool LevelSlotModified => Lead.IsLevelOrSlotModified() || (Lead & LeadRequired.UsesLevelCall) != 0;
|
2017-05-14 21:42:18 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public Frame(uint seed, FrameType type, LeadRequired lead)
|
|
|
|
{
|
|
|
|
Seed = seed;
|
|
|
|
Lead = lead;
|
|
|
|
FrameType = type;
|
|
|
|
}
|
2017-11-27 00:09:24 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Checks the Encounter Slot for RNG calls before the Nature loop.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="slot">Slot Data</param>
|
|
|
|
/// <param name="pk">Ancillary pk data for determining how to check level.</param>
|
|
|
|
/// <returns>Slot number for this frame & lead value.</returns>
|
|
|
|
public bool IsSlotCompatibile<T>(T slot, PKM pk) where T : EncounterSlot, IMagnetStatic, INumberedSlot, ISlotRNGType
|
|
|
|
{
|
2022-09-23 20:36:44 +00:00
|
|
|
if (FrameType != FrameType.MethodH && slot.Type is not (SlotType.HoneyTree or SlotType.BugContest)) // gen3 always does level rand
|
2017-11-27 00:09:24 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
bool hasLevelCall = slot.IsRandomLevel;
|
|
|
|
if (Lead.NeedsLevelCall() != hasLevelCall)
|
2017-11-30 05:31:52 +00:00
|
|
|
return false;
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2017-11-30 05:31:52 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Level is before Nature, but usually isn't varied. Check ESV calc first.
|
|
|
|
int s = GetSlot(slot);
|
|
|
|
if (s != slot.SlotNumber)
|
|
|
|
return false;
|
2017-11-30 05:31:52 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Check Level Now
|
|
|
|
int lvl = SlotRange.GetLevel(slot, Lead, RandLevel);
|
|
|
|
if (pk.HasOriginalMetLocation)
|
|
|
|
{
|
|
|
|
if (lvl != pk.Met_Level)
|
|
|
|
return false;
|
2017-11-27 00:09:24 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
else
|
2017-11-30 05:31:52 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (lvl > pk.Met_Level)
|
|
|
|
return false;
|
2017-11-30 05:31:52 +00:00
|
|
|
}
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Check if the slot is actually encounterable (considering Sweet Scent)
|
|
|
|
bool encounterable = SlotRange.GetIsEncounterable(slot, FrameType, (int)(OriginSeed >> 16), Lead);
|
|
|
|
return encounterable;
|
2017-05-14 21:42:18 +00:00
|
|
|
}
|
2021-07-30 21:05:23 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Gets the slot value for the input slot.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="slot">Slot Data</param>
|
|
|
|
/// <returns>Slot number for this frame & lead value.</returns>
|
|
|
|
private int GetSlot<T>(T slot) where T : EncounterSlot, IMagnetStatic, INumberedSlot, ISlotRNGType
|
2021-07-30 21:05:23 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
// Static and Magnet Pull do a slot search rather than slot mapping 0-99.
|
|
|
|
return Lead != LeadRequired.StaticMagnet
|
|
|
|
? SlotRange.GetSlot(slot.Type, RandESV, FrameType)
|
|
|
|
: SlotRange.GetSlotStaticMagnet(slot, RandESV);
|
2021-07-30 21:05:23 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Only use this for test methods.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="t"></param>
|
|
|
|
public int GetSlot(SlotType t) => SlotRange.GetSlot(t, RandESV, FrameType);
|
|
|
|
}
|
|
|
|
|
|
|
|
public interface ISlotRNGType
|
|
|
|
{
|
|
|
|
SlotType Type { get; }
|
2017-05-14 21:42:18 +00:00
|
|
|
}
|