function TntCharacter() {
	this.attack = [];
	this.effects = [];
	this.armorName = "None";
	this.armorValue = 0;
	this.plural = false;
	this.type = "Useless";
	this.level = 0;
	this.roguery = 0;
}

// Inherit from TntCreature
for (var m in TntCreature.prototype) {
	var f = TntCreature.prototype[m];
	if (typeof f == "function") {
		TntCharacter.prototype[m] = f;
	}
}

TntCharacter.statNames = ["STR", "CON", "DEX", "SPD", "INT", "WIZ", "LK", "CHR"];
TntCharacter.numStats = TntCharacter.statNames.length;

TntCharacter.prototype.getStat = function(statName) {
	return this[statName];
};

TntCharacter.prototype.setStats = function(stats) {
	var i;
	for (i=0; i<TntCharacter.numStats; ++i) {
		var statName = TntCharacter.statNames[i];
		var maxStatName = statName + "Max";
		this[statName] = stats[statName];
		this[maxStatName] = this[statName];
	}
};

TntCharacter.prototype.calcAdds = function() {
	this.Adds = TntGame.calcAdd(this.STR)
		+ TntGame.calcAdd(this.DEX)
		+ TntGame.calcAdd(this.SPD)
		+ TntGame.calcAdd(this.LK);
	if (this.type == "Warrior") this.Adds += this.level;
};

TntCharacter.prototype.getAdds = function() {
	this.calcAdds();
	var weaponAdds = 0;
	if (this.equippedWeapon) weaponAdds = this.equippedWeapon.adds;
	return this.Adds + weaponAdds;
};

TntCharacter.prototype.getMissileAdds = function() {
	this.calcAdds();
	var weaponAdds = 0;
	if (this.bow && this.ammo && this.ammo.quantity && (this.ammo.quantity > 0)) {
		weaponAdds = this.bow.adds;
		weaponAdds += this.ammo.adds;
	}
	return this.Adds + weaponAdds;
}

TntCharacter.prototype.displayStats = function() {
	for (i=0; i<TntCharacter.numStats; ++i) {
		var statMaxName = TntCharacter.statNames[i] + "Max";
		Adv.setElemValue(this.prefix + TntCharacter.statNames[i], this[TntCharacter.statNames[i]]);
		Adv.setElemValue(this.prefix + statMaxName, this[statMaxName]);
	}
	dice = this.getDice();
	Adv.setElemValue(this.prefix + "Dice", dice);
	adds = this.getAdds();
	Adv.setElemValue(this.prefix + "Adds", adds);
};

TntCharacter.prototype.display = function() {
	Adv.setElemValue(this.prefix + "Name", this.Name);
	Adv.setElemValue(this.prefix + "Type", this.type);
	Adv.setElemValue(this.prefix + "Level", this.level);
	this.displayStats();
	this.displayRoguery();
	this.displayAP();
// equipped weapon and armor... other equipment... spells... whatever...	
	this.displayWeapon();
	this.displayArmor();
	this.displayDice();
	this.displayAdds();
	this.displayMissileDice();
	this.displayMissileAdds();
	this.displayHits();
	this.displayBow();
	this.displayAmmo();
};

TntCharacter.prototype.displayWeapon = function() {
	Adv.setElemValue(this.prefix + "Weapon", this.equippedWeapon.name);
};

TntCharacter.prototype.displayArmor = function() {
	Adv.setElemValue(this.prefix + "Armor", this.armorName);
};

TntCharacter.prototype.displayBow = function() {
	if (this.bow) {
		var bowAdds = this.getMissileAdds();
		Adv.setElemValue(this.prefix + "Bow", this.bow.name);
	}
}

TntCharacter.prototype.displayAmmo = function() {
	Adv.setElemValue(this.prefix + "Ammo", this.ammo.name + " (qty: " + this.ammo.quantity + ")");
}

TntCharacter.prototype.displayMissileDice = function() {
	if (this.bow) {
		Adv.setElemValue(this.prefix + "MissileDice", this.getMissileDice());
	}
}

TntCharacter.prototype.displayMissileAdds = function() {
	if (this.bow) {
		Adv.setElemValue(this.prefix + "MissileAdds", this.getMissileAdds());
	}
}

TntCharacter.prototype.displayDice = function() {
	Adv.setElemValue(this.prefix + "Dice", this.getDice());
};

TntCharacter.prototype.displayAdds = function() {
	Adv.setElemValue(this.prefix + "Adds", this.getAdds());
};

TntCharacter.prototype.displayHits = function() {
	Adv.setElemValue(this.prefix + "Hits", this.armorValue);
};

TntCharacter.prototype.displayAP = function() {
	Adv.setElemValue(this.prefix + "AP", this.AP);
};

TntCharacter.prototype.displayRoguery = function() {
	Adv.setElemValue(this.prefix + "RGY", this.roguery);
};

TntCharacter.prototype.addAP = function(amount) {
	if (amount > 0) {
		this.AP += amount;
		this.displayAP();
	}
};

TntCharacter.prototype.rollSR = function(lvl, statName, grantAp) {
	var stt = this[statName];
	if (this.type == "Rogue") {
		if (statName == "LK" || statName == "CHR" || statName == "INT") {
			stt = this.roguery;
		}
	}
	var srr = TntGame.rollSR(lvl, stt, this.level);
	if (srr && srr.roll && grantAp) {
		this.addAP(srr.roll * lvl);
	}
	if (srr) {
		var output = "<p>" + statName + " SR, Target: " + srr.target + ", Roll: " + srr.roll + ", Total: " + srr.total + ", Success: " + srr.success + "</p>";
		srr.output = output;
	}
	return srr;
};

TntCharacter.prototype.resetStatsToMax = function() {
	var i;
	for (i=0; i<TntCharacter.numStats; ++i) {
		var statName = TntCharacter.statNames[i];
		var maxStatName = statName + "Max";
		this[statName] = this[maxStatName];
	}
};

TntCharacter.prototype.getWizardLevel = function() {
	return Math.floor(Math.max(this.DEX, this.INT, this.WIZ, this.CHR) / 10);
};

TntCharacter.prototype.getRogueLevel = function() {
	return Math.floor(Math.max(this.DEX, this.INT, this.WIZ, this.LK) / 10);
};

TntCharacter.prototype.getWarriorLevel = function() {
	return Math.floor(Math.max(this.STR, this.DEX, this.SPD, this.LK) / 10);
};

TntCharacter.prototype.getSpecialistLevel = function() {
	return Math.floor(Math.max(this.CON, this.INT, this.WIZ, this.CHR) / 10);
};

TntCharacter.prototype.calcLevel = function() {
	if (this.type == "Rogue") this.level = this.getRogueLevel();
	else if (this.type == "Warrior") this.level = this.getWarriorLevel();
	else if (this.type == "Wizard") this.level = this.getWizardLevel();
	else if (this.type == "Ranger" || this.type == "Leader") {
		this.level = this.getSpecialistLevel();
	}
	else this.level = 0;
	return this.level;
};

TntCharacter.prototype.getDice = function() {
	var dice = 0;
	if (this.equippedWeapon) dice = this.equippedWeapon.getDice();
	else dice = 1;
	return dice;
};

TntCharacter.prototype.getMissileDice = function() {
	var dice = 0;
	if (this.bow && this.ammo && this.ammo.quantity && (this.ammo.quantity > 0)) {
		dice = this.bow.dice + this.ammo.dice;
	}
	return dice;
}

TntCharacter.prototype.getLife = function() {
	return this.CON;
};

TntCharacter.prototype.getMaxLife = function() {
	return this.CONMax;
};

TntCharacter.prototype.setLife = function(life) {
	this.CON = life;
};

TntCharacter.prototype.resolveCombatResult = function() {
	var amount = this.getNormalDamage() + this.getMinimumDamage();
	amount -= this.getArmorValue();
	if (amount < 0) amount = 0;
	this.CON -= amount;
	this.CON -= this.getSpiteDamage();
	this.calcAdds();
	if (this.CON <= 0)
		return this.CONMax;
	else
		return 0;
};

TntCharacter.prototype.canCastSpells = function() {
	if (this.type == "Rogue") return true;
	if (this.type == "Warrior") return false;
	if (this.type == "Wizard") {
		var canCast = true;
		if ((typeof this.hand1 != "undefined") && this.hand1.dice > 2) canCast = false;
		else if ((typeof this.hand2 != "undefined") && this.hand2.dice > 2) canCast = false;
		else if (this.getDice() > 2) canCast = false;
		return canCast;
	}
	return false;
};

TntCharacter.prototype.hasFocus = function() {
	if (this.equippedWeapon.name == "Staff Ordinaire") return true;
	if (this.equippedWeapon.name.indexOf("Magic Wand") >= 0) return true;
	return false;
};
