Пример #1
0
        private static void FindNestPIDIV(PKM pk, EncounterStatic8N enc, bool shiny)
        {
            // Preserve Nature, Altform, Ability (only if HA)
            // Nest encounter RNG generation
            int       iv_count = enc.FlawlessIVCount;
            int       ability_param;
            int       gender_ratio = pk.PersonalInfo.Gender;
            const int nature_param = 255; // random nature in raids

            // TODO: Ability param for A2 raids
            if (enc.Ability == 0)
            {
                ability_param = 255;
            }
            else if (enc.Ability == -1)
            {
                ability_param = 254;
            }
            else
            {
                ability_param = enc.Ability >> 1;
            }

            var iterPKM = pk.Clone();

            while (true)
            {
                ulong seed = GetRandomULong();
                var   RNG  = new XOROSHIRO(seed);
                if (!shiny)
                {
                    SetValuesFromSeed8Unshiny(pk, RNG, iv_count, ability_param, gender_ratio, nature_param);
                }
                if (!(pk.Nature == iterPKM.Nature && pk.AltForm == iterPKM.AltForm))
                {
                    continue;
                }
                if (iterPKM.AbilityNumber == 4 && !(pk.Ability == iterPKM.Ability && pk.AbilityNumber == iterPKM.AbilityNumber))
                {
                    continue;
                }
                // can be ability capsuled
                pk.RefreshAbility(pk.AbilityNumber >> 1);
                break;
            }
        }
Пример #2
0
        private static void SetValuesFromSeed8Unshiny(PKM pk, XOROSHIRO rng, int iv_count, int ability_param, int gender_ratio, int nature_param)
        {
            pk.EncryptionConstant = (uint)rng.NextInt();
            var ftidsid = (uint)rng.NextInt(); // pass

            pk.PID = (uint)rng.NextInt();
            if (pk.PSV == ((ftidsid >> 16) ^ (ftidsid & 0xFFFF)) >> 4) // force unshiny!
            {
                pk.PID ^= 0x10000000;                                  // the rare case where you actually roll a full odds shiny in PKHeX. Apply for a lottery!
            }
            int[] ivs = { -1, -1, -1, -1, -1, -1 };
            for (int i = 0; i < iv_count; i++)
            {
                int idx = (int)rng.NextInt(6);
                while (ivs[idx] != -1)
                {
                    idx = (int)rng.NextInt(6);
                }
                ivs[idx] = 31;
            }
            for (int i = 0; i < 6; i++)
            {
                if (ivs[i] == -1)
                {
                    ivs[i] = (int)rng.NextInt(32);
                }
            }
            pk.IVs = ivs;
            int abil;

            if (ability_param == 254)
            {
                abil = (int)rng.NextInt(3);
            }
            else if (ability_param == 255)
            {
                abil = (int)rng.NextInt(2);
            }
            else
            {
                abil = ability_param;
            }
            pk.RefreshAbility(abil);
            if (gender_ratio == 255)
            {
                pk.SetGender(2);
            }
            else if (gender_ratio == 254)
            {
                pk.SetGender(1);
            }
            else if (gender_ratio == 0)
            {
                pk.SetGender(0);
            }
            else if ((int)rng.NextInt(252) + 1 < gender_ratio)
            {
                pk.SetGender(1);
            }
            else
            {
                pk.SetGender(0);
            }
            if (nature_param == 255)
            {
                pk.Nature = (int)rng.NextInt(25);
            }
            else
            {
                pk.Nature = nature_param;
            }
        }