/// <summary>
        /// Gets possible encounters that allow all moves requested to be learned.
        /// </summary>
        /// <param name="pk">Rough Pokémon data which contains the requested species, gender, and form.</param>
        /// <param name="generation">Specific generation to iterate versions for.</param>
        /// <param name="moves">Moves that the resulting <see cref="IEncounterable"/> must be able to learn.</param>
        /// <returns>A consumable <see cref="IEncounterable"/> list of possible encounters.</returns>
        public static IEnumerable <IEncounterable> GenerateEncounter(PKM pk, int generation, int[]?moves = null)
        {
            var vers = GameUtil.GetVersionsInGeneration(generation, pk.Version);

            return(GenerateEncounters(pk, moves, vers));
        }
        /// <summary>
        /// Gets possible <see cref="PKM"/> objects that allow all moves requested to be learned within a specific generation.
        /// </summary>
        /// <param name="pk">Rough Pokémon data which contains the requested species, gender, and form.</param>
        /// <param name="info">Trainer information of the receiver.</param>
        /// <param name="generation">Specific generation to iterate versions for.</param>
        /// <param name="moves">Moves that the resulting <see cref="IEncounterable"/> must be able to learn.</param>
        public static IEnumerable <PKM> GeneratePKMs(PKM pk, ITrainerInfo info, int generation, int[]?moves = null)
        {
            var vers = GameUtil.GetVersionsInGeneration(generation, pk.Version);

            return(GeneratePKMs(pk, info, moves, vers));
        }
Example #3
0
        /// <summary>
        /// Creates an instance of a SaveFile with a blank base.
        /// </summary>
        /// <param name="generation">Generation of the Save File.</param>
        /// <param name="trainerName">Trainer Name</param>
        /// <returns>Save File for that generation.</returns>
        public static SaveFile GetBlankSAV(int generation, string trainerName)
        {
            var ver = GameUtil.GetVersion(generation);

            return(GetBlankSAV(ver, trainerName));
        }
Example #4
0
        /// <summary>
        /// Creates an instance of a SaveFile with a blank base.
        /// </summary>
        /// <param name="generation">Generation of the Save File.</param>
        /// <param name="OT">Trainer Name</param>
        /// <returns>Save File for that generation.</returns>
        public static SaveFile getBlankSAV(int generation, string OT)
        {
            var ver = GameUtil.getVersion(generation);

            return(getBlankSAV(ver, OT));
        }
Example #5
0
        private CheckResult VerifyAbility(LegalityAnalysis data)
        {
            var pkm = data.pkm;
            var pi  = data.PersonalInfo;

            // Check ability is possible (within bounds)
            int ability   = pkm.Ability;
            int abilIndex = pi.GetAbilityIndex(ability);

            if (abilIndex < 0)
            {
                return(GetInvalid(LAbilityUnexpected));
            }

            var abilities = pi.Abilities;
            int format    = pkm.Format;

            if (format >= 6)
            {
                var num = pkm.AbilityNumber;
                if (!IsValidAbilityBits(num))
                {
                    return(INVALID);
                }

                // Check AbilityNumber points to ability
                int an = num >> 1;
                if (an >= abilities.Count || abilities[an] != ability)
                {
                    return(INVALID);
                }

                // Check AbilityNumber for transfers without unique abilities
                int gen = data.Info.Generation;
                if (gen is 3 or 4 or 5 && num != 4)
                {
                    // To determine AbilityNumber [PK5->PK6], check if the first ability in Personal matches the ability.
                    // It is not possible to flip it to the other index as capsule requires unique abilities.
                    if (abilities[0] == abilities[1] && num != 1)
                    {
                        // Check if any pre-evolution could have it flipped.
                        var evos = data.Info.EvoChainsAllGens[6];
                        var pt   = GameData.GetPersonal(GameUtil.GetVersion(format));
                        if (!GetWasDual(evos, pt, pkm))
                        {
                            return(INVALID);
                        }
                    }
                }
            }

            if (format >= 8) // Ability Patch
            {
                if (pkm.AbilityNumber == 4 && !pkm.LA)
                {
                    if (CanAbilityPatch(format, abilities, pkm.Species))
                    {
                        return(GetValid(LAbilityPatchUsed));
                    }

                    var e = data.EncounterOriginal;

                    if (e.Species != pkm.Species && CanAbilityPatch(format, PKX.Personal.GetFormEntry(e.Species, e.Form).Abilities, e.Species))
                    {
                        return(GetValid(LAbilityPatchUsed));
                    }

                    // Verify later, it may be encountered with its hidden ability without using an ability patch.
                }
            }

            var enc = data.EncounterMatch;

            if (enc is MysteryGift {
                Generation : >= 4
            } g)
            {
                return(VerifyAbilityMG(data, g, abilities));
            }

            if (format < 6)
            {
                return(VerifyAbility345(data, enc, abilities, abilIndex));
            }

            return(VerifyAbility(data, abilities, abilIndex));
        }
Example #6
0
        private CheckResult VerifyAbility(LegalityAnalysis data)
        {
            var pkm = data.pkm;
            var pi  = data.PersonalInfo;

            // Check ability is possible (within bounds)
            int ability = pkm.Ability;
            int abilval = pi.GetAbilityIndex(ability);

            if (abilval < 0)
            {
                return(GetInvalid(LAbilityUnexpected));
            }

            var abilities = pi.Abilities;
            int format    = pkm.Format;

            if (format >= 6)
            {
                // Check AbilityNumber is a single set bit
                var num = pkm.AbilityNumber;
                if (!(num != 0 && (num & (num - 1)) == 0)) // not [!zero, and power of 2]
                {
                    return(GetInvalid(LAbilityMismatchFlag));
                }

                // Check AbilityNumber points to ability
                int an = num >> 1;
                if (an >= abilities.Count || abilities[an] != ability)
                {
                    return(GetInvalid(LAbilityMismatchFlag));
                }

                // Check AbilityNumber for transfers without unique abilities
                int gen = data.Info.Generation;
                if (gen is 3 or 4 or 5 && num != 4)
                {
                    // To determine AbilityNumber [PK5->PK6], check if the first ability in Personal matches the ability.
                    // It is not possible to flip it to the other index as capsule requires unique abilities.
                    if (abilities[0] == abilities[1] && num != 1)
                    {
                        // Check if any pre-evolution could have it flipped.
                        var evos = data.Info.EvoChainsAllGens[6];
                        var pt   = GameData.GetPersonal(GameUtil.GetVersion(pkm.Format));
                        if (!GetWasDual(evos, pt, pkm))
                        {
                            return(GetInvalid(LAbilityMismatchFlag));
                        }
                    }
                }
            }

            if (format >= 8) // Ability Patch
            {
                if (pkm.AbilityNumber == 4 && CanAbilityPatch(format, abilities, pkm.Species))
                    return(GetValid(LAbilityPatchUsed));
            }

            var enc = data.EncounterMatch;

            if (enc is MysteryGift {
                Generation : >= 4
            } g)
            {
                return(VerifyAbilityMG(data, g, abilities));
            }

            if (format < 6)
            {
                return(VerifyAbility345(data, enc, abilities, abilval));
            }

            return(VerifyAbility(data, abilities, abilval));
        }