reimplemented 'pool' roll macro

This commit is contained in:
Valerie Wolfe 2024-04-03 14:57:21 -04:00
parent e8a8bdde85
commit 1a23989a8f
2 changed files with 35 additions and 2 deletions

View file

@ -81,6 +81,12 @@ namespace Dungeoneer.Interpreter {
public TokenSet() : base() { }
public TokenSet(List<Token> set) : base(set) { }
public Token Pop() {
Token output = this[0];
RemoveAt(0);
return output;
}
public override string ToString() {
var output = "";
foreach(Token token in this)

View file

@ -1,6 +1,7 @@
using System.Security.Cryptography;
using System.Text.RegularExpressions;
using Dungeoneer.Error;
using Dungeoneer.Interpreter;
namespace Dungeoneer {
@ -9,9 +10,35 @@ namespace Dungeoneer {
public static void Pool(TokenSet input) {
if(input.Count != 2)
throw new SyntaxException($"expected 2 arguments ({input.Count} given)");
foreach(var token in input)
);
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}");
}
}