Fix Rolemaster low-end open roll math

This commit is contained in:
2026-04-03 00:58:07 +02:00
parent 0059fde74f
commit 960197354a
5 changed files with 35 additions and 14 deletions

View File

@@ -23,6 +23,9 @@ public partial class RollDiceStrip
private static string RollDieDisplay(RollDieResult die)
{
if (string.Equals(die.Kind, RollDieKinds.RolemasterOpenEndedInitial, StringComparison.Ordinal) && !die.SignedContribution.HasValue)
return $"({die.Roll:00})";
return die.Kind switch
{
RollDieKinds.RolemasterOpenEndedHigh => $"+{die.Roll}",
@@ -101,7 +104,7 @@ public partial class RollDiceStrip
labels.Add("Rolemaster percentile");
break;
case RollDieKinds.RolemasterOpenEndedInitial:
labels.Add("Rolemaster open-ended initial");
labels.Add(die.SignedContribution.HasValue ? "Rolemaster open-ended initial" : "Rolemaster low-end trigger (ignored in total)");
break;
case RollDieKinds.RolemasterOpenEndedHigh:
labels.Add($"Rolemaster high follow-up (+{die.Roll})");

View File

@@ -1007,12 +1007,13 @@ public sealed class GameService : IGameService
{
var initialRoll = m_DiceRoller.Roll(expression.Sides);
var followUpRolls = new List<int>();
int? initialContribution = initialRoll <= fumbleRange ? null : initialRoll;
var dice = new List<RollDieResult>
{
CreateRolemasterDie(initialRoll, 1, RollDieKinds.RolemasterOpenEndedInitial, initialRoll)
CreateRolemasterDie(initialRoll, 1, RollDieKinds.RolemasterOpenEndedInitial, initialContribution)
};
var baseTotal = initialRoll;
var baseTotal = initialRoll <= fumbleRange ? 0 : initialRoll;
var subtractFollowUps = false;
if (initialRoll >= 96)
{
@@ -1134,7 +1135,7 @@ public sealed class GameService : IGameService
return followUpRolls;
}
private static RollDieResult CreateRolemasterDie(int roll, int sequence, string kind, int signedContribution)
private static RollDieResult CreateRolemasterDie(int roll, int sequence, string kind, int? signedContribution)
{
return new(roll, false, false, false, false, kind == RollDieKinds.RolemasterOpenEndedHigh, sequence, kind, signedContribution);
}
@@ -1150,6 +1151,18 @@ public sealed class GameService : IGameService
private static string BuildRolemasterOpenEndedBreakdown(int initialRoll, IReadOnlyList<int> followUpRolls, bool subtractFollowUps, int modifier, int total)
{
if (subtractFollowUps)
{
var segments = new List<string> { $"({FormatRolemasterTriggerRoll(initialRoll)})" };
segments.AddRange(followUpRolls.Select(roll => $"-{roll}"));
if (modifier > 0)
segments.Add($"+{modifier}");
else if (modifier < 0)
segments.Add(modifier.ToString());
return $"{string.Join(" ", segments)} = {total}";
}
var core = initialRoll.ToString();
if (followUpRolls.Count > 0)
{
@@ -1160,6 +1173,11 @@ public sealed class GameService : IGameService
return BuildModifierBreakdown(core, modifier, total);
}
private static string FormatRolemasterTriggerRoll(int roll)
{
return roll.ToString("00");
}
private static string BuildModifierBreakdown(string core, int modifier, int total)
{
return modifier switch
@@ -1404,7 +1422,7 @@ public sealed class GameService : IGameService
.Select(die => die.Roll.ToString())
.ToArray();
if (lowFollowUps.Length > 0)
return $"{openEndedInitial.Roll} - ({string.Join(" + ", lowFollowUps)}) | open-ended low";
return $"({FormatRolemasterTriggerRoll(openEndedInitial.Roll)}) {string.Join(" ", lowFollowUps.Select(roll => $"-{roll}"))} | open-ended low";
return $"{openEndedInitial.Roll} | open-ended";
}