2017-05-14 21:42:18 +00:00
|
|
|
|
namespace PKHeX.Core
|
|
|
|
|
{
|
|
|
|
|
public class Frame
|
|
|
|
|
{
|
2017-05-15 06:21:34 +00:00
|
|
|
|
public readonly uint Seed;
|
2017-05-14 21:42:18 +00:00
|
|
|
|
public readonly LeadRequired Lead;
|
2017-05-15 06:21:34 +00:00
|
|
|
|
|
|
|
|
|
private readonly FrameType FrameType;
|
|
|
|
|
private readonly RNG RNG;
|
2017-05-14 21:42:18 +00:00
|
|
|
|
|
2017-11-30 05:31:52 +00:00
|
|
|
|
public uint RandLevel { get; set; }
|
2017-05-14 21:42:18 +00:00
|
|
|
|
public uint ESV { get; set; }
|
2017-05-15 06:21:34 +00:00
|
|
|
|
|
2017-11-30 05:31:52 +00:00
|
|
|
|
public bool LevelSlotModified => Lead > LeadRequired.SynchronizeFail;
|
2017-05-14 21:42:18 +00:00
|
|
|
|
|
2017-05-15 06:21:34 +00:00
|
|
|
|
public Frame(uint seed, FrameType type, RNG rng, LeadRequired lead)
|
2017-05-14 21:42:18 +00:00
|
|
|
|
{
|
|
|
|
|
Seed = seed;
|
|
|
|
|
Lead = lead;
|
|
|
|
|
FrameType = type;
|
2017-05-15 06:21:34 +00:00
|
|
|
|
RNG = rng;
|
2017-05-14 21:42:18 +00:00
|
|
|
|
}
|
2017-11-27 00:09:24 +00:00
|
|
|
|
|
2017-11-30 05:31:52 +00: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>
|
|
|
|
|
/// <returns>Slot number for this frame & lead value.</returns>
|
|
|
|
|
public bool IsSlotCompatibile(EncounterSlot slot, PKM pkm)
|
2017-11-27 00:09:24 +00:00
|
|
|
|
{
|
2017-11-30 05:31:52 +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;
|
|
|
|
|
|
|
|
|
|
// Check Level Now
|
2017-11-30 07:20:49 +00:00
|
|
|
|
int lvl = SlotRange.GetLevel(slot, Lead, RandLevel);
|
2017-11-30 05:31:52 +00:00
|
|
|
|
if (lvl < 0) { } // todo
|
|
|
|
|
else if (pkm.HasOriginalMetLocation)
|
|
|
|
|
{
|
|
|
|
|
if (lvl != pkm.Met_Level)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else
|
2017-11-27 00:09:24 +00:00
|
|
|
|
{
|
2017-11-30 05:31:52 +00:00
|
|
|
|
if (lvl < pkm.Met_Level)
|
|
|
|
|
return false;
|
2017-11-27 00:09:24 +00:00
|
|
|
|
}
|
2017-11-30 05:31:52 +00:00
|
|
|
|
|
|
|
|
|
// Check if the slot is actually encounterable (considering Sweet Scent)
|
2017-11-30 07:20:49 +00:00
|
|
|
|
bool encounterable = SlotRange.GetIsEncounterable(slot, FrameType, 0, Lead);
|
2017-11-30 05:31:52 +00:00
|
|
|
|
return encounterable;
|
2017-11-27 00:09:24 +00:00
|
|
|
|
}
|
2017-11-30 05:31:52 +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(EncounterSlot slot)
|
|
|
|
|
{
|
|
|
|
|
// Static and Magnet Pull do a slot search rather than slot mapping 0-99.
|
|
|
|
|
return Lead != LeadRequired.StaticMagnet
|
|
|
|
|
? GetSlot(slot.Type)
|
|
|
|
|
: GetSlotStaticMagnet(slot);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Checks both Static and Magnet Pull ability type selection encounters to see if the encounter can be selected.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="slot">Slot Data</param>
|
|
|
|
|
/// <returns>Slot number from the slot data if the slot is selected on this frame, else an invalid slot value.</returns>
|
|
|
|
|
private int GetSlotStaticMagnet(EncounterSlot slot)
|
|
|
|
|
{
|
|
|
|
|
if (slot.Permissions.StaticIndex >= 0)
|
|
|
|
|
{
|
|
|
|
|
var index = ESV % slot.Permissions.StaticCount;
|
|
|
|
|
if (index == slot.Permissions.StaticIndex)
|
|
|
|
|
return slot.SlotNumber;
|
|
|
|
|
}
|
|
|
|
|
if (slot.Permissions.MagnetPullIndex >= 0)
|
|
|
|
|
{
|
|
|
|
|
var index = ESV % slot.Permissions.MagnetPullCount;
|
|
|
|
|
if (index == slot.Permissions.MagnetPullIndex)
|
|
|
|
|
return slot.SlotNumber;
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-27 00:09:24 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Only use this for test methods.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="t"></param>
|
|
|
|
|
/// <returns></returns>
|
2017-11-30 05:31:52 +00:00
|
|
|
|
public int GetSlot(SlotType t) => SlotRange.GetSlot(t, ESV, FrameType, Seed);
|
2017-05-14 21:42:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|