MediaWiki:Kalos Mechanism EN.js: Difference between revisions
Jump to navigation
Jump to search
(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()...") |
No edit summary |
||
Line 1: | Line 1: | ||
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(20, 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 get_attribute_cost_output() | function get_attribute_cost_output() | ||
{ | { |
Revision as of 17:07, 7 May 2019
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(20, 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 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;
}
}());