MediaWiki:Kalos Mechanism EN.js

From OGC
Revision as of 16:23, 7 May 2019 by Admin (talk | contribs) (Created page with "function get_attribute_cost_output() { var attribute_cost = new Array(); var raw_value = 0; attribute_cost['brawn'] = new Array(); attribute_cost['agility'] = new Array()...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Note: After publishing, 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 / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
function get_attribute_cost_output()
{
	var attribute_cost = new Array();
	var raw_value = 0;

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

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

	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['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['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['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['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'];

	attribute_cost['endurance']['value'] = Math.max(attribute_cost['brawn']['value'], attribute_cost['presence']['value']);

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

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

$(function () {
	var calculate_attribute_cost_button = document.getElementById('calculate_attribute_cost_button');

	if (calculate_attribute_cost_button != null)
	{
		var formatted_attribute_cost_output;
		
		formatted_attribute_cost_output = "<div class=\"sidebar_title\">Attribute Costs</div>\n";
		formatted_attribute_cost_output += '<div class="sidebar_subtitle">';
		formatted_attribute_cost_output += 'Enter your desired attribute values and click the button.';
		formatted_attribute_cost_output += '<table cellpadding="2" style="margin:auto 0;">';
		formatted_attribute_cost_output += '<tr>';
		formatted_attribute_cost_output += '<th align="left">Attribute</th>';
		formatted_attribute_cost_output += '<th align="center" style="padding-left: 15px; padding-right: 15px;">Value</th>';
		formatted_attribute_cost_output += '<th align="right">Cost</th>';
		formatted_attribute_cost_output += '</tr>';
		formatted_attribute_cost_output += '<tr>';
		formatted_attribute_cost_output += '<td align="left">Brawn</td>';
		formatted_attribute_cost_output += '<td align="center"><input id="brawn_value" type="text" size="2" style="text-align: right;" value="1"></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">Agility</td>';
		formatted_attribute_cost_output += '<td align="center"><input id="agility_value" type="text" size="2" style="text-align: right;" value="1"></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">Reason</td>';
		formatted_attribute_cost_output += '<td align="center"><input id="reason_value" type="text" size="2" style="text-align: right;" value="1"></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">Presence</td>';
		formatted_attribute_cost_output += '<td align="center"><input id="presence_value" type="text" size="2" style="text-align: right;" value="1"></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">Power</td>';
		formatted_attribute_cost_output += '<td align="center"><input id="power_value" type="text" size="2" style="text-align: right;" value="0"></td>';
		formatted_attribute_cost_output += '<td align="right"><span id="power_cost">0</span></td>';
		formatted_attribute_cost_output += '</tr>';
		formatted_attribute_cost_output += '<tr>';
		formatted_attribute_cost_output += '<td align="left">Endurance</td>';
		formatted_attribute_cost_output += '<td align="center"><span id="endurance_value">1</span></td>';
		formatted_attribute_cost_output += '<td align="right"></td>';
		formatted_attribute_cost_output += '</tr>';
		formatted_attribute_cost_output += '<tr>';
		formatted_attribute_cost_output += '<th align="left">Total</th>';
		formatted_attribute_cost_output += '<th align="center"></th>';
		formatted_attribute_cost_output += '<th align="right"><span id="total_cost">6</span></th>';
		formatted_attribute_cost_output += '</tr>';
		formatted_attribute_cost_output += '</table>';
		formatted_attribute_cost_output += '</div>';
		
		calculate_attribute_cost_button.innerHTML = '<input type="button" value="Calculate Attributes..." onclick="get_attribute_cost_output();" />';
		calculate_attribute_cost_output.innerHTML = formatted_attribute_cost_output;
	}
}());