Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function p($left,$right) {
- echo $left;
- if (!empty($right)) echo str_repeat(' ', 20-strlen(strip_tags($left))).$right;
- echo "\r\n";
- }
- function damage($d) {
- return '<span style="color:#FD0004;">'.$d.'</span>';
- }
- function AddAttack($name, $type, $energy, $min, $max, $attack_chance, $success_chance) {
- global $attacks;
- $i = count($attacks)+1;
- $attacks[$i]['name'] = $name;
- $attacks[$i]['type'] = $type;
- $attacks[$i]['energy'] = $energy;
- $attacks[$i]['min'] = $min;
- $attacks[$i]['max'] = $max;
- $attacks[$i]['attack_chance'] = $attack_chance;
- $attacks[$i]['success_chance'] = $success_chance;
- $attacks[$i]['used'] = 0;
- $attacks[$i]['hits'] = 0;
- $attacks[$i]['no_energy'] = 0;
- $attacks[$i]['remaining_energy_yes'] = 0;
- $attacks[$i]['remaining_energy_no'] = 0;
- $attacks[$i]['total_damage'] = 0;
- }
- $energy_per_round = 1000;
- $remaining_energy = 0;
- $number_of_rounds = 100;
- $attacks = array();
- $max_round = 0;
- $character_ac = 0;
- $character_dr = 0;
- if (isset($_POST['name'])) {
- foreach ($_POST['name'] as $index => $value) {
- $name = (string)preg_replace("/[^A-Za-z0-9]/", '', $_POST['name'][$index]);
- $type = (string)$_POST['type'][$index] == 'spell' ? 'spell' : 'physical';
- $energy = (int)preg_replace("/[^0-9]/", '', $_POST['energy'][$index]);
- $min = (int)preg_replace("/[^0-9]/", '', $_POST['min'][$index]);
- $max = (int)preg_replace("/[^0-9]/", '', $_POST['max'][$index]);
- $attack_chance = (int)preg_replace("/[^0-9]/", '', $_POST['attack_chance'][$index]);
- $success_chance = (int)preg_replace("/[^0-9]/", '', $_POST['success_chance'][$index]);
- if (!empty($name) && $energy > 0 && $max > 0 && $attack_chance > 0 && $success_chance > 0) {
- AddAttack($name,$type,$energy,$min,$max,$attack_chance,$success_chance);
- }
- }
- $energy_per_round = (int)preg_replace("/[^0-9]/", '', $_POST['energy_per_round']);
- if ($energy_per_round > 10000) $energy_per_round = 10000;
- if ($energy_per_round < 1) $energy_per_round = 1;
- $number_of_rounds = (int)preg_replace("/[^0-9]/", '', $_POST['number_of_rounds']);
- if ($number_of_rounds > 100000) $number_of_rounds = 50000;
- if ($number_of_rounds < 1) $number_of_rounds = 1;
- $character_ac = (int)preg_replace("/[^0-9]/", '', $_POST['character_ac']);
- if ($character_ac > 10000) $character_ac = 10000;
- if ($character_ac < 0) $character_ac = 0;
- $character_dr = (int)preg_replace("/[^0-9]/", '', $_POST['character_dr']);
- if ($character_dr > 10000) $character_dr = 10000;
- if ($character_dr < 0) $character_dr = 0;
- } else {
- // name type energy min max attack% success%
- AddAttack( 'physical', 'physical', 200, 10, 20, 45, 99);
- AddAttack( 'lbol', 'spell', 400, 5, 12, 35, 75);
- AddAttack( 'sbol', 'spell', 600, 10, 22, 20, 50);
- }
- ?>
- <HTML>
- <HEAD>
- <style>
- input[type="number"] {
- width:50px;
- }
- label {
- font-size:0.8em;
- }
- </style>
- </HEAD>
- <BODY>
- <form action="monster.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
- <?php for ($x = 1; $x <= 5; $x++):
- $name = empty($attacks[$x]['name']) ? '' : $attacks[$x]['name'];
- $type = empty($attacks[$x]['type']) ? '' : $attacks[$x]['type'];
- ?>
- <strong>Attack <?php echo $x; ?>:</strong>
- <label for="name<?php echo $x; ?>">Name:</label><input name="name[]" type="text" id="name<?php echo $x; ?>" size="7" value="<?php echo $name; ?>">
- <label for="type<?php echo $x; ?>">Type:</label>
- <select name="type[]" id="type<?php echo $x; ?>">
- <option value="spell" <?php if ($type=='spell') echo 'selected'; ?>>Spell</option>
- <option value="physical" <?php if ($type=='physical') echo 'selected'; ?>>Physical</option>
- </select>
- <?php foreach (array('energy', 'min', 'max', 'attack_chance', 'success_chance') as $var):
- $$var = empty($attacks[$x][$var]) ? '' : $attacks[$x][$var];
- ?>
- <label for="<?php echo $var.$x; ?>[]"><?php echo $var == 'success_chance' ? 'Accy/Cast%' : $var; ?>:</label> <input name="<?php echo $var; ?>[]" type="number" id="<?php echo $var.$x; ?>" value="<?php echo $$var; ?>">
- <?php endforeach; ?>
- <br>
- <?php endfor; ?>
- <br>
- <label for="energy_per_round">Monster's Energy per Round:</label>
- <input type="text" name="energy_per_round" id="energy_per_round" size="5" value="<?php echo $energy_per_round; ?>">
- <label for="character_ac">Character AC:</label>
- <input type="text" name="character_ac" id="character_ac" size="5" value="<?php echo $character_ac; ?>">
- <label for="character_dr">Character DR:</label>
- <input type="text" name="character_dr" id="character_dr" size="5" value="<?php echo $character_dr; ?>">
- <br><br>
- <label for="number_of_rounds"># Rounds:</label>
- <input type="text" name="number_of_rounds" id="number_of_rounds" size="5" value="<?php echo $number_of_rounds; ?>">
- <input type="submit" name="submit_hide_rounds" id="submit_hide_rounds" value="Execute & Show Stats Only"> <input type="submit" name="submit" id="submit" value="Execute & Show Rounds"> (Under 5,000 rounds)
- </form>
- <?php
- //normalize attack % for rand
- for ($x = 2; $x <= count($attacks); $x++) {
- $attacks[$x]['attack_chance'] += $attacks[$x-1]['attack_chance'];
- if ($x == count($attacks) && $attacks[$x]['attack_chance'] != 100) p('<span style="font-size:1.5em;font-weight:bold;color:#FF9600;">Attack chances do not total 100%!</span>');
- }
- ?>
- <PRE>
- <?php
- ob_start();
- p('==============================================');
- $total_damage = 0; $total_attacks = 0;
- $total_energy_remaining = 0; $max_energy_remaining = 0; $total_energy_used = 0;
- $last_attack_energy = 0; $last_attack_type = '';
- $energy_remaining_per_attack = 0; $energy_remaining_after_attack = array(1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 0);
- for ($round = 1; $round <= $number_of_rounds && !empty($attacks); $round++) {
- p('<strong>ROUND '.$round.'</strong> / Energy: '.$remaining_energy.' + '.$energy_per_round.' = '.($remaining_energy+$energy_per_round));
- $remaining_energy += $energy_per_round;
- $x = 1;
- $round_damage = 0;
- while ($x <= 6 /*&& $remaining_energy > 0*/) {
- $attack_chance = mt_rand(1,100);
- $last_attack_energy = 0;
- $last_attack_type = '';
- foreach ($attacks as $attack_num => $attack) {
- if ($attack_chance <= $attack['attack_chance']) {
- $last_attack_energy = $attack['energy'];
- $last_attack_type = $attack['type'];
- if ($remaining_energy < $attack['energy']) {
- p($attack['name'],'Not enough energy.');
- $attacks[$attack_num]['no_energy']++;
- $attacks[$attack_num]['remaining_energy_no'] += $remaining_energy;
- } else {
- $attacks[$attack_num]['used']++;
- $attacks[$attack_num]['remaining_energy_yes'] += $remaining_energy;
- $total_attacks++;
- $success_chance = $attack['success_chance'];
- if ($attack['type'] != 'spell' && $character_ac > 0) {
- //=((AC*AC)/100)/((ACCY*ACCY)/140)=fail %
- $success_chance = round(1-(($character_ac*$character_ac)/100)/(($success_chance*$success_chance)/140),2)*100;
- if ($success_chance < 9) $success_chance = 9;
- if ($success_chance > 99) $success_chance = 99;
- }
- $cast_chance = mt_rand(1,100);
- if ($cast_chance <= $success_chance) {
- $damage = mt_rand($attack['min'],$attack['max']);
- if ($attack['type'] != 'spell') $damage -= $character_dr;
- if ($damage < 0) $damage = 0;
- $total_damage += $damage;
- $round_damage += $damage;
- $remaining_energy -= $attack['energy'];
- $total_energy_used += $attack['energy'];
- $attacks[$attack_num]['hits']++;
- $attacks[$attack_num]['total_damage'] += $damage;
- p(damage($attack['name'].' for '.$damage),'Energy used: '.$attack['energy'].' ... Energy remaining: '.$remaining_energy);
- } else {
- if ($attack['type'] == 'spell') {
- $total_energy_used += round($attack['energy']/2,0);
- $remaining_energy -= round($attack['energy']/2,0);
- p($attack['name'].' (FAIL)','Energy used: '.round($attack['energy']/2,0).' ... Energy remaining: '.$remaining_energy);
- } else {
- $total_energy_used += $attack['energy'];
- $remaining_energy -= $attack['energy'];
- p($attack['name'].' (MISS)','Energy used: '.$attack['energy'].' ... Energy remaining: '.$remaining_energy);
- }
- }
- }
- break 1;
- }
- }
- $energy_remaining_per_attack += $remaining_energy;
- $energy_remaining_after_attack[$x] += $remaining_energy;
- if ($last_attack_type != 'spell') {
- if ($remaining_energy < $last_attack_energy) break 1;
- }
- $x++;
- }
- p('Damage for round: '.$round_damage.', Energy Remaining: '.$remaining_energy);
- if ($round_damage > $max_round) $max_round = $round_damage;
- if ($remaining_energy > $max_energy_remaining) $max_energy_remaining = $remaining_energy;
- $total_energy_remaining += $remaining_energy;
- p('==============================================');
- }
- $attack_html = ob_get_clean();
- if (!empty($attacks)) {
- p('');
- p('Total Attacks: '.$total_attacks);
- }
- $last_cast_percent = 0;
- foreach ($attacks as $attack) {
- p('');
- p('<strong>'.$attack['name'].'--</strong>');
- p('Hits: '.$attack['hits'].', '.($attack['type'] == 'spell' ? 'Fails' : 'Misses').': '.($attack['used']-$attack['hits']).', Success %: '.(round($attack['hits']/$attack['used'],3)*100));
- if ($attack['no_energy'] > 0) {
- p('');
- p('Attack chosen but not enough energy: '.(round($attack['no_energy']/($attack['no_energy']+$attack['used']), 4)*100).'%');
- p('Average energy available when attack used: '.(round($attack['remaining_energy_yes']/$attack['used'], 0)));
- p('Average energy available when attack could not be used: '.(round($attack['remaining_energy_no']/$attack['no_energy'], 0)));
- }
- p('');
- p('Total Damage: '.$attack['total_damage']);
- p(damage('Average Damage/'.($attack['type'] == 'spell' ? (($attack['used'] > $attack['hits']) ? 'Cast (including fails)':'Cast') : 'Swing').': '.round($attack['total_damage']/$attack['used'],2)));
- p('Average '.($attack['type'] == 'spell' ? 'Casts' : 'Swings').'/Round: '.round($attack['used']/$number_of_rounds,2));
- p(damage('Average Damage/Round: '.round($attack['total_damage']/$number_of_rounds,2)));
- p('Initial Attack Chance: '.($attack['attack_chance']-$last_cast_percent).'%');
- p('<strong><span style="color:#F006FF;">True Attack Chance: '.(round($attack['used']/$total_attacks,3)*100).'%</span></strong>');
- $last_cast_percent = $attack['attack_chance'];
- }
- if (!empty($attacks)) {
- p('');
- p('Total Rounds: '.$number_of_rounds);
- p('Total Damage: '.$total_damage);
- p('<h3>'.damage('Total AVG Damage / Round: '.round($total_damage/$number_of_rounds,2)).'</h3>');
- p('Max Round Seen: '.$max_round);
- p('');
- p('Average Energy Used/Attack: '.round($total_energy_used/$total_attacks,2));
- p('Average Energy Used/Round: '.round($total_energy_used/$number_of_rounds,2));
- p('Average Energy Remaining/Attack: '.round($energy_remaining_per_attack/$total_attacks,2));
- p('Average Energy Remaining/Round: '.round($total_energy_remaining/$number_of_rounds,2));
- p('Max Energy Remaining Seen at End of Round: '.$max_energy_remaining);
- p('');
- for ($x = 1; $x <= 6; $x++) {
- p('Average Energy Remaining after atack '.$x.': '.round($energy_remaining_after_attack[$x]/$number_of_rounds,2));
- }
- if (!isset($_POST['submit_hide_rounds'])) {
- p('');
- echo var_export($attacks, true)."\r\n";
- if ($number_of_rounds <= 5000) {
- p('');
- echo $attack_html;
- }
- }
- }
- ?>
- </PRE>
- </BODY></HTML>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement