Exemple #1
0
        private uint GenerateRandom(Gender gender, bool isShiny, short ability)
        {
            int cycles = 0;

Generate:
            if (cycles > 100)
            {
                return(0);
            }
            cycles++;

            var random     = new MersenneTwisterRandom();
            var thirtyBits = (uint)random.Next(1 << 30);
            var twoBits    = (uint)random.Next(1 << 2);
            var result     = (thirtyBits << 2) | twoBits;

Check:
            var cGender = StaticData.MaleRatio < 0.0f ? Gender.Genderless : (result % 256 < (byte)(StaticData.MaleRatio * byte.MaxValue) ? Gender.Male : Gender.Female);
            var cFirstAbility = (result / 65536 % 2) == 0;
            var cIsShiny      = (result % 65536) < 16;

            if (gender != cGender || ((ability == StaticData.Abilities.Ability_0.StaticData.ID) != cFirstAbility) || isShiny != cIsShiny)
            {
                goto Generate;
            }

            return(result);
        }
Exemple #2
0
        public Monster(short species) : base(Cached <MonsterStaticData> .Get(species))
        {
            var random     = new MersenneTwisterRandom();
            var thirtyBits = (uint)random.Next(1 << 30);
            var twoBits    = (uint)random.Next(1 << 2);

            PersonalityValue = (thirtyBits << 2) | twoBits;

            Nature = GenerateNature();

            IV = new Stats(
                (short)random.Next(0, 31),
                (short)random.Next(0, 31),
                (short)random.Next(0, 31),
                (short)random.Next(0, 31),
                (short)random.Next(0, 31),
                (short)random.Next(0, 31));

            /*
             * First Random Number:    x|xxxxx|xxxxx|xxxxx
             *                      -|DefIV|AtkIV|HP IV
             *
             * Second Random Number:   x|xxxxx|xxxxx|xxxxx
             *                      -|SpDIV|SpAIV|SpeIV
             */
        }