Exemple #1
0
        private string DicePoolModOpToString(Expr.DicePool.ModOperator modOp)
        {
            switch (modOp)
            {
            case Expr.DicePool.ModOperator.Equal:
                return("=");

            case Expr.DicePool.ModOperator.Less:
                return("<");

            case Expr.DicePool.ModOperator.LessEqual:
                return("<=");

            case Expr.DicePool.ModOperator.Greater:
                return(">");

            case Expr.DicePool.ModOperator.GreaterEqual:
                return(">=");

            default:
                return("??");
            }
        }
Exemple #2
0
        private void GetDicePoolModifiers(out Expr.DicePool.DicePoolMod mod, out Expr.DicePool.ModOperator modOp, out Expr modValue)
        {
            Token tMod = Consume(TokenType.Identifier, "Expect dice pool modifier after dice pool.");

            switch (tMod.Lexeme)
            {
            case "kh":
                mod = Expr.DicePool.DicePoolMod.KeepHighest;
                break;

            case "kl":
                mod = Expr.DicePool.DicePoolMod.KeepLowest;
                break;

            case "dh":
                mod = Expr.DicePool.DicePoolMod.DropHighest;
                break;

            case "dl":
                mod = Expr.DicePool.DicePoolMod.DropLowest;
                break;

            case "cs":
                mod = Expr.DicePool.DicePoolMod.CountSuccesses;
                break;

            default:
                throw new ParserException($"Expected dice pool modifier, got '{tMod}'.");
            }


            // Now there should be a operator
            Token tModOp = Peek();

            modValue = null;
            switch (tModOp.Type)
            {
            case TokenType.Equal:
                modOp = Expr.DicePool.ModOperator.Equal;
                Advance();
                break;

            case TokenType.Less:
                modOp = Expr.DicePool.ModOperator.Less;
                Advance();
                break;

            case TokenType.LessEqual:
                modOp = Expr.DicePool.ModOperator.LessEqual;
                Advance();
                break;

            case TokenType.Greater:
                modOp = Expr.DicePool.ModOperator.Greater;
                Advance();
                break;

            case TokenType.GreaterEqual:
                modOp = Expr.DicePool.ModOperator.GreaterEqual;
                Advance();
                break;

            case TokenType.Number:
                modOp    = Expr.DicePool.ModOperator.Equal;
                modValue = Primary();
                break;

            default:
                modOp    = Expr.DicePool.ModOperator.Equal;
                modValue = new Expr.Literal(1.0d);
                break;
                //throw new ParserException($"Expected dice mod operator, got '{tModOp}'.");
            }

            if (modValue == null)
            {
                modValue = Call();
            }

            if (mod == Expr.DicePool.DicePoolMod.KeepHighest || mod == Expr.DicePool.DicePoolMod.KeepLowest ||
                mod == Expr.DicePool.DicePoolMod.DropHighest || mod == Expr.DicePool.DicePoolMod.DropLowest)
            {
                if (modOp != Expr.DicePool.ModOperator.Equal)
                {
                    throw new ParserException($"{mod} only makes sense with operator equal.");
                }
            }
        }