| 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 Acme::CoC::Util; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 8 | 2 | ▶ | use Acme::CoC::Types; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 9 | |||||||||||||||||||
| 10 | 2 | ▶ | use Carp qw/croak/; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 11 | 2 | ▶ | use Smart::Args; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 12 | |||||||||||||||||||
| 13 | 2 | our $VERSION = '0.03'; | |||||||||||||||||
| 14 | |||||||||||||||||||
| 15 | 8 | ▶ | sub role { | ||||||||||||||||
|
Subroutine
role: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||
| 16 | 8 | args_pos | |||||||||||||||||
| 17 | my $self, | ||||||||||||||||||
| 18 | my $command => {isa => 'command'}, | ||||||||||||||||||
| 19 | ; | ||||||||||||||||||
| 20 | |||||||||||||||||||
| 21 | # 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. | ||||||||||||||||||
| 22 | 8 | ▶ | return $self->role_skill(get_target($command)) if is_ccb($command); | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 23 | |||||||||||||||||||
| 24 | 5 | $command =~ /([1-9][0-9]*)d([1-9][0-9]*)/; | |||||||||||||||||
| 25 | 5 | my $role_result = { | |||||||||||||||||
| 26 | message => 'input invalid command', | ||||||||||||||||||
| 27 | }; | ||||||||||||||||||
| 28 | 5 | ▶ | return $role_result unless $command; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 29 | |||||||||||||||||||
| 30 | 5 | ▶ | my $times = $1 || 1; | ||||||||||||||||
|
Condition50%1/2
$1 || 1
MC/DC0%0/1
$1 || 1
$1
Truth table50%1/2
A
A= $1
| |||||||||||||||||||
| 31 | 5 | ▶ | my $sided_dice = $2 || 100; | ||||||||||||||||
|
Condition50%1/2
$2 || 100
MC/DC0%0/1
$2 || 100
$2
Truth table50%1/2
A
A= $2
| |||||||||||||||||||
| 32 | 5 | my $results = []; | |||||||||||||||||
| 33 | 5 | my $sum = 0; | |||||||||||||||||
| 34 | |||||||||||||||||||
| 35 | 5 | for (1..$times) { | |||||||||||||||||
| 36 | 14 | my $rand_num = int(rand($sided_dice)) + 1; | |||||||||||||||||
| 37 | 14 | push @{ $results }, $rand_num; | |||||||||||||||||
| 38 | 14 | $sum += $rand_num; | |||||||||||||||||
| 39 | } | ||||||||||||||||||
| 40 | |||||||||||||||||||
| 41 | $role_result = { | ||||||||||||||||||
| 42 | 5 | dices => $results, | |||||||||||||||||
| 43 | sum => $sum, | ||||||||||||||||||
| 44 | }; | ||||||||||||||||||
| 45 | 5 | return $role_result; | |||||||||||||||||
| 46 | } | ||||||||||||||||||
| 47 | |||||||||||||||||||
| 48 | 3 | ▶ | sub role_skill { | ||||||||||||||||
|
Subroutine
role_skill: called CC=5 SCAR=16.7
| |||||||||||||||||||
| 49 | 3 | args_pos | |||||||||||||||||
| 50 | my $self, | ||||||||||||||||||
| 51 | my $target => {isa => 'Maybe[Int]', optional => 1}, | ||||||||||||||||||
| 52 | ; | ||||||||||||||||||
| 53 | 3 | my $role = $self->role('1d100'); | |||||||||||||||||
| 54 | 3 | ▶ | if (defined $target) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 55 | 2 | ▶ | if (is_extream($role->{dices}->[0], $target)) { | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 56 | 0 | $role->{result} = 'extream success'; | |||||||||||||||||
| 57 | } elsif (is_hard($role->{dices}->[0], $target)) { | ||||||||||||||||||
| 58 | 1 | $role->{result} = 'hard success'; | |||||||||||||||||
| 59 | } elsif (is_failed($role->{dices}->[0], $target)) { | ||||||||||||||||||
| 60 | 0 | $role->{result} = 'failed'; | |||||||||||||||||
| 61 | } else { | ||||||||||||||||||
| 62 | 1 | $role->{result} = 'normal success'; | |||||||||||||||||
| 63 | } | ||||||||||||||||||
| 64 | } | ||||||||||||||||||
| 65 | 3 | return $role; | |||||||||||||||||
| 66 | } | ||||||||||||||||||
| 67 | |||||||||||||||||||
| 68 | 2 | 1; | |||||||||||||||||
| 69 | __END__ | ||||||||||||||||||