Ejemplo n.º 1
0
        /// <summary>
        /// Sets the <see cref="PKM"/> property to a non-specific smart value.
        /// </summary>
        /// <param name="pkm">Pokémon to modify.</param>
        /// <param name="cmd">Modification</param>
        private static bool SetComplexProperty(PKM pkm, StringInstruction cmd)
        {
            if (cmd.PropertyName == nameof(pkm.MetDate))
            {
                pkm.MetDate = DateTime.ParseExact(cmd.PropertyValue, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None);
            }
            else if (cmd.PropertyName == nameof(pkm.EggMetDate))
            {
                pkm.EggMetDate = DateTime.ParseExact(cmd.PropertyValue, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None);
            }
            else if (cmd.PropertyName == nameof(pkm.EncryptionConstant) && cmd.PropertyValue == CONST_RAND)
            {
                pkm.EncryptionConstant = Util.Rand32();
            }
            else if ((cmd.PropertyName == nameof(pkm.Ability) || cmd.PropertyName == nameof(pkm.AbilityNumber)) && cmd.PropertyValue.StartsWith("$"))
            {
                pkm.RefreshAbility(Convert.ToInt16(cmd.PropertyValue[1]) - 0x30);
            }
            else if (cmd.PropertyName == nameof(pkm.PID) && cmd.PropertyValue == CONST_RAND)
            {
                pkm.SetPIDGender(pkm.Gender);
            }
            else if (cmd.PropertyName == nameof(pkm.EncryptionConstant) && cmd.PropertyValue == nameof(pkm.PID))
            {
                pkm.EncryptionConstant = pkm.PID;
            }
            else if (cmd.PropertyName == nameof(pkm.PID) && cmd.PropertyValue == CONST_SHINY)
            {
                pkm.SetShinyPID();
            }
            else if (cmd.PropertyName == nameof(pkm.Species) && cmd.PropertyValue == "0")
            {
                pkm.Data = new byte[pkm.Data.Length];
            }
            else if (cmd.PropertyName.StartsWith("IV") && cmd.PropertyValue == CONST_RAND)
            {
                SetRandomIVs(pkm, cmd);
            }
            else if (cmd.PropertyName == nameof(pkm.IsNicknamed) && string.Equals(cmd.PropertyValue, "false", StringComparison.OrdinalIgnoreCase))
            {
                pkm.IsNicknamed = false; pkm.Nickname = PKX.GetSpeciesNameGeneration(pkm.Species, pkm.Language, pkm.Format);
            }
            else
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
        public void ApplyToPKM(PKM pkm)
        {
            if (Species < 0)
            {
                return;
            }
            pkm.Species = Species;

            if (Nickname != null && Nickname.Length <= pkm.NickLength)
            {
                pkm.Nickname = Nickname;
            }
            else
            {
                pkm.Nickname = PKX.GetSpeciesName(pkm.Species, pkm.Language);
            }

            int gender = PKX.GetGenderFromString(Gender);

            pkm.Gender = Math.Max(0, gender);

            var list    = PKX.GetFormList(pkm.Species, types, forms, genders);
            int formnum = Array.IndexOf(list, Form);

            pkm.AltForm = Math.Max(0, formnum);

            var abils = pkm.PersonalInfo.Abilities;
            int index = Array.IndexOf(abils, Ability);

            pkm.RefreshAbility(Math.Max(0, Math.Min(2, index)));

            if (Shiny && !pkm.IsShiny)
            {
                pkm.SetShinyPID();
            }
            else if (!Shiny && pkm.IsShiny)
            {
                pkm.PID = Util.Rand32();
            }

            pkm.CurrentLevel      = Level;
            pkm.HeldItem          = Math.Max(0, HeldItem);
            pkm.CurrentFriendship = Friendship;
            pkm.Nature            = Nature;
            pkm.EVs   = EVs;
            pkm.IVs   = IVs;
            pkm.Moves = Moves;
        }