functions.php: handle very large numbers with handle_dice_roll_markup

This commit is contained in:
Zankaria 2024-10-15 21:10:00 +02:00
parent cc82987bb0
commit 585e5638fd

View file

@ -2813,10 +2813,12 @@ function handle_dice_roll_markup(array $matches, ?string $img_path): string {
$dice_faces = 6; $dice_faces = 6;
} }
$tot = $dice_offset; $tot = 0;
for ($i = 0; $i < $dice_count; $i++) { for ($i = 0; $i < $dice_count; $i++) {
$tot += mt_rand(1, $dice_faces); $tot += mt_rand(1, $dice_faces);
} }
// Ensure that final result is at least an integer.
$tot = abs((int)($dice_offset + $tot));
if ($img_path !== null) { if ($img_path !== null) {
$img_text = "<img src='{$config['root']}{$img_path}' alt='dice' title='dice' class=\"inline-dice\"/>"; $img_text = "<img src='{$config['root']}{$img_path}' alt='dice' title='dice' class=\"inline-dice\"/>";