#!/usr/bin/perl -w # script to generate dice rolls from Earthdawn's step/action dice system # john@kript.net # version .2 # # this is subject to the GNU GPL for licensing # # lets do this properly..:-) use strict; @ARGV == 1 || die "Usage: $0 Step Number\n"; $ARGV[0] > 1 || die "Step number must be greater than 2\n"; $ARGV[0] < 20 || die "Step number must be less then 20\n"; # Declare the variables my ($step, $type, $decrement, $increment); my (@results, @dicetoroll); #Initialise the variables $step = $ARGV[0]; sub DiceRoll { my ($dicetype, $count, $dice, $reroll, $type, $roll); my (@rolls); # initialise the variables $count = 0; $dicetype = shift @_; # generate a dice roll, if the dice is at its max value, roll again # and append it to the $roll variable $roll = int(rand($dicetype)) + 1; $reroll = 1; while ($roll % $dicetype == 0 && $roll != 0 && $reroll !=0) { $reroll = int(rand($dicetype)) + 1; $roll = $roll + $reroll; } return ($roll); } # # main code begins here # #determine the type of dice roll required SWITCH: { if ($step == 2) { @dicetoroll = (4); } if ($step == 3) { @dicetoroll = (4); } if ($step == 4) { @dicetoroll = (6); } if ($step == 5) { @dicetoroll = (8); } if ($step == 6) { @dicetoroll = (10); } if ($step == 7) { @dicetoroll = (12); } if ($step == 8) { @dicetoroll = (6,6); } if ($step == 9) { @dicetoroll = (8,6); } if ($step == 10) { @dicetoroll = (10,6); } if ($step == 11) { @dicetoroll = (10,8); } if ($step == 12) { @dicetoroll = (10,10); } if ($step == 13) { @dicetoroll = (10,12); } if ($step == 14) { @dicetoroll = (20,4); } if ($step == 15) { @dicetoroll = (20,6); } if ($step == 16) { @dicetoroll = (20,8); } if ($step == 17) { @dicetoroll = (20,10); } if ($step == 18) { @dicetoroll = (20,12); } if ($step == 19) { @dicetoroll = (20,6,6); } if ($step == 20) { @dicetoroll = (20,8,6); } } # this is a messay way of doing this, but since step 2 is a D4-1, this # decrements the die roll by one unless its allready 0 if ($step == 2) { $type = 4; $decrement = DiceRoll($type); unless ($decrement == 0) { $decrement-- }; push (@results, $decrement); print "decrement = $decrement\n"; } # set the counter to 0 $increment = 0; foreach $type (@dicetoroll) { $results[$increment] = DiceRoll($type); $increment++; } # The sorting's not perfect, but hey.. foreach (sort @results) { print "$_ "; } print "\n";