예제 #1
0
    /// <summary>
    /// Sanity checks the provided <see cref="PKM.Gender"/> value, and returns a sane value.
    /// </summary>
    /// <param name="pk"></param>
    /// <returns>Most-legal <see cref="PKM.Gender"/> value</returns>
    public static int GetSaneGender(this PKM pk)
    {
        int gt = pk.PersonalInfo.Gender;

        switch (gt)
        {
        case PersonalInfo.RatioMagicGenderless: return(2);

        case PersonalInfo.RatioMagicFemale: return(1);

        case PersonalInfo.RatioMagicMale: return(0);
        }
        if (!pk.IsGenderValid())
        {
            return(EntityGender.GetFromPIDAndRatio(pk.PID, gt));
        }
        return(pk.Gender);
    }
예제 #2
0
    private static bool IsAzurillEdgeCaseM(PKM pk, uint nature, uint oldpid)
    {
        // check for Azurill evolution edge case... 75% F-M is now 50% F-M; was this a F->M bend?
        int species = pk.Species;

        if (species is not((int)Species.Marill or(int) Species.Azumarill))
        {
            return(false);
        }

        const int AzurillGenderRatio = 0xBF;
        var       gender             = EntityGender.GetFromPIDAndRatio(pk.PID, AzurillGenderRatio);

        if (gender != 1)
        {
            return(false);
        }

        var pid = PIDGenerator.GetPokeWalkerPID(pk.TID, pk.SID, nature, 1, AzurillGenderRatio);

        return(pid == oldpid);
    }
예제 #3
0
파일: EntityPID.cs 프로젝트: Lusamine/PKHeX
    /// <summary>
    /// Gets a random PID according to specifications.
    /// </summary>
    /// <param name="rnd">RNG to use</param>
    /// <param name="species">National Dex ID</param>
    /// <param name="gender">Current Gender</param>
    /// <param name="origin">Origin Generation</param>
    /// <param name="nature">Nature</param>
    /// <param name="form">Form</param>
    /// <param name="oldPID">Current PID</param>
    /// <remarks>Used to retain ability bits.</remarks>
    /// <returns>Rerolled PID.</returns>
    public static uint GetRandomPID(Random rnd, int species, int gender, int origin, int nature, int form, uint oldPID)
    {
        // Gen6+ (and VC) PIDs do not tie PID to Nature/Gender/Ability
        if (origin >= 24)
        {
            return(rnd.Rand32());
        }

        // Below logic handles Gen3-5.
        // No need to get form specific entry, as Gen3-5 do not have that feature.
        int  gt         = PKX.Personal[species].Gender;
        bool g34        = origin <= 15;
        uint abilBitVal = g34 ? oldPID & 0x0000_0001 : oldPID & 0x0001_0000;

        bool g3unown      = origin <= 5 && species == (int)Species.Unown;
        bool singleGender = PersonalInfo.IsSingleGender(gt); // single gender, skip gender check

        while (true)                                         // Loop until we find a suitable PID
        {
            uint pid = rnd.Rand32();

            // Gen 3/4: Nature derived from PID
            if (g34 && pid % 25 != nature)
            {
                continue;
            }

            // Gen 3 Unown: Letter/form derived from PID
            if (g3unown)
            {
                var pidLetter = GetUnownForm3(pid);
                if (pidLetter != form)
                {
                    continue;
                }
            }
            else if (g34)
            {
                if (abilBitVal != (pid & 0x0000_0001)) // keep ability bits
                {
                    continue;
                }
            }
            else
            {
                if (abilBitVal != (pid & 0x0001_0000)) // keep ability bits
                {
                    continue;
                }
            }

            if (singleGender) // Set Gender(less)
            {
                return(pid);  // PID can be anything
            }
            // Gen 3/4/5: Gender derived from PID
            if (gender == EntityGender.GetFromPIDAndRatio(pid, gt))
            {
                return(pid);
            }
        }
    }