Пример #1
0
 public string VisitDicePoolExpr(Expr.DicePool expr)
 {
     return($"{{{expr.Arguments.Aggregate("", (s, expr1) => s + (string.IsNullOrEmpty(s) ? expr1.Accept(this) : $", {expr1.Accept(this)}"))}}}{DicePoolModToString(expr.Mod)}{DicePoolModOpToString(expr.ModOp)}{expr.ModValue.Accept(this)}");
 }
Пример #2
0
        public object VisitDicePoolExpr(Expr.DicePool expr)
        {
            switch (expr.Mod)
            {
            case Expr.DicePool.DicePoolMod.KeepHighest:
            {
                var results = new List <double>();
                foreach (var argument in expr.Arguments)
                {
                    var result = argument.Accept(this);
                    CheckNumberOperand(null, result);
                    results.Add((double)result);
                }

                var modValue = expr.ModValue.Accept(this);
                CheckNumberOperand(null, modValue);

                results.Sort();
                results.Reverse();
                return(results.Take(Convert.ToInt32(modValue)).Sum());
            }

            case Expr.DicePool.DicePoolMod.KeepLowest:
            {
                var results = new List <double>();
                foreach (var argument in expr.Arguments)
                {
                    var result = argument.Accept(this);
                    CheckNumberOperand(null, result);
                    results.Add((double)result);
                }

                var modValue = expr.ModValue.Accept(this);
                CheckNumberOperand(null, modValue);

                results.Sort();
                return(results.Take(Convert.ToInt32(modValue)).Sum());
            }

            case Expr.DicePool.DicePoolMod.DropHighest:
            {
                var results = new List <double>();
                foreach (var argument in expr.Arguments)
                {
                    var result = argument.Accept(this);
                    CheckNumberOperand(null, result);
                    results.Add((double)result);
                }

                var modValue = expr.ModValue.Accept(this);
                CheckNumberOperand(null, modValue);

                results.Sort();
                results.Reverse();
                return(results.Skip(Convert.ToInt32(modValue)).Sum());
            }

            case Expr.DicePool.DicePoolMod.DropLowest:
            {
                var results = new List <double>();
                foreach (var argument in expr.Arguments)
                {
                    var result = argument.Accept(this);
                    CheckNumberOperand(null, result);
                    results.Add((double)result);
                }

                var modValue = expr.ModValue.Accept(this);
                CheckNumberOperand(null, modValue);

                results.Sort();
                return(results.Skip(Convert.ToInt32(modValue)).Sum());
            }

            case Expr.DicePool.DicePoolMod.CountSuccesses:
            {
                var results = new List <double>();
                foreach (var argument in expr.Arguments)
                {
                    var result = argument.Accept(this);
                    CheckNumberOperand(null, result);
                    results.Add((double)result);
                }

                var modValue = expr.ModValue.Accept(this);
                CheckNumberOperand(null, modValue);
                switch (expr.ModOp)
                {
                case Expr.DicePool.ModOperator.Equal:
                    return((double)results.Count(d => Math.Abs(d - (double)modValue) < 0.00001));

                case Expr.DicePool.ModOperator.Less:
                    return((double)results.Count(d => d < (double)modValue));

                case Expr.DicePool.ModOperator.LessEqual:
                    return((double)results.Count(d => d <= (double)modValue));

                case Expr.DicePool.ModOperator.Greater:
                    return((double)results.Count(d => d > (double)modValue));

                case Expr.DicePool.ModOperator.GreaterEqual:
                    return((double)results.Count(d => d >= (double)modValue));

                default:
                    throw new InterpreterError($"Invalid dice pool modifier operator '{expr.ModOp}' for '{expr.Mod}'");
                }
            }

            default:
                throw new InterpreterError($"Unknown dice pool modifier '{expr.Mod}'");
            }
        }
Пример #3
0
 public string VisitDicePoolExpr(Expr.DicePool expr)
 {
     return($"(dP {{{expr.Arguments.Aggregate("", (s, expr1) => string.IsNullOrEmpty(s) ? $"{expr1.Accept(this)}" : s + $", {expr1.Accept(this)}")}}} {expr.Mod} {expr.ModOp} {expr.ModValue.Accept(this)})");
 }