Ejemplo n.º 1
0
        public override PKM convertToPKM(SaveFile SAV)
        {
            if (!IsPokémon)
            {
                return(null);
            }

            DateTime dt = DateTime.Now;

            if (Day == 0)
            {
                Day   = (byte)dt.Day;
                Month = (byte)dt.Month;
                Year  = (byte)dt.Year;
            }
            int currentLevel = Level > 0 ? Level : (int)(Util.rnd32() % 100 + 1);
            PK5 pk           = new PK5
            {
                Species      = Species,
                HeldItem     = HeldItem,
                Met_Level    = currentLevel,
                Nature       = Nature != 0xFF ? Nature : (int)(Util.rnd32() % 25),
                Gender       = PersonalTable.B2W2[Species].Gender == 255 ? 2 : (Gender != 2 ? Gender : PersonalTable.B2W2[Species].RandomGender),
                AltForm      = Form,
                Version      = OriginGame == 0 ? new[] { 20, 21, 22, 23 }[Util.rnd32() & 0x3] : OriginGame,
                Language     = Language == 0 ? SAV.Language : Language,
                Ball         = Pokéball,
                Move1        = Move1,
                Move2        = Move2,
                Move3        = Move3,
                Move4        = Move4,
                Met_Location = MetLocation,
                MetDate      = Date,
                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,

                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.B2W2[Species].BaseFriendship,
                FatefulEncounter = true,
            };

            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);
            if (OTGender == 3) // User's
            {
                pk.TID       = SAV.TID;
                pk.SID       = SAV.SID;
                pk.OT_Name   = SAV.OT;
                pk.OT_Gender = 1; // Red PKHeX OT
            }
            else
            {
                pk.TID       = IsEgg ? SAV.TID : TID;
                pk.SID       = IsEgg ? SAV.SID : SID;
                pk.OT_Name   = OT.Length > 0 ? OT : SAV.OT;
                pk.OT_Gender = OTGender % 2; // %2 just in case?
            }
            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];
            for (int i = 0; i < IVs.Length; i++)
            {
                finalIVs[i] = IVs[i] == 0xFF ? (int)(Util.rnd32() & 0x1F) : IVs[i];
            }
            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.HiddenAbility = av == 2;
            pk.Ability       = PersonalTable.B2W2.getAbilities(Species, pk.AltForm)[av];

            if (PID != 0)
            {
                pk.PID = PID;
            }
            else
            {
                pk.PID = Util.rnd32();
                // Force Ability
                if (av == 0)
                {
                    pk.PID &= 0xFFFEFFFF;
                }
                else
                {
                    pk.PID |= 0x10000;
                }
                // Force Gender
                do
                {
                    pk.PID = (pk.PID & 0xFFFFFF00) | Util.rnd32() & 0xFF;
                } while (!pk.getGenderIsValid());
                if (PIDType == 2) // Force Shiny
                {
                    uint gb = pk.PID & 0xFF;
                    pk.PID = (uint)(((gb ^ pk.TID ^ pk.SID) & 0xFFFE) << 16) | gb;
                    if (av == 0)
                    {
                        pk.PID &= 0xFFFEFFFE;
                    }
                    else
                    {
                        pk.PID |= 0x10001;
                    }
                }
                else if (PIDType != 1) // Force Not Shiny
                {
                    if (((pk.PID >> 16) ^ (pk.PID & 0xffff) ^ pk.SID ^ pk.TID) < 8)
                    {
                        pk.PID ^= 0x80000000;
                    }
                }
            }

            if (IsEgg)
            {
                // pk.IsEgg = true;
                pk.EggMetDate = Date;
                // Force hatch
                pk.IsEgg        = false;
                pk.Met_Location = 4; // Nuvema Town
            }

            pk.RefreshChecksum();
            return(pk);
        }
Ejemplo n.º 2
0
        private PKM preparePK5()
        {
            PK5 pk5 = pkm as PK5;

            if (pk5 == null)
            {
                return(null);
            }

            pk5.Species  = Util.getIndex(CB_Species);
            pk5.HeldItem = Util.getIndex(CB_HeldItem);
            pk5.TID      = Util.ToInt32(TB_TID.Text);
            pk5.SID      = Util.ToInt32(TB_SID.Text);
            pk5.EXP      = Util.ToUInt32(TB_EXP.Text);
            pk5.PID      = Util.getHEXval(TB_PID.Text);

            pk5.Nature           = (byte)Util.getIndex(CB_Nature);
            pk5.FatefulEncounter = CHK_Fateful.Checked;
            pk5.Gender           = PKX.getGender(Label_Gender.Text);
            pk5.AltForm          = (MT_Form.Enabled ? Convert.ToInt32(MT_Form.Text) : CB_Form.Enabled ? CB_Form.SelectedIndex : 0) & 0x1F;
            pk5.EV_HP            = Util.ToInt32(TB_HPEV.Text);
            pk5.EV_ATK           = Util.ToInt32(TB_ATKEV.Text);
            pk5.EV_DEF           = Util.ToInt32(TB_DEFEV.Text);
            pk5.EV_SPE           = Util.ToInt32(TB_SPEEV.Text);
            pk5.EV_SPA           = Util.ToInt32(TB_SPAEV.Text);
            pk5.EV_SPD           = Util.ToInt32(TB_SPDEV.Text);

            pk5.CNT_Cool   = Util.ToInt32(TB_Cool.Text);
            pk5.CNT_Beauty = Util.ToInt32(TB_Beauty.Text);
            pk5.CNT_Cute   = Util.ToInt32(TB_Cute.Text);
            pk5.CNT_Smart  = Util.ToInt32(TB_Smart.Text);
            pk5.CNT_Tough  = Util.ToInt32(TB_Tough.Text);
            pk5.CNT_Sheen  = Util.ToInt32(TB_Sheen.Text);

            pk5.PKRS_Days   = CB_PKRSDays.SelectedIndex;
            pk5.PKRS_Strain = CB_PKRSStrain.SelectedIndex;
            pk5.Nickname    = TB_Nickname.Text;
            pk5.Move1       = Util.getIndex(CB_Move1);
            pk5.Move2       = Util.getIndex(CB_Move2);
            pk5.Move3       = Util.getIndex(CB_Move3);
            pk5.Move4       = Util.getIndex(CB_Move4);
            pk5.Move1_PP    = Util.getIndex(CB_Move1) > 0 ? Util.ToInt32(TB_PP1.Text) : 0;
            pk5.Move2_PP    = Util.getIndex(CB_Move2) > 0 ? Util.ToInt32(TB_PP2.Text) : 0;
            pk5.Move3_PP    = Util.getIndex(CB_Move3) > 0 ? Util.ToInt32(TB_PP3.Text) : 0;
            pk5.Move4_PP    = Util.getIndex(CB_Move4) > 0 ? Util.ToInt32(TB_PP4.Text) : 0;
            pk5.Move1_PPUps = Util.getIndex(CB_Move1) > 0 ? CB_PPu1.SelectedIndex : 0;
            pk5.Move2_PPUps = Util.getIndex(CB_Move2) > 0 ? CB_PPu2.SelectedIndex : 0;
            pk5.Move3_PPUps = Util.getIndex(CB_Move3) > 0 ? CB_PPu3.SelectedIndex : 0;
            pk5.Move4_PPUps = Util.getIndex(CB_Move4) > 0 ? CB_PPu4.SelectedIndex : 0;

            pk5.IV_HP       = Util.ToInt32(TB_HPIV.Text);
            pk5.IV_ATK      = Util.ToInt32(TB_ATKIV.Text);
            pk5.IV_DEF      = Util.ToInt32(TB_DEFIV.Text);
            pk5.IV_SPE      = Util.ToInt32(TB_SPEIV.Text);
            pk5.IV_SPA      = Util.ToInt32(TB_SPAIV.Text);
            pk5.IV_SPD      = Util.ToInt32(TB_SPDIV.Text);
            pk5.IsEgg       = CHK_IsEgg.Checked;
            pk5.IsNicknamed = CHK_Nicknamed.Checked;

            pk5.OT_Name           = TB_OT.Text;
            pk5.CurrentFriendship = Util.ToInt32(TB_Friendship.Text);

            // Default Dates
            DateTime?egg_date     = null;
            int      egg_location = 0;

            if (CHK_AsEgg.Checked) // If encountered as an egg, load the Egg Met data from fields.
            {
                egg_date     = CAL_EggDate.Value;
                egg_location = Util.getIndex(CB_EggLocation);
            }
            // Egg Met Data
            pk5.EggMetDate   = egg_date;
            pk5.Egg_Location = egg_location;
            // Met Data
            pk5.MetDate      = CAL_MetDate.Value;
            pk5.Met_Location = Util.getIndex(CB_MetLocation);

            if (pk5.IsEgg && pk5.Met_Location == 0)    // If still an egg, it has no hatch location/date. Zero it!
            {
                pk5.MetDate = null;
            }

            pk5.Ball          = Util.getIndex(CB_Ball);
            pk5.Met_Level     = Util.ToInt32(TB_MetLevel.Text);
            pk5.OT_Gender     = PKX.getGender(Label_OTGender.Text);
            pk5.EncounterType = Util.getIndex(CB_EncounterType);
            pk5.Version       = Util.getIndex(CB_GameOrigin);
            pk5.Language      = Util.getIndex(CB_Language);

            // Toss in Party Stats
            Array.Resize(ref pk5.Data, pk5.SIZE_PARTY);
            pk5.Stat_Level     = Util.ToInt32(TB_Level.Text);
            pk5.Stat_HPCurrent = Util.ToInt32(Stat_HP.Text);
            pk5.Stat_HPMax     = Util.ToInt32(Stat_HP.Text);
            pk5.Stat_ATK       = Util.ToInt32(Stat_ATK.Text);
            pk5.Stat_DEF       = Util.ToInt32(Stat_DEF.Text);
            pk5.Stat_SPE       = Util.ToInt32(Stat_SPE.Text);
            pk5.Stat_SPA       = Util.ToInt32(Stat_SPA.Text);
            pk5.Stat_SPD       = Util.ToInt32(Stat_SPD.Text);

            if (HaX)
            {
                pk5.Ability    = (byte)Util.getIndex(DEV_Ability);
                pk5.Stat_Level = (byte)Math.Min(Convert.ToInt32(MT_Level.Text), byte.MaxValue);
            }
            else
            {
                pk5.Ability       = (byte)Array.IndexOf(abilitylist, CB_Ability.Text.Remove(CB_Ability.Text.Length - 4));
                pk5.HiddenAbility = CB_Ability.SelectedIndex > 1; // not 0 or 1
            }

            // Fix Moves if a slot is empty
            pk5.FixMoves();

            pk5.RefreshChecksum();
            return(pk5);
        }
Ejemplo n.º 3
0
        public PK5 convertToPK5(SAV6 SAV)
        {
            if (!IsPokémon)
                return null;

            DateTime dt = DateTime.Now;
            if (Day == 0)
            {
                Day = (byte)dt.Day;
                Month = (byte)dt.Month;
                Year = (byte)dt.Year;
            }
            int currentLevel = Level > 0 ? Level : (int)(Util.rnd32() % 100 + 1);
            PK5 pk = new PK5
            {
                Species = Species,
                HeldItem = HeldItem,
                Met_Level = currentLevel,
                Nature = Nature != 0xFF ? Nature : (int)(Util.rnd32() % 25),
                Gender = PKX.Personal[Species].Gender == 255 ? 2 : (Gender != 2 ? Gender : PKX.Personal[Species].RandomGender),
                AltForm = Form,
                Version = OriginGame == 0 ? new[] {20, 21, 22, 23}[Util.rnd32() & 0x3] : OriginGame,
                Language = Language == 0 ? SAV.Language : Language,
                Ball = Pokéball,
                Move1 = Move1,
                Move2 = Move2,
                Move3 = Move3,
                Move4 = Move4,
                Move1_PP = PKX.getBasePP(Move1),
                Move2_PP = PKX.getBasePP(Move2),
                Move3_PP = PKX.getBasePP(Move3),
                Move4_PP = PKX.getBasePP(Move4),
                Met_Location = MetLocation,
                Met_Day = Day,
                Met_Month = Month,
                Met_Year = Year - 2000,
                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,

                EXP = PKX.getEXP(Level, Species),

                // Ribbons
                RIB7_4 = RIB0_0, // Country Ribbon
                RIB7_5 = RIB0_1, // National Ribbon
                RIB7_6 = RIB0_2, // Earth Ribbon
                RIB7_7 = RIB0_3, // World Ribbon
                RIB3_2 = RIB0_4, // Classic Ribbon
                RIB3_3 = RIB0_5, // Premier Ribbon
                RIB2_3 = RIB0_6, // Event Ribbon
                RIB2_6 = RIB0_7, // Birthday Ribbon

                RIB2_7 = RIB1_0, // Special Ribbon
                RIB3_0 = RIB1_1, // Souvenir Ribbon
                RIB3_1 = RIB1_2, // Wishing Ribbon
                RIB7_1 = RIB1_3, // Battle Champ Ribbon
                RIB7_2 = RIB1_4, // Regional Champ Ribbon
                RIB7_3 = RIB1_5, // National Champ Ribbon
                RIB2_5 = RIB1_6, // World Champ Ribbon

                Friendship = PKX.getBaseFriendship(Species),
                FatefulEncounter = true,
            };
            if (OTGender == 3) // User's
            {
                pk.TID = 12345;
                pk.SID = 54321;
                pk.OT_Name = "PKHeX";
                pk.OT_Gender = 1; // Red PKHeX OT
            }
            else
            {
                pk.TID = TID;
                pk.SID = SID;
                pk.OT_Name = OT.Length > 0 ? OT : "PKHeX";
                pk.OT_Gender = OTGender % 2; // %2 just in case?
            }
            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];
            for (int i = 0; i < IVs.Length; i++)
                finalIVs[i] = IVs[i] == 0xFF ? (int)(Util.rnd32() & 0x1F) : IVs[i];
            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.HiddenAbility = av == 2;
            pk.Ability = PKX.Personal[PKX.Personal[Species].FormeIndex(Species, pk.AltForm)].Abilities[av];

            if (PID != 0) 
                pk.PID = PID;
            else
            {
                pk.PID = Util.rnd32();
                // Force Ability
                if (av == 0) pk.PID &= 0xFFFEFFFF; else pk.PID |= 0x10000;
                // Force Gender
                do { pk.PID = (pk.PID & 0xFFFFFF00) | Util.rnd32() & 0xFF; } while (!pk.getGenderIsValid());
                if (PIDType == 2) // Force Shiny
                {
                    uint gb = pk.PID & 0xFF;
                    pk.PID = (uint)(((gb ^ pk.TID ^ pk.SID) & 0xFFFE) << 16) | gb;
                    if (av == 0) pk.PID &= 0xFFFEFFFE; else pk.PID |= 0x10001;
                }
                else if (PIDType != 1) // Force Not Shiny
                {
                    if (((pk.PID >> 16) ^ (pk.PID & 0xffff) ^ pk.SID ^ pk.TID) < 8)
                        pk.PID ^= 0x80000000;
                }
            }

            if (IsEgg)
            {
                // pk.IsEgg = true;
                pk.Egg_Day = Day;
                pk.Egg_Month = Month;
                pk.Egg_Year = Year - 2000;
                // Force hatch
                pk.IsEgg = false;
                pk.Met_Location = 4; // Nuvema Town
            }

            pk.RefreshChecksum();
            return pk;
        }
Ejemplo n.º 4
0
        public PK5 convertToPK5()
        {
            // Double Check Location Data to see if we're already a PK5
            if (Data[0x5F] < 0x10 && BitConverter.ToUInt16(Data, 0x80) > 0x4000)
            {
                return(new PK5(Data));
            }

            DateTime moment = DateTime.Now;

            PK5 pk5 = new PK5(Data) // Convert away!
            {
                HeldItem      = 0,
                OT_Friendship = 70,
                // Apply new met date
                Met_Year  = moment.Year - 2000,
                Met_Month = moment.Month,
                Met_Day   = moment.Day
            };

            // Fix PP
            pk5.Move1_PP = getMovePP(pk5.Move1_PP, pk5.Move1_PPUps);
            pk5.Move2_PP = getMovePP(pk5.Move2_PP, pk5.Move2_PPUps);
            pk5.Move3_PP = getMovePP(pk5.Move3_PP, pk5.Move3_PPUps);
            pk5.Move4_PP = getMovePP(pk5.Move4_PP, pk5.Move4_PPUps);

            // Disassociate Nature and PID
            pk5.Nature = (int)(pk5.PID % 25);

            // Delete Platinum/HGSS Met Location Data
            BitConverter.GetBytes((uint)0).CopyTo(pk5.Data, 0x44);

            // Met / Crown Data Detection
            pk5.Met_Location = pk5.FatefulEncounter && Array.IndexOf(new[] { 251, 243, 244, 245 }, pk5.Species) >= 0
                ? (pk5.Species == 251 ? 30010 : 30012) // Celebi : Beast
                : 30001;                               // Pokétransfer (not Crown)

            // Delete HGSS Data
            BitConverter.GetBytes((ushort)0).CopyTo(pk5.Data, 0x86);
            if (HGSSBall > 0 && HGSSBall != 4)
            {
                pk5.Ball = HGSSBall;
            }

            // Transfer Nickname and OT Name
            pk5.Nickname = Nickname;
            pk5.OT_Name  = OT_Name;

            // Fix Level
            pk5.Met_Level = PKX.getLevel(pk5.Species, pk5.EXP);

            // Remove HM moves; Defog should be kept if both are learned.
            int[] banned = Moves.Contains(250) /*Whirlpool*/ && !Moves.Contains(432) /*Defog*/
                ? new[] { 15, 19, 57, 70, 432, 249, 127, 431 } // No Defog
                : new[] { 15, 19, 57, 70, 250, 249, 127, 431 };                      // No Whirlpool

            int[] newMoves = pk5.Moves;
            for (int i = 0; i < 4; i++)
            {
                if (banned.Contains(newMoves[i]))
                {
                    newMoves[i] = 0;
                }
            }
            pk5.Moves = newMoves;
            pk5.FixMoves();

            pk5.RefreshChecksum();
            return(pk5);
        }
Ejemplo n.º 5
0
        public PK5 convertToPK5()
        {
            // Double Check Location Data to see if we're already a PK5
            if (Data[0x5F] < 0x10 && BitConverter.ToUInt16(Data, 0x80) > 0x4000)
                return new PK5(Data);

            DateTime moment = DateTime.Now;

            PK5 pk5 = new PK5(Data) // Convert away!
            {
                HeldItem = 0,
                OT_Friendship = 70,
                // Apply new met date
                Met_Year = moment.Year - 2000,
                Met_Month = moment.Month,
                Met_Day = moment.Day
            };

            // Fix PP
            pk5.Move1_PP = PKX.getMovePP(pk5.Move1_PP, pk5.Move1_PPUps);
            pk5.Move2_PP = PKX.getMovePP(pk5.Move2_PP, pk5.Move2_PPUps);
            pk5.Move3_PP = PKX.getMovePP(pk5.Move3_PP, pk5.Move3_PPUps);
            pk5.Move4_PP = PKX.getMovePP(pk5.Move4_PP, pk5.Move4_PPUps);

            // Disassociate Nature and PID
            pk5.Nature = (int)(pk5.PID % 25);

            // Delete Platinum/HGSS Met Location Data
            BitConverter.GetBytes((uint)0).CopyTo(pk5.Data, 0x44);

            // Met / Crown Data Detection
            pk5.Met_Location = pk5.FatefulEncounter && Array.IndexOf(new[] {251, 243, 244, 245}, pk5.Species) >= 0
                ? (pk5.Species == 251 ? 30010 : 30012) // Celebi : Beast
                : 30001; // Pokétransfer (not Crown)

            // Delete HGSS Data
            BitConverter.GetBytes((ushort)0).CopyTo(pk5.Data, 0x86);
            if (HGSSBall > 0 && HGSSBall != 4)
                pk5.Ball = HGSSBall;

            // Transfer Nickname and OT Name
            pk5.Nickname = Nickname;
            pk5.OT_Name = OT_Name;

            // Fix Level
            pk5.Met_Level = PKX.getLevel(pk5.Species, pk5.EXP);

            // Remove HM moves; Defog should be kept if both are learned.
            int[] banned = Moves.Contains(250) /*Whirlpool*/ && !Moves.Contains(432) /*Defog*/
                ? new[] {15, 19, 57, 70, 432, 249, 127, 431} // No Defog
                : new[] {15, 19, 57, 70, 250, 249, 127, 431};// No Whirlpool

            int[] newMoves = pk5.Moves;
            for (int i = 0; i < 4; i++)
                if (banned.Contains(newMoves[i]))
                    newMoves[i] = 0;
            pk5.Moves = newMoves;
            pk5.FixMoves();

            pk5.RefreshChecksum();
            return pk5;
        }
Ejemplo n.º 6
0
        public PK5 convertToPK5(SAV6 SAV)
        {
            if (!IsPokémon)
            {
                return(null);
            }

            DateTime dt = DateTime.Now;

            if (Day == 0)
            {
                Day   = (byte)dt.Day;
                Month = (byte)dt.Month;
                Year  = (byte)dt.Year;
            }
            int currentLevel = Level > 0 ? Level : (int)(Util.rnd32() % 100 + 1);
            PK5 pk           = new PK5
            {
                Species      = Species,
                HeldItem     = HeldItem,
                Met_Level    = currentLevel,
                Nature       = Nature != 0xFF ? Nature : (int)(Util.rnd32() % 25),
                Gender       = PKX.Personal[Species].Gender == 255 ? 2 : (Gender != 2 ? Gender : PKX.Personal[Species].RandomGender),
                AltForm      = Form,
                Version      = OriginGame == 0 ? new[] { 20, 21, 22, 23 }[Util.rnd32() & 0x3] : OriginGame,
                Language     = Language == 0 ? SAV.Language : Language,
                Ball         = Pokéball,
                Move1        = Move1,
                Move2        = Move2,
                Move3        = Move3,
                Move4        = Move4,
                Move1_PP     = PKX.getBasePP(Move1),
                Move2_PP     = PKX.getBasePP(Move2),
                Move3_PP     = PKX.getBasePP(Move3),
                Move4_PP     = PKX.getBasePP(Move4),
                Met_Location = MetLocation,
                Met_Day      = Day,
                Met_Month    = Month,
                Met_Year     = Year - 2000,
                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,

                EXP = PKX.getEXP(Level, Species),

                // Ribbons
                RIB7_4 = RIB0_0, // Country Ribbon
                RIB7_5 = RIB0_1, // National Ribbon
                RIB7_6 = RIB0_2, // Earth Ribbon
                RIB7_7 = RIB0_3, // World Ribbon
                RIB3_2 = RIB0_4, // Classic Ribbon
                RIB3_3 = RIB0_5, // Premier Ribbon
                RIB2_3 = RIB0_6, // Event Ribbon
                RIB2_6 = RIB0_7, // Birthday Ribbon

                RIB2_7 = RIB1_0, // Special Ribbon
                RIB3_0 = RIB1_1, // Souvenir Ribbon
                RIB3_1 = RIB1_2, // Wishing Ribbon
                RIB7_1 = RIB1_3, // Battle Champ Ribbon
                RIB7_2 = RIB1_4, // Regional Champ Ribbon
                RIB7_3 = RIB1_5, // National Champ Ribbon
                RIB2_5 = RIB1_6, // World Champ Ribbon

                Friendship       = PKX.getBaseFriendship(Species),
                FatefulEncounter = true,
            };

            if (OTGender == 3) // User's
            {
                pk.TID       = 12345;
                pk.SID       = 54321;
                pk.OT_Name   = "PKHeX";
                pk.OT_Gender = 1; // Red PKHeX OT
            }
            else
            {
                pk.TID       = TID;
                pk.SID       = SID;
                pk.OT_Name   = OT.Length > 0 ? OT : "PKHeX";
                pk.OT_Gender = OTGender % 2; // %2 just in case?
            }
            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];
            for (int i = 0; i < IVs.Length; i++)
            {
                finalIVs[i] = (IVs[i] == 0xFF) ? (int)(Util.rnd32() & 0x1F) : IVs[i];
            }
            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;
            }
            if (av == 2)
            {
                pk.HiddenAbility = true;
            }
            pk.Ability = PKX.Personal[PKX.Personal[Species].FormeIndex(Species, pk.AltForm)].Abilities[av];

            if (PID != 0)
            {
                pk.PID = PID;
            }
            else
            {
                pk.PID = Util.rnd32();
                // Force Ability
                if (av == 0)
                {
                    pk.PID &= 0xFFFEFFFF;
                }
                else
                {
                    pk.PID |= 0x10000;
                }
                // Force Gender
                do
                {
                    pk.PID = (pk.PID & 0xFFFFFF00) | Util.rnd32() & 0xFF;
                } while (!pk.getGenderIsValid());
                if (PIDType == 2) // Force Shiny
                {
                    uint gb = pk.PID & 0xFF;
                    pk.PID = (uint)(((gb ^ pk.TID ^ pk.SID) & 0xFFFE) << 16) | gb;
                    if (av == 0)
                    {
                        pk.PID &= 0xFFFEFFFE;
                    }
                    else
                    {
                        pk.PID |= 0x10001;
                    }
                }
                else if (PIDType != 1) // Force Not Shiny
                {
                    if (((pk.PID >> 16) ^ (pk.PID & 0xffff) ^ pk.SID ^ pk.TID) < 8)
                    {
                        pk.PID ^= 0x80000000;
                    }
                }
            }

            if (IsEgg)
            {
                // pk.IsEgg = true;
                pk.Egg_Day   = Day;
                pk.Egg_Month = Month;
                pk.Egg_Year  = Year - 2000;
                // Force hatch
                pk.IsEgg        = false;
                pk.Met_Location = 4; // Nuvema Town
            }

            pk.RefreshChecksum();
            return(pk);
        }
Ejemplo n.º 7
0
        public override PKM convertToPKM(SaveFile SAV)
        {
            if (!IsPokémon)
                return null;

            DateTime dt = DateTime.Now;
            if (Day == 0)
            {
                Day = (byte)dt.Day;
                Month = (byte)dt.Month;
                Year = (byte)dt.Year;
            }
            int currentLevel = Level > 0 ? Level : (int)(Util.rnd32() % 100 + 1);
            PK5 pk = new PK5
            {
                Species = Species,
                HeldItem = HeldItem,
                Met_Level = currentLevel,
                Nature = Nature != 0xFF ? Nature : (int)(Util.rnd32() % 25),
                Gender = PersonalTable.B2W2[Species].Gender == 255 ? 2 : (Gender != 2 ? Gender : PersonalTable.B2W2[Species].RandomGender),
                AltForm = Form,
                Version = OriginGame == 0 ? new[] {20, 21, 22, 23}[Util.rnd32() & 0x3] : OriginGame,
                Language = Language == 0 ? SAV.Language : Language,
                Ball = Ball,
                Move1 = Move1,
                Move2 = Move2,
                Move3 = Move3,
                Move4 = Move4,
                Met_Location = MetLocation,
                MetDate = Date,
                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,

                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.B2W2[Species].BaseFriendship,
                FatefulEncounter = true,
            };
            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);
            if (OTGender == 3) // User's
            {
                pk.TID = SAV.TID;
                pk.SID = SAV.SID;
                pk.OT_Name = SAV.OT;
                pk.OT_Gender = 1; // Red PKHeX OT
            }
            else
            {
                pk.TID = IsEgg ? SAV.TID : TID;
                pk.SID = IsEgg ? SAV.SID : SID;
                pk.OT_Name = OT.Length > 0 ? OT : SAV.OT;
                pk.OT_Gender = OTGender % 2; // %2 just in case?
            }
            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];
            for (int i = 0; i < IVs.Length; i++)
                finalIVs[i] = IVs[i] == 0xFF ? (int)(Util.rnd32() & 0x1F) : IVs[i];
            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.HiddenAbility = av == 2;
            pk.Ability = PersonalTable.B2W2.getAbilities(Species, pk.AltForm)[av];

            if (PID != 0)
                pk.PID = PID;
            else
            {
                pk.PID = Util.rnd32();
                // Force Ability
                if (av == 0) pk.PID &= 0xFFFEFFFF; else pk.PID |= 0x10000;
                // Force Gender
                do { pk.PID = (pk.PID & 0xFFFFFF00) | Util.rnd32() & 0xFF; } while (!pk.getGenderIsValid());
                if (PIDType == 2) // Force Shiny
                {
                    uint gb = pk.PID & 0xFF;
                    pk.PID = (uint)(((gb ^ pk.TID ^ pk.SID) & 0xFFFE) << 16) | gb;
                    if (av == 0) pk.PID &= 0xFFFEFFFE; else pk.PID |= 0x10001;
                }
                else if (PIDType != 1) // Force Not Shiny
                {
                    if (((pk.PID >> 16) ^ (pk.PID & 0xffff) ^ pk.SID ^ pk.TID) < 8)
                        pk.PID ^= 0x80000000;
                }
            }

            if (IsEgg)
            {
                // pk.IsEgg = true;
                pk.EggMetDate = Date;
                // Force hatch
                pk.IsEgg = false;
                pk.Met_Location = 4; // Nuvema Town
            }

            pk.RefreshChecksum();
            return pk;
        }