2021-02-07 23:37:12 +01:00
|
|
|
#!/usr/bin/env perl
|
2012-09-18 03:32:07 +02:00
|
|
|
|
2021-07-11 00:00:22 +02:00
|
|
|
# SPDX-FileCopyrightText: 2021 Pragmatic Software <pragma78@gmail.com>
|
|
|
|
# SPDX-License-Identifier: MIT
|
2017-03-05 22:33:31 +01:00
|
|
|
|
2012-09-18 03:32:07 +02:00
|
|
|
# quick and dirty by :pragma
|
|
|
|
|
|
|
|
use Games::Dice qw/roll roll_array/;
|
|
|
|
|
|
|
|
my ($result, $rolls, $show);
|
|
|
|
|
2020-02-15 23:38:32 +01:00
|
|
|
if ($#ARGV < 0) {
|
|
|
|
print "Usage: roll [-show] <dice roll>; e.g.: roll 3d6+1. To see all individual dice rolls, add -show.\n";
|
|
|
|
die;
|
2012-09-18 03:32:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$rolls = join("", @ARGV);
|
|
|
|
|
2020-02-15 23:38:32 +01:00
|
|
|
if ($rolls =~ s/\s*-show\s*//) { $show = 1; }
|
2012-09-18 03:32:07 +02:00
|
|
|
|
2019-05-28 18:19:42 +02:00
|
|
|
if ($rolls =~ m/^\s*(\d+)d\d+(?:\+?-?\d+)?\s*$/) {
|
2020-02-15 23:38:32 +01:00
|
|
|
if ($1 > 100) {
|
|
|
|
print "Sorry, maximum of 100 rolls.\n";
|
|
|
|
die;
|
|
|
|
}
|
2012-09-18 03:32:07 +02:00
|
|
|
} else {
|
2020-02-15 23:38:32 +01:00
|
|
|
print "Usage: roll [-show] <dice roll>; e.g.: roll 3d6+1. To see all individual dice rolls, add -show.\n";
|
|
|
|
die;
|
2012-09-18 03:32:07 +02:00
|
|
|
}
|
|
|
|
|
2019-05-28 18:19:42 +02:00
|
|
|
if ($show) {
|
2020-02-15 23:38:32 +01:00
|
|
|
my @results = roll_array $rolls;
|
|
|
|
$result = 0;
|
|
|
|
foreach my $n (@results) { $result += $n; }
|
|
|
|
print "/me rolled $rolls for @results totaling $result.\n";
|
2012-09-18 03:32:07 +02:00
|
|
|
} else {
|
2020-02-15 23:38:32 +01:00
|
|
|
$result = roll $rolls;
|
|
|
|
print "/me rolled $rolls for $result.\n";
|
2012-09-18 03:32:07 +02:00
|
|
|
}
|