Пример #1
0
        public DiceExpression Adjust(int level_adjustment)
        {
            Array dmgs = Enum.GetValues(typeof(DamageExpressionType));

            // Choose the closest level and work out the differences (in throws / sides / constant)
            int min_difference            = int.MaxValue;
            int best_level                = 0;
            DamageExpressionType best_det = DamageExpressionType.Normal;
            DiceExpression       best_exp = null;

            for (int level = 1; level <= 30; ++level)
            {
                foreach (DamageExpressionType det in dmgs)
                {
                    DiceExpression exp = DiceExpression.Parse(Statistics.Damage(level, det));

                    int diff_throws = Math.Abs(fThrows - exp.Throws);
                    int diff_sides  = Math.Abs(fSides - exp.Sides) / 2;
                    int diff_const  = Math.Abs(fConstant - exp.Constant);

                    int difference = (diff_throws * 10) + (diff_sides * 100) + diff_const;
                    if (difference < min_difference)
                    {
                        min_difference = difference;
                        best_level     = level;
                        best_det       = det;
                        best_exp       = exp;
                    }
                }
            }

            if (best_exp == null)
            {
                return(this);
            }

            int throw_diff = fThrows - best_exp.Throws;
            int sides_diff = fSides - best_exp.Sides;
            int const_diff = fConstant - best_exp.Constant;

            // Adjust the new expression
            int            adj_level = Math.Max(best_level + level_adjustment, 1);
            DiceExpression adjusted  = DiceExpression.Parse(Statistics.Damage(adj_level, best_det));

            adjusted.Throws   += throw_diff;
            adjusted.Sides    += sides_diff;
            adjusted.Constant += const_diff;

            if (fThrows == 0)
            {
                adjusted.Throws = 0;
            }
            else
            {
                adjusted.Throws = Math.Max(adjusted.Throws, 1);
            }

            // Make sure we have a valid dice type
            switch (adjusted.Sides)
            {
            case 0:
            case 1:
            case 2:
            case 3:
            case 4:
                adjusted.Sides = 4;
                break;

            case 5:
            case 6:
                adjusted.Sides = 6;
                break;

            case 7:
            case 8:
                adjusted.Sides = 8;
                break;

            case 9:
            case 10:
                adjusted.Sides = 10;
                break;

            case 11:
            case 12:
            case 13:
            case 14:
            case 15:
            case 16:
                adjusted.Sides = 12;
                break;

            default:
                adjusted.Sides = 20;
                break;
            }

            return(adjusted);
        }
Пример #2
0
        public DiceExpression Adjust(int level_adjustment)
        {
            Array values = Enum.GetValues(typeof(DamageExpressionType));
            int   num    = 2147483647;
            int   num1   = 0;
            DamageExpressionType damageExpressionType = DamageExpressionType.Normal;
            DiceExpression       diceExpression       = null;

            for (int i = 1; i <= 30; i++)
            {
                foreach (DamageExpressionType value in values)
                {
                    DiceExpression diceExpression1 = DiceExpression.Parse(Statistics.Damage(i, value));
                    int            num2            = Math.Abs(this.fThrows - diceExpression1.Throws);
                    int            num3            = Math.Abs(this.fSides - diceExpression1.Sides) / 2;
                    int            num4            = Math.Abs(this.fConstant - diceExpression1.Constant);
                    int            num5            = num2 * 10 + num3 * 100 + num4;
                    if (num5 >= num)
                    {
                        continue;
                    }
                    num  = num5;
                    num1 = i;
                    damageExpressionType = value;
                    diceExpression       = diceExpression1;
                }
            }
            if (diceExpression == null)
            {
                return(this);
            }
            int            throws          = this.fThrows - diceExpression.Throws;
            int            sides           = this.fSides - diceExpression.Sides;
            int            constant        = this.fConstant - diceExpression.Constant;
            int            num6            = Math.Max(num1 + level_adjustment, 1);
            DiceExpression diceExpression2 = DiceExpression.Parse(Statistics.Damage(num6, damageExpressionType));
            DiceExpression throws1         = diceExpression2;

            throws1.Throws = throws1.Throws + throws;
            DiceExpression sides1 = diceExpression2;

            sides1.Sides = sides1.Sides + sides;
            DiceExpression constant1 = diceExpression2;

            constant1.Constant = constant1.Constant + constant;
            if (this.fThrows != 0)
            {
                diceExpression2.Throws = Math.Max(diceExpression2.Throws, 1);
            }
            else
            {
                diceExpression2.Throws = 0;
            }
            switch (diceExpression2.Sides)
            {
            case 0:
            case 1:
            case 2:
            case 3:
            case 4:
            {
                diceExpression2.Sides = 4;
                break;
            }

            case 5:
            case 6:
            {
                diceExpression2.Sides = 6;
                break;
            }

            case 7:
            case 8:
            {
                diceExpression2.Sides = 8;
                break;
            }

            case 9:
            case 10:
            {
                diceExpression2.Sides = 10;
                break;
            }

            case 11:
            case 12:
            case 13:
            case 14:
            case 15:
            case 16:
            {
                diceExpression2.Sides = 12;
                break;
            }

            default:
            {
                diceExpression2.Sides = 20;
                break;
            }
            }
            return(diceExpression2);
        }