Ejemplo n.º 1
0
 /// <summary>
 /// Checks if the input PK6 file is really a PK7, if so, updates the object.
 /// </summary>
 /// <param name="pk">PKM to check</param>
 /// <param name="prefer">Prefer a certain generation over another</param>
 /// <returns>Updated PKM if actually PK7</returns>
 private static PKM CheckPKMFormat7(PK6 pk, int prefer)
 {
     if (GameVersion.GG.Contains(pk.Version))
     {
         return(new PB7(pk.Data));
     }
     return(IsPK6FormatReallyPK7(pk, prefer) ? new PK7(pk.Data, pk.Identifier) : (PKM)pk);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates an instance of <see cref="PKM"/> from the given data.
        /// </summary>
        /// <param name="data">Raw data of the Pokemon file.</param>
        /// <param name="ident">Optional identifier for the Pokemon.  Usually the full path of the source file.</param>
        /// <returns>An instance of <see cref="PKM"/> created from the given <paramref name="data"/>, or null if <paramref name="data"/> is invalid.</returns>
        public static PKM getPKMfromBytes(byte[] data, string ident = null)
        {
            checkEncrypted(ref data);
            switch (getPKMDataFormat(data))
            {
            case 1:
                var PL1 = new PokemonList1(data, PokemonList1.CapacityType.Single, data.Length == PKX.SIZE_1JLIST);
                if (ident != null)
                {
                    PL1[0].Identifier = ident;
                }
                return(PL1[0]);

            case 2:
                var PL2 = new PokemonList2(data, PokemonList2.CapacityType.Single, data.Length == PKX.SIZE_2JLIST);
                if (ident != null)
                {
                    PL2[0].Identifier = ident;
                }
                return(PL2[0]);

            case 3:
                switch (data.Length)
                {
                case PKX.SIZE_3CSTORED: return(new CK3(data, ident));

                case PKX.SIZE_3XSTORED: return(new XK3(data, ident));

                default: return(new PK3(data, ident));
                }

            case 4:
                var pk = new PK4(data, ident);
                if (!pk.Valid || pk.Sanity != 0)
                {
                    var bk = new BK4(data, ident);
                    if (bk.Valid)
                    {
                        return(bk);
                    }
                }
                return(pk);

            case 5:
                return(new PK5(data, ident));

            case 6:
                PKM pkx = new PK6(data, ident);
                if (pkx.SM)
                {
                    pkx = new PK7(data, ident);
                }
                return(pkx);

            default:
                return(null);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates an instance of <see cref="PKM"/> from the given data.
        /// </summary>
        /// <param name="data">Raw data of the Pokemon file.</param>
        /// <param name="ident">Optional identifier for the Pokemon.  Usually the full path of the source file.</param>
        /// <param name="prefer">Optional identifier for the preferred generation.  Usually the generation of the destination save file.</param>
        /// <returns>An instance of <see cref="PKM"/> created from the given <paramref name="data"/>, or null if <paramref name="data"/> is invalid.</returns>
        public static PKM GetPKMfromBytes(byte[] data, string ident = null, int prefer = 7)
        {
            int format = GetPKMDataFormat(data);

            switch (format)
            {
            case 1:
                var PL1 = new PokeList1(data);
                if (ident != null)
                {
                    PL1[0].Identifier = ident;
                }
                return(PL1[0]);

            case 2:
                var PL2 = new PokeList2(data);
                if (ident != null)
                {
                    PL2[0].Identifier = ident;
                }
                return(PL2[0]);

            case 3:
                switch (data.Length)
                {
                case PKX.SIZE_3CSTORED: return(new CK3(data, ident));

                case PKX.SIZE_3XSTORED: return(new XK3(data, ident));

                default: return(new PK3(data, ident));
                }

            case 4:
                var pk = new PK4(data, ident);
                if (!pk.Valid || pk.Sanity != 0)
                {
                    var bk = new BK4(data, ident);
                    if (bk.Valid)
                    {
                        return(bk);
                    }
                }
                return(pk);

            case 5:
                return(new PK5(data, ident));

            case 6:
                var pkx = new PK6(data, ident);
                return(CheckPKMFormat7(pkx, prefer));

            default:
                return(null);
            }
        }
Ejemplo n.º 4
0
 private void B_Save_Click(object sender, EventArgs e)
 {
     for (int i = 0; i < seen.Length; i++)
     {
         PKM tempPkm = new PK6();
         tempPkm.Species = i + 1;
         SAV.setSeen(tempPkm, seen[i]);
         SAV.setCaught(tempPkm, caught[i]);
     }
     SAV.Data.CopyTo(Main.SAV.Data, 0);
     Main.SAV.Edited = true;
     Close();
 }
Ejemplo n.º 5
0
 protected override void setPKM(PKM pkm)
 {
     PK6 pk6 = pkm as PK6;
     // Apply to this Save File
     int CT = pk6.CurrentHandler;
     DateTime Date = DateTime.Now;
     pk6.Trade(OT, TID, SID, Country, SubRegion, Gender, false, Date.Day, Date.Month, Date.Year);
     if (CT != pk6.CurrentHandler) // Logic updated Friendship
     {
         // Copy over the Friendship Value only under certain circumstances
         if (pk6.Moves.Contains(216)) // Return
             pk6.CurrentFriendship = pk6.OppositeFriendship;
         else if (pk6.Moves.Contains(218)) // Frustration
             pkm.CurrentFriendship = pk6.OppositeFriendship;
     }
     pkm.RefreshChecksum();
 }
Ejemplo n.º 6
0
        public SAV_SimplePokedex()
        {
            InitializeComponent();
            WinFormsUtil.TranslateInterface(this, Main.curlanguage);
            seen = new bool[SAV.MaxSpeciesID];
            caught = new bool[SAV.MaxSpeciesID];

            string[] spec = Util.getSpeciesList(Main.curlanguage);
            for (int i = 0; i < seen.Length; i++)
            {
                PKM tempPkm = new PK6();
                tempPkm.Species = i + 1;
                seen[i] = SAV.getSeen(tempPkm);
                caught[i] = SAV.getCaught(tempPkm);
                CLB_Seen.Items.Add(spec[i + 1]);
                CLB_Caught.Items.Add(spec[i + 1]);
                CLB_Seen.SetItemChecked(i, seen[i]);
                CLB_Caught.SetItemChecked(i, caught[i]);
            }
            initialized = true;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Checks if the input PK6 file is really a PK7.
        /// </summary>
        /// <param name="pk">PK6 to check</param>
        /// <param name="preferredFormat">Prefer a certain generation over another</param>
        /// <returns>Boolean is a PK7</returns>
        private static bool IsPK6FormatReallyPK7(PK6 pk, int preferredFormat)
        {
            if (pk.Version > Legal.MaxGameID_6)
            {
                return(true);
            }
            if (pk.Enjoyment != 0 || pk.Fullness != 0)
            {
                return(false);
            }

            // Check Ranges
            if (pk.Species > Legal.MaxSpeciesID_6)
            {
                return(true);
            }
            if (pk.Moves.Any(move => move > Legal.MaxMoveID_6_AO))
            {
                return(true);
            }
            if (pk.RelearnMoves.Any(move => move > Legal.MaxMoveID_6_AO))
            {
                return(true);
            }
            if (pk.Ability > Legal.MaxAbilityID_6_AO)
            {
                return(true);
            }
            if (pk.HeldItem > Legal.MaxItemID_6_AO)
            {
                return(true);
            }

            int et = pk.EncounterType;

            if (et != 0)
            {
                if (pk.CurrentLevel < 100) // can't be hyper trained
                {
                    return(false);
                }

                if (pk.GenNumber != 4) // can't have encounter type
                {
                    return(true);
                }
                if (et > 24) // invalid encountertype
                {
                    return(true);
                }
            }

            int mb = BitConverter.ToUInt16(pk.Data, 0x16);

            if (mb > 0xAAA)
            {
                return(false);
            }
            for (int i = 0; i < 6; i++)
            {
                if ((mb >> (i << 1) & 3) == 3) // markings are 10 or 01 (or 00), never 11
                {
                    return(false);
                }
            }

            return(preferredFormat > 6);
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Checks if the input PK6 file is really a PK7, if so, updates the object.
 /// </summary>
 /// <param name="pk">PKM to check</param>
 /// <param name="prefer">Prefer a certain generation over another</param>
 /// <returns>Updated PKM if actually PK7</returns>
 private static PKM CheckPKMFormat7(PK6 pk, int prefer) => IsPK6FormatReallyPK7(pk, prefer) ? new PK7(pk.Data, pk.Identifier) : (PKM)pk;
Ejemplo n.º 9
0
        public static PKM convertToFormat(PKM pk, Type PKMType, out string comment)
        {
            bool timeMachine = true;

            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)
            {
                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 nameof(PK1):
                    pkm = PKMType == typeof(PK2) ? ((PK1)pk).convertToPK2() : null;
                    if (toFormat == 2)
                    {
                        break;
                    }
                    pkm = ((PK2)pk).convertToPK3();
                    if (toFormat == 3)
                    {
                        break;
                    }
                    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;

                //if (toFormat == 7)
                //    pkm = null; // pkm.convertPK1toPK7();
                //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();
                    //}
                    //else if (PKMType == typeof(PK3))
                    //{
                    //    pkm = ((PK2)pk).convertToPK3();
                    //}
                    //else
                    //    pkm = null;

                    pkm = ((PK2)pk).convertToPK3();
                    if (toFormat == 3)
                    {
                        break;
                    }
                    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 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 == 2)
                    {
                        pkm = ((PK3)pkm).convertToPK2();
                        break;
                    }
                    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;
                    }
                    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):
                    pkm = ((PK6)pkm).convertToPK7();
                    if (toFormat == 7)
                    {
                        break;
                    }
                    goto case nameof(PK7);

                case nameof(PK7):
                    break;
                }
            }

            else // fromFormat > toFormat - we're going backwards, normally unsupported - obviously not perfect, but its cool i guess
            {
                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 "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 "PK7":
                    if (
                        (toFormat == 6 && pk.Species > 721) ||
                        (toFormat == 5 && pk.Species > 649) ||
                        (toFormat == 4 && pk.Species > 493) ||
                        (toFormat == 3 && pk.Species > 386) ||
                        (toFormat == 2 && pk.Species > 251) ||
                        (toFormat == 1 && pk.Species > 151)
                        )
                    {
                        pkm = null; break;
                    }                          // how awkward im the worst

                    pkm = new PK6(pkm.Data, pkm.Identifier);
                    if (toFormat == 6)
                    {
                        break;
                    }
                    pkm = ((PK6)pkm).convertToPK5();
                    if (toFormat == 5)
                    {
                        break;
                    }
                    pkm = ((PK5)pkm).convertToPK4();
                    if (toFormat == 4)
                    {
                        break;
                    }
                    pkm = ((PK4)pkm).convertToPK3();
                    if (toFormat == 3)
                    {
                        break;
                    }
                    pkm = ((PK3)pkm).convertToPK2();
                    if (toFormat == 2)
                    {
                        break;
                    }
                    pkm = ((PK2)pkm).convertToPK1();
                    break;

                case "PK6":
                    if (
                        (toFormat == 5 && pk.Species > 649) ||
                        (toFormat == 4 && pk.Species > 493) ||
                        (toFormat == 3 && pk.Species > 386) ||
                        (toFormat == 2 && pk.Species > 251) ||
                        (toFormat == 1 && pk.Species > 151)
                        )
                    {
                        pkm = null; break;
                    }                               // how awkward im the worst

                    pkm = ((PK6)pkm).convertToPK5();
                    if (toFormat == 5)
                    {
                        break;
                    }
                    pkm = ((PK5)pkm).convertToPK4();
                    if (toFormat == 4)
                    {
                        break;
                    }
                    pkm = ((PK4)pkm).convertToPK3();
                    if (toFormat == 3)
                    {
                        break;
                    }
                    pkm = ((PK3)pkm).convertToPK2();
                    if (toFormat == 2)
                    {
                        break;
                    }
                    pkm = ((PK2)pkm).convertToPK1();
                    break;

                case "PK5":
                    if (
                        (toFormat == 4 && pk.Species > 493) ||
                        (toFormat == 3 && pk.Species > 386) ||
                        (toFormat == 2 && pk.Species > 251) ||
                        (toFormat == 1 && pk.Species > 151)
                        )
                    {
                        pkm = null; break;
                    }                               // how awkward im the worst

                    pkm = ((PK5)pkm).convertToPK4();
                    if (toFormat == 4)
                    {
                        break;
                    }
                    pkm = ((PK4)pkm).convertToPK3();
                    if (toFormat == 3)
                    {
                        break;
                    }
                    pkm = ((PK3)pkm).convertToPK2();
                    if (toFormat == 2)
                    {
                        break;
                    }
                    pkm = ((PK2)pkm).convertToPK1();
                    break;

                case "PK4":
                    if (
                        (toFormat == 3 && pk.Species > 386) ||
                        (toFormat == 2 && pk.Species > 251) ||
                        (toFormat == 1 && pk.Species > 151)
                        )
                    {
                        pkm = null; break;
                    }                               // how awkward im the worst

                    pkm = ((PK4)pkm).convertToPK3();
                    if (toFormat == 3)
                    {
                        break;
                    }
                    pkm = ((PK3)pkm).convertToPK2();
                    if (toFormat == 2)
                    {
                        break;
                    }
                    pkm = ((PK2)pkm).convertToPK1();
                    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 == 2 && pk.Species > 251) ||
                        (toFormat == 1 && pk.Species > 151)
                        )
                    {
                        pkm = null; break;
                    }                               // how awkward im the worst

                    pkm = ((PK3)pkm).convertToPK2();
                    if (toFormat == 2)
                    {
                        break;
                    }
                    pkm = ((PK2)pkm).convertToPK1();
                    break;
                }
            }

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

            return(pkm);
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Checks if the input PK6 file is really a PK7, if so, updates the object.
 /// </summary>
 /// <param name="pk">PKM to check</param>
 /// <param name="prefer">Prefer a certain generation over another</param>
 /// <returns>Updated PKM if actually PK7</returns>
 private static PKM checkPKMFormat7(PK6 pk, int prefer) => checkPK6is7(pk, prefer) ? new PK7(pk.Data, pk.Identifier) : (PKM)pk;
Ejemplo n.º 11
0
 /// <summary>
 /// Creates an instance of <see cref="PKM"/> from the given data.
 /// </summary>
 /// <param name="data">Raw data of the Pokemon file.</param>
 /// <param name="ident">Optional identifier for the Pokemon.  Usually the full path of the source file.</param>
 /// <returns>An instance of <see cref="PKM"/> created from the given <paramref name="data"/>, or null if <paramref name="data"/> is invalid.</returns>
 public static PKM getPKMfromBytes(byte[] data, string ident = null)
 {
     checkEncrypted(ref data);
     switch (getPKMDataFormat(data))
     {
         case 1:
             var PL1 = new PokemonList1(data, PokemonList1.CapacityType.Single, data.Length == PKX.SIZE_1JLIST);
             if (ident != null)
                 PL1[0].Identifier = ident;
             return PL1[0];
         case 2:
             var PL2 = new PokemonList2(data, PokemonList2.CapacityType.Single, data.Length == PKX.SIZE_2JLIST);
             if (ident != null)
                 PL2[0].Identifier = ident;
             return PL2[0];
         case 3:
             switch (data.Length) { 
                 case PKX.SIZE_3CSTORED: return new CK3(data, ident);
                 case PKX.SIZE_3XSTORED: return new XK3(data, ident);
                 default: return new PK3(data, ident);
             }
         case 4:
             var pk = new PK4(data, ident);
             if (!pk.Valid || pk.Sanity != 0)
             {
                 var bk = new BK4(data, ident);
                 if (bk.Valid)
                     return bk;
             }
             return pk;
         case 5:
             return new PK5(data, ident);
         case 6:
             PKM pkx = new PK6(data, ident);
             if (pkx.SM)
                 pkx = new PK7(data, ident);
             return pkx;
         default:
             return null;
     }
 }
Ejemplo n.º 12
0
        public override PKM convertToPKM(SaveFile SAV)
        {
            if (!IsPokémon)
            {
                return(null);
            }

            int currentLevel = Level > 0 ? Level : (int)(Util.rnd32() % 100 + 1);
            var pi           = PersonalTable.AO[Species];
            PK6 pk           = new PK6
            {
                Species            = Species,
                HeldItem           = HeldItem,
                TID                = TID,
                SID                = SID,
                Met_Level          = currentLevel,
                Nature             = Nature != 0xFF ? Nature : (int)(Util.rnd32() % 25),
                Gender             = Gender != 3 ? Gender : pi.RandomGender,
                AltForm            = Form,
                EncryptionConstant = EncryptionConstant != 0 ? EncryptionConstant : Util.rnd32(),
                Version            = OriginGame != 0 ? OriginGame : SAV.Game,
                Language           = Language != 0 ? Language : SAV.Language,
                Ball               = Ball,
                Country            = SAV.Country,
                Region             = SAV.SubRegion,
                ConsoleRegion      = SAV.ConsoleRegion,
                Move1              = Move1, Move2 = Move2, Move3 = Move3, Move4 = Move4,
                RelearnMove1       = RelearnMove1, RelearnMove2 = RelearnMove2,
                RelearnMove3       = RelearnMove3, RelearnMove4 = RelearnMove4,
                Met_Location       = MetLocation,
                Egg_Location       = EggLocation,
                CNT_Cool           = CNT_Cool,
                CNT_Beauty         = CNT_Beauty,
                CNT_Cute           = CNT_Cute,
                CNT_Smart          = CNT_Smart,
                CNT_Tough          = CNT_Tough,
                CNT_Sheen          = CNT_Sheen,

                OT_Name        = OT.Length > 0 ? OT : SAV.OT,
                OT_Gender      = OTGender != 3 ? OTGender % 2 : SAV.Gender,
                HT_Name        = OT.Length > 0 ? SAV.OT : "",
                HT_Gender      = OT.Length > 0 ? SAV.Gender : 0,
                CurrentHandler = OT.Length > 0 ? 1 : 0,

                EXP = PKX.getEXP(Level, Species),

                // Ribbons
                RibbonCountry  = RibbonCountry,
                RibbonNational = RibbonNational,

                RibbonEarth    = RibbonEarth,
                RibbonWorld    = RibbonWorld,
                RibbonClassic  = RibbonClassic,
                RibbonPremier  = RibbonPremier,
                RibbonEvent    = RibbonEvent,
                RibbonBirthday = RibbonBirthday,
                RibbonSpecial  = RibbonSpecial,
                RibbonSouvenir = RibbonSouvenir,

                RibbonWishing          = RibbonWishing,
                RibbonChampionBattle   = RibbonChampionBattle,
                RibbonChampionRegional = RibbonChampionRegional,
                RibbonChampionNational = RibbonChampionNational,
                RibbonChampionWorld    = RibbonChampionWorld,

                OT_Friendship    = pi.BaseFriendship,
                OT_Intensity     = OT_Intensity,
                OT_Memory        = OT_Memory,
                OT_TextVar       = OT_TextVar,
                OT_Feeling       = OT_Feeling,
                FatefulEncounter = true,

                EVs = EVs,
            };

            pk.Move1_PP = pk.getMovePP(Move1, 0);
            pk.Move2_PP = pk.getMovePP(Move2, 0);
            pk.Move3_PP = pk.getMovePP(Move3, 0);
            pk.Move4_PP = pk.getMovePP(Move4, 0);

            pk.MetDate = Date ?? DateTime.Now;

            if (SAV.Generation > 6 && OriginGame == 0) // Gen7
            {
                pk.Version = (int)GameVersion.OR;
            }

            if (pk.CurrentHandler == 0) // OT
            {
                pk.OT_Memory    = 3;
                pk.OT_TextVar   = 9;
                pk.OT_Intensity = 1;
                pk.OT_Feeling   = Util.rand.Next(0, 9);
            }
            else
            {
                pk.HT_Memory     = 3;
                pk.HT_TextVar    = 9;
                pk.HT_Intensity  = 1;
                pk.HT_Feeling    = Util.rand.Next(0, 9);
                pk.HT_Friendship = pk.OT_Friendship;
            }
            pk.IsNicknamed = IsNicknamed;
            pk.Nickname    = IsNicknamed ? Nickname : PKX.getSpeciesName(Species, pk.Language);

            // More 'complex' logic to determine final values

            // Dumb way to generate random IVs.
            int[] finalIVs = new int[6];
            switch (IVs[0])
            {
            case 0xFE:
                finalIVs[0] = 31;
                do       // 31 HP IV, 2 other 31s
                {
                    for (int i = 1; i < 6; i++)
                    {
                        finalIVs[i] = IVs[i] > 31 ? (int)(Util.rnd32() & 0x1F) : IVs[i];
                    }
                } while (finalIVs.Count(r => r == 31) < 3);     // 31 + 2*31
                break;

            case 0xFD:
                do       // 2 other 31s
                {
                    for (int i = 0; i < 6; i++)
                    {
                        finalIVs[i] = IVs[i] > 31 ? (int)(Util.rnd32() & 0x1F) : IVs[i];
                    }
                } while (finalIVs.Count(r => r == 31) < 2);     // 2*31
                break;

            default:     // Random IVs
                for (int i = 0; i < 6; i++)
                {
                    finalIVs[i] = IVs[i] > 31 ? (int)(Util.rnd32() & 0x1F) : IVs[i];
                }
                break;
            }
            pk.IVs = finalIVs;

            int av = 0;

            switch (AbilityType)
            {
            case 00:     // 0 - 0
            case 01:     // 1 - 1
            case 02:     // 2 - H
                av = AbilityType;
                break;

            case 03:     // 0/1
            case 04:     // 0/1/H
                av = (int)(Util.rnd32() % (AbilityType - 1));
                break;
            }
            pk.Ability       = PersonalTable.AO.getAbilities(Species, pk.AltForm)[av];
            pk.AbilityNumber = 1 << av;

            switch (PIDType)
            {
            case 00:     // Specified
                pk.PID = PID;
                break;

            case 01:     // Random
                pk.PID = Util.rnd32();
                break;

            case 02:     // Random Shiny
                pk.PID = Util.rnd32();
                pk.PID = (uint)(((TID ^ SID ^ (pk.PID & 0xFFFF)) << 16) + (pk.PID & 0xFFFF));
                break;

            case 03:     // Random Nonshiny
                do
                {
                    pk.PID = Util.rnd32();
                } while ((uint)(((TID ^ SID ^ (pk.PID & 0xFFFF)) << 16) + (pk.PID & 0xFFFF)) < 16);
                break;
            }

            if (IsEgg)
            {
                pk.IsEgg      = true;
                pk.EggMetDate = Date;
            }

            pk.RefreshChecksum();
            return(pk);
        }
Ejemplo n.º 13
0
Archivo: WC6.cs Proyecto: kwsch/PKHeX
        public override PKM convertToPKM(SaveFile SAV)
        {
            if (!IsPokémon)
                return null;

            int currentLevel = Level > 0 ? Level : (int)(Util.rnd32()%100 + 1);
            PK6 pk = new PK6
            {
                Species = Species,
                HeldItem = HeldItem,
                TID = TID,
                SID = SID,
                Met_Level = currentLevel,
                Nature = Nature != 0xFF ? Nature : (int)(Util.rnd32() % 25),
                Gender = PersonalTable.AO[Species].Gender == 255 ? 2 : (Gender != 3 ? Gender : PersonalTable.AO[Species].RandomGender),
                AltForm = Form,
                EncryptionConstant = EncryptionConstant == 0 ? Util.rnd32() : EncryptionConstant,
                Version = OriginGame == 0 ? SAV.Game : OriginGame,
                Language = Language == 0 ? SAV.Language : Language,
                Ball = Ball,
                Country = SAV.Country,
                Region = SAV.SubRegion,
                ConsoleRegion = SAV.ConsoleRegion,
                Move1 = Move1, Move2 = Move2, Move3 = Move3, Move4 = Move4,
                RelearnMove1 = RelearnMove1, RelearnMove2 = RelearnMove2,
                RelearnMove3 = RelearnMove3, RelearnMove4 = RelearnMove4,
                Met_Location = MetLocation,
                Egg_Location = EggLocation,
                CNT_Cool = CNT_Cool,
                CNT_Beauty = CNT_Beauty,
                CNT_Cute = CNT_Cute,
                CNT_Smart = CNT_Smart,
                CNT_Tough = CNT_Tough,
                CNT_Sheen = CNT_Sheen,

                OT_Name = OT.Length > 0 ? OT : SAV.OT,
                OT_Gender = OTGender != 3 ? OTGender % 2 : SAV.Gender,
                HT_Name = OT.Length > 0 ? SAV.OT : "",
                HT_Gender = OT.Length > 0 ? SAV.Gender : 0,
                CurrentHandler = OT.Length > 0 ? 1 : 0,
                
                EXP = PKX.getEXP(Level, Species),

                // Ribbons
                RibbonCountry = RibbonCountry,
                RibbonNational = RibbonNational,

                RibbonEarth = RibbonEarth,
                RibbonWorld = RibbonWorld,
                RibbonClassic = RibbonClassic,
                RibbonPremier = RibbonPremier,
                RibbonEvent = RibbonEvent,
                RibbonBirthday = RibbonBirthday,
                RibbonSpecial = RibbonSpecial,
                RibbonSouvenir = RibbonSouvenir,

                RibbonWishing = RibbonWishing,
                RibbonChampionBattle = RibbonChampionBattle,
                RibbonChampionRegional = RibbonChampionRegional,
                RibbonChampionNational = RibbonChampionNational,
                RibbonChampionWorld = RibbonChampionWorld,
                
                OT_Friendship = PersonalTable.AO[Species].BaseFriendship,
                OT_Intensity = OT_Intensity,
                OT_Memory = OT_Memory,
                OT_TextVar = OT_TextVar,
                OT_Feeling = OT_Feeling,
                FatefulEncounter = true,

                EVs = EVs,
            };
            pk.Move1_PP = pk.getMovePP(Move1, 0);
            pk.Move2_PP = pk.getMovePP(Move2, 0);
            pk.Move3_PP = pk.getMovePP(Move3, 0);
            pk.Move4_PP = pk.getMovePP(Move4, 0);

            pk.MetDate = Date ?? DateTime.Now;

            if (SAV.Generation > 6) // Gen7
            {
                pk.Version = (int)GameVersion.OR;
            }

            if (pk.CurrentHandler == 0) // OT
            {
                pk.OT_Memory = 3;
                pk.OT_TextVar = 9;
                pk.OT_Intensity = 1;
                pk.OT_Feeling = Util.rand.Next(0, 9);
            }
            else
            {
                pk.HT_Memory = 3;
                pk.HT_TextVar = 9;
                pk.HT_Intensity = 1;
                pk.HT_Feeling = Util.rand.Next(0, 9);
                pk.HT_Friendship = pk.OT_Friendship;
            }
            pk.IsNicknamed = IsNicknamed;
            pk.Nickname = IsNicknamed ? Nickname : PKX.getSpeciesName(Species, pk.Language);

            // More 'complex' logic to determine final values
            
            // Dumb way to generate random IVs.
            int[] finalIVs = new int[6];
            switch (IVs[0])
            {
                case 0xFE:
                    finalIVs[0] = 31;
                    do { // 31 HP IV, 2 other 31s
                    for (int i = 1; i < 6; i++)
                        finalIVs[i] = IVs[i] > 31 ? (int)(Util.rnd32() & 0x1F) : IVs[i];
                    } while (finalIVs.Count(r => r == 31) < 3); // 31 + 2*31
                    break;
                case 0xFD: 
                    do { // 2 other 31s
                    for (int i = 0; i < 6; i++)
                        finalIVs[i] = IVs[i] > 31 ? (int)(Util.rnd32() & 0x1F) : IVs[i];
                    } while (finalIVs.Count(r => r == 31) < 2); // 2*31
                    break;
                default: // Random IVs
                    for (int i = 0; i < 6; i++)
                        finalIVs[i] = IVs[i] > 31 ? (int)(Util.rnd32() & 0x1F) : IVs[i];
                    break;
            }
            pk.IVs = finalIVs;

            int av = 0;
            switch (AbilityType)
            {
                case 00: // 0 - 0
                case 01: // 1 - 1
                case 02: // 2 - H
                    av = AbilityType;
                    break;
                case 03: // 0/1
                case 04: // 0/1/H
                    av = (int)(Util.rnd32()%(AbilityType - 1));
                    break;
            }
            pk.Ability = PersonalTable.AO.getAbilities(Species, pk.AltForm)[av];
            pk.AbilityNumber = 1 << av;

            switch (PIDType)
            {
                case 00: // Specified
                    pk.PID = PID;
                    break;
                case 01: // Random
                    pk.PID = Util.rnd32();
                    break;
                case 02: // Random Shiny
                    pk.PID = Util.rnd32();
                    pk.PID = (uint)(((TID ^ SID ^ (pk.PID & 0xFFFF)) << 16) + (pk.PID & 0xFFFF));
                    break;
                case 03: // Random Nonshiny
                    do { pk.PID = Util.rnd32(); } while ((uint)(((TID ^ SID ^ (pk.PID & 0xFFFF)) << 16) + (pk.PID & 0xFFFF)) < 16);
                    break;
            }

            if (IsEgg)
            {
                pk.IsEgg = true;
                pk.EggMetDate = Date;
            }

            pk.RefreshChecksum();
            return pk;
        }