Ejemplo n.º 1
0
        /// <summary>
        /// Sets past-generation Pokemon as Battle Ready for games that support it
        /// </summary>
        /// <param name="pk">Return PKM</param>
        /// <param name="trainer">Trainer to handle the <see cref="pk"/></param>
        private static void ApplyBattleVersion(this PKM pk, ITrainerInfo trainer)
        {
            if (!SetBattleVersion)
            {
                return;
            }
            if (pk.IsNative)
            {
                return;
            }
            if (!(pk is IBattleVersion bvPk))
            {
                return;
            }

            var oldBattleVersion = bvPk.BattleVersion;
            var relearn          = pk.RelearnMoves;

            pk.ClearRelearnMoves();
            bvPk.BattleVersion = trainer.Game;

            var la = new LegalityAnalysis(pk);

            if (!la.Valid)
            {
                bvPk.BattleVersion = oldBattleVersion;
                pk.SetRelearnMoves(relearn);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sets the <see cref="PKM.RelearnMoves"/> based on a legality check's suggestions.
        /// </summary>
        /// <param name="pk"></param>
        public static void SetSuggestedRelearnMoves(this PKM pk)
        {
            if (pk.Format < 6)
            {
                return;
            }
            pk.ClearRelearnMoves();
            var la = new LegalityAnalysis(pk);

            var m = la.GetSuggestedRelearn();

            if (m.All(z => z == 0))
            {
                if (!pk.WasEgg && !pk.WasEvent && !pk.WasEventEgg && !pk.WasLink)
                {
                    if (pk.Version != (int)GameVersion.CXD)
                    {
                        var encounter = la.GetSuggestedMetInfo();
                        if (encounter != null)
                        {
                            m = encounter.Relearn;
                        }
                    }
                }
            }

            if (pk.RelearnMoves.SequenceEqual(m))
            {
                return;
            }
            if (m.Count > 3)
            {
                pk.SetRelearnMoves(m);
            }
        }
Ejemplo n.º 3
0
        private static bool InnerBruteForce(PKM pk, GameVersion game, bool shiny, int abilitynum, ShowdownSet set)
        {
            pk.ClearRelearnMoves();
            switch (game)
            {
            case GameVersion.RD:
            case GameVersion.BU:
            case GameVersion.YW:
            case GameVersion.GN:
                pk.Met_Location = 30013;
                pk.Met_Level    = 100;
                break;

            case GameVersion.GD:
            case GameVersion.SV:
            case GameVersion.C:
                pk.Met_Location = 30017;
                pk.Met_Level    = 100;
                break;

            case GameVersion.CXD:
                pk.Met_Location = 30001;
                pk.Met_Level    = 100;
                break;

            default:
                pk.SetSuggestedMetLocation();
                break;
            }
            pk.SetSuggestedRelearnMoves();
            pk.CurrentHandler = 1;
            pk.HT_Name        = "Archit";
            pk.PID            = PKX.GetRandomPID(pk.Species, pk.Gender, pk.Version, pk.Nature, pk.Format,
                                                 (uint)(pk.AbilityNumber * 0x10001));
            if (shiny)
            {
                pk.SetShiny();
            }
            if (pk.PID == 0)
            {
                pk.PID = PKX.GetRandomPID(pk.Species, pk.Gender, pk.Version, pk.Nature, pk.Format,
                                          (uint)(pk.AbilityNumber * 0x10001));
                if (shiny)
                {
                    pk.SetShiny();
                }
            }

            pk.RefreshAbility(abilitynum);
            pk.SetSuggestedMemories();
            if (pk.GenNumber < 6)
            {
                pk.EncryptionConstant = pk.PID;
            }

            if (CommonErrorHandling2(pk))
            {
                pk.HyperTrain();
                if (shiny)
                {
                    pk.SetShiny();
                }
                return(true);
            }

            pk.HyperTrain();
            bool legalized = new LegalityAnalysis(pk).Valid;

            AlternateAbilityRefresh(pk);
            if (pk.GenNumber < 6 && !legalized)
            {
                pk.EncryptionConstant = pk.PID;
            }

            if (new LegalityAnalysis(pk).Valid&& pk.Format >= pk.GenNumber)
            {
                pk.SetHappiness();
                if (shiny && pk.IsShiny)
                {
                    return(true);
                }
                if (!set.Shiny || pk.IsShiny)
                {
                    return(true);
                }

                pk.SetShinySID();
                if (new LegalityAnalysis(pk).Valid)
                {
                    return(true);
                }

                pk.SetShiny();
                if (new LegalityAnalysis(pk).Valid)
                {
                    return(true);
                }
            }
            else
            {
                var edge = EncounterMovesetGenerator.GenerateEncounters(pk).OfType <EncounterStatic>();
                foreach (EncounterStatic el in edge)
                {
                    ApplyEncounterAttributes(pk, set, el);
                    var la = new LegalityAnalysis(pk);
                    if (la.Valid)
                    {
                        return(true);
                    }
                    Debug.WriteLine(la.Report());
                }
            }

            return(false);
        }