Ejemplo n.º 1
0
        public static string ExtractDamage(string source)
        {
            string[] separators = { ",", ";", ".", ":", Environment.NewLine };
            string[] sections   = source.Split(separators, StringSplitOptions.RemoveEmptyEntries);

            foreach (string section in sections)
            {
                string str = section.Trim().ToLower();

                if (str.Contains("damage") || str.Contains("dmg"))
                {
                    return(str);
                }
            }

            foreach (string section in sections)
            {
                DiceExpression exp = DiceExpression.Parse(section);
                if (exp != null)
                {
                    return(section);
                }
            }

            return("");
        }
Ejemplo n.º 2
0
        public static DiceExpression Parse(string str)
        {
            DiceExpression diceExpression = new DiceExpression();

            try
            {
                bool   flag     = false;
                bool   flag1    = false;
                char[] chrArray = new char[] { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' };
                str = str.ToLower();
                str = str.Replace("+", " + ");
                str = str.Replace("-", " - ");
                string[] strArrays = str.Split(null);
                for (int i = 0; i < (int)strArrays.Length; i++)
                {
                    string str1 = strArrays[i];
                    if (str1 == "damage" || str1 == "dmg")
                    {
                        break;
                    }
                    if (str1 == "-" && flag)
                    {
                        flag1 = true;
                    }
                    else if (str1.IndexOfAny(chrArray) != -1)
                    {
                        int num = str1.IndexOf("d");
                        if (num != -1)
                        {
                            string str2 = str1.Substring(0, num);
                            string str3 = str1.Substring(num + 1);
                            if (str2 != "")
                            {
                                diceExpression.Throws = int.Parse(str2);
                            }
                            diceExpression.Sides = int.Parse(str3);
                        }
                        else if (diceExpression.Constant == 0)
                        {
                            diceExpression.Constant = int.Parse(str1);
                            if (flag1)
                            {
                                diceExpression.Constant = -diceExpression.Constant;
                            }
                        }
                        flag = true;
                    }
                }
            }
            catch
            {
                diceExpression = null;
            }
            if (diceExpression != null && diceExpression.Throws == 0 && diceExpression.Constant == 0)
            {
                diceExpression = null;
            }
            return(diceExpression);
        }
Ejemplo n.º 3
0
        public static string ExtractDamage(string source)
        {
            string str;

            string[] newLine    = new string[] { ",", ";", ".", ":", Environment.NewLine };
            string[] strArrays  = source.Split(newLine, StringSplitOptions.RemoveEmptyEntries);
            string[] strArrays1 = strArrays;
            int      num        = 0;

            while (true)
            {
                if (num < (int)strArrays1.Length)
                {
                    string lower = strArrays1[num].Trim().ToLower();
                    if (lower.Contains("damage") || lower.Contains("dmg"))
                    {
                        str = lower;
                        break;
                    }
                    else
                    {
                        num++;
                    }
                }
                else
                {
                    string[] strArrays2 = strArrays;
                    int      num1       = 0;
                    while (num1 < (int)strArrays2.Length)
                    {
                        string str1 = strArrays2[num1];
                        if (DiceExpression.Parse(str1) == null)
                        {
                            num1++;
                        }
                        else
                        {
                            str = str1;
                            return(str);
                        }
                    }
                    return("");
                }
            }
            return(str);
        }
Ejemplo n.º 4
0
        public static void AdjustPowerLevel(CreaturePower cp, int delta)
        {
            if (cp.Attack != null)
            {
                PowerAttack attack = cp.Attack;
                attack.Bonus = attack.Bonus + delta;
            }
            string str = AI.ExtractDamage(cp.Details);

            if (str != "")
            {
                DiceExpression diceExpression = DiceExpression.Parse(str);
                if (diceExpression != null)
                {
                    DiceExpression diceExpression1 = diceExpression.Adjust(delta);
                    if (diceExpression1 != null && diceExpression.ToString() != diceExpression1.ToString())
                    {
                        cp.Details = cp.Details.Replace(str, string.Concat(diceExpression1, " damage"));
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public static void AdjustPowerLevel(CreaturePower cp, int delta)
        {
            if (cp.Attack != null)
            {
                cp.Attack.Bonus += delta;
            }

            // Adjust power damage
            string dmg_str = AI.ExtractDamage(cp.Details);

            if (dmg_str != "")
            {
                DiceExpression exp = DiceExpression.Parse(dmg_str);
                if (exp != null)
                {
                    DiceExpression exp_adj = exp.Adjust(delta);
                    if ((exp_adj != null) && (exp.ToString() != exp_adj.ToString()))
                    {
                        cp.Details = cp.Details.Replace(dmg_str, exp_adj + " damage");
                    }
                }
            }
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
        public static DiceExpression Parse(string str)
        {
            DiceExpression exp = new DiceExpression();

            try
            {
                bool   started = false;
                bool   minus   = false;
                char[] digits  = { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' };

                str = str.ToLower();
                str = str.Replace("+", " + ");
                str = str.Replace("-", " - ");

                string[] tokens = str.Split(null);
                foreach (string token in tokens)
                {
                    if ((token == "damage") || (token == "dmg"))
                    {
                        break;
                    }

                    if ((token == "-") && (started))
                    {
                        minus = true;
                        continue;
                    }

                    if (token.IndexOfAny(digits) == -1)
                    {
                        continue;
                    }

                    // Has a 'd'
                    int d_index = token.IndexOf("d");
                    if (d_index != -1)
                    {
                        string throws = token.Substring(0, d_index);
                        string sides  = token.Substring(d_index + 1);

                        if (throws != "")
                        {
                            exp.Throws = int.Parse(throws);
                        }

                        exp.Sides = int.Parse(sides);
                    }
                    else
                    {
                        if (exp.Constant == 0)
                        {
                            exp.Constant = int.Parse(token);

                            if (minus)
                            {
                                exp.Constant = -exp.Constant;
                            }
                        }
                    }

                    started = true;
                }
            }
            catch
            {
                // Parse error?
                exp = null;
            }

            if ((exp != null) && (exp.Throws == 0) && (exp.Constant == 0))
            {
                exp = null;
            }

            return(exp);
        }
Ejemplo n.º 8
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);
        }