示例#1
0
        private string DicePoolModToString(Expr.DicePool.DicePoolMod mod)
        {
            switch (mod)
            {
            case Expr.DicePool.DicePoolMod.KeepHighest:
                return("kh");

            case Expr.DicePool.DicePoolMod.KeepLowest:
                return("kl");

            case Expr.DicePool.DicePoolMod.DropHighest:
                return("dh");

            case Expr.DicePool.DicePoolMod.DropLowest:
                return("dl");

            case Expr.DicePool.DicePoolMod.CountSuccesses:
                return("cs");

            default:
                return("??");
            }
        }
示例#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.");
                }
            }
        }