Example #1
0
        /*
        public static ComboBoxItem[] NatureDropDownCollection()
        {
            ComboBoxItem[] natures = new ComboBoxItem[] {
                new ComboBoxItem("Any", -1),
                new ComboBoxItem(Functions.NatureStrings(3), 3),
                new ComboBoxItem(Functions.NatureStrings(5), 5),
                new ComboBoxItem(Functions.NatureStrings(2), 2),
                new ComboBoxItem(Functions.NatureStrings(20), 20),
                new ComboBoxItem(Functions.NatureStrings(23), 23),
                new ComboBoxItem(Functions.NatureStrings(11), 11),
                new ComboBoxItem(Functions.NatureStrings(8), 8),
                new ComboBoxItem(Functions.NatureStrings(13), 13),
                new ComboBoxItem(Functions.NatureStrings(1), 1),
                new ComboBoxItem(Functions.NatureStrings(16), 16),
                new ComboBoxItem(Functions.NatureStrings(15), 15),
                new ComboBoxItem(Functions.NatureStrings(14), 14),
                new ComboBoxItem(Functions.NatureStrings(4), 4),
                new ComboBoxItem(Functions.NatureStrings(17), 17),
                new ComboBoxItem(Functions.NatureStrings(19), 19),
                new ComboBoxItem(Functions.NatureStrings(7), 7),
                new ComboBoxItem(Functions.NatureStrings(22), 22),
                new ComboBoxItem(Functions.NatureStrings(10), 10),
                new ComboBoxItem(Functions.NatureStrings(21), 21),
                new ComboBoxItem(Functions.NatureStrings(9), 9),
                new ComboBoxItem(Functions.NatureStrings(18), 18),
                new ComboBoxItem(Functions.NatureStrings(6), 6),
                new ComboBoxItem(Functions.NatureStrings(0), 0),
                new ComboBoxItem(Functions.NatureStrings(24), 24),
                new ComboBoxItem(Functions.NatureStrings(12), 12)
            };

            return natures;
        }
         */
        public static List<Nature> NatureDropDownCollectionSynch()
        {
            List<Nature> natures = NatureDropDownCollection();
            natures[0] = new Nature(-1, new double[] {0, 0, 0, 0, 0, 0});

            return natures;
        }
Example #2
0
        //private bool[] valid = new bool[6] { false, false, false, false, false, false };
        //public bool[] Valid
        //{
        //    get { return valid; }
        //    set { valid = value; }
        //}
        public IVCheck(
            Pokemon pokemon, uint level, Nature nature,
            Characteristic characteristic, uint[] stats)
        {
            this.pokemon = pokemon;
            this.nature = nature;

            //  Initialize our possibilities lists.
            Possibilities = new List<List<uint>>
                {
                    new List<uint>(),
                    new List<uint>(),
                    new List<uint>(),
                    new List<uint>(),
                    new List<uint>(),
                    new List<uint>()
                };

            //  we are going to build out an array of all
            //  of the base stats based on the Pokemon.
            //
            var baseStats = new double[]
                {
                    pokemon.BaseHp, pokemon.BaseAtk, pokemon.BaseDef,
                    pokemon.BaseSpA, pokemon.BaseSpD, pokemon.BaseSpe
                };

            //uint minHp = 31;
            //uint maxHp = 0;

            //remains constant?
            double ev = 0;

            //  This is our internal storage for the IV ranges that
            //  we get with the initial set of data, before the
            //  characteristic correction.
            var minIvs = new uint[] {31, 31, 31, 31, 31, 31};
            var maxIvs = new uint[] {0, 0, 0, 0, 0, 0};

            //  hrm can we get rid of this?
            var valid = new[] {false, false, false, false, false, false};

            //  Do the iterative test on the Hit Points
            for (uint hpCnt = 0; hpCnt <= 31; hpCnt++)
            {
                uint hp = (uint) Math.Floor(((hpCnt + 2*baseStats[0] + Math.Floor((ev/4.0)))*level/100.0)) + 10 + level;

                if (hp == stats[0])
                {
                    valid[0] = true;

                    if (hpCnt >= maxIvs[0])
                    {
                        maxIvs[0] = hpCnt;
                    }
                    if (hpCnt <= minIvs[0])
                    {
                        minIvs[0] = hpCnt;
                    }
                }
            }

            //  Do the iterative test on all other IVs, since they are
            //  all the same we will iterate through our list of items
            for (int cnt = 1; cnt < 6; cnt++)
            {
                for (uint statCnt = 0; statCnt <= 31; statCnt++)
                {
                    var stat =
                        (uint)
                        Math.Floor((Math.Floor(((baseStats[cnt]*2.0 + statCnt + Math.Floor(ev/4.0))*level)/100.0) + 5.0)*
                                   nature.Adjustments[cnt]);

                    if (stat == stats[cnt])
                    {
                        valid[cnt] = true;

                        if (statCnt >= maxIvs[cnt])
                        {
                            maxIvs[cnt] = statCnt;
                        }
                        if (statCnt <= minIvs[cnt])
                        {
                            minIvs[cnt] = statCnt;
                        }
                    }
                }
            }

            uint characteristicHigh = 31;

            //  Correct for the characteristic, building
            //  our final array of the valid values for
            //  each.
            if (characteristic != null)
            {
                if (valid[characteristic.AffectedStat])
                {
                    //  Set this to zero so we can begin to keep track
                    characteristicHigh = 0;

                    //  If this is not null we need to iterate through the ranges
                    //  of the IV that is referenced and cull out those that are
                    //  not possible.
                    for (uint charCnt = minIvs[characteristic.AffectedStat];
                         charCnt <= maxIvs[characteristic.AffectedStat];
                         charCnt++)
                    {
                        if ((charCnt%5) == characteristic.Mod5result)
                        {
                            Possibilities[(int) characteristic.AffectedStat].Add(charCnt);

                            characteristicHigh = charCnt;
                        }
                    }
                }
            }

            //  Now we want to go and explode out all of the other items, skipping
            //  the characteristic affected stat is there was one.  We are also
            //  going to clip to the high mark of the characteristic stat
            for (uint statCnt = 0; statCnt <= 5; statCnt++)
            {
                if (valid[statCnt])
                {
                    //  Make sure we dont make any changes to the characteristic stat
                    if (characteristic == null || characteristic.AffectedStat != statCnt)
                    {
                        //
                        for (uint charCnt = minIvs[statCnt];
                             charCnt <= maxIvs[statCnt];
                             charCnt++)
                        {
                            if (charCnt <= characteristicHigh)
                            {
                                Possibilities[(int) statCnt].Add(charCnt);
                            }
                        }
                    }
                }
            }

            //  Should be done now, but may add the hidden power in the future
        }
Example #3
0
        //private bool[] valid = new bool[6] { false, false, false, false, false, false };
        //public bool[] Valid
        //{
        //    get { return valid; }
        //    set { valid = value; }
        //}

        public IVCheck(
            Pokemon pokemon, uint level, Nature nature,
            Characteristic characteristic, uint[] stats)
        {
            this.pokemon = pokemon;
            this.nature  = nature;

            //  Initialize our possibilities lists.
            Possibilities = new List <List <uint> >
            {
                new List <uint>(),
                new List <uint>(),
                new List <uint>(),
                new List <uint>(),
                new List <uint>(),
                new List <uint>()
            };

            //  we are going to build out an array of all
            //  of the base stats based on the Pokemon.
            //
            var baseStats = new double[]
            {
                pokemon.BaseHp, pokemon.BaseAtk, pokemon.BaseDef,
                pokemon.BaseSpA, pokemon.BaseSpD, pokemon.BaseSpe
            };


            //uint minHp = 31;
            //uint maxHp = 0;

            //remains constant?
            double ev = 0;

            //  This is our internal storage for the IV ranges that
            //  we get with the initial set of data, before the
            //  characteristic correction.
            var minIvs = new uint[] { 31, 31, 31, 31, 31, 31 };
            var maxIvs = new uint[] { 0, 0, 0, 0, 0, 0 };

            //  hrm can we get rid of this?
            var valid = new[] { false, false, false, false, false, false };

            //  Do the iterative test on the Hit Points
            for (uint hpCnt = 0; hpCnt <= 31; hpCnt++)
            {
                uint hp = (uint)Math.Floor(((hpCnt + 2 * baseStats[0] + Math.Floor((ev / 4.0))) * level / 100.0)) + 10 + level;

                if (hp == stats[0])
                {
                    valid[0] = true;

                    if (hpCnt >= maxIvs[0])
                    {
                        maxIvs[0] = hpCnt;
                    }
                    if (hpCnt <= minIvs[0])
                    {
                        minIvs[0] = hpCnt;
                    }
                }
            }

            //  Do the iterative test on all other IVs, since they are
            //  all the same we will iterate through our list of items
            for (int cnt = 1; cnt < 6; cnt++)
            {
                for (uint statCnt = 0; statCnt <= 31; statCnt++)
                {
                    var stat =
                        (uint)
                        Math.Floor((Math.Floor(((baseStats[cnt] * 2.0 + statCnt + Math.Floor(ev / 4.0)) * level) / 100.0) + 5.0) *
                                   nature.Adjustments[cnt]);

                    if (stat == stats[cnt])
                    {
                        valid[cnt] = true;

                        if (statCnt >= maxIvs[cnt])
                        {
                            maxIvs[cnt] = statCnt;
                        }
                        if (statCnt <= minIvs[cnt])
                        {
                            minIvs[cnt] = statCnt;
                        }
                    }
                }
            }

            uint characteristicHigh = 31;

            //  Correct for the characteristic, building
            //  our final array of the valid values for
            //  each.
            if (characteristic != null)
            {
                if (valid[characteristic.AffectedStat])
                {
                    //  Set this to zero so we can begin to keep track
                    characteristicHigh = 0;

                    //  If this is not null we need to iterate through the ranges
                    //  of the IV that is referenced and cull out those that are
                    //  not possible.
                    for (uint charCnt = minIvs[characteristic.AffectedStat];
                         charCnt <= maxIvs[characteristic.AffectedStat];
                         charCnt++)
                    {
                        if ((charCnt % 5) == characteristic.Mod5result)
                        {
                            Possibilities[(int)characteristic.AffectedStat].Add(charCnt);

                            characteristicHigh = charCnt;
                        }
                    }
                }
            }

            //  Now we want to go and explode out all of the other items, skipping
            //  the characteristic affected stat is there was one.  We are also
            //  going to clip to the high mark of the characteristic stat
            for (uint statCnt = 0; statCnt <= 5; statCnt++)
            {
                if (valid[statCnt])
                {
                    //  Make sure we dont make any changes to the characteristic stat
                    if (characteristic == null || characteristic.AffectedStat != statCnt)
                    {
                        //
                        for (uint charCnt = minIvs[statCnt];
                             charCnt <= maxIvs[statCnt];
                             charCnt++)
                        {
                            if (charCnt <= characteristicHigh)
                            {
                                Possibilities[(int)statCnt].Add(charCnt);
                            }
                        }
                    }
                }
            }

            //  Should be done now, but may add the hidden power in the future
        }
Example #4
0
        //  Add a list new Pokemon and do the breakdown
        public void Add(
            uint hp,
            uint atk,
            uint def,
            uint spa,
            uint spd,
            uint spe,
            Nature nature,
            string ability,
            GenderGenderRatio gender)
        {
            string ivs = hp + " / " + atk + " / " + def + " / " + spa + " / " + spd + " / " + spe;

            Pokemon.Add(new CalculateChainSidPokemon(ivs, nature.Name, ability, gender.ShortName));

            // Build the block for the 2nd IV here.
            uint iv2    = spe + (spa << 5) + (spd << 10);
            uint iv2set = iv2 ^ 0x8000;

            uint iv1    = hp + (atk << 5) + (def << 10);
            uint iv1set = iv1 ^ 0x8000;

            var candidatePids = new List <CandidatePid>();

            //  Now we want to start with IV2 and call the RNG for
            //  values between 0 and FFFF in the low order bits.
            for (uint cnt = 0; cnt <= 0x1FFFE; cnt++)
            {
                uint iv2_test;

                //  We want to test with the high bit
                //  both set and not set, so we're going
                //  to sneakily do them both.  god help
                //  me if i ever have to figure this out
                //  in the future.
                iv2_test = (cnt & 1) == 0 ? iv2 : iv2set;

                //  Set our test seed here so we can start
                //  working backwards to see if the rest
                //  of the information we were provided
                //  is a match.

                uint seed = (iv2_test << 16) + (cnt % 0xFFFF);

                var rng = new PokeRngR(seed);

                uint iv1_rng = rng.GetNext16BitNumber();

                //  Check for a canididate here
                if (iv1_rng == iv1 || iv1_rng == iv1set)
                {
                    //  Get the whole adjust number in a loop
                    uint adjust = 0x0;

                    for (int adjustCnt = 0; adjustCnt < 13; adjustCnt++)
                    {
                        uint adjustRng = rng.GetNext16BitNumber() & 1U;
                        adjust |= (adjustRng << (15 - adjustCnt));
                    }

                    //  Get what we think was the initial PID
                    uint pid2 = rng.GetNext16BitNumber(); //  HIGHID
                    uint pid1 = rng.GetNext16BitNumber(); //  LOWID

                    uint adjustedLow = adjust | (pid1 & 7);

                    uint abilityNumber = adjustedLow & 1;
                    uint genderNumber  = adjustedLow & 0xFF;

                    // lol make this not suck
                    if ((ability == "Single Ability" ||
                         (
                             (abilityNumber == 0 && ability == "Ability 0") ||
                             (abilityNumber == 1 && ability == "Ability 1")
                         )) &&
                        gender.Matches(genderNumber))
                    {
                        var candidatePid = new CandidatePid {
                            AdjustedLow = adjustedLow, NaturalHigh = pid2
                        };
                        candidatePids.Add(candidatePid);
                    }
                }
            }

            var newSids = new List <uint>();

            foreach (uint sid in CandidateSids)
            {
                //  Check each candiate pid that we found for the
                //  IV values and then see if the final PID with
                //  a particular nature/gender is a match.  If so
                //  we can go ahead and add the sid to the new
                //  list and exit early.
                foreach (CandidatePid candidatePid in candidatePids)
                {
                    //  Build our full adjusted PID
                    uint adjustedHigh = candidatePid.AdjustedLow ^ Id ^ sid;
                    adjustedHigh &= 0xFFF8;
                    adjustedHigh += (candidatePid.NaturalHigh & 7);

                    //  for testing out the nature comparison
                    uint pid = (adjustedHigh << 16) + candidatePid.AdjustedLow;

                    //  If any of them work, we will add this to
                    //  the new candidateSids list and break to
                    //  go to the next seed.  Check the nature.
                    uint pidNature = pid % 25;

                    if (nature.Number == pidNature)
                    {
                        newSids.Add(sid);
                        break;
                    }
                }
            }

            CandidateSids = newSids;
        }
        //  Add a list new Pokemon and do the breakdown
        public void Add(
            uint hp,
            uint atk,
            uint def,
            uint spa,
            uint spd,
            uint spe,
            Nature nature,
            string ability,
            GenderGenderRatio gender)
        {
            string ivs = hp + " / " + atk + " / " + def + " / " + spa + " / " + spd + " / " + spe;
            Pokemon.Add(new CalculateChainSidPokemon(ivs, nature.Name, ability, gender.ShortName));

            // Build the block for the 2nd IV here.
            uint iv2 = spe + (spa << 5) + (spd << 10);
            uint iv2set = iv2 ^ 0x8000;

            uint iv1 = hp + (atk << 5) + (def << 10);
            uint iv1set = iv1 ^ 0x8000;

            var candidatePids = new List<CandidatePid>();

            //  Now we want to start with IV2 and call the RNG for
            //  values between 0 and FFFF in the low order bits.
            for (uint cnt = 0; cnt <= 0x1FFFE; cnt++)
            {
                uint iv2_test;

                //  We want to test with the high bit
                //  both set and not set, so we're going
                //  to sneakily do them both.  god help
                //  me if i ever have to figure this out
                //  in the future.
                iv2_test = (cnt & 1) == 0 ? iv2 : iv2set;

                //  Set our test seed here so we can start
                //  working backwards to see if the rest
                //  of the information we were provided
                //  is a match.

                uint seed = (iv2_test << 16) + (cnt%0xFFFF);

                var rng = new PokeRngR(seed);

                uint iv1_rng = rng.GetNext16BitNumber();

                //  Check for a canididate here
                if (iv1_rng == iv1 || iv1_rng == iv1set)
                {
                    //  Get the whole adjust number in a loop
                    uint adjust = 0x0;

                    for (int adjustCnt = 0; adjustCnt < 13; adjustCnt++)
                    {
                        uint adjustRng = rng.GetNext16BitNumber()%2U;
                        adjust |= (adjustRng << (15 - adjustCnt));
                    }

                    //  Get what we think was the initial PID
                    uint pid2 = rng.GetNext16BitNumber(); //  HIGHID
                    uint pid1 = rng.GetNext16BitNumber(); //  LOWID

                    uint adjustedLow = adjust | (pid1 & 7);

                    uint abilityNumber = adjustedLow%0x2;
                    uint genderNumber = adjustedLow & 0xFF;

                    // lol make this not suck
                    if ((ability == "Single Ability" ||
                         (
                             (abilityNumber == 0 && ability == "Ability 0") ||
                             (abilityNumber == 1 && ability == "Ability 1")
                         )) &&
                        gender.Matches(genderNumber))
                    {
                        var candidatePid = new CandidatePid {AdjustedLow = adjustedLow, NaturalHigh = pid2};
                        candidatePids.Add(candidatePid);
                    }
                }
            }

            var newSids = new List<uint>();

            foreach (uint sid in CandidateSids)
            {
                //  Check each candiate pid that we found for the
                //  IV values and then see if the final PID with
                //  a particular nature/gender is a match.  If so
                //  we can go ahead and add the sid to the new
                //  list and exit early.
                foreach (CandidatePid candidatePid in candidatePids)
                {
                    //  Build our full adjusted PID
                    uint adjustedHigh = candidatePid.AdjustedLow ^ Id ^ sid;
                    adjustedHigh &= 0xFFF8;
                    adjustedHigh += (candidatePid.NaturalHigh & 7);

                    //  for testing out the nature comparison
                    uint pid = (adjustedHigh << 16) + candidatePid.AdjustedLow;

                    //  If any of them work, we will add this to
                    //  the new candidateSids list and break to
                    //  go to the next seed.  Check the nature.
                    uint pidNature = pid%25;

                    if (nature.Number == pidNature)
                    {
                        newSids.Add(sid);
                        break;
                    }
                }
            }

            CandidateSids = newSids;
        }