dungeoneer-cs/src/Roll.cs

48 lines
1 KiB
C#
Raw Normal View History

using System.Security.Cryptography;
using System.Text.RegularExpressions;
2024-04-03 14:57:21 -04:00
using Dungeoneer.Error;
using Dungeoneer.Interpreter;
namespace Dungeoneer {
2024-04-01 21:41:04 -04:00
public static class RollMacro {
public static void Pool(TokenSet input) {
if(input.Count != 2)
2024-04-03 14:57:21 -04:00
throw new SyntaxException($"expected 2 arguments ({input.Count} given)");
DiceToken dicePool = null;
DcToken target = null;
foreach(var token in input) {
switch(token) {
case DiceToken dice:
if(dicePool != null)
throw new SyntaxException("two dice");
dicePool = dice;
break;
case DcToken dc:
if(target != null)
throw new SyntaxException("two dc values");
target = dc;
break;
}
}
bool success = false;
foreach(var roll in dicePool.Result) {
if(roll > target.Value) {
success = true;
break;
}
}
string message = success ? $"{Format.Green}pass" : "{Format.Red}fail";
Console.WriteLine($"{dicePool} > {target}\n => {message}{Format.Reset}");
2024-04-01 21:41:04 -04:00
}
}
}