Esempio n. 1
0
        /// <summary>
        /// Converts a PKM from one Generation 3 format to another. If it matches the destination format, the conversion will automatically return.
        /// </summary>
        /// <param name="pk">PKM to convert</param>
        /// <param name="desiredFormatType">Format/Type to convert to</param>
        /// <remarks><see cref="PK3"/>, <see cref="CK3"/>, and <see cref="XK3"/> are supported.</remarks>
        /// <returns>Converted PKM</returns>
        private static PKM InterConvertPK3(PKM pk, Type desiredFormatType)
        {
            // if already converted it instantly returns
            switch (desiredFormatType.Name)
            {
            case nameof(CK3):
                return(pk.ConvertToCK3());

            case nameof(XK3):
                return(pk.ConvertToXK3());

            case nameof(PK3):
                return(pk.ConvertToPK3());

            default: throw new FormatException();
            }
        }
Esempio n. 2
0
        public static PKM ConvertToType(PKM pk, Type PKMType, out string comment)
        {
            if (pk == null || pk.Species == 0)
            {
                comment = "Null input. Aborting.";
                return(null);
            }

            Type fromType   = pk.GetType();
            int  fromFormat = int.Parse(fromType.Name.Last().ToString());
            int  toFormat   = int.Parse(PKMType.Name.Last().ToString());

            Debug.WriteLine($"Trying to convert {fromType.Name} to {PKMType.Name}.");

            PKM pkm = null;

            if (fromType == PKMType)
            {
                comment = "No need to convert, current format matches requested format.";
                return(pk);
            }
            if (fromFormat <= toFormat || fromFormat == 2)
            {
                pkm = pk.Clone();
                if (pkm.IsEgg) // force hatch
                {
                    pkm.IsEgg = false;
                    if (pkm.AO)
                    {
                        pkm.Met_Location = 318; // Battle Resort
                    }
                    else if (pkm.XY)
                    {
                        pkm.Met_Location = 38; // Route 7
                    }
                    else if (pkm.Gen5)
                    {
                        pkm.Met_Location = 16; // Route 16
                    }
                    else
                    {
                        pkm.Met_Location = 30001; // Pokétransfer
                    }
                    pkm.IsNicknamed = false;
                    pkm.Nickname    = PKX.GetSpeciesNameGeneration(pkm.Species, pkm.Language, fromFormat);
                }
                switch (fromType.Name)
                {
                case nameof(PK1):
                    if (toFormat == 2)
                    {
                        pkm = PKMType == typeof(PK2) ? ((PK1)pk).ConvertToPK2() : null;
                        break;
                    }
                    if (toFormat == 7)
                    {
                        pkm = ((PK1)pk).ConvertToPK7();
                    }
                    break;

                case nameof(PK2):
                    if (PKMType == typeof(PK1))
                    {
                        if (pk.Species > 151)
                        {
                            comment = $"Cannot convert a {PKX.GetSpeciesName(pkm.Species, ((PK2)pkm).Japanese ? 1 : 2)} to {PKMType.Name}";
                            return(null);
                        }
                        pkm = ((PK2)pk).ConvertToPK1();
                        pkm.ClearInvalidMoves();
                    }
                    else
                    {
                        pkm = null;
                    }
                    break;

                case nameof(CK3):
                case nameof(XK3):
                    // interconverting C/XD needs to visit main series format
                    // ends up stripping purification/shadow etc stats
                    pkm = pkm.ConvertToPK3();
                    goto case nameof(PK3);     // fall through

                case nameof(PK3):
                    if (toFormat == 3)     // Gen3 Inter-trading
                    {
                        switch (PKMType.Name)
                        {
                        case nameof(CK3): pkm = pkm.ConvertToCK3(); break;

                        case nameof(XK3): pkm = pkm.ConvertToXK3(); break;

                        case nameof(PK3): pkm = pkm.ConvertToPK3(); break;         // already converted, instantly returns

                        default: throw new FormatException();
                        }
                        break;
                    }
                    if (fromType.Name != nameof(PK3))
                    {
                        pkm = pkm.ConvertToPK3();
                    }

                    pkm = ((PK3)pkm).ConvertToPK4();
                    if (toFormat == 4)
                    {
                        break;
                    }
                    goto case nameof(PK4);

                case nameof(BK4):
                    pkm = ((BK4)pkm).ConvertToPK4();
                    if (toFormat == 4)
                    {
                        break;
                    }
                    goto case nameof(PK4);

                case nameof(PK4):
                    if (PKMType == typeof(BK4))
                    {
                        pkm = ((PK4)pkm).ConvertToBK4();
                        break;
                    }
                    if (pkm.Species == 172 && pkm.AltForm != 0)
                    {
                        comment = "Cannot transfer Spiky-Eared Pichu forward.";
                        return(null);
                    }
                    pkm = ((PK4)pkm).ConvertToPK5();
                    if (toFormat == 5)
                    {
                        break;
                    }
                    goto case nameof(PK5);

                case nameof(PK5):
                    pkm = ((PK5)pkm).ConvertToPK6();
                    if (toFormat == 6)
                    {
                        break;
                    }
                    goto case nameof(PK6);

                case nameof(PK6):
                    if (pkm.Species == 25 && pkm.AltForm != 0)     // cosplay pikachu
                    {
                        comment = "Cannot transfer Cosplay Pikachu forward.";
                        return(null);
                    }
                    pkm = ((PK6)pkm).ConvertToPK7();
                    if (toFormat == 7)
                    {
                        break;
                    }
                    goto case nameof(PK7);

                case nameof(PK7):
                    break;
                }
            }

            comment = pkm == null
                ? $"Cannot convert a {fromType.Name} to a {PKMType.Name}."
                : $"Converted from {fromType.Name} to {PKMType.Name}.";

            return(pkm);
        }