33 lines
649 B
C#
33 lines
649 B
C#
using System.Text.RegularExpressions;
|
|
|
|
namespace Dungeoneer {
|
|
|
|
public sealed class Command {
|
|
|
|
public static void Roll(IList<string> args) {
|
|
// don't do anything with empty expressions
|
|
if(args.Count == 0)
|
|
return;
|
|
|
|
// pass to subcommands
|
|
var first = args[0];
|
|
if(Program.RollMacros.ContainsKey(first)) {
|
|
Program.RollMacros[first](args);
|
|
return;
|
|
}
|
|
|
|
// create new parsed expression object and pretty-print
|
|
var roll = new RollExpression(args);
|
|
var result = roll.Result;
|
|
if(result == null)
|
|
Console.WriteLine("invalid expression");
|
|
else
|
|
Console.WriteLine($"{roll.Print}\n => {result}");
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|