// ab.js

/*
  3EProfiler character sheet source file.
  Copyright (C) 2008 Myth-Weavers Games
  **
*/

// **

// Implements functions used for maintining the attack bonus table.

// Dependencies:
//    general.js

// function AttackCalc()
// Calculates the attack workspace
function AttackCalc() {
	for (var counter = 1; counter <=2; counter++) {
		
		// Look up the ability used
		var ability = String(sheet()["AB" + counter + "Type"].value).toLowerCase();
		ability = String(ability).substr(0, 3);
		
	if (ability == "str") ability = "Str";
	else if (ability == "con") ability = "Con";
	else if (ability == "dex") ability = "Dex";
	else if (ability == "int") ability = "Int";
	else if (ability == "wis") ability = "Wis";
	else if (ability == "cha") ability = "Cha";
	else
	{
		// Not a valid ability name.
		ability = "none";
	}
		
		
		// Substitude the Modifier according to their type.
		if (ability != "none") {
			sheet()["AB" + counter + "Ability"].value = sheet()[ability + "Mod"].value;
		}
		
		// Summation
		
		ZeroFill(
				 sheet()["AB" + counter + "HalfLevel"],
				 sheet()["AB" + counter + "Ability"],
				 sheet()["AB" + counter + "Class"],
				 sheet()["AB" + counter + "Prof"],
				 sheet()["AB" + counter + "Feat"],
				 sheet()["AB" + counter + "Misc"],
				 sheet()["AB" + counter + "Enh"]);
		
		sheet()["AB" + counter].value = Add(
				 sheet()["AB" + counter + "HalfLevel"].value,
				 sheet()["AB" + counter + "Ability"].value,
				 sheet()["AB" + counter + "Class"].value,
				 sheet()["AB" + counter + "Prof"].value,
				 sheet()["AB" + counter + "Feat"].value,
				 sheet()["AB" + counter + "Misc"].value,
				 sheet()["AB" + counter + "Enh"].value);
	}
}

// function DamageCalc()
// Calculates the damage workspace
function DamageCalc() {
	for (var counter = 1; counter <=2; counter++) {
		
		// Look up the ability used
		var ability = String(sheet()["DB" + counter + "Type"].value).toLowerCase();
		ability = String(ability).substr(0, 3);
		
	if (ability == "str") ability = "Str";
	else if (ability == "con") ability = "Con";
	else if (ability == "dex") ability = "Dex";
	else if (ability == "int") ability = "Int";
	else if (ability == "wis") ability = "Wis";
	else if (ability == "cha") ability = "Cha";
	else
	{
		// Not a valid ability name.
		ability = "none";
	}
		
		
		// Substitude the Modifier according to their type.
		if (ability != "none") {
			sheet()["DB" + counter + "Ability"].value = sheet()[ability + "Mod"].value;
		}
		
		// Summation
		
		ZeroFill(
				 sheet()["DB" + counter + "Ability"],
				 sheet()["DB" + counter + "Feat"],
				 sheet()["DB" + counter + "Misc"],
				 sheet()["DB" + counter + "Misc2"],
				 sheet()["DB" + counter + "Enh"]);
		
		sheet()["DB" + counter].value = Add(
				 sheet()["DB" + counter + "Ability"].value,
				 sheet()["DB" + counter + "Feat"].value,
				 sheet()["DB" + counter + "Misc"].value,
				 sheet()["DB" + counter + "Misc2"].value,
				 sheet()["DB" + counter + "Enh"].value);
	}
}