Exemple #1
0
    protected BulkStorage(byte[] data, Type t, int start, int slotsPerBox = 30) : base(data)
    {
        Box         = start;
        SlotsPerBox = slotsPerBox;

        blank = EntityBlank.GetBlank(t);
        var slots = (Data.Length - Box) / blank.SIZE_STORED;

        BoxCount = slots / SlotsPerBox;
    }
Exemple #2
0
        /// <summary>
        /// Imports a <see cref="set"/> to create a new <see cref="PKM"/> with a context of <see cref="tr"/>.
        /// </summary>
        /// <param name="tr">Source/Destination trainer</param>
        /// <param name="set">Set data to import</param>
        /// <param name="msg">Result code indicating success or failure</param>
        /// <returns>Legalized PKM (hopefully legal)</returns>
        public static PKM GetLegalFromSet(this ITrainerInfo tr, IBattleTemplate set, out LegalizationResult msg)
        {
            var template = EntityBlank.GetBlank(tr);

            if (template.Version == 0)
            {
                template.Version = tr.Game;
            }
            template.ApplySetDetails(set);
            return(tr.GetLegalFromSet(set, template, out msg));
        }
Exemple #3
0
        /// <summary>
        /// Gets a legal <see cref="PKM"/> from a random in-game encounter's data.
        /// </summary>
        /// <param name="tr">Trainer Data to use in generating the encounter</param>
        /// <param name="species">Species ID to generate</param>
        /// <param name="form">Form to generate; if left null, picks first encounter</param>
        /// <param name="shiny"></param>
        /// <param name="alpha"></param>
        /// <param name="attempt"></param>
        /// <param name="pk">Result legal pkm</param>
        /// <returns>True if a valid result was generated, false if the result should be ignored.</returns>
        public static bool GetRandomEncounter(this ITrainerInfo tr, int species, int?form, bool shiny, bool alpha, ref int attempt, out PKM?pk)
        {
            var blank = EntityBlank.GetBlank(tr);

            pk = GetRandomEncounter(blank, tr, species, form, shiny, alpha, ref attempt);
            if (pk == null)
            {
                return(false);
            }

            pk = EntityConverter.ConvertToType(pk, blank.GetType(), out _);
            return(pk != null);
        }
Exemple #4
0
        public void HiddenPowerTest(int h, int a, int b, int c, int d, int s, MoveType type, int power, Type pkmType)
        {
            var pkm = EntityBlank.GetBlank(pkmType);

            pkm.IV_HP  = h;
            pkm.IV_ATK = a;
            pkm.IV_DEF = b;
            pkm.IV_SPA = c;
            pkm.IV_SPD = d;
            pkm.IV_SPE = s;

            pkm.HPType.Should().Be((int)type - 1); // no normal type, down-shift by 1
            pkm.HPPower.Should().Be(power);
        }
        public static void HasSmogonSets(Type t, GameVersion game, int species, int form = 0)
        {
            var blank = EntityBlank.GetBlank(t);

            blank.Version = (int)game;
            blank.Species = species;
            blank.Form    = form;

            var smogon = new SmogonSetList(blank);

            smogon.Valid.Should().BeTrue("Sets should exist for this setup");
            var count = smogon.Sets.Count;

            count.Should().BeGreaterThan(0, "At least one set should exist");
            smogon.SetConfig.Count.Should().Be(count, "Unparsed text should be captured and match result count");
            smogon.SetText.Count.Should().Be(count, "Reformatted text should be captured and match result count");
        }
Exemple #6
0
    /// <summary>
    /// Converts a PKM from one Generation format to another. If it matches the destination format, the conversion will automatically return.
    /// </summary>
    /// <param name="pk">PKM to convert</param>
    /// <param name="destType">Format/Type to convert to</param>
    /// <param name="result">Comments regarding the transfer's success/failure</param>
    /// <returns>Converted PKM</returns>
    public static PKM?ConvertToType(PKM pk, Type destType, out EntityConverterResult result)
    {
        Type fromType = pk.GetType();

        if (fromType == destType)
        {
            result = None;
            return(pk);
        }

        var entity = ConvertPKM(pk, destType, fromType, out result);

        if (entity is not null)
        {
            if (RejuvenateHOME != EntityRejuvenationSetting.None)
            {
                RejuvenatorHOME.Rejuvenate(entity, pk);
            }
            return(entity);
        }

        if (AllowIncompatibleConversion != EntityCompatibilitySetting.AllowIncompatibleAll)
        {
            if (result is not NoTransferRoute)
            {
                return(null);
            }
            if (AllowIncompatibleConversion != EntityCompatibilitySetting.AllowIncompatibleSane)
            {
                return(null);
            }
        }

        // Try Incompatible Conversion
        entity = EntityBlank.GetBlank(destType);
        pk.TransferPropertiesWithReflection(entity);
        if (!IsCompatibleWithModifications(entity))
        {
            return(null); // NoTransferRoute
        }
        result = SuccessIncompatibleReflection;
        return(entity);
    }
    /// <summary>
    /// Gets all encounters where a <see cref="species"/> can learn all input <see cref="moves"/>.
    /// </summary>
    public static IEnumerable <IEncounterable> GetLearn(int species, int[] moves, int form = 0)
    {
        if (species <= 0)
        {
            return(Array.Empty <IEncounterable>());
        }
        if (moves.Any(z => z < 0))
        {
            return(Array.Empty <IEncounterable>());
        }

        var blank = EntityBlank.GetBlank(PKX.Generation);

        blank.Species = species;
        blank.Form    = form;

        var vers = GameUtil.GameVersions;

        return(EncounterMovesetGenerator.GenerateEncounters(blank, moves, vers));
    }
Exemple #8
0
    /// <summary>
    /// Converts a PKM from one Generation format to another. If it matches the destination format, the conversion will automatically return.
    /// </summary>
    /// <param name="pk">PKM to convert</param>
    /// <param name="destType">Format/Type to convert to</param>
    /// <param name="result">Comments regarding the transfer's success/failure</param>
    /// <returns>Converted PKM</returns>
    public static PKM?ConvertToType(PKM pk, Type destType, out EntityConverterResult result)
    {
        Type fromType = pk.GetType();

        if (fromType == destType)
        {
            result = None;
            return(pk);
        }

        var pkm = ConvertPKM(pk, destType, fromType, out result);

        if (!AllowIncompatibleConversion || pkm != null)
        {
            return(pkm);
        }

        if (pk is PK8 && destType == typeof(PB8))
        {
            result = SuccessIncompatibleManual;
            return(new PB8((byte[])pk.Data.Clone()));
        }

        if (pk is PB8 && destType == typeof(PK8))
        {
            result = SuccessIncompatibleManual;
            return(new PK8((byte[])pk.Data.Clone()));
        }

        // Try Incompatible Conversion
        pkm = EntityBlank.GetBlank(destType);
        pk.TransferPropertiesWithReflection(pkm);
        if (!IsCompatibleWithModifications(pkm))
        {
            return(null); // NoTransferRoute
        }
        result = SuccessIncompatibleReflection;
        return(pkm);
    }
Exemple #9
0
        /// <summary>
        /// Gets a legal <see cref="PKM"/> from a random in-game encounter's data.
        /// </summary>
        /// <param name="blank">Template data that will have its properties modified</param>
        /// <param name="tr">Trainer Data to use in generating the encounter</param>
        /// <param name="species">Species ID to generate</param>
        /// <param name="form">Form to generate; if left null, picks first encounter</param>
        /// <param name="shiny"></param>
        /// <param name="alpha"></param>
        /// <param name="attempt"></param>
        /// <returns>Result legal pkm, null if data should be ignored.</returns>
        private static PKM?GetRandomEncounter(PKM blank, ITrainerInfo tr, int species, int?form, bool shiny, bool alpha, ref int attempt)
        {
            blank.Species = species;
            blank.Gender  = blank.GetSaneGender();
            if (species is ((int)Species.Meowstic)or((int)Species.Indeedee))
            {
                if (form == null)
                {
                    blank.Form = blank.Gender;
                }
                else
                {
                    blank.Gender = (int)form;
                }
            }

            var template = EntityBlank.GetBlank(tr.Generation, (GameVersion)tr.Game);

            if (form != null)
            {
                blank.Form = (int)form;
                var item = GetFormSpecificItem(tr.Game, blank.Species, (int)form);
                if (item != null)
                {
                    blank.HeldItem = (int)item;
                }
                if (blank.Species == (int)Species.Keldeo && blank.Form == 1)
                {
                    blank.Move1 = (int)Move.SecretSword;
                }
            }
            if (form == null)
            {
                var f = GetAvailableForm(blank);
                if (f == -1)
                {
                    return(null);
                }
                blank.Form = f;
            }
            if (blank.GetIsFormInvalid(tr, blank.Form))
            {
                return(null);
            }
            attempt++;
            var ssettext = new ShowdownSet(blank).Text.Split('\r')[0];

            if (shiny && !SimpleEdits.IsShinyLockedSpeciesForm(blank.Species, blank.Form))
            {
                ssettext += Environment.NewLine + "Shiny: Yes";
            }
            if (template is IAlpha && alpha)
            {
                ssettext += Environment.NewLine + "Alpha: Yes";
            }
            var sset = new ShowdownSet(ssettext);
            var set  = new RegenTemplate(sset)
            {
                Nickname = string.Empty
            };

            template.ApplySetDetails(set);
            var success = tr.TryAPIConvert(set, template, out PKM pk);

            if (success == LegalizationResult.Regenerated)
            {
                if (form == null)
                {
                    return(pk);
                }
                if (pk.Form == (int)form)
                {
                    return(pk);
                }
            }

            // just get a legal pkm and return. Only validate form and not shininess or alpha.
            var legalencs = EncounterMovesetGenerator.GeneratePKMs(blank, tr).Where(z => new LegalityAnalysis(z).Valid);
            var firstenc  = GetFirstEncounter(legalencs, form);

            if (firstenc == null)
            {
                attempt--;
                return(null);
            }
            var originspecies = firstenc.Species;

            if (originspecies != blank.Species)
            {
                firstenc.Species      = blank.Species;
                firstenc.CurrentLevel = 100;
                if (!firstenc.IsNicknamed)
                {
                    firstenc.Nickname = SpeciesName.GetSpeciesNameGeneration(firstenc.Species, firstenc.Language, firstenc.Format);
                }
                firstenc.SetMoves(firstenc.GetMoveSet());
                firstenc.RefreshAbility(firstenc.AbilityNumber >> 1);
            }
            var second = EntityConverter.ConvertToType(firstenc, blank.GetType(), out _);

            if (second == null)
            {
                return(null);
            }
            second.HeldItem = blank.HeldItem;
            if (second is IScaledSizeValue sv)
            {
                sv.HeightAbsolute = sv.CalcHeightAbsolute;
                sv.WeightAbsolute = sv.CalcWeightAbsolute;
            }
            if (form == null || second.Form == (int)form)
            {
                return(second);
            }
            // force form and check legality as a last ditch effort.
            second.Form = (int)form;
            second.SetSuggestedFormArgument(originspecies);
            if (second is IScaledSizeValue sc)
            {
                sc.HeightAbsolute = sc.CalcHeightAbsolute;
                sc.WeightAbsolute = sc.CalcWeightAbsolute;
            }
            if (new LegalityAnalysis(second).Valid)
            {
                return(second);
            }
            return(null);
        }