﻿/************************************************************

	casting.js

	スキル詠唱時間シミュレータ

	(C) 2004 - 2006 Raginfo : www.raginfo.net

************************************************************/

var dex_total;
var fenc_point;
var bless_point;
var saff_point;
var bragi_point;

//function keydown : Enter キー押下時に計算する
function keydown(){
	if((event.keyCode == 13) || (event.keyCode == 108)){
		correct();
	}
}

//function correct : 入力された値の検証
function correct(){
	dex_total = parseInt(document.select.dextotal.selectedIndex);

	if((isNaN(dex_total)) || ((dex_total < 0) || (dex_total > 150))){
		if(dex_total > 150){
			dex_total = 150;
			document.select.dextotal.value = 150;
			document.select.dextotal.selectedIndex = 149;
		}
		else{
			dex_total = 1;
			document.select.dextotal.value = 1;
			document.select.dextotal.selectedIndex = 0;
		}
	}

	if(document.select.fencard.checked == true){
		fenc_point = 1.25;
	}
	else{
		fenc_point = 1.0;
	}

	if(document.select.blessing.checked == true){
		if(dex_total <= 140){
			bless_point = 10.0;
		}
		else{
			dex_total = 150;
			bless_point = 0;
		}
	}
	else{
		bless_point = 0;
	}

	if(document.select.saffragium.checked == true){
		saff_point = 0.55;
	}
	else{
		saff_point = 1.0;
	}

	if(document.select.a_poem_of_bragi.checked == true){
		bragi_point = 0.70;
	}
	else{
		bragi_point = 1.0;
	}

	for(var j = 1; j <= 15; j ++){
		document.timelist.label[j - 1].value = j;
	}

	calculate();
}

//function calculate : 結果の計算
function calculate(){
	var basetime = new Array(5.0, 15.0, 5.0, 15.0, 7.0, 10.5, 2.0, 5.0, 4.0, 15.0, 9.0, 9.0);
	var result = new Array("");

	var spelltime = (150.0 - dex_total - bless_point) / 150.0;
	var correctc = spelltime * fenc_point * saff_point * bragi_point;

	for(var i = 1; i <= 15; i ++){
		result[i] = i * correctc;
		var string = new String(result[i]);
		document.timelist.time[i - 1].value = string.slice(0, 5);
	}

	var string0 = new String(basetime[0] * correctc);
	var string1 = new String(basetime[1] * correctc);
	var string2 = new String(basetime[2] * correctc);
	var string3 = new String(basetime[3] * correctc);
	var string4 = new String(basetime[4] * correctc);
	var string5 = new String(basetime[5] * correctc);
	var string6 = new String(basetime[6] * correctc);
	var string7 = new String(basetime[7] * correctc);
	var string8 = new String(basetime[8] * correctc);
	var string9 = new String(basetime[9] * correctc);
	var string10 = new String(basetime[10] * correctc);
	var string11 = new String(basetime[11] * correctc);

	document.spelllist.heavens_drive.value = string0.slice(0, 5);
	document.spelllist.meteor_storm.value = string1.slice(0, 5);
	document.spelllist.water_ball.value = string2.slice(0, 5);
	document.spelllist.storm_gust.value = string3.slice(0, 5);
	document.spelllist.jupiter_thunder.value = string4.slice(0, 5);
	document.spelllist.lord_of_vermilion.value = string5.slice(0, 5);
	document.spelllist.holy_light.value = string6.slice(0, 5);
	document.spelllist.sanctuary.value = string7.slice(0, 5);
	document.spelllist.magnificat.value = string8.slice(0, 5);
	document.spelllist.magnus_exorcismus.value = string9.slice(0, 5);
	document.spelllist.melt_down.value = string10.slice(0, 5);
	document.spelllist.basilica.value = string11.slice(0, 5);
}
