MediaWiki:Kalos Mechanism DE.js

From OGC
Jump to: navigation, search

Note: After saving, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Clear the cache in Tools → Preferences
function getQueryVariable(variable)
{
	var query = window.location.search.substring(1);
	var vars = query.split("&");

	for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split("=");
		if(pair[0] == variable){return pair[1];}
	}

	return(false);
}

function get_attribute_value(attribute_value)
{
	attribute_value = parseInt(attribute_value);
	
	if (isNaN(attribute_value))
	{
		attribute_value = 0;
	}

	attribute_value = Math.max(0, attribute_value);
	attribute_value = Math.min(10, attribute_value);

	return attribute_value;
}

function calculate_attribute_cost(attribute_value)
{
	var attribute_cost = 0;
	
	switch (parseInt(attribute_value))
	{
		case 0:
			attribute_cost = 0;
			break;
		case 1:
			attribute_cost = 1;
			break;
		case 2:
			attribute_cost = 2;
			break;
		case 3:
			attribute_cost = 3;
			break;
		case 4:
			attribute_cost = 5;
			break;
		case 5:
			attribute_cost = 7;
			break;
		case 6:
			attribute_cost = 9;
			break;
		case 7:
			attribute_cost = 12;
			break;
		case 8:
			attribute_cost = 15;
			break;
		case 9:
			attribute_cost = 18;
			break;
		case 10:
			attribute_cost = 22;
			break;
		case 11:
			attribute_cost = 26;
			break;
		case 12:
			attribute_cost = 30;
			break;
		case 13:
			attribute_cost = 35;
			break;
		case 14:
			attribute_cost = 40;
			break;
		case 15:
			attribute_cost = 45;
			break;
		case 16:
			attribute_cost = 51;
			break;
		case 17:
			attribute_cost = 57;
			break;
		case 18:
			attribute_cost = 63;
			break;
		case 19:
			attribute_cost = 70;
			break;
		case 20:
			attribute_cost = 77;
			break;
		default:
			attribute_cost = 77;
			break;
	}
	
	return attribute_cost;
}

function format_attribute_cost_output(attribute_cost)
{
	var formatted_attribute_cost_output;
	
	formatted_attribute_cost_output = "<div class=\"sidebar_title\">Attributkostenrechner</div>\n";
	formatted_attribute_cost_output += '<div class="sidebar_subtitle">';
	formatted_attribute_cost_output += 'Gib die gewünschte Attributsverteilung ein, um dir die Gesamtkosten anzeigen zu lassen:';
	formatted_attribute_cost_output += '<table cellpadding="2" style="margin:auto 0;">';
	formatted_attribute_cost_output += '<tr>';
	formatted_attribute_cost_output += '<th align="left">Attribut</th>';
	formatted_attribute_cost_output += '<th align="center" style="padding-left: 15px; padding-right: 15px;">Attributswert</th>';
	formatted_attribute_cost_output += '<th align="right">Kosten (CP)</th>';
	formatted_attribute_cost_output += '</tr>';
	formatted_attribute_cost_output += '<tr>';
	formatted_attribute_cost_output += '<td align="left">Geschick</td>';
	formatted_attribute_cost_output += '<td align="center"><input id="agility_value" type="text" size="2" style="text-align: right" value="' + attribute_cost['agility']['value'] + '" onblur="get_attribute_cost_output()"></td>';
	formatted_attribute_cost_output += '<td align="right"><span id="agility_cost">' + attribute_cost['agility']['cost'] + '</span></td>';
	formatted_attribute_cost_output += '</tr>';
	formatted_attribute_cost_output += '<tr>';
	formatted_attribute_cost_output += '<td align="left">Kraft</td>';
	formatted_attribute_cost_output += '<td align="center"><input id="brawn_value" type="text" size="2" style="text-align: right" value="' + attribute_cost['brawn']['value'] + '" onblur="get_attribute_cost_output()"></td>';
	formatted_attribute_cost_output += '<td align="right"><span id="brawn_cost">' + attribute_cost['brawn']['cost'] + '</span></td>';
	formatted_attribute_cost_output += '</tr>';
	formatted_attribute_cost_output += '<tr>';
	formatted_attribute_cost_output += '<td align="left">Ausdauer</td>';
	formatted_attribute_cost_output += '<td align="center"><input id="endurance_value" type="text" size="2" style="text-align: right" value="' + attribute_cost['endurance']['value'] + '" onblur="get_attribute_cost_output()"></td>';
	formatted_attribute_cost_output += '<td align="right"><span id="endurance_cost">' + attribute_cost['endurance']['cost'] + '</span></td>';
	formatted_attribute_cost_output += '</tr>';
	formatted_attribute_cost_output += '<tr>';
	formatted_attribute_cost_output += '<td align="left">Wille</td>';
	formatted_attribute_cost_output += '<td align="center"><input id="presence_value" type="text" size="2" style="text-align: right" value="' + attribute_cost['presence']['value'] + '" onblur="get_attribute_cost_output()"></td>';
	formatted_attribute_cost_output += '<td align="right"><span id="presence_cost">' + attribute_cost['presence']['cost'] + '</span></td>';
	formatted_attribute_cost_output += '</tr>';
	formatted_attribute_cost_output += '<tr>';
	formatted_attribute_cost_output += '<td align="left">Intelligenz</td>';
	formatted_attribute_cost_output += '<td align="center"><input id="reason_value" type="text" size="2" style="text-align: right" value="' + attribute_cost['reason']['value'] + '" onblur="get_attribute_cost_output()"></td>';
	formatted_attribute_cost_output += '<td align="right"><span id="reason_cost">' + attribute_cost['reason']['cost'] + '</span></td>';
	formatted_attribute_cost_output += '</tr>';
	formatted_attribute_cost_output += '<tr>';
	formatted_attribute_cost_output += '<td align="left">Macht</td>';
	formatted_attribute_cost_output += '<td align="center"><input id="power_value" type="text" size="2" style="text-align: right" value="' + attribute_cost['power']['value'] + '" onblur="get_attribute_cost_output()"></td>';
	formatted_attribute_cost_output += '<td align="right"><span id="power_cost">' + attribute_cost['power']['cost'] + '</span></td>';
	formatted_attribute_cost_output += '</tr>';
	formatted_attribute_cost_output += '<tr>';
	formatted_attribute_cost_output += '<th align="left">Gesamtkosten:</th>';
	formatted_attribute_cost_output += '<th align="center"></th>';
	formatted_attribute_cost_output += '<th align="right"><span id="total_cost">' + attribute_cost['total']['cost'] + '</span></th>';
	formatted_attribute_cost_output += '</tr>';
	formatted_attribute_cost_output += '</table>';
	formatted_attribute_cost_output += '</div>';
		
	return formatted_attribute_cost_output;
}

function get_attribute_cost_output()
{
	var attribute_cost = new Array();
	var raw_value = 0;

	attribute_cost['agility'] = new Array();
	attribute_cost['brawn'] = new Array();
	attribute_cost['endurance'] = new Array();
	attribute_cost['presence'] = new Array();
	attribute_cost['reason'] = new Array();
	attribute_cost['power'] = new Array();
	attribute_cost['total'] = new Array();

	attribute_cost['total']['cost'] = 0;

	attribute_cost['agility']['value'] = get_attribute_value(document.getElementById('agility_value').value);
	attribute_cost['agility']['cost'] = calculate_attribute_cost(attribute_cost['agility']['value']);
	attribute_cost['total']['cost'] += attribute_cost['agility']['cost'];

	attribute_cost['brawn']['value'] = get_attribute_value(document.getElementById('brawn_value').value);
	attribute_cost['brawn']['cost'] = calculate_attribute_cost(attribute_cost['brawn']['value']);
	attribute_cost['total']['cost'] += attribute_cost['brawn']['cost'];

	attribute_cost['endurance']['value'] = get_attribute_value(document.getElementById('endurance_value').value);
	attribute_cost['endurance']['cost'] = calculate_attribute_cost(attribute_cost['endurance']['value']);
	attribute_cost['total']['cost'] += attribute_cost['endurance']['cost'];

	attribute_cost['presence']['value'] = get_attribute_value(document.getElementById('presence_value').value);
	attribute_cost['presence']['cost'] = calculate_attribute_cost(attribute_cost['presence']['value']);
	attribute_cost['total']['cost'] += attribute_cost['presence']['cost'];

	attribute_cost['reason']['value'] = get_attribute_value(document.getElementById('reason_value').value);
	attribute_cost['reason']['cost'] = calculate_attribute_cost(attribute_cost['reason']['value']);
	attribute_cost['total']['cost'] += attribute_cost['reason']['cost'];

	attribute_cost['power']['value'] = get_attribute_value(document.getElementById('power_value').value);
	attribute_cost['power']['cost'] = calculate_attribute_cost(attribute_cost['power']['value']);
	attribute_cost['total']['cost'] += attribute_cost['power']['cost'];

	document.getElementById("calculate_attribute_cost_output_DE").innerHTML = format_attribute_cost_output(attribute_cost);
}

//
// Inserts the HTML into the page
//

$(function () {

	var page_title = getQueryVariable("title");

	if (page_title.indexOf("ulletproof_Blues") >= 0) {
		endurance_cost_default = 1;
		total_cost_default = 6;
	} else {
		endurance_cost_default = 0;
		total_cost_default = 5;
	}
	
	var calculate_attribute_cost_output_div = document.getElementById('calculate_attribute_cost_output_DE');

	if (calculate_attribute_cost_output_div != null)
	{
		formatted_attribute_cost_output = "<div class=\"sidebar_title\">Attributkostenrechner</div>\n";
		formatted_attribute_cost_output += '<div class="sidebar_subtitle">';
		formatted_attribute_cost_output += 'Gib die gewünschte Attributsverteilung ein, um dir die Gesamtkosten anzeigen zu lassen:';
		formatted_attribute_cost_output += '<table cellpadding="2" style="margin:auto 0;">';
		formatted_attribute_cost_output += '<tr>';
		formatted_attribute_cost_output += '<th align="left">Attribut</th>';
		formatted_attribute_cost_output += '<th align="center" style="padding-left: 15px; padding-right: 15px;">Attributswert</th>';
		formatted_attribute_cost_output += '<th align="right">Kosten (CP)</th>';
		formatted_attribute_cost_output += '</tr>';
		formatted_attribute_cost_output += '<tr>';
		formatted_attribute_cost_output += '<td align="left">Geschick</td>';
		formatted_attribute_cost_output += '<td align="center"><input id="agility_value" type="text" size="2" style="text-align: right;" value="1" onblur="get_attribute_cost_output()"></td>';
		formatted_attribute_cost_output += '<td align="right"><span id="agility_cost">1</span></td>';
		formatted_attribute_cost_output += '</tr>';
		formatted_attribute_cost_output += '<tr>';
		formatted_attribute_cost_output += '<td align="left">Kraft</td>';
		formatted_attribute_cost_output += '<td align="center"><input id="brawn_value" type="text" size="2" style="text-align: right;" value="1" onblur="get_attribute_cost_output()"></td>';
		formatted_attribute_cost_output += '<td align="right"><span id="brawn_cost">1</span></td>';
		formatted_attribute_cost_output += '</tr>';
		formatted_attribute_cost_output += '<tr>';
		formatted_attribute_cost_output += '<td align="left">Ausdauer</td>';
		formatted_attribute_cost_output += '<td align="center"><input id="endurance_value" type="text" size="2" style="text-align: right;" value="1" onblur="get_attribute_cost_output()"></td>';
		formatted_attribute_cost_output += '<td align="right"><span id="endurance_cost">1</span></td>';
		formatted_attribute_cost_output += '</tr>';
		formatted_attribute_cost_output += '<tr>';
		formatted_attribute_cost_output += '<td align="left">Wille</td>';
		formatted_attribute_cost_output += '<td align="center"><input id="presence_value" type="text" size="2" style="text-align: right;" value="1" onblur="get_attribute_cost_output()"></td>';
		formatted_attribute_cost_output += '<td align="right"><span id="presence_cost">1</span></td>';
		formatted_attribute_cost_output += '</tr>';
		formatted_attribute_cost_output += '<tr>';
		formatted_attribute_cost_output += '<td align="left">Intelligenz</td>';
		formatted_attribute_cost_output += '<td align="center"><input id="reason_value" type="text" size="2" style="text-align: right;" value="1" onblur="get_attribute_cost_output()"></td>';
		formatted_attribute_cost_output += '<td align="right"><span id="reason_cost">1</span></td>';
		formatted_attribute_cost_output += '</tr>';
		formatted_attribute_cost_output += '<tr>';
		formatted_attribute_cost_output += '<td align="left">Macht</td>';
		formatted_attribute_cost_output += '<td align="center"><input id="power_value" type="text" size="2" style="text-align: right;" value="'+ endurance_cost_default +'" onblur="get_attribute_cost_output()"></td>';
		formatted_attribute_cost_output += '<td align="right"><span id="power_cost">'+ endurance_cost_default +'</span></td>';
		formatted_attribute_cost_output += '</tr>';
		formatted_attribute_cost_output += '<tr>';
		formatted_attribute_cost_output += '<th align="left">Gesamtkosten:</th>';
		formatted_attribute_cost_output += '<th align="center"></th>';
		formatted_attribute_cost_output += '<th align="right"><span id="total_cost">'+ total_cost_default +'</span></th>';
		formatted_attribute_cost_output += '</tr>';
		formatted_attribute_cost_output += '</table>';
		formatted_attribute_cost_output += '</div>';
		
		calculate_attribute_cost_output_DE.innerHTML = formatted_attribute_cost_output;
	}
}());