From 8f59c28565366c3f494690172b62e4ab5126b3e5 Mon Sep 17 00:00:00 2001 From: Alex Kerr Date: Thu, 22 Jan 2015 14:16:32 +0000 Subject: [PATCH] OSRIC::Util::d exports correctly --- lib/OSRIC/Character.pm | 2 +- lib/OSRIC/Util.pm | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/OSRIC/Character.pm b/lib/OSRIC/Character.pm index b5f8931..e8ccc26 100644 --- a/lib/OSRIC/Character.pm +++ b/lib/OSRIC/Character.pm @@ -72,7 +72,7 @@ sub generate_stats # * Class specific boosts. # * Perhaps an alternate system where players can choose what number # to allocate to what stat. - $self->{stats}->{$stat} = (d(6) + d(6) + d(6)); + $self->{stats}->{$stat} = d(6, 3); } } diff --git a/lib/OSRIC/Util.pm b/lib/OSRIC/Util.pm index 1a5c079..633cd93 100644 --- a/lib/OSRIC/Util.pm +++ b/lib/OSRIC/Util.pm @@ -1,10 +1,19 @@ package OSRIC::Util; +use Exporter qw/import/; +our @EXPORT = qw/d/; # Rolls a dice of the specified number: sub d { - my $n = shift; - return int(rand($n)); + # The range of the dice: + my $range = shift; + + # Optional: The number of dice thrown. + my $n = shift // 1; + + my $i = 0; + $i += int(rand($range)); + return $i; } 1;