| 1 | package Acme::CoC::Dice; | ||||||||||||
| 2 | |||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 2 | ▶ | use utf8; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | |||||||||||||
| 7 | 2 | ▶ | use Carp qw/croak/; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | |||||||||||||
| 9 | 2 | our $VERSION = '0.01'; | |||||||||||
| 10 | |||||||||||||
| 11 | sub role { | ||||||||||||
| 12 | 4 | ▶ | my ($self, $command) = @_; | ||||||||||
|
Subroutine
role: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||
| 13 | |||||||||||||
| 14 | # MdN in $command can be separated to M/d/N, and M is the times of roling dice, N is the number of sided dice. | ||||||||||||
| 15 | 4 | ▶ | return $self->role_skill if $command =~ /^skill$/; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 16 | |||||||||||||
| 17 | 3 | $command =~ /([1-9][0-9]*)d([1-9][0-9]*)/; | |||||||||||
| 18 | 3 | my $role_result = { | |||||||||||
| 19 | message => 'input invalid command', | ||||||||||||
| 20 | }; | ||||||||||||
| 21 | 3 | ▶ | return $role_result unless $command; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 22 | |||||||||||||
| 23 | 3 | ▶ | my $times = $1 || 1; | ||||||||||
|
Condition50%1/2
$1 || 1
MC/DC0%0/1
$1 || 1
$1
Truth table50%1/2
A
A= $1
| |||||||||||||
| 24 | 3 | ▶ | my $sided_dice = $2 || 100; | ||||||||||
|
Condition50%1/2
$2 || 100
MC/DC0%0/1
$2 || 100
$2
Truth table50%1/2
A
A= $2
| |||||||||||||
| 25 | 3 | my $results = []; | |||||||||||
| 26 | 3 | my $sum = 0; | |||||||||||
| 27 | |||||||||||||
| 28 | 3 | for (1..$times) { | |||||||||||
| 29 | 12 | my $rand_num = int(rand($sided_dice)) + 1; | |||||||||||
| 30 | 12 | push @{ $results }, $rand_num; | |||||||||||
| 31 | 12 | $sum += $rand_num; | |||||||||||
| 32 | } | ||||||||||||
| 33 | |||||||||||||
| 34 | $role_result = { | ||||||||||||
| 35 | 3 | dices => $results, | |||||||||||
| 36 | sum => $sum, | ||||||||||||
| 37 | }; | ||||||||||||
| 38 | 3 | return $role_result; | |||||||||||
| 39 | } | ||||||||||||
| 40 | |||||||||||||
| 41 | sub role_skill { | ||||||||||||
| 42 | 1 | ▶ | my ($self) = @_; | ||||||||||
|
Subroutine
role_skill: called CC=1 SCAR=0.0
| |||||||||||||
| 43 | |||||||||||||
| 44 | 1 | return $self->role('1d100'); | |||||||||||
| 45 | } | ||||||||||||
| 46 | |||||||||||||
| 47 | 2 | 1; | |||||||||||
| 48 | __END__ | ||||||||||||