// statblock.js

// 3EProfiler (tm) character sheet source file.
// Copyright (C) 2008 Myth-Weavers Games.

// Generates a statblock with one click of ease.

/* The Statblock format is as below:
Name LinkToCharacterSheet
Gender Alignment Race Class Level, Init +n, HP n/n
AC n (AC anaylsis here), Fort +n, Ref +n, Will +n, Speed n
Abilities Str n, Dex n, Con n, Int n, Wis n, Cha n
Condition n
Powers n++
*/

// void GenerateStatblock()
// Fill the statblock field with automatically parsed stats.
function GenerateStatblock(autosave) {
	
	if (autosave != "true") {
		if (sheet().SBGenUponSave.checked == false)
			return;
	}

	var finalStat = "";
	
	// Character names with link to sheet.
	finalStat = "[size=4][B]" + sheet().Name.value + "[/B][/size]";
	finalStat = "[url=http://www.myth-weavers.com/sheetview.php?sheetid=" + String(sheet().id.value) + "]" + finalStat + "[/url]";
	
	// Class
	finalStat = finalStat + ", " + sheet().Race.value + " " + sheet().Class.value;
	
	if (sheet().Paragon.value != "")
		finalStat = finalStat + ", " + sheet().Paragon.value;
		
	if (sheet().Epic.value != "")
		finalStat = finalStat + ", " + sheet().Epic.value;
		
	// LINE BREAK
	finalStat = finalStat + "\n";
	
	// Init, HP, Bloodied, Healing Surges.
	finalStat = finalStat + "[B]Init[/B] " + sheet().Init.value + " [B]HP[/B] " + sheet().HPCurrent.value + "/" + sheet().HPMax.value + " [B]Bloodied[/B] " + sheet().HPHalf.value;
	finalStat = finalStat + " [B]Healing Surge[/B] " + sheet().HPQuarter.value + " (" + sheet().HealingSurgeUses.value + " used /" + sheet().HealingSurgePerDay.value + ")";
	
	// LINE BREAK
	finalStat = finalStat + "\n";
	
	// Defenses, Speed.
	finalStat = finalStat + "[B]AC[/B] " + sheet().AC.value + " [B]Fort[/B] " + sheet().Fort.value + " [B]Reflex[/B] " + sheet().Reflex.value + " [B]Will[/B] " + sheet().Will.value + " [B]Speed[/B] " + sheet().Speed.value;
	
	// LINE BREAK
	finalStat = finalStat + "\n";
	
	// Stats
	finalStat = finalStat + "[B]Str[/B] " + sheet().Str.value + " (" + sheet().StrMod.value + ") ";
	finalStat = finalStat + " [B]Con[/B] " + sheet().Con.value + " (" + sheet().ConMod.value + ") ";
	finalStat = finalStat + " [B]Dex[/B] " + sheet().Dex.value + " (" + sheet().DexMod.value + ") ";
	finalStat = finalStat + " [B]Int[/B] " + sheet().Int.value + " (" + sheet().IntMod.value + ") ";
	finalStat = finalStat + " [B]Wis[/B] " + sheet().Wis.value + " (" + sheet().WisMod.value + ") ";
	finalStat = finalStat + " [B]Cha[/B] " + sheet().Cha.value + " (" + sheet().ChaMod.value + ") ";
	
	// LINE BREAK
	finalStat = finalStat + "\n";
	
	// Powers
	// Receives a list of powers.
	var powers = PowerCheck();
	finalStat = finalStat + powers;
	
	// LINE BREAK
	finalStat = finalStat + "\n";
	
	// Conditions, Notes, whatnot.
	finalStat = finalStat + "[B]Notes[/B] " + sheet().text7.value;
	
	//Outputs the Statblock
	sheet().statsummary.value = finalStat;
}

// checks for Power
// function PowerCheck()
function PowerCheck() {
	var p = 1;	
	var output = "";
	var block = "";
	
	for (p=1; p<=28; p++) {
		
		if (p < 10) {
			    i = "0" + p;
			  } else {
			    i = p;
			  } 
		
		// Checks if there is a power. If there is, add it to the list. If the power is used, it's displayed as Italics instead.	
		
		if (sheet()["Power" + i].value != "") {
			
			if (sheet()["Power" + i + "Use"].checked == true) {
				block = "\'[STRIKE]" + sheet()["Power" + i].value + "[/STRIKE]\'";
			}
			else {
				block = "\'" + sheet()["Power" + i].value + "\'";
			}
			
			if (sheet()["d4p" + i + "desc"].value != "") {
				block = "[OOC=" + block + "][B]" + sheet()["Power" + i].value + "[/B]\n"+ sheet()["d4p" + i + "desc"].value + "[/OOC]";
			}
			
			if (output == "") {
				output = output + block;
			} else {
				output = output + ", " + block;
			}
		}
	}
	
	return output;
}
