/// <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) { var updatevalues = pk.Species != set.Species; if (updatevalues) { pk.Species = set.Species; } pk.ApplySetGender(set); if (Form != pk.Form) { pk.SetForm(Form); } pk.SetFormArgument(enc); if (updatevalues) { pk.RefreshAbility(pk.AbilityNumber >> 1); } var usedlang = lang ?? (LanguageID)pk.Language; var gen = new LegalityAnalysis(pk).Info.Generation; var nickname = Legal.GetMaxLengthNickname(gen, usedlang) < set.Nickname.Length ? set.Nickname.Substring(0, Legal.GetMaxLengthNickname(gen, usedlang)) : set.Nickname; if (!WordFilter.IsFiltered(nickname, out _)) { pk.SetNickname(nickname); } else { pk.ClearNickname(); } pk.CurrentLevel = set.Level; }
/// <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> public static void SetSpeciesLevel(this PKM pk, IBattleTemplate set, int Form, IEncounterable enc) { pk.Species = set.Species; pk.ApplySetGender(set); pk.SetAltForm(Form); pk.SetFormArgument(enc); pk.RefreshAbility(pk.AbilityNumber >> 1); var gen = new LegalityAnalysis(pk).Info.Generation; var nickname = Legal.GetMaxLengthNickname(gen, LanguageID.English) < set.Nickname.Length ? set.Nickname.Substring(0, Legal.GetMaxLengthNickname(gen, LanguageID.English)) : set.Nickname; if (!WordFilter.IsFiltered(nickname, out _)) { pk.SetNickname(nickname); } else { pk.ClearNickname(); } pk.CurrentLevel = set.Level; if (pk.CurrentLevel == 50) { pk.CurrentLevel = 100; // VGC Override } }
/// <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> public static void SetSpeciesLevel(this PKM pk, ShowdownSet set, int Form) { pk.Species = set.Species; pk.ApplySetGender(set); pk.SetAltForm(Form); pk.SetNickname(set.Nickname); pk.CurrentLevel = set.Level; if (pk.CurrentLevel == 50) { pk.CurrentLevel = 100; // VGC Override } }
/// <summary> /// Quick Gender Toggle /// </summary> /// <param name="pk">PKM whose gender needs to be toggled</param> /// <param name="set">Showdown Set for Gender reference</param> public static void FixGender(this PKM pk, IBattleTemplate set) { pk.ApplySetGender(set); var la = new LegalityAnalysis(pk); if (la.Valid) { return; } string Report = la.Report(); if (Report.Contains(LegalityCheckStrings.LPIDGenderMismatch)) { pk.Gender = pk.Gender == 0 ? 1 : 0; } if (pk.Gender != 0 && pk.Gender != 1) { pk.Gender = pk.GetSaneGender(); } }
/// <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;