Flag invalid mystry mew seeds, like channel

This commit is contained in:
Kurt 2024-03-23 21:35:46 -05:00
parent acdb9f12b3
commit c6f12515c6
2 changed files with 50 additions and 8 deletions

View file

@ -48,15 +48,25 @@ public sealed class EncounterGenerator3 : IEncounterGenerator
}
if (e is not EncounterSlot3 slot)
{
if (e is WC3 { TID16: 40122 } channel)
if (e is WC3 wc3)
{
var chk = ChannelJirachi.GetPossible(info.PIDIV.OriginSeed);
if (chk.Pattern is not ChannelJirachiRandomResult.None)
info.PIDIV = info.PIDIV.AsEncounteredVia(new(chk.Seed, LeadRequired.None));
else
info.ManualFlag = EncounterYieldFlag.InvalidPIDIV;
yield return channel;
yield break;
if (wc3.TID16 == 40122) // CHANNEL Jirachi
{
var chk = ChannelJirachi.GetPossible(info.PIDIV.OriginSeed);
if (chk.Pattern is not ChannelJirachiRandomResult.None)
info.PIDIV = info.PIDIV.AsEncounteredVia(new(chk.Seed, LeadRequired.None));
else
info.ManualFlag = EncounterYieldFlag.InvalidPIDIV;
yield return wc3;
yield break;
}
if (wc3.TID16 == 06930) // MYSTRY Mew
{
if (!MystryMew.IsValidSeed(info.PIDIV.OriginSeed))
info.ManualFlag = EncounterYieldFlag.InvalidPIDIV;
yield return wc3;
yield break;
}
}
yield return e;
continue;

View file

@ -54,6 +54,13 @@ public static class MystryMew
return seed;
}
/// <summary>
/// Checks if the seed is a known seed.
/// </summary>
/// <param name="seed">Origin seed (for the PID/IV)</param>
/// <returns>True if the seed is known.</returns>
public static bool IsValidSeed(uint seed) => GetSeedIndex(seed) != -1;
/// <summary>
/// Checks if the seed is a known seed.
/// </summary>
@ -72,4 +79,29 @@ public static class MystryMew
return -1;
}
/// <summary>
/// Get the index and subindex of the seed in the known seed list.
/// </summary>
/// <param name="seed">Origin seed (for the PID/IV)</param>
/// <returns>Tuple of indexes; -1 if not found.</returns>
public static (int Index, int SubIndex) GetSeedIndexes(uint seed)
{
var seeds = Seeds;
if (seed <= ushort.MaxValue)
{
var index = seeds.BinarySearch((ushort)seed);
return (index, -1);
}
for (int i = 0; i < 5; i++)
{
seed = LCRNG.Prev5(seed);
if (seed <= ushort.MaxValue)
{
var index = seeds.BinarySearch((ushort)seed);
return (index, i);
}
}
return (-1, -1);
}
}