/// <summary> /// Clone trainerdata and mutate the language and then return the clone /// </summary> /// <param name="tr">Trainerdata to clone</param> /// <param name="lang">language to mutate</param> /// <returns></returns> public static ITrainerInfo MutateLanguage(this ITrainerInfo tr, LanguageID?lang) { if (lang is LanguageID.UNUSED_6 or LanguageID.Hacked or null) { return(tr); } if (tr is PokeTrainerDetails p) { var clone = PokeTrainerDetails.Clone(p); clone.Language = (int)lang; return(clone); } if (tr is SimpleTrainerInfo s) { return(new SimpleTrainerInfo((GameVersion)s.Game) { OT = s.OT, TID = s.TID, SID = s.SID, Gender = s.Gender, Language = (int)lang, ConsoleRegion = s.ConsoleRegion, Region = s.Region, Country = s.Country, Generation = s.Generation }); } return(tr); }
/// <summary> /// Clone trainerdata and mutate the language and then return the clone /// </summary> /// <param name="tr">Trainerdata to clone</param> /// <param name="lang">language to mutate</param> /// <returns></returns> public static ITrainerInfo MutateLanguage(this ITrainerInfo tr, LanguageID?lang, GameVersion ver) { if (lang is LanguageID.UNUSED_6 or LanguageID.Hacked or null) { return(tr); } if (tr is PokeTrainerDetails p) { var clone = PokeTrainerDetails.Clone(p); clone.Language = (int)lang; clone.OT = MutateOT(clone.OT, lang, ver); return(clone); } if (tr is SimpleTrainerInfo s) { var version = GameUtil.GameVersions.FirstOrDefault(z => ver.Contains(z) && z != GameVersion.BU); return(new SimpleTrainerInfo(version) { OT = MutateOT(s.OT, lang, version), TID = s.TID, SID = s.SID, Gender = s.Gender, Language = (int)lang, ConsoleRegion = s.ConsoleRegion != 0 ? s.ConsoleRegion : (byte)1, Region = s.Region != 0 ? s.Region : (byte)7, Country = s.Country != 0 ? s.Country : (byte)49, Generation = s.Generation, }); } return(tr); }
/// <summary> /// Clone trainerdata and mutate the language and then return the clone /// </summary> /// <param name="tr">Trainerdata to clone</param> /// <param name="lang">language to mutate</param> /// <returns></returns> public static ITrainerInfo MutateLanguage(this ITrainerInfo tr, LanguageID?lang) { if (lang == LanguageID.UNUSED_6 || lang == LanguageID.Hacked || lang == null) { return(tr); } if (tr is PokeTrainerDetails p) { var clone = PokeTrainerDetails.Clone(p); clone.Language = (int)lang; return(clone); } if (tr is SimpleTrainerInfo s) { var sti = new SimpleTrainerInfo((GameVersion)s.Game); sti.OT = s.OT; sti.TID = s.TID; sti.SID = s.SID; sti.Generation = s.Gender; sti.Language = (int)lang; sti.ConsoleRegion = s.ConsoleRegion; sti.Region = s.Region; sti.Country = s.Country; sti.Generation = s.Generation; return(sti); } return(tr); }
/// <summary> /// Tries to regenerate the <see cref="pk"/> into a valid pkm. /// </summary> /// <param name="tr">Source/Destination trainer</param> /// <param name="pk">Currently invalid pkm data</param> /// <returns>Legalized PKM (hopefully legal)</returns> public static PKM Legalize(this ITrainerInfo tr, PKM pk) { var set = new ShowdownSet(ShowdownSet.GetShowdownText(pk)); var legal = tr.GetLegalFromTemplate(pk, set, out var satisfied); if (satisfied) { return(legal); } var dest = new PokeTrainerDetails(pk.Clone()); var resetForm = ShowdownUtil.IsInvalidForm(set.Form); legal = BruteForce.ApplyDetails(pk, set, resetForm, dest); legal.SetTrainerData(dest); return(legal); }
/// <summary> /// Tries to regenerate the <see cref="pk"/> into a valid pkm. /// </summary> /// <param name="tr">Source/Destination trainer</param> /// <param name="pk">Currently invalid pkm data</param> /// <returns>Legalized PKM (hopefully legal)</returns> public static PKM Legalize(this ITrainerInfo tr, PKM pk) { var set = new RegenTemplate(pk) { Ball = (Ball)pk.Ball, ShinyType = pk.ShinyXor == 0 ? Shiny.AlwaysSquare : pk.IsShiny ? Shiny.AlwaysStar : Shiny.Never }; var legal = tr.GetLegalFromTemplate(pk, set, out var satisfied); if (satisfied) { return(legal); } var dest = new PokeTrainerDetails(pk.Clone()); var resetForm = ShowdownUtil.IsInvalidForm(set.Form); legal = BruteForce.ApplyDetails(pk, set, resetForm, dest); legal.SetTrainerData(dest); return(legal); }