This project has moved. For the latest updates, please go here.

This is the code for the back end of the requirement. This may help you understand how the item is tested against the requirement.


        public bool CanReachTargetValues(double targetCalcedBuffedTinkedDoT, double targetBuffedMeleeDefenseBonus, double targetBuffedAttackBonus)
        {
            double buffedMeleeDefenseBonus = GetBuffedDoubleValueKey(DoubleValueKey.MeleeDefenseBonus);
            double buffedAttackBonus = GetBuffedDoubleValueKey(DoubleValueKey.AttackBonus);

            double variance = gameItemInfo.GetValueDouble(DoubleValueKey.Variance, 0.0);
            int maxDamage = GetBuffedLogValueKey(IntValueKey.MaxDamage);

            int numberOfTinksLeft = Math.Max(10 - gameItemInfo.GetValueInt(IntValueKey.NumberTimesTinkered, 0), 0);

            if (gameItemInfo.GetValueInt(IntValueKey.Imbued, 0) == 0)
                numberOfTinksLeft--; // Factor in an imbue tink

            // If this is not a loot generated item, it can't be tinked
            if (gameItemInfo.GetValueInt(IntValueKey.Material, 0) == 0)
                numberOfTinksLeft = 0;

            for (int i = 1; i <= numberOfTinksLeft; i++)
            {
                if (buffedMeleeDefenseBonus < targetBuffedMeleeDefenseBonus)
                    buffedMeleeDefenseBonus += .01;
                else if (buffedAttackBonus < targetBuffedAttackBonus)
                    buffedAttackBonus += .01;
                else
                {
                    double ironTinkDoT = CalculateDamageOverTime(maxDamage + 24 + 1, variance);
                    double graniteTinkDoT = CalculateDamageOverTime(maxDamage + 24, variance*.8);

                    if (ironTinkDoT >= graniteTinkDoT)
                        maxDamage++;
                    else
                        variance *= .8;
                }
            }

            return CalculateDamageOverTime(maxDamage + 24, variance) >= targetCalcedBuffedTinkedDoT && buffedMeleeDefenseBonus >= targetBuffedMeleeDefenseBonus && buffedAttackBonus >= targetBuffedAttackBonus;
        }

        /// <summary>
        /// maxDamage * ((1 - critChance) * (2 - variance) / 2 + (critChance * critMultiplier));
        /// </summary>
        /// <param name="maxDamage"></param>
        /// <param name="variance"></param>
        /// <param name="critChance"></param>
        /// <param name="critMultiplier"></param>
        /// <returns></returns>
        public static double CalculateDamageOverTime(int maxDamage, double variance, double critChance = .1, double critMultiplier = 2)
        {
            return maxDamage * ((1 - critChance) * (2 - variance) / 2 + (critChance * critMultiplier));
        }

Last edited Mar 15, 2013 at 2:16 AM by Mag_nus, version 6