here is my code, minus the form and basic page layout HTML
Code:
/***************************************************************************
// Make sure all data sent to the sheet is within allowable parameters
//
// skill: from 0 to 300 inclusive
// prime: Prime Stat no lower than 0 (curently no cap set since this bar keeps moving). Form limits to 999
// trivial: no lower than 0. No max set since no max has been indicated. Form limits to 999
// mod: tradeskill mod limited from 0 to 100 inclusive.
*/
if ($data) {
if ($data['skill'] < 1) $data['skill'] = '0';
if ($data['skill'] > 300) $data['skill'] = 300;
if ($data['prime'] < 1) $data['prime'] = '0';
//if ($data['prime'] > 405) $data['prime'] = 405;
if ($data['trivial'] < 1) $data['trivial'] = '0';
if ($data['mod'] < 1) $data['mod'] = '0';
if ($data['mod'] > 100) $data['mod'] = 100;
}
/***************************************************************************
// HTML form display bellow
*/?>
HTML cut out here...
<?php
/***************************************************************************
//
// If data is set. start the table below the HTML form
*/
if (isset($data)) {
print "<table cellpadding=\"2\" hspace=\"10\" bordercolor=\"#400000\" border=\"2\" cellspacing=\"0\">
<tr bgcolor=\"#E3E4D3\"><td>";
//set a modified skill value
$skill = floor($data['skill']*(100+$data['mod'])/100);
//run the base success formula as decided by the community
if ($data['trivial'] < 68) {
$success = $skill - $data['trivial'] + 66;
} else {
$success = ($skill-($data['trivial'] * 0.75)) + 51.5;
}
// If skill is 0, ignore tradeskill AA
// if skill is greater, calculate the fail modifier to success, and increment success by that.
if ($data['skill'] > 0) {
$fail = 100-$success;
$fail = $aa*$fail/100;
$success += $fail;
}
//cap success
if ($success < 5) $success = 5;
if ($success > 95) $success = 95;
//as skill gets greater than trivial, in steps of 40, reduce the chance to fail further.
//this could probably be done formulaicly instead of conditionally
if ($data['skill'] > $data['trivial']) {
if (($data['skill']-$data['trivial']) >= 200) {
$success = 100;
} else if (($data['skill']-$data['trivial']) >= 160) {
$success = 100 - ((100-$success)*(.20));
} else if (($data['skill']-$data['trivial']) >= 120) {
$success = 100 - ((100-$success)*(.40));
} else if (($data['skill']-$data['trivial']) >= 80) {
$success = 100 - ((100-$success)*(.60));
} else if (($data['skill']-$data['trivial']) >= 40) {
$success = 100 - ((100-$success)*(.80));
}
}
//display the new calculated data
print "Ajusted Skill = $skill<br>";
print "Success chance = $success%<br>";
/***************************************************************************
// calculate the success chances. Sorry about the nonsense variable names, I was making them for the original formulas
// from soe.
// Also $si is an array for easy future changes when all data for tradeskill dificulties are in and I make a dropdown
// with the apropriate data.
//
// $s = stat
// $si[0] = tradeskill dificulty
// $si[1] = is the flag (1|0) for if there is an alternate stat
// $second = second check. Used to signify the chance for skillup on the second pass.
// n is used to signify the chance of skillup on first pass
// $nf = n for failed combine. (n was used in original formula given by SOE.) N is the FIRST check.
// $ns = n for success. (again, this is the first check)
// $suf = skillup chance on a failed combine.
// $sus = skillup chance on a combine that succeded.
// $sut = overall chance of skillup
//
*/
if (($data['trivial'] > $data['skill']) and ($data['skill'] < 300)) {
// standby code for if I implement the dropdown
//$si=split('-',$data['trade']);
// if the stat used is for a tradeskill that has an alternate stat, leave the stat as is
// otherwise, reduce the stat by 15. It cannot be less than 0.
if ($si[1]) {
$s = $data['prime'];
} else {
$s = $data['prime']-15;
}
if ($s < 0) $s=0;
// calculate the chance of skillup from pass one.
// note that there is half the chance if the combine was a fialure
// cap both at 100
$nf = ($s*10)/($si[0]*2)/10;
$ns = ($s*10)/$si[0]/10;
if ($ns > 100) $ns = 100;
if ($nf > 100) $nf = 100;
// calculate the chance of skillup from pass two.
//
// if BASE skill is less than or equal to 15, pass two is 100%
// or do the new formula is the base skill is greater than 175
// else, the skill is between 15 and 176, use the old formula
//
if ($data['skill'] <= 15) {
$second = 1;
} else if ($data['skill'] > 175) {
$second = (12.5-((10/125.0)*($data['skill']-175)))/100;
} else {
$second = (200-$data['skill'])/200;
}
// round the two chances, and make a total chance.
$suf = round($nf*$second,2);
$sus = round($ns*$second,2);
$sut = round((($sus*$success/100) + ($suf*(100-$success)/100)),2);
} else { // if base skill is higher than the trivial, or base skill is 300 (or more) there is no chance of skillup.
$sus = 0;
$suf = 0;
$sut = 0;
}
print "Chance of skill up on Success: $sus%, on failure: $suf%, <strong>overall $sut%</strong>";
print "</td></tr></table>";
}
?>