2024-03-31 21:02:02 -04:00
|
|
|
using System.Security.Cryptography;
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
2024-04-03 12:01:06 -04:00
|
|
|
using Dungeoneer.Interpreter;
|
2024-03-31 21:02:02 -04:00
|
|
|
|
|
|
|
namespace Dungeoneer {
|
|
|
|
|
2024-04-01 21:41:04 -04:00
|
|
|
public class RollResult {
|
|
|
|
public dynamic Value { get; private set; }
|
|
|
|
|
|
|
|
private RollResult() { Value = null; }
|
|
|
|
public RollResult(string expression) {
|
|
|
|
Value = Scripting.Expr($"eval('{expression}')");
|
|
|
|
}
|
|
|
|
|
|
|
|
internal static class Style {
|
|
|
|
internal const string Default = "\x1b[1m";
|
|
|
|
|
|
|
|
internal const string BoolTrue = "\x1b[32;1m";
|
|
|
|
internal const string BoolFalse = "\x1b[31;1m";
|
|
|
|
}
|
|
|
|
|
|
|
|
public override string ToString() {
|
|
|
|
string style;
|
|
|
|
switch(Value) {
|
|
|
|
case bool boolValue:
|
|
|
|
style = boolValue ? Style.BoolTrue : Style.BoolFalse;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
style = Style.Default;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $"{style}{Value}{Format.Reset}";
|
|
|
|
}
|
|
|
|
|
|
|
|
public static RollResult Wrap(dynamic value) {
|
|
|
|
var output = new RollResult();
|
|
|
|
output.Value = value;
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2024-03-31 21:02:02 -04:00
|
|
|
public class RollExpression {
|
|
|
|
private IList<string> Parts;
|
|
|
|
public string Print { get; private set; }
|
|
|
|
public string Expression { get; private set; }
|
2024-04-01 21:41:04 -04:00
|
|
|
public RollResult Result {
|
2024-03-31 21:02:02 -04:00
|
|
|
get {
|
2024-04-01 21:41:04 -04:00
|
|
|
try { return new RollResult(Expression); }
|
2024-03-31 21:02:02 -04:00
|
|
|
catch { return null; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public RollExpression(IList<string> parts) {
|
|
|
|
this.Parts = parts;
|
|
|
|
this.Print = "";
|
|
|
|
this.Expression = "";
|
|
|
|
|
|
|
|
// build expression from string parts
|
|
|
|
foreach(string piece in Parts) {
|
|
|
|
// die expression substitution
|
|
|
|
var dieCheck = DiceToken.Match(piece);
|
|
|
|
if(dieCheck.Success) {
|
|
|
|
var token = new DiceToken(dieCheck);
|
|
|
|
|
2024-04-02 21:05:08 -04:00
|
|
|
this.Print += $"{token} ";
|
|
|
|
this.Expression += $"{token.Value} ";
|
2024-03-31 21:02:02 -04:00
|
|
|
} else {
|
|
|
|
var part = $"{piece} ";
|
|
|
|
this.Expression += part;
|
|
|
|
this.Print += part;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2024-04-01 21:41:04 -04:00
|
|
|
public static class RollMacro {
|
|
|
|
|
2024-04-03 12:01:06 -04:00
|
|
|
public static void Pool(TokenSet input) {
|
|
|
|
/*
|
2024-04-01 21:41:04 -04:00
|
|
|
foreach(var roll in rolls)
|
|
|
|
if(roll > dc.Value) {
|
|
|
|
success = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
var result = RollResult.Wrap(success);
|
2024-04-03 12:01:06 -04:00
|
|
|
Console.WriteLine($"{dice}\n => {result}");*/
|
2024-04-01 21:41:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2024-03-31 21:02:02 -04:00
|
|
|
}
|
|
|
|
|