2017-05-14 14:42:18 -07:00
|
|
|
|
namespace PKHeX.Core
|
|
|
|
|
{
|
2019-10-03 19:09:02 -07:00
|
|
|
|
public sealed class Frame
|
2017-05-14 14:42:18 -07:00
|
|
|
|
{
|
2017-12-01 21:23:37 -08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Ending seed value for the frame (prior to nature call).
|
|
|
|
|
/// </summary>
|
2017-05-14 23:21:34 -07:00
|
|
|
|
public readonly uint Seed;
|
2017-05-14 14:42:18 -07:00
|
|
|
|
public readonly LeadRequired Lead;
|
2017-05-14 23:21:34 -07:00
|
|
|
|
|
|
|
|
|
private readonly FrameType FrameType;
|
2017-05-14 14:42:18 -07:00
|
|
|
|
|
2017-12-01 21:23:37 -08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Starting seed for the frame (to generate the frame).
|
|
|
|
|
/// </summary>
|
|
|
|
|
public uint OriginSeed { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// RNG Call Value for the Level Calc
|
|
|
|
|
/// </summary>
|
2017-11-29 21:31:52 -08:00
|
|
|
|
public uint RandLevel { get; set; }
|
2018-09-14 22:37:47 -07:00
|
|
|
|
|
2017-12-01 21:23:37 -08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// RNG Call Value for the Encounter Slot Calc
|
|
|
|
|
/// </summary>
|
2017-12-01 16:33:03 -08:00
|
|
|
|
public uint RandESV { get; set; }
|
2017-05-14 23:21:34 -07:00
|
|
|
|
|
2018-05-12 12:28:48 -07:00
|
|
|
|
public bool LevelSlotModified => Lead.IsLevelOrSlotModified() || (Lead & LeadRequired.UsesLevelCall) != 0;
|
2017-05-14 14:42:18 -07:00
|
|
|
|
|
2019-10-26 12:33:58 -07:00
|
|
|
|
public Frame(uint seed, FrameType type, LeadRequired lead)
|
2017-05-14 14:42:18 -07:00
|
|
|
|
{
|
|
|
|
|
Seed = seed;
|
|
|
|
|
Lead = lead;
|
|
|
|
|
FrameType = type;
|
|
|
|
|
}
|
2017-11-26 16:09:24 -08:00
|
|
|
|
|
2017-11-29 21:31:52 -08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Checks the Encounter Slot for RNG calls before the Nature loop.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="slot">Slot Data</param>
|
|
|
|
|
/// <param name="pkm">Ancillary pkm data for determining how to check level.</param>
|
2018-10-31 13:52:09 -07:00
|
|
|
|
/// <returns>Slot number for this frame & lead value.</returns>
|
2021-07-30 14:05:23 -07:00
|
|
|
|
public bool IsSlotCompatibile<T>(T slot, PKM pkm) where T : EncounterSlot, IMagnetStatic, INumberedSlot, ISlotRNGType
|
2017-11-26 16:09:24 -08:00
|
|
|
|
{
|
2021-08-05 15:18:43 -07:00
|
|
|
|
if (FrameType != FrameType.MethodH) // gen3 always does level rand
|
|
|
|
|
{
|
|
|
|
|
bool hasLevelCall = slot.IsRandomLevel;
|
|
|
|
|
if (Lead.NeedsLevelCall() != hasLevelCall)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2017-12-01 21:23:37 -08:00
|
|
|
|
|
2017-11-29 21:31:52 -08:00
|
|
|
|
// Level is before Nature, but usually isn't varied. Check ESV calc first.
|
|
|
|
|
int s = GetSlot(slot);
|
|
|
|
|
if (s != slot.SlotNumber)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// Check Level Now
|
2017-11-29 23:20:49 -08:00
|
|
|
|
int lvl = SlotRange.GetLevel(slot, Lead, RandLevel);
|
2017-11-30 22:34:57 -08:00
|
|
|
|
if (pkm.HasOriginalMetLocation)
|
2017-11-29 21:31:52 -08:00
|
|
|
|
{
|
|
|
|
|
if (lvl != pkm.Met_Level)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else
|
2017-11-26 16:09:24 -08:00
|
|
|
|
{
|
2017-12-01 15:13:03 -05:00
|
|
|
|
if (lvl > pkm.Met_Level)
|
2017-11-29 21:31:52 -08:00
|
|
|
|
return false;
|
2017-11-26 16:09:24 -08:00
|
|
|
|
}
|
2017-11-29 21:31:52 -08:00
|
|
|
|
|
|
|
|
|
// Check if the slot is actually encounterable (considering Sweet Scent)
|
2017-12-01 22:49:38 -08:00
|
|
|
|
bool encounterable = SlotRange.GetIsEncounterable(slot, FrameType, (int)(OriginSeed >> 16), Lead);
|
2017-11-29 21:31:52 -08:00
|
|
|
|
return encounterable;
|
2017-11-26 16:09:24 -08:00
|
|
|
|
}
|
2017-11-29 21:31:52 -08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the slot value for the input slot.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="slot">Slot Data</param>
|
2018-10-31 13:52:09 -07:00
|
|
|
|
/// <returns>Slot number for this frame & lead value.</returns>
|
2021-07-30 14:05:23 -07:00
|
|
|
|
private int GetSlot<T>(T slot) where T : EncounterSlot, IMagnetStatic, INumberedSlot, ISlotRNGType
|
2017-11-29 21:31:52 -08:00
|
|
|
|
{
|
|
|
|
|
// Static and Magnet Pull do a slot search rather than slot mapping 0-99.
|
2018-05-12 08:13:39 -07:00
|
|
|
|
return Lead != LeadRequired.StaticMagnet
|
2021-07-30 14:05:23 -07:00
|
|
|
|
? SlotRange.GetSlot(slot.Type, RandESV, FrameType)
|
2017-12-02 22:34:54 -08:00
|
|
|
|
: SlotRange.GetSlotStaticMagnet(slot, RandESV);
|
2017-11-29 21:31:52 -08:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-26 16:09:24 -08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Only use this for test methods.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="t"></param>
|
|
|
|
|
/// <returns></returns>
|
2017-12-01 16:33:03 -08:00
|
|
|
|
public int GetSlot(SlotType t) => SlotRange.GetSlot(t, RandESV, FrameType);
|
2017-05-14 14:42:18 -07:00
|
|
|
|
}
|
2021-07-30 14:05:23 -07:00
|
|
|
|
|
|
|
|
|
public interface ISlotRNGType
|
|
|
|
|
{
|
|
|
|
|
SlotType Type { get; }
|
|
|
|
|
}
|
2017-05-14 14:42:18 -07:00
|
|
|
|
}
|