Пример #1
0
Файл: PK4.cs Проект: kwsch/PKHeX
        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
                MetDate = moment
            };

            // Arceus Type Changing -- Plate forcibly removed.
            if (pk5.Species == 493)
                pk5.AltForm = 0;

            // Fix PP
            pk5.Move1_PP = pk5.getMovePP(pk5.Move1, pk5.Move1_PPUps);
            pk5.Move2_PP = pk5.getMovePP(pk5.Move2, pk5.Move2_PPUps);
            pk5.Move3_PP = pk5.getMovePP(pk5.Move3, pk5.Move3_PPUps);
            pk5.Move4_PP = pk5.getMovePP(pk5.Move4, 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.Gen4 && 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);
            pk5.Ball = Ball;

            // 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) && Moves.Contains(432) // Whirlpool & Defog
                ? new[] {15, 19, 57, 70, 250, 249, 127, 431} // No Whirlpool
                : new[] {15, 19, 57, 70,      249, 127, 431};// Transfer via advantageous game

            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;
        }
Пример #2
0
 public override void CopyTo(PK5 pk5) => pk5.SetHeldMailData(Data);
Пример #3
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
                MetDate = moment
            };

            // Arceus Type Changing -- Plate forcibly removed.
            if (pk5.Species == 493)
            {
                pk5.AltForm = 0;
            }

            // Fix PP
            pk5.Move1_PP = pk5.getMovePP(pk5.Move1, pk5.Move1_PPUps);
            pk5.Move2_PP = pk5.getMovePP(pk5.Move2, pk5.Move2_PPUps);
            pk5.Move3_PP = pk5.getMovePP(pk5.Move3, pk5.Move3_PPUps);
            pk5.Move4_PP = pk5.getMovePP(pk5.Move4, 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.Gen4 && 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);
            pk5.Ball = Ball;

            // 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) && Moves.Contains(432) // Whirlpool & Defog
                ? new[] { 15, 19, 57, 70, 250, 249, 127, 431 } // No Whirlpool
                : new[] { 15, 19, 57, 70, 249, 127, 431 };            // Transfer via advantageous game

            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);
        }
Пример #4
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);
        }
Пример #5
0
 public override void CopyTo(PK5 pk5) => pk5.HeldMailData = Data;
Пример #6
0
 public override void CopyTo(PK5 pk5) => Data.CopyTo(pk5.HeldMail);
Пример #7
0
Файл: PGF.cs Проект: kwsch/PKHeX
        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;
        }