Beispiel #1
0
        /// <summary>
        /// Fetches <see cref="PKM.RelearnMoves"/> based on the provided <see cref="LegalityAnalysis"/>.
        /// </summary>
        /// <param name="legal"><see cref="LegalityAnalysis"/> which contains parsed information pertaining to legality.</param>
        /// <returns><see cref="PKM.RelearnMoves"/> best suited for the current <see cref="PKM"/> data.</returns>
        public static IReadOnlyList <int> GetSuggestedRelearnMoves(this LegalityAnalysis legal)
        {
            var m = legal.GetSuggestedRelearnMovesFromEncounter();

            if (m.Any(z => z != 0))
            {
                return(m);
            }

            var enc = legal.EncounterMatch;

            if (enc is MysteryGift || enc is EncounterEgg)
            {
                return(m);
            }

            var encounter = EncounterSuggestion.GetSuggestedMetInfo(legal.pkm);

            if (encounter is IRelearn r && r.Relearn.Count > 0)
            {
                return(r.Relearn);
            }

            return(m);
        }
Beispiel #2
0
        /// <summary>
        /// Force hatches a PKM by applying the current species name and a valid Met Location from the origin game.
        /// </summary>
        /// <param name="pkm">PKM to apply hatch details to</param>
        /// <remarks>
        /// <see cref="PKM.IsEgg"/> is not checked; can be abused to re-hatch already hatched <see cref="PKM"/> inputs.
        /// <see cref="PKM.MetDate"/> is not modified; must be updated manually if desired.
        /// </remarks>
        private static void ForceHatchPKM(PKM pkm)
        {
            pkm.IsEgg    = false;
            pkm.Nickname = PKX.GetSpeciesNameGeneration(pkm.Species, pkm.Language, pkm.Format);
            var loc = EncounterSuggestion.GetSuggestedEggMetLocation(pkm);

            if (loc >= 0)
            {
                pkm.Met_Location = loc;
            }
        }
Beispiel #3
0
        private void SetEggMetData(PKM pk, ITrainerInfo tr, DateTime today)
        {
            pk.Met_Location = Math.Max(0, EncounterSuggestion.GetSuggestedEggMetLocation(pk));
            pk.Met_Level    = EncounterSuggestion.GetSuggestedEncounterEggMetLevel(pk);

            if (Generation >= 4)
            {
                bool traded = (int)Version == tr.Game;
                pk.Egg_Location = EncounterSuggestion.GetSuggestedEncounterEggLocationEgg(pk, traded);
                pk.EggMetDate   = today;
            }
            pk.Egg_Location = EggLocation;
            pk.EggMetDate   = today;
        }
Beispiel #4
0
        /// <summary>
        /// Force hatches a PKM by applying the current species name and a valid Met Location from the origin game.
        /// </summary>
        /// <param name="pkm">PKM to apply hatch details to</param>
        /// <remarks>
        /// <see cref="PKM.IsEgg"/> is not checked; can be abused to re-hatch already hatched <see cref="PKM"/> inputs.
        /// <see cref="PKM.MetDate"/> is not modified; must be updated manually if desired.
        /// </remarks>
        private static void ForceHatchPKM(PKM pkm)
        {
            pkm.IsEgg = false;
            pkm.SetNickname();
            pkm.CurrentFriendship = pkm.PersonalInfo.BaseFriendship;
            var loc = EncounterSuggestion.GetSuggestedEggMetLocation(pkm);

            if (loc >= 0)
            {
                pkm.Met_Location = loc;
            }
            if (pkm.Gen6)
            {
                pkm.SetHatchMemory6();
            }
        }
Beispiel #5
0
        /// <summary>
        /// Fetches <see cref="PKM.RelearnMoves"/> based on the provided <see cref="LegalityAnalysis"/>.
        /// </summary>
        /// <param name="legal"><see cref="LegalityAnalysis"/> which contains parsed information pertaining to legality.</param>
        /// <param name="enc">Encounter the relearn moves should be suggested for. If not provided, will try to detect it via legality analysis. </param>
        /// <returns><see cref="PKM.RelearnMoves"/> best suited for the current <see cref="PKM"/> data.</returns>
        public static IReadOnlyList <int> GetSuggestedRelearnMoves(this LegalityAnalysis legal, IEncounterable?enc = null)
        {
            var m = legal.GetSuggestedRelearnMovesFromEncounter();

            if (m.Any(z => z != 0))
            {
                return(m);
            }

            enc ??= legal.EncounterMatch;
            if (enc is MysteryGift or EncounterEgg)
            {
                return(m);
            }

            if (enc is EncounterSlot6AO {
                CanDexNav : true
            } dn)
            {
                var moves = legal.Info.Moves;
                for (int i = 0; i < moves.Length; i++)
                {
                    if (moves[i].Valid)
                    {
                        continue;
                    }

                    var move = legal.pkm.GetMove(i);
                    if (dn.CanBeDexNavMove(move))
                    {
                        return new[] { move, 0, 0, 0 }
                    }
                    ;
                }
            }

            var encounter = EncounterSuggestion.GetSuggestedMetInfo(legal.pkm);

            if (encounter is IRelearn r && r.Relearn.Count > 0)
            {
                return(r.Relearn);
            }

            return(m);
        }
    }
Beispiel #6
0
        /// <summary>
        /// Fetches <see cref="PKM.RelearnMoves"/> based on the provided <see cref="LegalityAnalysis"/>.
        /// </summary>
        /// <param name="legal"><see cref="LegalityAnalysis"/> which contains parsed information pertaining to legality.</param>
        /// <param name="enc">Encounter the relearn moves should be suggested for. If not provided, will try to detect it via legality analysis. </param>
        /// <returns><see cref="PKM.RelearnMoves"/> best suited for the current <see cref="PKM"/> data.</returns>
        public static IReadOnlyList <int> GetSuggestedRelearnMoves(this LegalityAnalysis legal, IEncounterTemplate?enc = null)
        {
            enc ??= legal.EncounterOriginal;
            var m = legal.GetSuggestedRelearnMovesFromEncounter(enc);

            if (m.Any(z => z != 0))
            {
                return(m);
            }

            if (enc is MysteryGift or EncounterEgg)
            {
                return(m);
            }

            if (enc is EncounterSlot6AO {
                CanDexNav : true
            } dn)
            {
                var moves = legal.Info.Moves;
                for (int i = 0; i < moves.Length; i++)
                {
                    if (!moves[i].ShouldBeInRelearnMoves())
                    {
                        continue;
                    }

                    var move = legal.pkm.GetMove(i);

                    if (dn.CanBeDexNavMove(move))
                    {
                        return new[] { move, 0, 0, 0 }
                    }
                    ;
                }
            }

            var encounter = EncounterSuggestion.GetSuggestedMetInfo(legal.pkm);

            if (encounter is IRelearn {
                Relearn : { Count : > 0 } r
            })
Beispiel #7
0
        public static ModifyResult SetSuggestedMetData(BatchInfo info)
        {
            var pk        = info.Entity;
            var encounter = EncounterSuggestion.GetSuggestedMetInfo(pk);

            if (encounter == null)
            {
                return(ModifyResult.Error);
            }

            int level        = encounter.LevelMin;
            int location     = encounter.Location;
            int minimumLevel = EncounterSuggestion.GetLowestLevel(pk, encounter.LevelMin);

            pk.Met_Level    = level;
            pk.Met_Location = location;
            pk.CurrentLevel = Math.Max(minimumLevel, level);

            return(ModifyResult.Modified);
        }
Beispiel #8
0
 private static void SetMetData(PKM pk)
 {
     pk.Met_Level    = EncounterSuggestion.GetSuggestedEncounterEggMetLevel(pk);
     pk.Met_Location = Math.Max(0, EncounterSuggestion.GetSuggestedEggMetLocation(pk));
 }
Beispiel #9
0
        public static ModifyResult SetMinimumCurrentLevel(BatchInfo info)
        {
            var result = EncounterSuggestion.IterateMinimumCurrentLevel(info.Entity, info.Legal);

            return(result ? ModifyResult.Modified : ModifyResult.Filtered);
        }
Beispiel #10
0
        public PKM ConvertToPKM(ITrainerInfo SAV)
        {
            int gen = Math.Max(2, Version.GetGeneration());
            var pk  = PKMConverter.GetBlank(gen);

            SAV.ApplyToPKM(pk);

            pk.Species      = Species;
            pk.Nickname     = PKX.GetSpeciesNameGeneration(Species, SAV.Language, gen);
            pk.CurrentLevel = Level;
            pk.Version      = (int)Version;

            var moves = Legal.GetEggMoves(pk, Species, pk.AltForm, Version);

            if (moves.Length == 0)
            {
                moves = Legal.GetEncounterMoves(pk, Level, Version);
            }
            pk.Moves = moves;
            pk.SetMaximumPPCurrent(moves);
            pk.OT_Friendship = pk.PersonalInfo.BaseFriendship;

            pk.SetRandomIVs(flawless: 3);

            if (pk.Format <= 2 && Version != GameVersion.C)
            {
                return(pk);
            }

            pk.Met_Level    = EncounterSuggestion.GetSuggestedEncounterEggMetLevel(pk);
            pk.Met_Location = Math.Max(0, EncounterSuggestion.GetSuggestedEggMetLocation(pk));

            if (pk.Format < 3)
            {
                return(pk);
            }

            pk.Ball = 4;

            int gender = Util.Rand.Next(2);
            int nature = Util.Rand.Next(25);

            gender = pk.GetSaneGender(gender);
            if (pk.Format <= 5)
            {
                pk.SetPIDGender(gender);
                pk.SetPIDNature(nature);
                pk.RefreshAbility(pk.PIDAbility);
            }
            else
            {
                pk.PID    = Util.Rand32();
                pk.Nature = nature;
                pk.Gender = gender;
                pk.RefreshAbility(Util.Rand.Next(2));
            }

            bool traded = (int)Version == SAV.Game;
            var  today  = pk.MetDate = DateTime.Today;

            if (pk.GenNumber >= 4)
            {
                pk.Egg_Location = EncounterSuggestion.GetSuggestedEncounterEggLocationEgg(pk, traded);
                pk.EggMetDate   = today;
            }

            if (pk.Format < 6)
            {
                return(pk);
            }
            if (pk.Gen6)
            {
                pk.SetHatchMemory6();
            }

            pk.SetRandomEC();
            pk.RelearnMoves = moves;

            return(pk);
        }
Beispiel #11
0
 /// <summary>
 /// Gets an object containing met data properties that might be legal.
 /// </summary>
 public EncounterStatic GetSuggestedMetInfo() => EncounterSuggestion.GetSuggestedMetInfo(pkm);
Beispiel #12
0
        /// <summary>
        /// Sets the <see cref="PKM"/> data with a suggested value based on its <see cref="LegalityAnalysis"/>.
        /// </summary>
        /// <param name="name">Property to modify.</param>
        /// <param name="info">Cached info storing Legal data.</param>
        /// <param name="propValue">Suggestion string which starts with <see cref="CONST_SUGGEST"/></param>
        private static ModifyResult SetSuggestedPKMProperty(string name, PKMInfo info, string propValue)
        {
            bool isAll() => propValue.EndsWith("All", true, CultureInfo.CurrentCulture);
            bool isNone() => propValue.EndsWith("None", true, CultureInfo.CurrentCulture);

            var pk = info.Entity;

            switch (name)
            {
            // pb7 only
            case nameof(PB7.Stat_CP) when pk is PB7 pb7:
                pb7.ResetCP();
                return(ModifyResult.Modified);

            case nameof(PB7.HeightAbsolute) when pk is PB7 pb7:
                pb7.HeightAbsolute = pb7.CalcHeightAbsolute;
                return(ModifyResult.Modified);

            case nameof(PB7.WeightAbsolute) when pk is PB7 pb7:
                pb7.WeightAbsolute = pb7.CalcWeightAbsolute;
                return(ModifyResult.Modified);

            // Date Copy
            case nameof(PKM.EggMetDate):
                pk.EggMetDate = pk.MetDate;
                return(ModifyResult.Modified);

            case nameof(PKM.MetDate):
                pk.MetDate = pk.EggMetDate;
                return(ModifyResult.Modified);

            case nameof(PKM.Nature) when pk.Format >= 8:
                pk.Nature = pk.StatNature;
                return(ModifyResult.Modified);

            case nameof(PKM.StatNature) when pk.Format >= 8:
                pk.StatNature = pk.Nature;
                return(ModifyResult.Modified);

            case nameof(PKM.Stats):
                pk.ResetPartyStats();
                return(ModifyResult.Modified);

            case nameof(IHyperTrain.HyperTrainFlags):
                pk.SetSuggestedHyperTrainingData();
                return(ModifyResult.Modified);

            case nameof(PKM.RelearnMoves):
                if (pk.Format >= 8)
                {
                    pk.ClearRecordFlags();
                    if (isAll())
                    {
                        pk.SetRecordFlags();     // all
                    }
                    else if (!isNone())
                    {
                        pk.SetRecordFlags(pk.Moves);     // whatever fit the current moves
                    }
                }
                pk.SetRelearnMoves(info.SuggestedRelearn);
                return(ModifyResult.Modified);

            case PROP_RIBBONS:
                if (isNone())
                {
                    RibbonApplicator.RemoveAllValidRibbons(pk);
                }
                else     // All
                {
                    RibbonApplicator.SetAllValidRibbons(pk);
                }
                return(ModifyResult.Modified);

            case nameof(PKM.Met_Location):
                var encounter = EncounterSuggestion.GetSuggestedMetInfo(pk);
                if (encounter == null)
                {
                    return(ModifyResult.Error);
                }

                int level    = encounter.LevelMin;
                int location = encounter.Location;
                int minlvl   = EncounterSuggestion.GetLowestLevel(pk, encounter.LevelMin);

                pk.Met_Level    = level;
                pk.Met_Location = location;
                pk.CurrentLevel = Math.Max(minlvl, level);

                return(ModifyResult.Modified);

            case nameof(PKM.Heal):
                pk.Heal();
                return(ModifyResult.Modified);

            case nameof(PKM.HealPP):
                pk.HealPP();
                return(ModifyResult.Modified);

            case nameof(PKM.Move1_PP):
            case nameof(PKM.Move2_PP):
            case nameof(PKM.Move3_PP):
            case nameof(PKM.Move4_PP):
                pk.SetSuggestedMovePP(name[4] - '1');     // 0-3 int32
                return(ModifyResult.Modified);

            case nameof(PKM.Moves):
                return(SetMoves(pk, info.Legality.GetMoveSet()));

            case nameof(PKM.Ball):
                BallApplicator.ApplyBallLegalByColor(pk);
                return(ModifyResult.Modified);

            default:
                return(ModifyResult.Error);
            }
        }
Beispiel #13
0
        public PKM ConvertToPKM(ITrainerInfo SAV)
        {
            int gen = Version.GetGeneration();

            if (gen < 2)
            {
                gen     = 2;
                Version = GameVersion.C;
            }
            var pk = PKMConverter.GetBlank(gen);

            SAV.ApplyToPKM(pk);

            pk.Species      = Species;
            pk.Nickname     = PKX.GetSpeciesNameGeneration(Species, SAV.Language, gen);
            pk.CurrentLevel = Level;
            pk.Version      = (int)Version;
            int[] moves = GetCurrentEggMoves(pk);
            pk.Moves = moves;
            pk.SetMaximumPPCurrent(moves);
            pk.OT_Friendship = pk.PersonalInfo.BaseFriendship;

            pk.SetRandomIVs(flawless: 3);

            if (pk.Format <= 2 && Version != GameVersion.C)
            {
                return(pk);
            }

            pk.Met_Level    = EncounterSuggestion.GetSuggestedEncounterEggMetLevel(pk);
            pk.Met_Location = Math.Max(0, EncounterSuggestion.GetSuggestedEggMetLocation(pk));

            if (pk.Format < 3)
            {
                return(pk);
            }

            pk.Ball = 4;

            int gender = pk.PersonalInfo.RandomGender;
            int nature = Util.Rand.Next(25);

            if (pk.Format <= 5)
            {
                pk.SetPIDGender(gender);
                pk.Gender = gender;
                pk.SetPIDNature(nature);
                pk.Nature = nature;
                pk.RefreshAbility(pk.PIDAbility);
            }
            else
            {
                pk.PID    = Util.Rand32();
                pk.Nature = nature;
                pk.Gender = gender;
                pk.RefreshAbility(Util.Rand.Next(2));
            }

            bool traded = (int)Version == SAV.Game;
            var  today  = pk.MetDate = DateTime.Today;

            if (pk.GenNumber >= 4)
            {
                pk.Egg_Location = EncounterSuggestion.GetSuggestedEncounterEggLocationEgg(pk, traded);
                pk.EggMetDate   = today;
            }

            if (pk.Format < 6)
            {
                return(pk);
            }
            if (pk.Gen6)
            {
                pk.SetHatchMemory6();
            }

            switch (Species)
            {
            case 774:     // Minior
                pk.AltForm = Util.Rand.Next(7, 14);
                break;

            case 664:     // Scatterbug
                pk.AltForm = Legal.GetVivillonPattern(SAV.Country, SAV.SubRegion);
                break;
            }

            pk.SetRandomEC();
            pk.RelearnMoves = moves;

            return(pk);
        }