57 lines
1.9 KiB
C#
57 lines
1.9 KiB
C#
namespace RpgRoller.Services;
|
|
|
|
public static class RollBreakdownFormatter
|
|
{
|
|
public static string BuildBreakdown(IEnumerable<int> diceValues, int modifier, int total)
|
|
{
|
|
var dicePart = string.Join("+", diceValues);
|
|
if (string.IsNullOrWhiteSpace(dicePart))
|
|
dicePart = "0";
|
|
|
|
return BuildModifierBreakdown(dicePart, modifier, total);
|
|
}
|
|
|
|
public 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)
|
|
{
|
|
var followUpBreakdown = string.Join("+", followUpRolls);
|
|
core = $"{core}+{followUpBreakdown}";
|
|
}
|
|
|
|
return BuildModifierBreakdown(core, modifier, total);
|
|
}
|
|
|
|
public static string BuildRolemasterRetryBreakdown(string firstAttemptBreakdown, int retryBonus, string retryAttemptBreakdown, int finalTotal)
|
|
{
|
|
return $"{firstAttemptBreakdown}; retry(+{retryBonus}): {retryAttemptBreakdown}; final={finalTotal}";
|
|
}
|
|
|
|
public static string FormatRolemasterTriggerRoll(int roll)
|
|
{
|
|
return roll.ToString("00");
|
|
}
|
|
|
|
public static string BuildModifierBreakdown(string core, int modifier, int total)
|
|
{
|
|
return modifier switch
|
|
{
|
|
> 0 => $"{core}+{modifier}={total}",
|
|
< 0 => $"{core}{modifier}={total}",
|
|
_ => $"{core}={total}"
|
|
};
|
|
}
|
|
} |