A Dice Roller

= 0; $a--) { // crit fail if ($allRolls[$a][0] == 1) { $ACline[] = 0; } // 20 always hits elseif ($allRolls[$a][0] == 20) { // confirmed? if ($allRolls[$a][1] + $allRolls[$a][3] >= $ac) { $ACline[] = array_sum($allRolls[$a][5]) + array_sum($allRolls[$a][4]); } else { $ACline[] = array_sum($allRolls[$a][4]); } } // normal attack else { if ($allRolls[$a][0] + $allRolls[$a][2] >= $ac) { // crit if ($allRolls[$a][0] >= $crit_range && $allRolls[$a][1] + $allRolls[$a][3]>= $ac) { $ACline[] = array_sum($allRolls[$a][5]) + array_sum($allRolls[$a][4]); } // normal hit else { $ACline[] = array_sum($allRolls[$a][4]); } } // miss else { $ACline[] = 0; } } } // for each attack if ($config == 1) { $allAC[] = $ACline; } elseif ($config == 2) { $allAC2[] = $ACline; } else { echo "out of range config in processAC()"; } } // for each AC } function printAC () { global $allRolls, $allRolls2; global $allAC, $allAC2; global $crit_range, $crit_range2, $bonus_hit, $bonus_hit2, $bonus_hit1, $bonus_hit2a, $bonus_hit2b; $min = min($bonus_hit, $bonus_hit2, $bonus_hit1, $bonus_hit2a, $bonus_hit2b) + 2; $max = max($bonus_hit, $bonus_hit2, $bonus_hit1, $bonus_hit2a, $bonus_hit2b) + 20; processAC($allRolls, $crit_range, $min, $max, 1); processAC($allRolls2, $crit_range2, $min, $max, 2); for ($i = 0; $i <= $max - $min; $i++) { echo " \n"; // AC range echo " ". $allAC[$i][0]; // first line if ($i == 0) { echo " or less\n"; } // last line, highest possible AC (only 20s) elseif ($i == count($allAC) - 1) { echo "+\n"; } // single damage level else { echo "\n"; } echo " ". (array_sum($allAC[$i])-$allAC[$i][0]) ."\n"; echo " ". (array_sum($allAC2[$i])-$allAC2[$i][0]) ."\n"; echo " \n"; } return; } // d20, crit d20, Modifiers, crit modifiers, damage, crit damage function addAttack($to_hit, $damage, $crit_range, $crit_mult, $dice_num, $dice_sides, $config) { global $allRolls, $allRolls2; $currentRoll = array(); $total_damage = array(); // d20 $currentRoll[] = roll(20); // in case of crit if ($currentRoll[0] == 1 || $currentRoll[0] >= $crit_range) { // crit confirm $currentRoll[] = roll(20); } else { $currentRoll[] = 0; } // modifiers $currentRoll[] = $to_hit; // crit mods if ($currentRoll[0] >= $crit_range) { // crit confirm $currentRoll[] = $to_hit; } else { $currentRoll[] = 0; } // damage array $total_damage[] = $damage; for ($i = 0; $i < $dice_num; $i++) { $total_damage[] = roll($dice_sides); } $currentRoll[] = $total_damage; // if crit $total_damage = array(); if ($currentRoll[0] >= $crit_range) { // start at 1 since we already added base damage for ($j = 1; $j < $crit_mult; $j++) { $total_damage[] = $damage; for ($i = 0; $i < $dice_num; $i++) { $total_damage[] = roll($dice_sides); } } $currentRoll[] = $total_damage; } else { $currentRoll[] = 0; } if ($config == 1) { $allRolls[] = $currentRoll; } elseif ($config == 2) { $allRolls2[] = $currentRoll; } else { echo "Invalid config!"; } } function makeAttacks () { global $numtrials; global $bonus_hit, $bonus_damage, $attacks, $crit_range, $crit_mult, $dice_num, $dice_sides; global $bonus_hit1, $bonus_damage1, $attacks1, $crit_range1, $crit_mult1, $dice_num1, $dice_sides1; global $bonus_hit2, $bonus_damage2, $attacks2, $crit_range2, $crit_mult2, $dice_num2, $dice_sides2; global $bonus_hit2a, $bonus_damage2a, $attacks2a, $crit_range2a, $crit_mult2a, $dice_num2a, $dice_sides2a; global $bonus_hit2b, $bonus_damage2b, $attacks2b, $crit_range2b, $crit_mult2b, $dice_num2b, $dice_sides2b; // for each iteration for ($t = 0; $t < $numtrials; $t++) { // Config 1 for ($a = 0; $a < $attacks; $a++) { addAttack($bonus_hit, $bonus_damage, $crit_range, $crit_mult, $dice_num, $dice_sides, 1); } for ($a = 0; $a < $attacks1; $a++) { addAttack($bonus_hit1, $bonus_damage1, $crit_range1, $crit_mult1, $dice_num1, $dice_sides1, 1); } // Config 2, 1st weapon for ($a = 0; $a < $attacks2; $a++) { addAttack($bonus_hit2, $bonus_damage2, $crit_range2, $crit_mult2, $dice_num2, $dice_sides2, 2); } // Config 2, 2nd weapon for ($a = 0; $a < $attacks2a; $a++) { addAttack($bonus_hit2a, $bonus_damage2a, $crit_range2a, $crit_mult2a, $dice_num2a, $dice_sides2a, 2); } // Config 2, 3nd weapon for ($a = 0; $a < $attacks2b; $a++) { addAttack($bonus_hit2b, $bonus_damage2b, $crit_range2b, $crit_mult2b, $dice_num2b, $dice_sides2b, 2); } } } // do it! makeAttacks(); // Calculate the average damage per attack $averageRolls = 0; for ($i = 0; $i < count($allRolls); $i++) { // 4 is the damage array $averageRolls += array_sum($allRolls[$i][4]); // if we crit if ($allRolls[$i][0] >= $crit_range) { // 5 is the damage array for a crit $averageRolls += array_sum($allRolls[$i][5]); } } $totalDamage = $averageRolls; $averageRolls /= $numtrials; $numAttacks = count($allRolls); ?>

Enemy
AC
Config 1 Config 2
Config 1 Config 2
To Hit: To Hit:
Base Damage: Base Damage:
# of dice: # of dice:
Sides on dice: Sides on dice:
Crit Range: Crit Range:
Crit Multiplier: Crit Multiplier:
# of Attacks: # of Attacks:
# of Trials: