blob: d888f64a0dab4de7ef7b1417dd10eb3872acbed0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
#!/usr/bin/env php
<?php
$string = $argv[1];
preg_match('/([0-9]*)d([0-9]+)(([+-][0-9]+))?/', $string, $matches);
$dice = (int)$matches[1];
$die_size = (int)$matches[2];
@$mod = (int)$matches[3];
if ($dice<1) $dice = 1;
$total = 0;
for ($i=0; $i < $dice; $i++) {
$v = mt_rand(1, $die_size);
echo $v.'+';
$total += $v;
}
echo $mod;
$total += $mod;
echo ' = '.$total."\n";
|