Add frame level checking

still WIP but should be working fairly well
This commit is contained in:
Kurt 2017-11-29 23:20:49 -08:00
parent d3d7d7d50d
commit 9930e8765a
5 changed files with 62 additions and 16 deletions

View file

@ -35,7 +35,7 @@
return false; return false;
// Check Level Now // Check Level Now
int lvl = SlotRange.GetLevel(slot, FrameType, Lead, RandLevel); int lvl = SlotRange.GetLevel(slot, Lead, RandLevel);
if (lvl < 0) { } // todo if (lvl < 0) { } // todo
else if (pkm.HasOriginalMetLocation) else if (pkm.HasOriginalMetLocation)
{ {
@ -49,7 +49,7 @@
} }
// Check if the slot is actually encounterable (considering Sweet Scent) // Check if the slot is actually encounterable (considering Sweet Scent)
bool encounterable = SlotRange.GetIsEncounterable(slot, FrameType); bool encounterable = SlotRange.GetIsEncounterable(slot, FrameType, 0, Lead);
return encounterable; return encounterable;
} }

View file

@ -57,6 +57,7 @@ namespace PKHeX.Core
var prev = info.RNG.Prev(f.Seed); // ESV var prev = info.RNG.Prev(f.Seed); // ESV
var rand = prev >> 16; var rand = prev >> 16;
f.ESV = rand; f.ESV = rand;
f.RandLevel = f.Seed >> 16;
yield return f; yield return f;
// Generate frames for other slots after the regular slots // Generate frames for other slots after the regular slots
@ -147,6 +148,7 @@ namespace PKHeX.Core
var rand = f.Seed >> 16; var rand = f.Seed >> 16;
{ {
f.ESV = rand; f.ESV = rand;
f.RandLevel = rand;
yield return f; yield return f;
} }
@ -171,7 +173,7 @@ namespace PKHeX.Core
continue; continue;
var rand = f.Seed >> 16; var rand = f.Seed >> 16;
yield return info.GetFrame(prev, LeadRequired.StaticMagnet, rand, p16); yield return info.GetFrame(prev, LeadRequired.StaticMagnet, rand, rand);
} }
} }

View file

@ -22,7 +22,7 @@ namespace PKHeX.Core
case FrameType.MethodH: case FrameType.MethodH:
return HSlot(type, rand); return HSlot(type, rand);
case FrameType.MethodJ: case FrameType.MethodJ:
return JSlot(type, rand); return JSlot(type, rand, seed);
case FrameType.MethodK: case FrameType.MethodK:
return KSlot(type, rand, seed); return KSlot(type, rand, seed);
} }
@ -56,16 +56,18 @@ namespace PKHeX.Core
private static int KSlot(SlotType type, uint rand, uint seed) private static int KSlot(SlotType type, uint rand, uint seed)
{ {
var ESV = rand % 100; var ESV = rand % 100;
uint prev() => (RNG.LCRNG.Prev(seed) >> 16) % 100;
switch (type) switch (type)
{ {
case SlotType.Rock_Smash:
case SlotType.Surf: case SlotType.Surf:
return CalcSlot(ESV, H_Surf); return CalcSlot(prev(), H_Surf);
case SlotType.Super_Rod: case SlotType.Super_Rod:
case SlotType.Good_Rod: case SlotType.Good_Rod:
case SlotType.Old_Rod: case SlotType.Old_Rod:
return CalcSlot(ESV, K_SuperRod); return CalcSlot(prev(), K_SuperRod);
case SlotType.BugContest: case SlotType.BugContest:
return CalcSlot(ESV, K_BCC); return CalcSlot(prev(), K_BCC);
case SlotType.Grass_Safari: case SlotType.Grass_Safari:
case SlotType.Surf_Safari: case SlotType.Surf_Safari:
case SlotType.Old_Rod_Safari: case SlotType.Old_Rod_Safari:
@ -75,22 +77,24 @@ namespace PKHeX.Core
return 0; // (int)(rand % 10); /* Block Slot Priority not implemented */ return 0; // (int)(rand % 10); /* Block Slot Priority not implemented */
case SlotType.Headbutt: case SlotType.Headbutt:
case SlotType.Headbutt_Special: case SlotType.Headbutt_Special:
return CalcSlot(ESV, K_Headbutt); return CalcSlot(prev(), K_Headbutt);
default: default:
return CalcSlot(ESV, H_Regular); return CalcSlot(ESV, H_Regular);
} }
} }
private static int JSlot(SlotType type, uint rand) private static int JSlot(SlotType type, uint rand, uint seed)
{ {
uint ESV = rand / 656; uint ESV = rand / 656;
uint prev() => (RNG.LCRNG.Prev(seed) >> 16) / 656;
switch (type) switch (type)
{ {
case SlotType.Old_Rod: case SlotType.Old_Rod:
case SlotType.Rock_Smash:
case SlotType.Surf: case SlotType.Surf:
return CalcSlot(ESV, H_Surf); return CalcSlot(prev(), H_Surf);
case SlotType.Good_Rod: case SlotType.Good_Rod:
case SlotType.Super_Rod: case SlotType.Super_Rod:
return CalcSlot(ESV, J_SuperRod); return CalcSlot(prev(), J_SuperRod);
case SlotType.HoneyTree: case SlotType.HoneyTree:
return 0; return 0;
default: default:
@ -129,21 +133,54 @@ namespace PKHeX.Core
return -1; return -1;
} }
public static int GetLevel(EncounterSlot slot, FrameType frameType, LeadRequired seed, uint lvlrand) public static int GetLevel(EncounterSlot slot, LeadRequired lead, uint lvlrand)
{ {
if (seed == LeadRequired.PressureHustleSpirit) if (lead == LeadRequired.PressureHustleSpirit)
return slot.LevelMax; return slot.LevelMax;
if (slot.LevelMin == slot.LevelMax) if (slot.LevelMin == slot.LevelMax)
return slot.LevelMin; return slot.LevelMin;
int delta = slot.LevelMax - slot.LevelMin + 1; int delta = slot.LevelMax - slot.LevelMin + 1;
var adjust = (int)(lvlrand % delta); var adjust = (int)(lvlrand % delta);
var lvl = slot.LevelMin + adjust; return slot.LevelMin + adjust;
return -1; // lvl; todo
} }
public static bool GetIsEncounterable(EncounterSlot slot, FrameType frameType) public static bool GetIsEncounterable(EncounterSlot slot, FrameType frameType, int rand, LeadRequired lead)
{ {
if (slot.Type.IsSweetScentType())
return true;
return true; // todo return true; // todo
return GetCanEncounter(slot, frameType, rand, lead);
}
private static bool GetCanEncounter(EncounterSlot slot, FrameType frameType, int rand, LeadRequired lead)
{
int proc = frameType == FrameType.MethodJ ? rand / 656 : rand % 100;
if (slot.Type.HasFlag(SlotType.Rock_Smash))
return proc < 60;
if (frameType == FrameType.MethodH)
return true; // fishing encounters are disjointed by the hooked message.
// fishing
if (slot.Type.HasFlag(SlotType.Old_Rod))
{
if (proc < 25)
return true;
if (proc < 50)
return lead == LeadRequired.None;
}
else if (slot.Type.HasFlag(SlotType.Good_Rod))
{
if (proc < 50)
return true;
if (proc < 75 && lead == LeadRequired.None)
return lead == LeadRequired.None;
}
else if (slot.Type.HasFlag(SlotType.Super_Rod))
{
if (proc < 75)
return true;
return lead == LeadRequired.None; // < 100 always true
}
return false; // shouldn't hit here
} }
} }
} }

View file

@ -408,6 +408,7 @@ namespace PKHeX.Core
var slot = baseSlot.Clone(); var slot = baseSlot.Clone();
slot.Species = species; slot.Species = species;
slot.Type = t; slot.Type = t;
slot.SlotNumber = i;
slots.Add(slot); slots.Add(slot);
} }
return slots; return slots;
@ -428,6 +429,7 @@ namespace PKHeX.Core
LevelMax = data[ofs + 0 + i * 8], LevelMax = data[ofs + 0 + i * 8],
LevelMin = data[ofs + 1 + i * 8], LevelMin = data[ofs + 1 + i * 8],
Species = Species, Species = Species,
SlotNumber = i,
Type = t Type = t
}); });
} }
@ -450,6 +452,7 @@ namespace PKHeX.Core
LevelMin = data[ofs + 0 + i * 4], LevelMin = data[ofs + 0 + i * 4],
LevelMax = data[ofs + 1 + i * 4], LevelMax = data[ofs + 1 + i * 4],
Species = Species, Species = Species,
SlotNumber = i,
Type = t Type = t
}); });
} }

View file

@ -106,5 +106,9 @@ namespace PKHeX.Core
{ {
return t.HasFlag(SlotType.Old_Rod) || t.HasFlag(SlotType.Good_Rod) || t.HasFlag(SlotType.Super_Rod); return t.HasFlag(SlotType.Old_Rod) || t.HasFlag(SlotType.Good_Rod) || t.HasFlag(SlotType.Super_Rod);
} }
internal static bool IsSweetScentType(this SlotType t)
{
return !(t.IsFishingRodType() || t.HasFlag(SlotType.Rock_Smash));
}
} }
} }