Skip to content

Instantly share code, notes, and snippets.

@VienosNotes
Created April 14, 2012 11:15
Show Gist options
  • Select an option

  • Save VienosNotes/2383660 to your computer and use it in GitHub Desktop.

Select an option

Save VienosNotes/2383660 to your computer and use it in GitHub Desktop.
character making for CoC
use 5.14.0;
use List::Util qw/sum/;
use Tie::IxHash;
use Data::Dumper;
use POSIX;
my @params_a = ("STR", "CON", "POW", "DEX", "APP");
my @params_b = ("SIZ", "INT");
my %all;
tie %all, "Tie::IxHash";
for (@params_a) {
$all{$_} = sum_roll(3,6);
}
for (@params_b) {
$all{$_} = num_plus_sum_roll(6,2,6);
}
$all{EDU} = num_plus_sum_roll(3,3,6);
for (keys %all) {
say $_ . ": " . $all{$_}[0];
}
say;
say "SAN: POW x 5 = " . $all{POW}[1] * 5;
say "アイデア: INT x 5 = " . $all{INT}[1] * 5;
say "知識: EDU x 5 = " . $all{EDU}[1] * 5;
say "最大正気度: 99";
say "耐久力: (CON + SIZ) / 2 = " . ceil(($all{CON}[1] + $all{SIZ}[1])/2);
say "マジックポイント: POW = " . $all{POW}[1];
say "正気度: POW x 5 = " . $all{POW}[1] * 5;
sub sum_roll {
my ($count, $faces) = @_;
my $ret = "";
my $val = 0;
if (wantarray) {
return map { int rand($faces) + 1 } 1..$count;
} else {
for (1..$count) {
my $tmp = int rand($faces) + 1;
$ret .= $tmp . " + ";
$val += $tmp;
}
chop $ret;
chop $ret;
chop $ret;
return ["$ret = $val", $val];
}
}
sub num_plus_sum_roll {
my ($num, $count, $faces) = @_;
my $ret = "";
my $val = 0;
my @roll = sum_roll($count, $faces);
$val = $num + sum @roll;
$ret = "$num + " . join(" + ", @roll) . " = $val";
return [$ret, $val];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment