Exemplo n.º 1
0
        private bool checkCompatible(PKM pk)
        {
            if (pk.Species > SAV.MaxSpeciesID)
            {
                return(false);
            }

            if (pk.HeldItem > SAV.MaxItemID)
            {
                pk.HeldItem = 0;
            }
            if (pk.Nickname.Length > SAV.NickLength)
            {
                pk.Nickname = pk.Nickname.Substring(0, SAV.NickLength);
            }
            if (pk.OT_Name.Length > SAV.OTLength)
            {
                pk.OT_Name = pk.OT_Name.Substring(0, SAV.OTLength);
            }
            if (pk.Moves.Any(move => move > SAV.MaxMoveID))
            {
                pk.Moves = pk.Moves.Select(move => move <= SAV.MaxMoveID ? move : 0).ToArray();
                pk.FixMoves();
            }
            if (pk.EVs.Any(ev => ev > SAV.MaxEV))
            {
                pk.EVs = pk.EVs.Select(ev => Math.Min(SAV.MaxEV, ev)).ToArray();
            }
            if (pk.IVs.Any(ev => ev > SAV.MaxEV))
            {
                pk.IVs = pk.IVs.Select(iv => Math.Min(SAV.MaxIV, iv)).ToArray();
            }

            return(true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Resets the <see cref="PKM"/>'s moves and sets the requested version.
        /// </summary>
        /// <param name="v">Reference to the object to set the <see cref="version"/></param>
        /// <param name="pk">Reference to the same object that gets moves reset</param>
        /// <param name="version">Version to apply</param>
        public static void AdaptToBattleVersion(this IBattleVersion v, PKM pk, GameVersion version)
        {
            var moves = MoveLevelUp.GetEncounterMoves(pk, pk.CurrentLevel, version);

            pk.Move1        = pk.Move2 = pk.Move3 = pk.Move4 = 0;
            pk.RelearnMove1 = pk.RelearnMove2 = pk.RelearnMove3 = pk.RelearnMove4 = 0;
            pk.SetMoves(moves);
            pk.FixMoves();
            v.BattleVersion = (int)version;
        }
Exemplo n.º 3
0
        private static void SetPIDSID(PKM pk, bool shiny, bool XD = false)
        {
            uint hp  = (uint)pk.IV_HP;
            uint atk = (uint)pk.IV_ATK;
            uint def = (uint)pk.IV_DEF;
            uint spa = (uint)pk.IV_SPA;
            uint spd = (uint)pk.IV_SPD;
            uint spe = (uint)pk.IV_SPE;

            void LoadOldIVs()
            {
                pk.IV_HP  = (int)hp;
                pk.IV_ATK = (int)atk;
                pk.IV_DEF = (int)def;
                pk.IV_SPA = (int)spa;
                pk.IV_SPD = (int)spd;
                pk.IV_SPE = (int)spe;
            }

            uint nature = (uint)pk.Nature;
            var  type   = XD ? RNGReporter.FrameType.ColoXD : RNGReporter.FrameType.Method1;
            var  pidsid = IVtoPIDGenerator.Generate(hp, atk, def, spa, spd, spe, nature, 0, type);

            if (pk.Species == 490 && pk.Gen4)
            {
                pk.WasEgg           = true;
                pk.Egg_Location     = 2002;
                pk.FatefulEncounter = true;
            }
            pk.PID = Util.GetHexValue(pidsid[0]);
            if (pk.GenNumber < 5)
            {
                pk.EncryptionConstant = pk.PID;
            }
            pk.SID = Convert.ToInt32(pidsid[1]);
            if (shiny)
            {
                pk.SetShinySID();
            }
            var    recheckLA     = new LegalityAnalysis(pk);
            string updatedReport = recheckLA.Report();

            Debug.WriteLine(updatedReport);
            if (!updatedReport.Contains(LPIDTypeMismatch))
            {
                return;
            }

            var NatureHPIVs = IVtoPIDGenerator.GetIVPID(nature, pk.HPType, XD);

            Debug.WriteLine(XD);
            pk.PID = Util.GetHexValue(NatureHPIVs[0]);
            if (pk.GenNumber < 5)
            {
                pk.EncryptionConstant = pk.PID;
            }

            SetIVs(pk, NatureHPIVs);
            if (shiny)
            {
                pk.SetShinySID();
            }

            recheckLA     = new LegalityAnalysis(pk);
            updatedReport = recheckLA.Report();

            bool pidsidmethod = updatedReport.Contains(LPIDTypeMismatch);

            if (pidsid[0] == "0" && pidsid[1] == "0" && pidsidmethod)
            {
                pk.PID = PKX.GetRandomPID(pk.Species, pk.Gender, pk.Version, pk.Nature, pk.Format, (uint)(pk.AbilityNumber * 0x10001));
                LoadOldIVs();
            }
            if (shiny)
            {
                pk.SetShinySID();
            }

            recheckLA     = new LegalityAnalysis(pk);
            updatedReport = recheckLA.Report();
            if (updatedReport.Contains(LPIDGenderMismatch))
            {
                pk.Gender = pk.Gender == 0 ? 1 : 0;
                var recheckLA2 = new LegalityAnalysis(pk);
                updatedReport = recheckLA2.Report();
            }
            if (updatedReport.Contains(LHyperBelow100))
            {
                pk.CurrentLevel = 100;
                var recheckLA2 = new LegalityAnalysis(pk);
                updatedReport = recheckLA2.Report();
            }
            var la = new LegalityAnalysis(pk);

            if (la.Valid)
            {
                return;
            }
            // Fix Moves if a slot is empty
            pk.FixMoves();

            pk.RefreshAbility(pk.AbilityNumber < 6 ? pk.AbilityNumber >> 1 : 0);
            if (updatedReport.Contains(LPIDTypeMismatch) || UsesEventBasedMethod(pk.Species, pk.Moves, PIDType.Method_2))
            {
                if (pk.GenNumber == 3 || UsesEventBasedMethod(pk.Species, pk.Moves, PIDType.Method_2))
                {
                    pk = M2EventFix(pk, shiny);
                    if (!new LegalityAnalysis(pk).Report().Contains(LPIDTypeMismatch) || UsesEventBasedMethod(pk.Species, pk.Moves, PIDType.Method_2))
                    {
                        return;
                    }
                }
                LoadOldIVs();
            }
        }
Exemplo n.º 4
0
        private static PKM SetToEgg(PKM pkm, int origin, GameVersion gameVersion)
        {
            int dayCare      = origin <= 4 ? Locations.Daycare4 : Locations.Daycare5;
            int metLevel     = origin <= 4 ? 0 : 1;
            int currentLevel = origin <= 4 ? 5 : 1;

            // 非初级形态
            PKM tmp = pkm.Clone();

            tmp.IsEgg        = true;
            tmp.Egg_Location = dayCare;
            tmp.Data[0xA8]   = tmp.Data[0xA8 + 1] = 0;    //Milotic
            List <CheckResult> checkResult = EncounterFinder.FindVerifiedEncounter(tmp).Parse;

            if (checkResult.IsPropStrInEleList("Comment", LegalityCheckStrings.LEvoInvalid))
            {
                return(null);
            }

            int language = pkm.Language;

            pkm.Nickname     = SpeciesName.GetSpeciesNameGeneration((int)Species.None, language, pkm.Format);
            pkm.IsNicknamed  = true;
            pkm.IsEgg        = true;
            pkm.HeldItem     = 0;
            pkm.CurrentLevel = currentLevel;
            pkm.StatNature   = pkm.Nature;
            pkm.RefreshAbility(new Random().Next(0, 3));

            pkm.SetIVs();
            pkm.EVs = new int[6];

            pkm.Ball         = (int)Ball.Poke;
            pkm.Met_Location = 0;
            pkm.Met_Level    = metLevel;
            pkm.Egg_Location = dayCare;

            ReflectUtils.methods.TryGetValue("GetEggMoves", out MethodInfo method);
            int[] result = (int[])method.Invoke(null, new object[] { pkm, pkm.Species, pkm.AltForm, gameVersion });
            pkm.SetMoves(new List <int>());
            if (result.Length == 0)
            {
                pkm.SetRelearnMoves(pkm.GetSuggestedRelearnMoves());
            }
            else
            {
                pkm.SetRelearnMoves(GetEggMovesRandom(pkm, result));
            }
            pkm.SetMoves(pkm.RelearnMoves);
            pkm.SetMovesPPUpsToZero();
            pkm.SetMaximumPPCurrent();
            pkm.FixMoves();

            // 8代独有数据
            if (pkm.Format == 8)
            {
                PK8 pk8 = (PK8)pkm;
                pk8.DynamaxLevel  = 0;
                pk8.CanGigantamax = false;
            }

            pkm.ClearAllRibbon();
            pkm.ClearCurrentHandler();
            pkm.ClearMemories();
            pkm.ClearRecordFlags();
            pkm.CurrentFriendship = 4;

            return(pkm);
        }
Exemplo n.º 5
0
        private PKM setPIDSID(PKM pk, bool shiny, bool XD = false)
        {
            uint hp     = (uint)pk.IV_HP;
            uint atk    = (uint)pk.IV_ATK;
            uint def    = (uint)pk.IV_DEF;
            uint spa    = (uint)pk.IV_SPA;
            uint spd    = (uint)pk.IV_SPD;
            uint spe    = (uint)pk.IV_SPE;
            uint nature = (uint)pk.Nature;

            string[] pidsid = { "", "" };
            if (XD)
            {
                pidsid = IVtoPIDGenerator.XDPID(hp, atk, def, spa, spd, spe, nature, 0);
            }
            else
            {
                pidsid = IVtoPIDGenerator.M1PID(hp, atk, def, spa, spd, spe, nature, 0);
            }
            pk.PID = Util.GetHexValue(pidsid[0]);
            pk.SID = Convert.ToInt32(pidsid[1]);
            if (shiny)
            {
                pk.SetShinySID();
            }
            LegalityAnalysis recheckLA     = new LegalityAnalysis(pk);
            string           updatedReport = recheckLA.Report(false);

            if (debug)
            {
                Console.WriteLine(updatedReport);
            }
            if (updatedReport.Contains("Invalid: Encounter Type PID mismatch."))
            {
                List <List <uint> > ivspreads = new List <List <uint> >();
                if (!XD)
                {
                    ivspreads.Add(new List <uint> {
                        0, 0, 0, 0, 0, 7
                    });                                                 // 1 Hardy
                    ivspreads.Add(new List <uint> {
                        0, 0, 0, 0, 1, 1
                    });                                                 // 2 Lonely
                    ivspreads.Add(new List <uint> {
                        0, 0, 0, 0, 1, 3
                    });                                                 // 3 Brave
                    ivspreads.Add(new List <uint> {
                        0, 0, 0, 0, 0, 2
                    });                                                 // 4 Adamant
                    ivspreads.Add(new List <uint> {
                        0, 0, 0, 0, 0, 7
                    });                                                 // 5 Naughty
                    ivspreads.Add(new List <uint> {
                        0, 0, 0, 0, 0, 19
                    });                                                  // Bold
                    ivspreads.Add(new List <uint> {
                        0, 0, 0, 0, 0, 0
                    });                                                 // Docile
                    ivspreads.Add(new List <uint> {
                        0, 0, 0, 0, 0, 0
                    });                                                 // Relaxed
                    ivspreads.Add(new List <uint> {
                        0, 0, 0, 0, 0, 3
                    });                                                 // Impish
                    ivspreads.Add(new List <uint> {
                        0, 0, 0, 0, 1, 8
                    });                                                 // Lax
                    ivspreads.Add(new List <uint> {
                        0, 0, 0, 0, 1, 10
                    });                                                  // Timid
                    ivspreads.Add(new List <uint> {
                        0, 0, 0, 0, 0, 1
                    });                                                 // Hasty
                    ivspreads.Add(new List <uint> {
                        0, 0, 0, 0, 0, 1
                    });                                                 // Serious
                    ivspreads.Add(new List <uint> {
                        0, 0, 0, 0, 0, 16
                    });                                                  // Jolly
                    ivspreads.Add(new List <uint> {
                        0, 0, 0, 0, 1, 8
                    });                                                 // Naive
                    ivspreads.Add(new List <uint> {
                        0, 0, 0, 0, 0, 0
                    });                                                 // Modest
                    ivspreads.Add(new List <uint> {
                        0, 0, 0, 0, 0, 0
                    });                                                 // Mild
                    ivspreads.Add(new List <uint> {
                        0, 0, 0, 0, 0, 22
                    });                                                  // Quiet
                    ivspreads.Add(new List <uint> {
                        0, 0, 0, 0, 1, 5
                    });                                                 // Bashful
                    ivspreads.Add(new List <uint> {
                        0, 0, 0, 0, 0, 5
                    });                                                 // Rash
                    ivspreads.Add(new List <uint> {
                        0, 0, 0, 0, 0, 1
                    });                                                 // Calm
                    ivspreads.Add(new List <uint> {
                        0, 0, 0, 0, 0, 1
                    });                                                 // Gentle
                    ivspreads.Add(new List <uint> {
                        0, 0, 0, 0, 1, 14
                    });                                                  // Sassy
                    ivspreads.Add(new List <uint> {
                        0, 0, 0, 0, 0, 2
                    });                                                 // Careful
                    ivspreads.Add(new List <uint> {
                        0, 0, 0, 0, 0, 6
                    });                                                 // Quirky
                }
                else
                {
                    ivspreads.Add(new List <uint> {
                        7, 17, 7, 23, 20, 22
                    });                                                     // XDHardy
                    ivspreads.Add(new List <uint> {
                        29, 22, 5, 14, 27, 4
                    });                                                     // XDLonely
                    ivspreads.Add(new List <uint> {
                        24, 10, 14, 15, 20, 16
                    });                                                       // XDBrave
                    ivspreads.Add(new List <uint> {
                        23, 20, 8, 16, 11, 21
                    });                                                      // XDAdamant
                    ivspreads.Add(new List <uint> {
                        18, 9, 25, 0, 18, 25
                    });                                                     // XDNaughty
                    ivspreads.Add(new List <uint> {
                        6, 1, 0, 17, 7, 7
                    });                                                  // XDBold
                    ivspreads.Add(new List <uint> {
                        27, 4, 18, 16, 16, 11
                    });                                                      // XDDocile
                    ivspreads.Add(new List <uint> {
                        22, 23, 20, 12, 2, 5
                    });                                                     // XDRelaxed
                    ivspreads.Add(new List <uint> {
                        18, 6, 10, 28, 29, 20
                    });                                                      // XDImpish
                    ivspreads.Add(new List <uint> {
                        20, 28, 29, 22, 5, 29
                    });                                                      // XDLax
                    ivspreads.Add(new List <uint> {
                        21, 16, 11, 5, 8, 13
                    });                                                     // XDTimid
                    ivspreads.Add(new List <uint> {
                        27, 1, 23, 10, 12, 9
                    });                                                     // XDHasty
                    ivspreads.Add(new List <uint> {
                        0, 6, 2, 15, 9, 29
                    });                                                   // XDSerious
                    ivspreads.Add(new List <uint> {
                        17, 17, 15, 23, 8, 17
                    });                                                      // XDJolly
                    ivspreads.Add(new List <uint> {
                        16, 15, 20, 4, 31, 19
                    });                                                      // XDNaive
                    ivspreads.Add(new List <uint> {
                        13, 27, 30, 3, 20, 8
                    });                                                     // XDModest
                    ivspreads.Add(new List <uint> {
                        19, 4, 31, 4, 21, 23
                    });                                                     // XDMild
                    ivspreads.Add(new List <uint> {
                        4, 26, 23, 12, 11, 1
                    });                                                     // XDQuiet
                    ivspreads.Add(new List <uint> {
                        8, 26, 0, 4, 18, 27
                    });                                                    // XDBashful
                    ivspreads.Add(new List <uint> {
                        11, 9, 1, 6, 2, 0
                    });                                                  // XDRash
                    ivspreads.Add(new List <uint> {
                        1, 6, 13, 26, 23, 4
                    });                                                    // XDCalm
                    ivspreads.Add(new List <uint> {
                        29, 15, 9, 16, 31, 22
                    });                                                      // XDGentle
                    ivspreads.Add(new List <uint> {
                        17, 23, 8, 21, 25, 13
                    });                                                      // XDSassy
                    ivspreads.Add(new List <uint> {
                        25, 8, 0, 1, 20, 25
                    });                                                    // XDCareful
                    ivspreads.Add(new List <uint> {
                        29, 16, 31, 6, 10, 18
                    });                                                      // XDQuirky
                }
                pk.IV_HP  = Convert.ToInt32(ivspreads[Convert.ToInt32(nature)][0]);
                pk.IV_ATK = Convert.ToInt32(ivspreads[Convert.ToInt32(nature)][1]);
                pk.IV_DEF = Convert.ToInt32(ivspreads[Convert.ToInt32(nature)][2]);
                pk.IV_SPA = Convert.ToInt32(ivspreads[Convert.ToInt32(nature)][3]);
                pk.IV_SPD = Convert.ToInt32(ivspreads[Convert.ToInt32(nature)][4]);
                pk.IV_SPE = Convert.ToInt32(ivspreads[Convert.ToInt32(nature)][5]);
                if (debug)
                {
                    Console.WriteLine(pk.IV_HP + " " + pk.IV_ATK + " " + pk.IV_DEF + " " + pk.IV_SPA + " " + pk.IV_SPD + " " + pk.IV_SPE);
                }
                if (!XD)
                {
                    pidsid = IVtoPIDGenerator.M1PID((uint)pk.IV_HP, (uint)pk.IV_ATK, (uint)pk.IV_DEF, (uint)pk.IV_SPA, (uint)pk.IV_SPD, (uint)pk.IV_SPE, nature, 0);
                }
                else
                {
                    pidsid = IVtoPIDGenerator.XDPID((uint)pk.IV_HP, (uint)pk.IV_ATK, (uint)pk.IV_DEF, (uint)pk.IV_SPA, (uint)pk.IV_SPD, (uint)pk.IV_SPE, nature, 0);
                }
                pk.PID = Util.GetHexValue(pidsid[0]);
                if (pk.GenNumber < 5)
                {
                    pk.EncryptionConstant = pk.PID;
                }
                pk.SID = Convert.ToInt32(pidsid[1]);
                if (pidsid[0] == "0" && pidsid[1] == "0")
                {
                    pk.PID    = PKX.GetRandomPID(pk.Species, pk.Gender, pk.Version, pk.Nature, pk.Format, (uint)(pk.AbilityNumber * 0x10001));
                    pk.IV_HP  = (int)hp;
                    pk.IV_ATK = (int)atk;
                    pk.IV_DEF = (int)def;
                    pk.IV_SPA = (int)spa;
                    pk.IV_SPD = (int)spd;
                    pk.IV_SPE = (int)spe;
                }
                if (hp >= 30)
                {
                    pk.HT_HP = true;
                }
                if (atk >= 30)
                {
                    pk.HT_ATK = true;
                }
                if (def >= 30)
                {
                    pk.HT_DEF = true;
                }
                if (spa >= 30)
                {
                    pk.HT_SPA = true;
                }
                if (spd >= 30)
                {
                    pk.HT_SPD = true;
                }
                if (spe >= 30)
                {
                    pk.HT_SPE = true;
                }
                if (shiny)
                {
                    pk.SetShinySID();
                }
                recheckLA     = new LegalityAnalysis(pk);
                updatedReport = recheckLA.Report(false);
                if (updatedReport.Contains("PID-Gender mismatch."))
                {
                    if (pk.Gender == 0)
                    {
                        pk.Gender = 1;
                    }
                    else
                    {
                        pk.Gender = 0;
                    }
                    LegalityAnalysis recheckLA2 = new LegalityAnalysis(pk);
                    updatedReport = recheckLA2.Report(false);
                }
                LegalityAnalysis Legality = new LegalityAnalysis(pk);
                if (Legality.Valid)
                {
                    return(pk);
                }
                // Fix Moves if a slot is empty
                pk.FixMoves();

                // PKX is now filled
                pk.RefreshChecksum();
                pk.RefreshAbility(pk.AbilityNumber < 6 ? pk.AbilityNumber >> 1 : 0);
                if (updatedReport.Contains("Invalid: Encounter Type PID mismatch."))
                {
                    pk.HT_HP  = false;
                    pk.HT_ATK = false;
                    pk.HT_DEF = false;
                    pk.HT_SPA = false;
                    pk.HT_SPD = false;
                    pk.HT_SPE = false;
                    pk.IV_HP  = (int)hp;
                    pk.IV_ATK = (int)atk;
                    pk.IV_DEF = (int)def;
                    pk.IV_SPA = (int)spa;
                    pk.IV_SPD = (int)spd;
                    pk.IV_SPE = (int)spe;
                }
            }
            return(pk);
        }