2020-02-01 23:30:32 +01:00
|
|
|
#!/usr/bin/perl
|
2012-09-18 03:32:07 +02:00
|
|
|
|
2017-03-05 22:33:31 +01:00
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
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
|
|
|
}
|