Add slot level / IsEncounterable beginnings

dynamic level -> calc level
no sweet scent -> proc available (rock smash/fish)

change frame checking in encountergenerator to save which frame it was
found on (unused but possibly later can capture this for output)
This commit is contained in:
Kurt
2017-11-29 21:31:52 -08:00
parent fdc52e2c19
commit d3d7d7d50d
6 changed files with 95 additions and 37 deletions

View File

@@ -295,7 +295,8 @@ private static IEnumerable<IEncounterable> GenerateRawEncounters4(PKM pkm, Legal
var slots = FrameFinder.GetFrames(info.PIDIV, pkm).ToList();
foreach (var z in GetValidWildEncounters(pkm))
{
if (slots.Any(s => s.EncounterSlot(z.Type, z) == z.SlotNumber))
var frame = slots.FirstOrDefault(s => s.IsSlotCompatibile(z, pkm));
if (frame != null)
yield return z;
else
deferred.Add(z);
@@ -329,7 +330,8 @@ private static IEnumerable<IEncounterable> GenerateRawEncounters3(PKM pkm, Legal
var slots = FrameFinder.GetFrames(info.PIDIV, pkm).ToList();
foreach (var z in GetValidWildEncounters(pkm))
{
if (slots.Any(s => s.EncounterSlot(z.Type, z) == z.SlotNumber))
var frame = slots.FirstOrDefault(s => s.IsSlotCompatibile(z, pkm));
if (frame != null)
yield return z;
else
deferred.Add(z);

View File

@@ -8,11 +8,10 @@ public class Frame
private readonly FrameType FrameType;
private readonly RNG RNG;
public uint RandLevel { get; set; }
public uint ESV { get; set; }
public void SetOriginSeed(int Offset) => OriginSeed = RNG.Reverse(Seed, Offset);
public bool LevelSlotModified => Lead > LeadRequired.SynchronizeFail;
public uint OriginSeed;
public bool LevelSlotModified => Lead > LeadRequired.SynchronizeFail;
public Frame(uint seed, FrameType type, RNG rng, LeadRequired lead)
{
@@ -22,30 +21,78 @@ public Frame(uint seed, FrameType type, RNG rng, LeadRequired lead)
RNG = rng;
}
public int EncounterSlot(SlotType t, EncounterSlot slot)
/// <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)
{
if (Lead == LeadRequired.StaticMagnet)
{
if (slot.Permissions.MagnetPullIndex >= 0)
{
var index = ESV % slot.Permissions.MagnetPullCount;
return index == slot.Permissions.MagnetPullIndex ? slot.SlotNumber : -1;
}
// Level is before Nature, but usually isn't varied. Check ESV calc first.
int s = GetSlot(slot);
if (s != slot.SlotNumber)
return false;
if (slot.Permissions.StaticIndex >= 0)
{
var index = ESV % slot.Permissions.StaticCount;
return index == slot.Permissions.StaticIndex ? slot.SlotNumber : -1;
}
return -1;
// Check Level Now
int lvl = SlotRange.GetLevel(slot, FrameType, Lead, RandLevel);
if (lvl < 0) { } // todo
else if (pkm.HasOriginalMetLocation)
{
if (lvl != pkm.Met_Level)
return false;
}
return EncounterSlot(t);
else
{
if (lvl < pkm.Met_Level)
return false;
}
// Check if the slot is actually encounterable (considering Sweet Scent)
bool encounterable = SlotRange.GetIsEncounterable(slot, FrameType);
return encounterable;
}
/// <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;
}
/// <summary>
/// Only use this for test methods.
/// </summary>
/// <param name="t"></param>
/// <returns></returns>
public int EncounterSlot(SlotType t) => SlotRange.GetSlot(t, ESV, FrameType, Seed);
public int GetSlot(SlotType t) => SlotRange.GetSlot(t, ESV, FrameType, Seed);
}
}

View File

@@ -96,11 +96,11 @@ private static IEnumerable<Frame> GenerateLeadSpecificFrames3(Frame f, FrameGene
if (f.Lead == LeadRequired.CuteCharm) // 100% required for frame base
{
if (cc)
yield return info.GetFrame(prev2, LeadRequired.CuteCharm, p2);
yield return info.GetFrame(prev2, LeadRequired.CuteCharm, p2, p1);
yield break;
}
lead = cc ? LeadRequired.CuteCharm : LeadRequired.CuteCharmFail;
yield return info.GetFrame(prev2, lead, p2);
yield return info.GetFrame(prev2, lead, p2, p1);
}
// Pressure, Hustle, Vital Spirit = Force Maximum Level from slot
@@ -110,7 +110,7 @@ private static IEnumerable<Frame> GenerateLeadSpecificFrames3(Frame f, FrameGene
// 1 Nature
bool max = p0 % 2 == 1;
lead = max ? LeadRequired.PressureHustleSpirit : LeadRequired.PressureHustleSpiritFail;
yield return info.GetFrame(prev2, lead, p2);
yield return info.GetFrame(prev2, lead, p2, p1);
// Keen Eye, Intimidate
// -2 ESV
@@ -121,7 +121,7 @@ private static IEnumerable<Frame> GenerateLeadSpecificFrames3(Frame f, FrameGene
if (max) // same result as above, no need to recalculate
{
lead = LeadRequired.IntimidateKeenEye;
yield return info.GetFrame(prev2, lead, p2);
yield return info.GetFrame(prev2, lead, p2, p1);
}
// Static or Magnet Pull
@@ -134,7 +134,7 @@ private static IEnumerable<Frame> GenerateLeadSpecificFrames3(Frame f, FrameGene
{
// Since a failed proc is indistinguishable from the default frame calls, only generate if it succeeds.
lead = LeadRequired.StaticMagnet;
yield return info.GetFrame(prev2, lead, p1);
yield return info.GetFrame(prev2, lead, p1, p0);
}
}
@@ -162,8 +162,8 @@ private static IEnumerable<Frame> RefineFrames4(IEnumerable<Frame> frames, Frame
var prev = info.RNG.Prev(f.Seed);
var p16 = prev >> 16;
yield return info.GetFrame(prev, LeadRequired.IntimidateKeenEye, p16);
yield return info.GetFrame(prev, LeadRequired.PressureHustleSpirit, p16);
yield return info.GetFrame(prev, LeadRequired.IntimidateKeenEye, p16, p16);
yield return info.GetFrame(prev, LeadRequired.PressureHustleSpirit, p16, p16);
// Slot Modifiers before ESV
var force = (info.DPPt ? p16 >> 15 : p16 & 1) == 1;
@@ -171,7 +171,7 @@ private static IEnumerable<Frame> RefineFrames4(IEnumerable<Frame> frames, Frame
continue;
var rand = f.Seed >> 16;
yield return info.GetFrame(prev, LeadRequired.StaticMagnet, rand);
yield return info.GetFrame(prev, LeadRequired.StaticMagnet, rand, p16);
}
}

View File

@@ -13,7 +13,7 @@ public class FrameGenerator
public readonly bool Safari3;
public Frame GetFrame(uint seed, LeadRequired lead) => new Frame(seed, FrameType, RNG, lead);
public Frame GetFrame(uint seed, LeadRequired lead, uint esv) => new Frame(seed, FrameType, RNG, lead) {ESV = esv};
public Frame GetFrame(uint seed, LeadRequired lead, uint esv, uint lvl) => new Frame(seed, FrameType, RNG, lead) {ESV = esv, RandLevel = lvl};
/// <summary>
/// Gets the Search Criteria parameters necessary for generating <see cref="SeedInfo"/> and <see cref="Frame"/> objects.

View File

@@ -129,12 +129,21 @@ private static int CalcSlot(uint esv, Range[] ranges)
return -1;
}
private static Range[] Reverse(Range[] r)
public static int GetLevel(EncounterSlot slot, FrameType frameType, LeadRequired seed, uint lvlrand)
{
var arr = new Range[r.Length];
for (int i = 0; i < arr.Length; ++i)
arr[i] = r[r.Length - 1 - i];
return arr;
if (seed == LeadRequired.PressureHustleSpirit)
return slot.LevelMax;
if (slot.LevelMin == slot.LevelMax)
return slot.LevelMin;
int delta = slot.LevelMax - slot.LevelMin + 1;
var adjust = (int)(lvlrand % delta);
var lvl = slot.LevelMin + adjust;
return -1; // lvl; todo
}
public static bool GetIsEncounterable(EncounterSlot slot, FrameType frameType)
{
return true; // todo
}
}
}

View File

@@ -192,8 +192,8 @@ public void PIDIVEncounterSlotTest()
var type = SlotType.Grass;
var slots = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 9 };
Assert.IsTrue(slots.All(s => r2.Any(z => z.EncounterSlot(type) == s)), "Required slots not present.");
var slotsForType = r2.Where(z => !z.LevelSlotModified).Select(z => z.EncounterSlot(type)).Distinct().OrderBy(z => z);
Assert.IsTrue(slots.All(s => r2.Any(z => z.GetSlot(type) == s)), "Required slots not present.");
var slotsForType = r2.Where(z => !z.LevelSlotModified).Select(z => z.GetSlot(type)).Distinct().OrderBy(z => z);
Assert.IsTrue(slotsForType.SequenceEqual(slots), "Unexpected slots present.");
}
// Test for Method H and K