Flag wild slots that don't match 32bit correlation

This commit is contained in:
Kurt 2021-02-13 22:45:07 -08:00
parent 834d0d77ba
commit a65ab2accc
3 changed files with 45 additions and 6 deletions

View file

@ -11,17 +11,17 @@ namespace PKHeX.Core
{
internal static class EncounterGenerator8
{
public static IEnumerable<IEncounterable> GetEncounters(PKM pkm)
public static IEnumerable<IEncounterable> GetEncounters(PKM pkm, LegalInfo info)
{
var chain = EncounterOrigin.GetOriginChain(pkm);
return pkm.Version switch
{
(int)GameVersion.GO => EncounterGenerator7.GetEncountersGO(pkm, chain),
_ => GetEncountersMainline(pkm, chain)
_ => GetEncountersMainline(pkm, chain, info)
};
}
private static IEnumerable<IEncounterable> GetEncountersMainline(PKM pkm, IReadOnlyList<EvoCriteria> chain)
private static IEnumerable<IEncounterable> GetEncountersMainline(PKM pkm, IReadOnlyList<EvoCriteria> chain, LegalInfo info)
{
// Static Encounters can collide with wild encounters (close match); don't break if a Static Encounter is yielded.
int ctr = 0;
@ -52,6 +52,9 @@ namespace PKHeX.Core
case PartialMatch: partial ??= z; break;
}
}
bool slotFrame = Overworld8RNG.ValidateOverworldEncounter(pkm);
info.PIDIVMatches = slotFrame;
// if (ctr != 0) yield break;
foreach (var z in GetValidWildEncounters(pkm, chain))
{
@ -63,6 +66,7 @@ namespace PKHeX.Core
case PartialMatch: partial ??= z; break;
}
}
info.PIDIVMatches = true;
if (ctr != 0) yield break;
foreach (var z in GetValidEncounterTrades(pkm, chain))
@ -77,10 +81,19 @@ namespace PKHeX.Core
}
if (deferred != null)
{
if (deferred is EncounterSlot8)
info.PIDIVMatches = slotFrame;
yield return deferred;
info.PIDIVMatches = true;
}
if (partial != null)
{
if (deferred is EncounterSlot8)
info.PIDIVMatches = slotFrame;
yield return partial;
}
}
}
}

View file

@ -27,7 +27,7 @@ namespace PKHeX.Core
5 => EncounterGenerator5.GetEncounters(pkm),
6 => EncounterGenerator6.GetEncounters(pkm),
7 => EncounterGenerator7.GetEncounters(pkm),
8 => EncounterGenerator8.GetEncounters(pkm),
8 => EncounterGenerator8.GetEncounters(pkm, info),
_ => Array.Empty<IEncounterable>(),
};
}

View file

@ -54,14 +54,14 @@
}
private const int NoMatchIVs = -1;
private const int UNSET = -1;
private static int GetIsMatchEnd(PKM pk, Xoroshiro128Plus xoro, int start = 0, int end = 3)
{
for (int iv_count = start; iv_count <= end; iv_count++)
{
var copy = xoro;
int[] ivs = {31, 31, 31, 31, 31, 31};
const int UNSET = -1;
int[] ivs = { UNSET, UNSET, UNSET, UNSET, UNSET, UNSET };
const int MAX = 31;
for (int i = 0; i < iv_count; i++)
{
@ -70,6 +70,9 @@
ivs[index] = MAX;
}
if (!IsValidSequence(pk, ivs, ref copy))
continue;
if (pk is not IScaledSize s)
continue;
var height = (int) copy.NextInt(0x81) + (int) copy.NextInt(0x80);
@ -84,6 +87,29 @@
return NoMatchIVs;
}
private static bool IsValidSequence(PKM pk, int[] template, ref Xoroshiro128Plus rng)
{
for (int i = 0; i < 6; i++)
{
if (template[i] != UNSET)
continue;
var expect = (int) rng.NextInt(32);
var actual = i switch
{
0 => pk.IV_HP,
1 => pk.IV_ATK,
2 => pk.IV_DEF,
3 => pk.IV_SPA,
4 => pk.IV_SPD,
_ => pk.IV_SPE,
};
if (expect != actual)
return false;
}
return true;
}
private static uint GetShinyPID(int tid, int sid, uint pid, int type)
{
return (uint)(((tid ^ sid ^ (pid & 0xFFFF) ^ type) << 16) | (pid & 0xFFFF));