MediaWiki:Common.js/CalculateStats.js

var level=null, selected1=null, selected2=null, selected3=null, selected4=null;

$( '.statCalculator' ).each( function{	var html = 'Level:  \		Type: \		Weapon \		Armor \		 \		Submit ';	$('.statCalculator').empty.html(html); } )

function attackOrArmor {	if(isNaN(document.getElementById("input").value)) { alert("Please enter a numerical value in the input field"); } else {		level = parseInt(document.getElementById("input").value); selected1 = document.getElementById("options")[document.getElementById("options").selectedIndex].value; $('#firstButton').hide; if(selected1 == "Weapon") {			var html = ' Class: \ Melee \ Ranged \ Magic \ \			Submit ', $class = $(' ').html(html); $('.statCalculator').append($class); }		else if(selected1 == "Armor") {			var html = ' Type: \ Power \ Tank \ Hybrid \ \			Slot: \ Head \ Body \ Legs \ Shield \ Gloves \ <option value="Boots">Boots \ <option value="Cape">Cape \ \			<button type="button" onclick="whichSlot" id="secondButton">Submit ', $slot = $(' ').html(html); $('.statCalculator').append($slot); }	} }

function whichClass {	selected2 = document.getElementById("options2")[document.getElementById("options2").selectedIndex].value; $('#secondButton').hide; if(selected2 == "Melee") {		var html = ' \ <option value="Main-hand">Main-hand \ <option value="Off-hand">Off-hand \ <option value="Two-handed">Two-handed \ \		<button type="button" onclick="whichHand" id="thirdButton">Submit ', $hands = $(' ').html(html); $('.statCalculator').append($hands); }	else if(selected2 == "Ranged") {		var html = ' \ <option value="Ammunition">Ammunition \ <option value="Shortbow">Shortbow \ <option value="Shieldbow">Shieldbow \ <option value="Two-handed crossbow">Two-handed crossbow \ \		<button type="button" onclick="whichHand" id="thirdButton">Submit ', $hands = $(' ').html(html); $('.statCalculator').append($hands); }	else if(selected2 == "Magic") { 		printResults; } }

function whichHand {	selected3 = document.getElementById("options3")[document.getElementById("options3").selectedIndex].value; $('#thirdButton').hide; if((selected3 == "Main-hand") || (selected3 == "Off-hand") || (selected3 == "Two-handed")) {		var html = ' Speed: \ <option value="Fastest">Fastest \ <option value="Fast">Fast \ <option value="Average">Average \ \		<button type="button" onclick="printResults" id="fourthButton">Submit ', $speed = $(' ').html(html); $('.statCalculator').append($speed); }	else {		printResults; } }

function whichSlot {	selected2 = document.getElementById("options2")[document.getElementById("options2").selectedIndex].value; selected3 = document.getElementById("options3")[document.getElementById("options3").selectedIndex].value; $('#secondButton').hide; printResults; }

function printResults {	if(selected2 == 'Melee') selected4 = document.getElementById("options4")[document.getElementById("options4").selectedIndex].value; $('#fourthButton').hide; var html=null; if(selected1 == 'Weapon') {		html = ' \ <button type="button" onclick="reset">Reset '; }	else {		html = ' \ <button type="button" onclick="reset">Reset '; }	var $table = $(' ').html(html); $('.statCalculator').append($table); }

function reset {	var html = 'Level: <input type="text" name="Level" id="input" value="1"> \ Type: \ <option value="Weapon">Weapon \ <option value="Armor">Armor \ \		<button type="button" onclick="attackOrArmor" id="firstButton">Submit '; $('.statCalculator').empty.html(html); }

function accuracyValue {	return Math.round((((level*level*level)/1250)+(4*level)+40)*2.5); }

function damageValue {	if(selected2 == 'Melee') {		if(selected3 == 'Main-hand') {			if(selected4 == 'Fastest') return(Math.floor(level*9.6)); else if(selected4 == 'Fast') return(Math.floor(level*12.25)); else return(Math.floor(level*14.9)); }		else if(selected3 == 'Off-hand') {			if(selected4 == 'Fastest') return(Math.floor(level*4.8)); else if(selected4 == 'Fast') return(Math.floor(level*6.125)); else return(Math.floor(level*7.45)); }		else //two-handed weapon {			if(selected4 == 'Fastest') return(Math.floor(level*14.4)); else if(selected4 == 'Fast') return(Math.floor(level*18.375)); else return(Math.floor(level*22.35)); }	}	else if(selected2 == 'Ranged') {		if(selected3 == 'Ammunition') return(Math.floor(level*9.6)); else if(selected3 == 'Shortbow') return(Math.floor(level*8.775)); else if(selected3 == 'Shieldbow') return(Math.floor(level*5.3)); else return(Math.floor(level*12.75)); }	else {		return 0; } }

function armorValue {	if(selected2 == 'Tank') {		var base = (((level*level*level)/1250)+(4*level)+40); switch(selected3) {			case 'Head':return Math.floor(base*0.5); case 'Body':return Math.floor(base*0.575); case 'Legs':return Math.floor(base*0.55); case 'Shield':return Math.floor(base*0.5); case 'Gloves':return Math.floor(base*0.125); case 'Boots':return Math.floor(base*0.125); case 'Cape':return Math.floor(base*0.075); default: return 0; }	}	else if(selected2 == 'Power') {		var base = ((((level-5)*(level-5)*(level-5))/1250)+(4*(level-5))+40); switch(selected3) {			case 'Head':return Math.floor(base*0.5); case 'Body':return Math.floor(base*0.575); case 'Legs':return Math.floor(base*0.55); case 'Shield':return Math.floor(base*0.5); case 'Gloves':return Math.floor(base*0.125); case 'Boots':return Math.floor(base*0.125); case 'Cape':return Math.floor(base*0.075); default: return 0; }	}	else //Hybrid armor {		var base = ((((level-15)*(level-15)*(level-15))/1250)+(4*(level-15))+40); switch(selected3) {			case 'Head':return Math.floor(base*0.5); case 'Body':return Math.floor(base*0.575); case 'Legs':return Math.floor(base*0.55); case 'Shield':return Math.floor(base*0.5); case 'Gloves':return Math.floor(base*0.125); case 'Boots':return Math.floor(base*0.125); case 'Cape':return Math.floor(base*0.075); default: return 0; }	} }

function lifeValue {	if(selected2 == 'Tank') {		switch(selected3) {			case 'Head':return (level*12); case 'Body':return (level*24); case 'Legs':return (level*18); case 'Shield':return (level*15); case 'Gloves':return (level*3); case 'Boots':return (level*3); default :return 0; }	}	else if(selected2 == 'Power') {		switch(selected3) {			case 'Head':return ((level-10)*12); case 'Body':return ((level-10)*24); case 'Legs':return ((level-10)*18); case 'Shield':return ((level-10)*15); case 'Gloves':return ((level-10)*3); case 'Boots':return ((level-10)*3); default :return 0; }	}	else //Hybrid armor {		switch(selected3) {			case 'Head':return ((level-15)*12); case 'Body':return ((level-15)*24); case 'Legs':return ((level-15)*18); case 'Shield':return ((level-15)*15); case 'Gloves':return ((level-15)*3); case 'Boots':return ((level-15)*3); default :return 0; }	} }

function damageValue2 {	if(selected2 == 'Power') {		switch(selected3) {			case 'Head':return Math.floor(level*9.6*0.02); case 'Body':return Math.floor(level*9.6*0.035); case 'Legs':return Math.floor(level*9.6*0.025); case 'Gloves':return Math.floor(level*9.6*0.01); case 'Boots':return Math.floor(level*9.6*0.01); default :return 0; }	}	else return 0; }