-
Notifications
You must be signed in to change notification settings - Fork 0
/
Display.cs
125 lines (110 loc) · 3.84 KB
/
Display.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
using System.Linq;
using System.Collections.Generic;
using System.Threading;
static class Display
{
public static Result Total(string desc, IList<int> rolls)
{
return new Result {
Description = desc,
Summary = notable(rolls.Sum()),
Verbose = string.Format("[{0}]", string.Join(" ", rolls.Select(r => normalDigit(r))))
};
}
public static Result FATE(string desc, IList<int> rolls)
{
return new Result
{
Description = desc,
Summary = rolls.Sum() > 0 ? notable("+" + rolls.Sum().ToString()) :
notable(rolls.Sum()),
Verbose = string.Format("[{0}]", string.Join(" ", rolls.Select(r => r > 0 ? good("+") : r < 0 ? bad("-") : " ")))
};
}
public static Result Binary(string desc, IList<int> rolls, int successTarget, int failureTarget)
{
var ss = rolls.Where(r => r >= successTarget);
var fs = rolls.Where(r => r <= failureTarget);
return new Result {
Description = desc,
Summary = ss.Count() == rolls.Count() ? "[Success]" :
fs.Count() == rolls.Count() ? $"[{bad("Dramatic")} Failure]" : "[Failure]",
Verbose = string.Format("[{0}]", string.Join(" ", rolls.Select(r => (r >= successTarget) ? successDigit(r) : (r <= failureTarget ? bad(r) : normalDigit(r)))))
};
}
public static Result Successes(string desc, IList<int> rolls, int target, int extraSuccesses = 0)
{
var ss = rolls.Where(r => r >= target);
return new Result {
Description = desc,
Summary = ss.Any() ? string.Format("[Success: {0}]", notable(ss.Count() + extraSuccesses)) : "[Failure]",
Verbose = string.Format("[{0}]", string.Join(" ", rolls.Select(r => (r >= target) ? successDigit(r) : normalDigit(r))))
};
}
public static Result ExplodingSuccesses(string desc, int successTarget, int successes, int botches, bool exceptional, IList<IList<IList<int>>> lists)
{
string fmtG(IList<int> g)
{
return string.Join("->", g.Select((r, ix) => fmtR(r, ix == g.Count-1)));
}
string fmtR(int r, bool last)
{
if (r >= successTarget)
{
if (!last)
{
return good(r);
}
else
{
return successDigit(r);
}
}
else
{
if (r == 1 && botches > 0)
{
return bad(r);
}
else
{
return normalDigit(r);
}
}
}
var resultLists = new List<string>();
foreach (var rolls in lists)
{
var ss = rolls.SelectMany(x => x).Where(r => r >= successTarget);
resultLists.Add(string.Format("[{0}]", string.Join(" ", rolls.Select(fmtG))));
}
return new Result
{
Description = desc,
Summary = exceptional ? $"[{good("Exceptional")} Success: {notable(successes)}]" :
successes > 0 ? $"[Success: {notable(successes)}]" :
(botches > 0 ? $"[{bad("Dramatic")} Failure]" : "[Failure]"),
Verbose = string.Join(" ", resultLists)
};
}
private static string good(object text)
{
return string.Format("\x000309{0}\x03", text);
}
private static string bad(object text)
{
return string.Format("\x000304{0}\x03", text);
}
private static string notable(object text)
{
return string.Format("\x0002{0}\x02", text);
}
private static string successDigit(object text)
{
return string.Format("{0}", text);
}
private static string normalDigit(object text)
{
return string.Format("\x000314{0}\x03", text);
}
}