private static void SetNature(PKM pk, IBattleTemplate set) { var val = Math.Min((int)Nature.Quirky, Math.Max((int)Nature.Hardy, set.Nature)); pk.SetNature(val); if (pk.Species == (int)Species.Toxtricity) { if (pk.AltForm == EvolutionMethod.GetAmpLowKeyResult(val)) { pk.Nature = val; // StatNature already set } return; } // Try setting the actual nature (in the event the StatNature was set instead) var orig = pk.Nature; if (orig == val) { return; } var la = new LegalityAnalysis(pk); pk.Nature = val; var la2 = new LegalityAnalysis(pk); var enc1 = la.EncounterOriginal; var enc2 = la2.EncounterOriginal; if ((!ReferenceEquals(enc1, enc2) && !(enc1 is EncounterEgg)) || la2.Info.Parse.Any(z => z.Identifier == CheckIdentifier.Nature && !z.Valid)) { pk.Nature = orig; } }
/// <summary> /// Method to find the PID and IV associated with a nest. Shinies are just allowed /// since there is no way GameFreak actually brute-forces top half of the PID to flag illegals. /// </summary> /// <param name="pk">Passed PKM</param> /// <param name="enc">Nest encounter object</param> /// <param name="shiny">Shiny boolean</param> private static void FindNestPIDIV <T>(PK8 pk, T enc, bool shiny) where T : EncounterStatic8Nest <T> { // Preserve Nature, Altform (all abilities should be possible in gen 8, so no need to early return on a mismatch for enc HA bool vs set HA bool) // Nest encounter RNG generation var iterPKM = pk.Clone(); if (pk.Species == (int)Species.Toxtricity && pk.AltForm != EvolutionMethod.GetAmpLowKeyResult(pk.Nature)) { enc.ApplyDetailsTo(pk, GetRandomULong()); pk.RefreshAbility(iterPKM.AbilityNumber >> 1); pk.StatNature = iterPKM.StatNature; return; } if (shiny && enc is EncounterStatic8U) { // Dynamax Adventure shinies are always XOR 1 pk.PID ^= (uint)(((pk.TID ^ pk.SID ^ (pk.PID & 0xFFFF) ^ 1) << 16) | (pk.PID & 0xFFFF)); } if (shiny || !UseXOROSHIRO) { return; } var count = 0; do { ulong seed = GetRandomULong(); enc.ApplyDetailsTo(pk, seed); if (IsMatchCriteria <T>(pk, iterPKM)) { break; } } while (++count < 10_000); pk.Species = iterPKM.Species; // possible evolution // can be ability capsuled if (Legal.FormChange.Contains(pk.Species) || pk.Species == (int)Species.Zygarde) { pk.AltForm = iterPKM.AltForm; // set alt form if it can be freely changed! } pk.RefreshAbility(iterPKM.AbilityNumber >> 1); pk.StatNature = iterPKM.StatNature; }
private static void SetNature(PKM pk, IBattleTemplate set) { if (pk.Nature == set.Nature) { return; } var val = Math.Min((int)Nature.Quirky, Math.Max((int)Nature.Hardy, set.Nature)); if (pk.Species == (int)Species.Toxtricity) { if (pk.Form == EvolutionMethod.GetAmpLowKeyResult(val)) { pk.Nature = val; // StatNature already set } if (pk.Format >= 8 && pk.StatNature != pk.Nature && pk.StatNature != 12 && (pk.StatNature > 24 || pk.StatNature % 6 == 0)) // Only Serious Mint for Neutral Natures { pk.StatNature = 12; } return; } pk.SetNature(val); // Try setting the actual nature (in the event the StatNature was set instead) var orig = pk.Nature; if (orig == val) { return; } var la = new LegalityAnalysis(pk); pk.Nature = val; var la2 = new LegalityAnalysis(pk); var enc1 = la.EncounterMatch; var enc2 = la2.EncounterMatch; if ((!ReferenceEquals(enc1, enc2) && enc1 is not EncounterEgg) || la2.Results.Any(z => z.Identifier == CheckIdentifier.Nature && !z.Valid)) { pk.Nature = orig; } if (pk.Format >= 8 && pk.StatNature != pk.Nature && pk.StatNature is 0 or 6 or 18 or >= 24) // Only Serious Mint for Neutral Natures { pk.StatNature = (int)Nature.Serious; } }
/// <summary> /// Method to find the PID and IV associated with a nest. Shinies are just allowed /// since there is no way GameFreak actually brute-forces top half of the PID to flag illegals. /// </summary> /// <param name="pk">Passed PKM</param> /// <param name="enc">Nest encounter object</param> /// <param name="shiny">Shiny boolean</param> private static void FindNestPIDIV <T>(PK8 pk, T enc, bool shiny) where T : EncounterStatic8Nest <T> { // Preserve Nature, Altform, Ability (only if HA) // Nest encounter RNG generation var iterPKM = pk.Clone(); if (enc.Ability != -1 && (pk.AbilityNumber == 4) != (enc.Ability == 4)) { return; } if (pk.Species == (int)Species.Toxtricity && pk.AltForm != EvolutionMethod.GetAmpLowKeyResult(pk.Nature)) { enc.ApplyDetailsTo(pk, GetRandomULong()); pk.RefreshAbility(iterPKM.AbilityNumber >> 1); pk.StatNature = iterPKM.StatNature; return; } if (shiny || !UseXOROSHIRO) { return; } var count = 0; do { ulong seed = GetRandomULong(); enc.ApplyDetailsTo(pk, seed); if (IsMatchCriteria <T>(pk, iterPKM)) { break; } } while (++count < 10_000); pk.Species = iterPKM.Species; // possible evolution // can be ability capsuled pk.RefreshAbility(iterPKM.AbilityNumber >> 1); pk.StatNature = iterPKM.StatNature; }
/// <summary> /// Set Species and Level with nickname (Helps with PreEvos) /// </summary> /// <param name="pk">PKM to modify</param> /// <param name="set">Set to use as reference</param> /// <param name="Form">Form to apply</param> /// <param name="enc">Encounter detail</param> /// <param name="lang">Language to apply</param> public static void SetSpeciesLevel(this PKM pk, IBattleTemplate set, int Form, IEncounterable enc, LanguageID?lang = null) { pk.ApplySetGender(set); var evolutionRequired = pk.Species != set.Species; if (evolutionRequired) { pk.Species = set.Species; } if (Form != pk.Form) { pk.SetForm(Form); } // Don't allow invalid tox nature, set random nature first and then statnature later if (pk.Species == (int)Species.Toxtricity) { while (true) { var result = EvolutionMethod.GetAmpLowKeyResult(pk.Nature); if (result == pk.Form) { break; } pk.Nature = Util.Rand.Next(25); } } pk.SetSuggestedFormArgument(enc.Species); if (evolutionRequired) { pk.RefreshAbility(pk.AbilityNumber >> 1); } pk.CurrentLevel = set.Level; if (pk.Met_Level > pk.CurrentLevel) { pk.Met_Level = pk.CurrentLevel; } if (set.Level != 100 && set.Level == enc.LevelMin && (pk.Format == 3 || pk.Format == 4)) { pk.EXP = Experience.GetEXP(enc.LevelMin + 1, PersonalTable.HGSS[enc.Species].EXPGrowth) - 1; } var currentlang = (LanguageID)pk.Language; var finallang = lang ?? currentlang; if (finallang == LanguageID.Hacked) { finallang = LanguageID.English; } pk.Language = (int)finallang; // check if nickname even needs to be updated if (set.Nickname.Length == 0 && finallang == currentlang && !evolutionRequired) { return; } var gen = enc.Generation; var maxlen = Legal.GetMaxLengthNickname(gen, finallang); var nickname = set.Nickname.Length > maxlen?set.Nickname.Substring(0, maxlen) : set.Nickname; if (!WordFilter.IsFiltered(nickname, out _)) { pk.SetNickname(nickname); } else { pk.ClearNickname(); } }
/// <summary> /// Set Species and Level with nickname (Helps with PreEvos) /// </summary> /// <param name="pk">PKM to modify</param> /// <param name="set">Set to use as reference</param> /// <param name="Form">Form to apply</param> /// <param name="enc">Encounter detail</param> /// <param name="lang">Language to apply</param> public static void SetSpeciesLevel(this PKM pk, IBattleTemplate set, int Form, IEncounterable enc, LanguageID?lang = null) { pk.ApplySetGender(set); var evolutionRequired = pk.Species != set.Species; if (evolutionRequired) { pk.Species = set.Species; } if (Form != pk.Form) { pk.SetForm(Form); } // Don't allow invalid tox nature, set random nature first and then statnature later if (pk.Species == (int)Species.Toxtricity) { while (true) { var result = EvolutionMethod.GetAmpLowKeyResult(pk.Nature); if (result == pk.Form) { break; } pk.Nature = Util.Rand.Next(25); } } pk.SetSuggestedFormArgument(enc.Species); if (evolutionRequired) { pk.RefreshAbility(pk.AbilityNumber >> 1); } pk.CurrentLevel = set.Level; if (pk.Met_Level > pk.CurrentLevel) { pk.Met_Level = pk.CurrentLevel; } if (set.Level != 100 && set.Level == enc.LevelMin && pk.Format is 3 or 4) { pk.EXP = Experience.GetEXP(enc.LevelMin + 1, PersonalTable.HGSS[enc.Species].EXPGrowth) - 1; } var currentlang = (LanguageID)pk.Language; var finallang = lang ?? currentlang; if (finallang == LanguageID.Hacked) { finallang = LanguageID.English; } pk.Language = (int)finallang; // check if nickname even needs to be updated if (set.Nickname.Length == 0 && finallang == currentlang && !evolutionRequired) { return; } // don't bother checking encountertrade nicknames for length validity if (enc is EncounterTrade { HasNickname : true })
/// <summary> /// Set Species and Level with nickname (Helps with PreEvos) /// </summary> /// <param name="pk">PKM to modify</param> /// <param name="set">Set to use as reference</param> /// <param name="Form">Form to apply</param> /// <param name="enc">Encounter detail</param> /// <param name="lang">Language to apply</param> public static void SetSpeciesLevel(this PKM pk, IBattleTemplate set, int Form, IEncounterable enc, LanguageID?lang = null) { pk.ApplySetGender(set); var evolutionRequired = pk.Species != set.Species; var formchange = Form != pk.Form; if (evolutionRequired) { pk.Species = set.Species; } if (formchange) { pk.Form = Form; } if ((evolutionRequired || formchange) && pk is IScaledSizeValue sv) { sv.HeightAbsolute = sv.CalcHeightAbsolute; sv.WeightAbsolute = sv.CalcWeightAbsolute; } // Don't allow invalid tox nature, set random nature first and then statnature later if (pk.Species == (int)Species.Toxtricity) { while (true) { var result = EvolutionMethod.GetAmpLowKeyResult(pk.Nature); if (result == pk.Form) { break; } pk.Nature = Util.Rand.Next(25); } } pk.SetSuggestedFormArgument(enc.Species); if (evolutionRequired) { pk.RefreshAbility(pk.AbilityNumber >> 1); } pk.CurrentLevel = set.Level; if (pk.Met_Level > pk.CurrentLevel) { pk.Met_Level = pk.CurrentLevel; } if (set.Level != 100 && set.Level == enc.LevelMin && pk.Format is 3 or 4) { pk.EXP = Experience.GetEXP(enc.LevelMin + 1, PersonalTable.HGSS[enc.Species].EXPGrowth) - 1; } var currentlang = (LanguageID)pk.Language; var finallang = lang ?? currentlang; if (finallang == LanguageID.Hacked) { finallang = LanguageID.English; } pk.Language = (int)finallang; // check if nickname even needs to be updated if (set.Nickname.Length == 0 && finallang == currentlang && !evolutionRequired) { return; } // don't bother checking encountertrade nicknames for length validity if (enc is EncounterTrade { HasNickname : true } et&& et.Nicknames.Contains(set.Nickname)) { // Nickname matches the requested nickname already if (pk.Nickname == set.Nickname) { return; } // This should be illegal except Meister Magikarp in BDSP, however trust the user and set corresponding OT var index = et.Nicknames.ToList().IndexOf(set.Nickname); pk.Nickname = set.Nickname; if (pk.Format >= 3) { pk.OT_Name = et.TrainerNames[index]; } } var gen = enc.Generation; var maxlen = Legal.GetMaxLengthNickname(gen, finallang); var newnick = RegenUtil.MutateNickname(set.Nickname, finallang, (GameVersion)pk.Version); var nickname = newnick.Length > maxlen ? newnick[..maxlen] : newnick;