Force PID for shiny ponyta

This commit is contained in:
Kurt 2022-02-05 15:57:34 -08:00
parent ea327a5c03
commit 07b3efd14d
2 changed files with 50 additions and 0 deletions

View file

@ -59,6 +59,18 @@ public sealed record EncounterStatic8a(GameVersion Version) : EncounterStatic(Ve
pk.SetRandomEC();
}
protected override void SetPINGA(PKM pk, EncounterCriteria criteria)
{
var pi = pk.PersonalInfo;
int gender = criteria.GetGender(Gender, pi);
int nature = (int)criteria.GetNature(Nature);
int ability = criteria.GetAbilityFromNumber(Ability);
PIDGenerator.SetRandomWildPID(pk, pk.Format, nature, ability, gender);
pk.PID = Overworld8aRNG.AdaptPID(pk, Shiny, pk.PID);
SetIVs(pk);
pk.StatNature = pk.Nature;
}
protected override void ApplyDetailsBall(PKM pk) => pk.Ball = Gift ? Ball : (int)Core.Ball.LAPoke;
public override bool IsMatchExact(PKM pkm, DexLevel evo)

View file

@ -0,0 +1,38 @@
namespace PKHeX.Core;
/// <summary>
/// Contains logic for the Generation 8 (Legends: Arceus) overworld spawns that walk around the overworld.
/// </summary>
public static class Overworld8aRNG
{
public static uint AdaptPID(PKM pk, Shiny shiny, uint pid)
{
if (shiny == Shiny.Never)
{
if (GetIsShiny(pk.TID, pk.SID, pid))
pid ^= 0x1000_0000;
}
else if (shiny != Shiny.Random)
{
if (!GetIsShiny(pk.TID, pk.SID, pid))
pid = GetShinyPID(pk.TID, pk.SID, pid, 0);
}
return pid;
}
private static uint GetShinyPID(int tid, int sid, uint pid, int type)
{
return (uint)(((tid ^ sid ^ (pid & 0xFFFF) ^ type) << 16) | (pid & 0xFFFF));
}
private static bool GetIsShiny(int tid, int sid, uint pid)
{
return GetShinyXor(pid, (uint)((sid << 16) | tid)) < 16;
}
private static uint GetShinyXor(uint pid, uint oid)
{
var xor = pid ^ oid;
return (xor ^ (xor >> 16)) & 0xFFFF;
}
}