Ejemplo n.º 1
0
        public bool SetRegenSettings(IEnumerable <string> lines)
        {
            var  split = RegenUtil.Split(lines);
            bool any   = false;

            foreach (var s in split)
            {
                var key   = s.Key;
                var value = s.Value;
                switch (key)
                {
                case nameof(Ball):
                    Ball = Aesthetics.GetBallFromString(value);
                    break;

                case nameof(Shiny):
                    ShinyType = Aesthetics.GetShinyType(value);
                    break;

                case nameof(Language):
                    Language = Aesthetics.GetLanguageId(value);
                    break;

                default:
                    continue;
                }
                any = true;
            }
            return(any);
        }
Ejemplo n.º 2
0
 /// <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);
 }
Ejemplo n.º 3
0
 /// <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);
 }
Ejemplo n.º 4
0
 /// <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);
 }
Ejemplo n.º 5
0
        public static ITrainerInfo DefaultFallback(int gen = 8, LanguageID?lang = null)
        {
            var fallback = gen > 7 ? DefaultFallback8 : DefaultFallback7;

            if (lang == null)
            {
                return(fallback);
            }
            return(new SimpleTrainerInfo((GameVersion)fallback.Game)
            {
                Language = (int)lang
            });
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Fetches an appropriate trainer based on the requested <see cref="generation"/>.
        /// </summary>
        /// <param name="generation">Generation the trainer should inhabit</param>
        /// <param name="lang">Language to request for</param>
        /// <returns>Null if no trainer found for this version.</returns>
        public ITrainerInfo?GetTrainerFromGen(int generation, LanguageID?lang = null)
        {
            var possible = Database.Where(z => z.Key.GetGeneration() == generation).ToList();

            if (lang != null)
            {
                possible = possible.Select(z =>
                {
                    var filtered = z.Value.Where(x => x.Language == (int)lang).ToList();
                    return(new KeyValuePair <GameVersion, List <ITrainerInfo> >(z.Key, filtered));
                }).Where(z => z.Value.Count != 0).ToList();
            }
            return(GetRandomTrainer(possible));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Fetches an appropriate trainer based on the requested <see cref="ver"/> group.
        /// </summary>
        /// <param name="ver">Version the trainer should originate from</param>
        /// <param name="lang">Language to request for</param>
        /// <returns>Null if no trainer found for this version.</returns>
        private ITrainerInfo?GetTrainerFromGroup(GameVersion ver, LanguageID?lang = null)
        {
            var possible = Database.Where(z => ver.Contains(z.Key)).ToList();

            if (lang != null)
            {
                possible = possible.Select(z =>
                {
                    var filtered = z.Value.Where(x => x.Language == (int)lang).ToList();
                    return(new KeyValuePair <GameVersion, List <ITrainerInfo> >(z.Key, filtered));
                }).Where(z => z.Value.Count != 0).ToList();
            }
            return(GetRandomTrainer(possible));
        }
Ejemplo n.º 8
0
        public static string MutateNickname(string nick, LanguageID?lang, GameVersion game)
        {
            // Length checks are handled later in SetSpeciesLevel
            if (game.GetGeneration() >= 8 || lang == null)
            {
                return(nick);
            }
            var full = lang == LanguageID.Japanese || lang == LanguageID.Korean || lang == LanguageID.ChineseS || lang == LanguageID.ChineseT;

            if (full && GlyphLegality.ContainsHalfWidth(nick))
            {
                return(GlyphLegality.StringConvert(nick, StringConversionType.FullWidth));
            }
            if (!full && GlyphLegality.ContainsFullWidth(nick))
            {
                return(GlyphLegality.StringConvert(nick, StringConversionType.HalfWidth));
            }
            return(nick);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Fetches an appropriate trainer based on the requested <see cref="ver"/>.
        /// </summary>
        /// <param name="ver">Version the trainer should originate from</param>
        /// <param name="lang">Language to request for</param>
        /// <returns>Null if no trainer found for this version.</returns>
        public ITrainerInfo?GetTrainer(GameVersion ver, LanguageID?lang = null)
        {
            if (ver <= 0)
            {
                return(null);
            }

            if (ver >= GameVersion.RB)
            {
                return(GetTrainerFromGroup(ver, lang));
            }

            if (Database.TryGetValue(ver, out var list))
            {
                return(GetRandomChoice(list));
            }

            return(null);
        }
Ejemplo n.º 10
0
        private static string MutateOT(string OT, LanguageID?lang, GameVersion game)
        {
            if (game.GetGeneration() >= 8 || lang == null)
            {
                return(OT);
            }
            var full = lang == LanguageID.Japanese || lang == LanguageID.Korean || lang == LanguageID.ChineseS || lang == LanguageID.ChineseT;

            if (full && GlyphLegality.ContainsHalfWidth(OT))
            {
                var max      = Legal.GetMaxLengthOT(game.GetGeneration(), (LanguageID)lang);
                var modified = GlyphLegality.StringConvert(OT, StringConversionType.FullWidth);
                return(modified.Substring(0, Math.Min(modified.Length, max)));
            }
            if (!full && GlyphLegality.ContainsFullWidth(OT))
            {
                var max      = Legal.GetMaxLengthOT(game.GetGeneration(), (LanguageID)lang);
                var modified = GlyphLegality.StringConvert(OT, StringConversionType.HalfWidth);
                return(modified.Substring(0, Math.Min(modified.Length, max)));
            }
            return(OT);
        }
Ejemplo n.º 11
0
 public static void SetLanguage(this PKM pk, LanguageID?lang = null) => pk.Language = lang != null ? (int)lang : pk.Language;
Ejemplo n.º 12
0
        /// <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.Species = set.Species;
            pk.ApplySetGender(set);
            pk.SetForm(Form);
            pk.SetFormArgument(enc);
            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;
        }
Ejemplo n.º 13
0
        /// <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();
            }
        }
Ejemplo n.º 14
0
        /// <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;
Ejemplo n.º 15
0
        /// <summary>
        /// Gets a possible Trainer Data for the requested <see cref="generation"/>.
        /// </summary>
        /// <param name="generation">Generation of origin requested.</param>
        /// <param name="fallback">Fallback trainer data if no new parent is found.</param>
        /// <param name="lang">Language to request for</param>
        /// <returns>Parent trainer data that originates from the <see cref="PKM.Version"/>. If none found, will return the <see cref="fallback"/>.</returns>
        public static ITrainerInfo GetSavedTrainerData(int generation, ITrainerInfo?fallback = null, LanguageID?lang = null)
        {
            var trainer = Database.GetTrainerFromGen(generation, lang);

            if (trainer != null)
            {
                return(trainer);
            }

            if (fallback == null)
            {
                return(DefaultFallback(generation, lang));
            }
            if (lang == null)
            {
                return(fallback);
            }
            if ((int)lang == fallback.Language)
            {
                return(fallback);
            }
            return(DefaultFallback(generation, lang));
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Gets a possible Trainer Data for the provided <see cref="pk"/>.
        /// </summary>
        /// <param name="pk">Pokémon that will receive the trainer details.</param>
        /// <param name="fallback">Fallback trainer data if no new parent is found.</param>
        /// <param name="lang">Language to request for</param>
        /// <returns>Parent trainer data that originates from the <see cref="PKM.Version"/>. If none found, will return the <see cref="fallback"/>.</returns>
        public static ITrainerInfo GetSavedTrainerData(PKM pk, ITrainerInfo?fallback = null, LanguageID?lang = null)
        {
            int origin = pk.GenNumber;
            int format = pk.Format;

            if (format != origin)
            {
                return(GetSavedTrainerData(format, fallback, lang));
            }
            return(GetSavedTrainerData((GameVersion)pk.Version, origin, fallback, lang));
        }
Ejemplo n.º 17
0
        /// <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
            })
Ejemplo n.º 18
0
        /// <summary>
        /// Gets a possible Trainer Data for the requested <see cref="version"/>.
        /// </summary>
        /// <param name="version">Version of origin requested.</param>
        /// <param name="gen">Generation of origin requested.</param>
        /// <param name="fallback">Fallback trainer data if no new parent is found.</param>
        /// <param name="lang">Language to request for</param>
        /// <returns>Parent trainer data that originates from the <see cref="PKM.Version"/>. If none found, will return the <see cref="fallback"/>.</returns>
        public static ITrainerInfo GetSavedTrainerData(GameVersion version, int gen, ITrainerInfo?fallback = null, LanguageID?lang = null)
        {
            var byVer = Database.GetTrainer(version, lang);

            return(byVer ?? GetSavedTrainerData(gen, fallback, lang));
        }
Ejemplo n.º 19
0
 /// <summary>
 /// Fetches an appropriate trainer based on the requested <see cref="version"/>.
 /// </summary>
 /// <param name="version">Version the trainer should originate from</param>
 /// <param name="lang">Language to request for</param>
 /// <returns>Null if no trainer found for this version.</returns>
 public ITrainerInfo?GetTrainer(int version, LanguageID?lang = null) => GetTrainer((GameVersion)version, lang);