Beispiel #1
0
        public static bool IsPKMCompatibleWithModifications(PKM pk, IGameValueLimit limit)
        {
            if (pk.Species > limit.MaxSpeciesID)
            {
                return(false);
            }

            if (pk.HeldItem > limit.MaxItemID)
            {
                pk.HeldItem = 0;
            }

            if (pk.Nickname.Length > limit.NickLength)
            {
                pk.Nickname = pk.Nickname.Substring(0, pk.NickLength);
            }

            if (pk.OT_Name.Length > limit.OTLength)
            {
                pk.OT_Name = pk.OT_Name.Substring(0, pk.OTLength);
            }

            if (pk.Moves.Any(move => move > limit.MaxMoveID))
            {
                pk.ClearInvalidMoves();
            }

            if (pk.EVs.Any(ev => ev > limit.MaxEV))
            {
                pk.EVs = pk.EVs.Select(ev => Math.Min(limit.MaxEV, ev)).ToArray();
            }

            if (pk.IVs.Any(iv => iv > limit.MaxIV))
            {
                pk.IVs = pk.IVs.Select(iv => Math.Min(limit.MaxIV, iv)).ToArray();
            }

            return(true);
        }
Beispiel #2
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="PKMType">Format/Type to convert to</param>
        /// <param name="comment">Comments regarding the transfer's success/failure</param>
        /// <returns>Converted PKM</returns>
        public static PKM ConvertToType(PKM pk, Type PKMType, out string comment)
        {
            if (pk == null)
            {
                comment = $"Bad {nameof(pk)} input. Aborting.";
                return(null);
            }

            Type fromType = pk.GetType();

            if (fromType == PKMType)
            {
                comment = "No need to convert, current format matches requested format.";
                return(pk);
            }

            if (IsNotTransferrable(pk, out comment))
            {
                return(null);
            }

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

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

            if (fromFormat > toFormat && fromFormat != 2)
            {
                comment = $"Cannot convert a {fromType.Name} to a {PKMType.Name}.";
                return(null);
            }

            PKM pkm = pk.Clone();

            if (pkm.IsEgg)
            {
                ForceHatchPKM(pkm);
            }

            switch (fromType.Name)
            {
            case nameof(PK1):
                if (toFormat == 7)     // VC->Bank
                {
                    pkm = ((PK1)pk).ConvertToPK7();
                }
                else if (toFormat == 2)     // GB<->GB
                {
                    pkm = ((PK1)pk).ConvertToPK2();
                }
                break;

            case nameof(PK2):
                if (toFormat == 7)     // VC->Bank
                {
                    pkm = ((PK2)pk).ConvertToPK7();
                }
                else if (toFormat == 1)     // GB<->GB
                {
                    if (pk.Species > 151)
                    {
                        comment = $"Cannot convert a {PKX.GetSpeciesName(pkm.Species, pkm.Japanese ? 1 : 2)} to {PKMType.Name}";
                        return(null);
                    }
                    pkm = ((PK2)pk).ConvertToPK1();
                    pkm.ClearInvalidMoves();
                }
                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
                {
                    pkm = InterConvertPK3(pkm, PKMType);
                    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;
                }
                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);
        }
Beispiel #3
0
        private static PKM ConvertPKM(PKM pk, Type PKMType, Type fromType, int toFormat, ref string comment)
        {
            PKM pkm = pk.Clone();

            if (pkm.IsEgg)
            {
                ForceHatchPKM(pkm);
            }

            switch (fromType.Name)
            {
            case nameof(PK1):
                if (toFormat == 7)     // VC->Bank
                {
                    pkm = ((PK1)pk).ConvertToPK7();
                }
                else if (toFormat == 2)     // GB<->GB
                {
                    pkm = ((PK1)pk).ConvertToPK2();
                }
                break;

            case nameof(PK2):
                if (toFormat == 7)     // VC->Bank
                {
                    pkm = ((PK2)pk).ConvertToPK7();
                }
                else if (toFormat == 1)     // GB<->GB
                {
                    if (pk.Species > 151)
                    {
                        comment = $"Cannot convert a {PKX.GetSpeciesName(pkm.Species, pkm.Japanese ? 1 : 2)} to {PKMType.Name}";
                        return(pkm);
                    }
                    pkm = ((PK2)pk).ConvertToPK1();
                    pkm.ClearInvalidMoves();
                }
                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
                {
                    pkm = InterConvertPK3(pkm, PKMType);
                    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;
                }
                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(pkm);
                }
                pkm = ((PK6)pkm).ConvertToPK7();
                if (toFormat == 7)
                {
                    break;
                }
                goto case nameof(PK7);

            case nameof(PK7):
                break;
            }
            return(pkm);
        }
Beispiel #4
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);
        }
Beispiel #5
0
        private static PKM ConvertPKM(PKM pk, Type PKMType, Type fromType, int toFormat, ref string comment)
        {
            PKM pkm = pk.Clone();

            if (pkm.IsEgg)
            {
                pkm.ForceHatchPKM();
            }

            switch (fromType.Name)
            {
            case nameof(PK1):
                if (toFormat == 7)     // VC->Bank
                {
                    pkm = ((PK1)pk).ConvertToPK7();
                }
                else if (toFormat == 2)     // GB<->GB
                {
                    pkm = ((PK1)pk).ConvertToPK2();
                }
                break;

            case nameof(PK2):
                if (toFormat == 7)     // VC->Bank
                {
                    pkm = ((PK2)pk).ConvertToPK7();
                }
                else if (toFormat == 1)     // GB<->GB
                {
                    if (pk.Species > 151)
                    {
                        comment = $"Cannot convert a {PKX.GetSpeciesName(pkm.Species, pkm.Japanese ? 1 : 2)} to {PKMType.Name}";
                        return(pkm);
                    }
                    pkm = ((PK2)pk).ConvertToPK1();
                    pkm.ClearInvalidMoves();
                }
                break;

            case nameof(CK3):
                pkm = ((CK3)pkm).ConvertToPK3();
                goto case nameof(PK3);     // fall through

            case nameof(XK3):
                pkm = ((XK3)pkm).ConvertToPK3();
                goto case nameof(PK3);     // fall through

            case nameof(PK3):
                if (toFormat == 3)
                {
                    if (PKMType == typeof(CK3))
                    {
                        pkm = ((PK3)pkm).ConvertToCK3();
                    }
                    else if (PKMType == typeof(XK3))
                    {
                        pkm = ((PK3)pkm).ConvertToXK3();
                    }
                    break;
                }

                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;
                }
                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(pkm);
                }
                pkm = ((PK6)pkm).ConvertToPK7();
                if (toFormat == 7)
                {
                    break;
                }
                goto case nameof(PK7);

            case nameof(PK7):
                break;
            }
            return(pkm);
        }