-
Notifications
You must be signed in to change notification settings - Fork 0
/
hero.pl
executable file
·72 lines (64 loc) · 1.23 KB
/
hero.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/perl
use Games::Dice qw(roll_array roll);
use List::Util qw(reduce sum);
use POSIX qw(floor);
use Term::ANSIColor;
use Getopt::Std;
use Switch;
#use warnings;
use strict;
sub colorize;
our $opt_k;
my $dice = $ARGV[0];
my ($stun, $body);
getopt('k:');
my @roll;
my $mode;
if($opt_k) {
$mode = "Killing attack";
} elsif (scalar(@ARGV) == 1) {
$mode = "Normal attack";
} else {
$mode = "Skill Test";
}
print "$mode\n";
my (@roll, $stun, $body);
switch ($mode) {
case "Killing attack" {
@roll = roll_array($opt_k . "d6");
colorize(@roll);
$body = sum @roll;
my $kill = roll('1d6') - 1;
$kill = $kill == 0 ? 1 : $kill;
$stun = $body * $kill;
print "$body * $kill = $stun\n";
} case "Normal attack" {
@roll = roll_array($dice . "d6");
colorize(@roll);
$stun = sum @roll;
$body = reduce { $a + floor($b/2) } 0, @roll;
} else {
@roll = roll_array("3d6");
print join(" ", @roll) . "\n";
print sum(@roll) . "\n";
exit(1);
}
}
print "Stun: $stun\n";
print "Body: $body\n";
########
sub colorize {
(@roll) = @_;
my $color;
foreach my $roll (@roll) {
if($roll == 1) {
$color = "cyan";
} elsif($roll == 6) {
$color = "bright_red";
} else {
$color = "white";
}
print colored [$color], $roll . " ";
}
print "\n";
}