/// <summary> /// Set IV Values for the pokemon /// </summary> /// <param name="pk"></param> /// <param name="set"></param> /// <param name="method"></param> /// <param name="hpType"></param> /// <param name="original"></param> private static void SetIVsPID(this PKM pk, ShowdownSet set, PIDType method, int hpType, PKM original) { // Useful Values for computation int Species = pk.Species; int Nature = pk.Nature; int Gender = pk.Gender; int AbilityNumber = pk.AbilityNumber; // 1,2,4 (HA) // Find the encounter var li = EncounterFinder.FindVerifiedEncounter(original); // TODO: Something about the gen 5 events. Maybe check for nature and shiny val and not touch the PID in that case? // Also need to figure out hidden power handling in that case.. for PIDType 0 that may isn't even be possible. if (li.EncounterMatch is EncounterStatic8N || li.EncounterMatch is EncounterStatic8NC || li.EncounterMatch is EncounterStatic8ND) { pk.IVs = set.IVs; var e = (EncounterStatic)li.EncounterMatch; if (AbilityNumber == 4 && (e.Ability == 0 || e.Ability == 1 || e.Ability == 2)) { return; } var pk8 = (PK8)pk; switch (e) { case EncounterStatic8NC c: FindNestPIDIV(pk8, c, set.Shiny); break; case EncounterStatic8ND c: FindNestPIDIV(pk8, c, set.Shiny); break; case EncounterStatic8N c: FindNestPIDIV(pk8, c, set.Shiny); break; } } else if (pk.GenNumber > 4 || pk.VC) { pk.IVs = set.IVs; if (Species == 658 && pk.AltForm == 1) { pk.IVs = new[] { 20, 31, 20, 31, 31, 20 } } ; if (method != PIDType.G5MGShiny) { pk.PID = PKX.GetRandomPID(Util.Rand, Species, Gender, pk.Version, Nature, pk.Format, pk.PID); if (li.Generation != 5) { return; } while (true) { if (li.EncounterMatch is EncounterStatic s && (s.Gift || s.Roaming || s.Ability != 4 || s.Location == 75)) { break; } if (pk is PK5 p && p.NPokémon) { break; } var result = (pk.PID & 1) ^ (pk.PID >> 31) ^ (pk.TID & 1) ^ (pk.SID & 1); if (result == 0) { break; } pk.PID = PKX.GetRandomPID(Util.Rand, Species, Gender, pk.Version, Nature, pk.Format, pk.PID); } } } else { pk.IVs = set.IVs; if (li.EncounterMatch is PCD d) { if (d.Gift.PK.PID != 1) { pk.PID = d.Gift.PK.PID; } else if (pk.Nature != pk.PID % 25) { pk.SetPIDNature(Nature); } return; } if (li.EncounterMatch is EncounterEgg) { pk.SetPIDNature(Nature); return; } FindPIDIV(pk, method, hpType); ValidateGender(pk); } }
/// <summary> /// Set IV Values for the pokemon /// </summary> /// <param name="pk"></param> /// <param name="set"></param> /// <param name="method"></param> /// <param name="hpType"></param> /// <param name="original"></param> private static void SetIVsPID(this PKM pk, IBattleTemplate set, PIDType method, int hpType, PKM original) { // Useful Values for computation int Species = pk.Species; int Nature = pk.Nature; int Gender = pk.Gender; int AbilityNumber = pk.AbilityNumber; // 1,2,4 (HA) // Find the encounter var li = EncounterFinder.FindVerifiedEncounter(original); if (li.EncounterMatch is MysteryGift mg) { var ivs = pk.IVs; for (int i = 0; i < mg.IVs.Length; i++) { if (mg.IVs[i] > 31) { ivs[i] = set.IVs[i]; } else { ivs[i] = mg.IVs[i]; } } pk.IVs = ivs; } else { pk.IVs = set.IVs; } // TODO: Something about the gen 5 events. Maybe check for nature and shiny val and not touch the PID in that case? // Also need to figure out hidden power handling in that case.. for PIDType 0 that may isn't even be possible. if (li.EncounterMatch is EncounterStatic8N || li.EncounterMatch is EncounterStatic8NC || li.EncounterMatch is EncounterStatic8ND) { var e = (EncounterStatic)li.EncounterMatch; if (AbilityNumber == 4 && (e.Ability == 0 || e.Ability == 1 || e.Ability == 2)) { return; } var pk8 = (PK8)pk; switch (e) { case EncounterStatic8NC c: FindNestPIDIV(pk8, c, set.Shiny); break; case EncounterStatic8ND c: FindNestPIDIV(pk8, c, set.Shiny); break; case EncounterStatic8N c: FindNestPIDIV(pk8, c, set.Shiny); break; } } else if (pk.GenNumber > 4 || pk.VC) { if (Species == 658 && pk.AltForm == 1) { pk.IVs = new[] { 20, 31, 20, 31, 31, 20 } } ; if (li.EncounterMatch is WC6 w6 && w6.PIDType == Shiny.FixedValue) { return; } if (li.EncounterMatch is WC7 w7 && w7.PIDType == Shiny.FixedValue) { return; } if (li.EncounterMatch is WC8 w8 && w8.PIDType == Shiny.FixedValue) { return; } if (pk.Version >= 24) { return; // Don't even bother changing IVs for Gen 6+ because why bother } if (method != PIDType.G5MGShiny) { var origpid = pk.PID; pk.PID = PKX.GetRandomPID(Util.Rand, Species, Gender, pk.Version, Nature, pk.Format, pk.PID); if (!li.EncounterMatch.Equals(EncounterFinder.FindVerifiedEncounter(pk).EncounterMatch)) { pk.PID = origpid; // Bad things happen when you change the PID! } if (li.Generation != 5) { return; } if (pk is PK5 p && p.NPokémon) { return; } if (li.EncounterMatch is EncounterStatic s && (s.Gift || s.Roaming || s.Ability != 4 || s.Location == 75)) { return; } while (true) { var result = (pk.PID & 1) ^ (pk.PID >> 31) ^ (pk.TID & 1) ^ (pk.SID & 1); if (result == 0) { break; } pk.PID = PKX.GetRandomPID(Util.Rand, Species, Gender, pk.Version, Nature, pk.Format, pk.PID); } } } else { if (li.EncounterMatch is PCD d) { if (d.Gift.PK.PID != 1) { pk.PID = d.Gift.PK.PID; } else if (pk.Nature != pk.PID % 25) { pk.SetPIDNature(Nature); } return; } if (li.EncounterMatch is EncounterEgg) { pk.SetPIDNature(Nature); return; } if (li.EncounterMatch is EncounterTradePID t) { t.SetEncounterTradeIVs(pk); return; // Fixed PID, no need to mutate } FindPIDIV(pk, method, hpType, set.Shiny); ValidateGender(pk); } }