Пример #1
0
        internal static PKM convertToFormat(PKM pk, int Format, out string comment)
        {
            if (pk == null)
            {
                comment = "Null input. Aborting.";
                return(null);
            }
            if (pk.Format == Format)
            {
                comment = "No need to convert, current format matches requested format.";
                return(pk);
            }
            if (pk.Format > Format)
            {
                comment = "Cannot convert a PKM backwards." + Environment.NewLine
                          + "Current Format: " + pk.Format + Environment.NewLine
                          + "Desired Format: " + Format;
                return(null);
            }
            string currentFormat = pk.Format.ToString();
            PKM    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
                }
            }
            if (pkm.Format == 3 && Format > 3)
            {
                pkm = ((PK3)pkm).convertToPK4();
            }
            if (pkm.Format == 4 && Format > 4)
            {
                pkm = ((PK4)pkm).convertToPK5();
            }
            if (pkm.Format == 5 && Format > 5)
            {
                pkm = ((PK5)pkm).convertToPK6();
            }
            comment = $"Converted from pk{currentFormat} to pk{Format}";
            return(pkm);
        }
Пример #2
0
 internal static PKM convertToFormat(PKM pk, int Format, out string comment)
 {
     if (pk == null)
     {
         comment = "Null input. Aborting.";
         return null;
     }
     if (pk.Format == Format)
     {
         comment = "No need to convert, current format matches requested format.";
         return pk;
     }
     if (pk.Format > Format)
     {
         comment = "Cannot convert a PKM backwards." + Environment.NewLine
                   + "Current Format: " + pk.Format + Environment.NewLine
                   + "Desired Format: " + Format;
         return null;
     }
     string currentFormat = pk.Format.ToString();
     PKM 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
     }
     if (pkm.Format == 3 && Format > 3)
         pkm = (pkm as PK3).convertToPK4();
     if (pkm.Format == 4 && Format > 4)
         pkm = (pkm as PK4).convertToPK5();
     if (pkm.Format == 5 && Format > 5)
         pkm = (pkm as PK5).convertToPK6();
     comment = $"Converted from pk{currentFormat} to pk{Format}";
     return pkm;
 }
Пример #3
0
        internal static PKM convertToFormat(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());

            Console.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
                    }
                }
                switch (fromType.Name)
                {
                case "PK1":
                    if (toFormat == 2)
                    {
                        pkm = PKMType == typeof(PK2) ? ((PK1)pk).convertToPK2() : null;
                        break;
                    }
                    if (toFormat == 7)
                    {
                        pkm = null;     // pkm.convertPK1toPK7();
                    }
                    break;

                case "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();
                    }
                    else
                    {
                        pkm = null;
                    }
                    break;

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

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

                        case "XK3": pkm = pkm.convertToXK3(); break;

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

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

                    pkm = ((PK3)pkm).convertToPK4();
                    if (toFormat == 4)
                    {
                        if (PKMType == typeof(BK4))
                        {
                            pkm = ((PK4)pkm).convertToBK4();
                        }
                        break;
                    }
                    pkm = ((PK4)pkm).convertToPK5();
                    if (toFormat == 5)
                    {
                        break;
                    }
                    pkm = ((PK5)pkm).convertToPK6();
                    if (toFormat == 6)
                    {
                        break;
                    }
                    pkm = new PK7(pkm.Data, pkm.Identifier);
                    break;

                case "PK4":
                    if (PKMType == typeof(BK4))
                    {
                        pkm = ((PK4)pkm).convertToBK4();
                        break;
                    }
                    pkm = ((PK4)pkm).convertToPK5();
                    if (toFormat == 5)
                    {
                        break;
                    }
                    pkm = ((PK5)pkm).convertToPK6();
                    if (toFormat == 6)
                    {
                        break;
                    }
                    pkm = new PK7(pkm.Data, pkm.Identifier);
                    break;

                case "BK4":
                    pkm = ((BK4)pkm).convertToPK4();
                    if (toFormat == 4)
                    {
                        break;
                    }
                    pkm = ((PK4)pkm).convertToPK5();
                    if (toFormat == 5)
                    {
                        break;
                    }
                    pkm = ((PK5)pkm).convertToPK6();
                    if (toFormat == 6)
                    {
                        break;
                    }
                    pkm = new PK7(pkm.Data, pkm.Identifier);
                    break;

                case "PK5":
                    pkm = ((PK5)pkm).convertToPK6();
                    break;

                case "PK6":
                    pkm = new PK7(pkm.Data, pkm.Identifier);
                    break;
                }
            }

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

            return(pkm);
        }
Пример #4
0
        public void populateFields(PKM pk, bool focus = true)
        {
            if (pk == null) { Util.Error("Attempted to load a null file."); return; }

            if ((pk.Format >= 3 && pk.Format > SAV.Generation) // pk3-7, can't go backwards
                || (pk.Format <= 2 && SAV.Generation > 2 && SAV.Generation < 7)) // pk1-2, can't go 3-6
            { Util.Alert($"Can't load Gen{pk.Format} to Gen{SAV.Generation} games."); return; }

            bool oldInit = fieldsInitialized;
            fieldsInitialized = fieldsLoaded = false;
            if (focus)
                Tab_Main.Focus();

            pkm = pk.Clone();

            if (fieldsInitialized & !pkm.ChecksumValid)
                Util.Alert("PKX File has an invalid checksum.");

            if (pkm.Format != SAV.Generation) // past gen format
            {
                string c;
                pkm = PKMConverter.convertToFormat(pkm, SAV.PKMType, out c);
                if (pk.Format != pkm.Format && focus) // converted
                    Util.Alert("Converted File.");
            }

            try { getFieldsfromPKM(); }
            catch { fieldsInitialized = oldInit; throw; }

            CB_EncounterType.Visible = Label_EncounterType.Visible = pkm.Gen4;
            fieldsInitialized = oldInit;
            updateIVs(null, null);
            updatePKRSInfected(null, null);
            updatePKRSCured(null, null);

            if (HaX)
            {
                MT_Level.Text = pkm.Stat_Level.ToString();
                MT_Form.Text = pkm.AltForm.ToString();
                if (pkm.Stat_HPMax != 0) // stats present
                {
                    Stat_HP.Text = pkm.Stat_HPCurrent.ToString();
                    Stat_ATK.Text = pkm.Stat_ATK.ToString();
                    Stat_DEF.Text = pkm.Stat_DEF.ToString();
                    Stat_SPA.Text = pkm.Stat_SPA.ToString();
                    Stat_SPD.Text = pkm.Stat_SPD.ToString();
                    Stat_SPE.Text = pkm.Stat_SPE.ToString();
                }
            }
            fieldsLoaded = true;

            Label_HatchCounter.Visible = CHK_IsEgg.Checked && SAV.Generation > 1;
            Label_Friendship.Visible = !CHK_IsEgg.Checked && SAV.Generation > 1;

            // Set the Preview Box
            dragout.Image = pk.Sprite;
            updateLegality();
        }
        internal static PKM convertToFormat(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());
            Console.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
                }
                switch (fromType.Name)
                {
                    case "PK1":
                        if (toFormat == 2)
                        {
                            pkm = PKMType == typeof (PK2) ? ((PK1) pk).convertToPK2() : null;
                            break;
                        }
                        if (toFormat == 7)
                            pkm = null; // pkm.convertPK1toPK7();
                        break;
                    case "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();
                        }
                        else
                            pkm = null;
                        break;
                    case "CK3":
                    case "XK3":
                        // interconverting C/XD needs to visit main series format
                        // ends up stripping purification/shadow etc stats
                        pkm = pkm.convertToPK3();
                        goto case "PK3"; // fall through
                    case "PK3":
                        if (toFormat == 3) // Gen3 Inter-trading
                        {
                            switch (PKMType.Name)
                            {
                                case "CK3": pkm = pkm.convertToCK3(); break;
                                case "XK3": pkm = pkm.convertToXK3(); break;
                                case "PK3": pkm = pkm.convertToPK3(); break; // already converted, instantly returns
                                default: throw new FormatException();
                            }
                            break;
                        }
                        if (fromType.Name != "PK3")
                            pkm = pkm.convertToPK3();

                        pkm = ((PK3)pkm).convertToPK4();
                        if (toFormat == 4)
                        {
                            if (PKMType == typeof (BK4))
                                pkm = ((PK4) pkm).convertToBK4();
                            break;
                        }
                        pkm = ((PK4)pkm).convertToPK5();
                        if (toFormat == 5)
                            break;
                        pkm = ((PK5)pkm).convertToPK6();
                        if (toFormat == 6)
                            break;
                        pkm = new PK7(pkm.Data, pkm.Identifier);
                        break;
                    case "PK4":
                        if (PKMType == typeof(BK4))
                        {
                            pkm = ((PK4)pkm).convertToBK4();
                            break;
                        }
                        pkm = ((PK4)pkm).convertToPK5();
                        if (toFormat == 5)
                            break;
                        pkm = ((PK5)pkm).convertToPK6();
                        if (toFormat == 6)
                            break;
                        pkm = new PK7(pkm.Data, pkm.Identifier);
                        break;
                    case "BK4":
                        pkm = ((BK4)pkm).convertToPK4();
                        if (toFormat == 4)
                            break;
                        pkm = ((PK4)pkm).convertToPK5();
                        if (toFormat == 5)
                            break;
                        pkm = ((PK5)pkm).convertToPK6();
                        if (toFormat == 6)
                            break;
                        pkm = new PK7(pkm.Data, pkm.Identifier);
                        break;
                    case "PK5":
                        pkm = ((PK5)pkm).convertToPK6();
                        break;
                    case "PK6":
                        pkm = new PK7(pkm.Data, pkm.Identifier);
                        break;
                }
            }

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

            return pkm;
        }