function TntCreature() {}

// It is intended that other classes inherit from this class.

TntCreature.prototype.setPrefix = function(prefix) {
	this.prefix = prefix;
};

TntCreature.prototype.setName = function(name) {
	this.Name = name;
};

TntCreature.prototype.getName = function() {
	return this.Name;
};

TntCreature.prototype.setArmorValue = function(armorValue) {
	this.armorValue = armorValue;
};

TntCreature.prototype.getArmorValue = function() {
	return this.armorValue;
};

TntCreature.prototype.calculateAttack = function() {
	var allDice = this.getDice();
	var ranDice = allDice;
	var extDice = 0;
	if (ranDice > 20) {
		ranDice = 20;
		extDice = allDice - ranDice;
		var ext2Dice = extDice % 6;
		extDice -= ext2Dice;
		ranDice += ext2Dice;
	}
	var fateDice = Math.floor(extDice / 6);
	var rolled = Adv.myrandom.dice(ranDice, 6);
	if (fateDice) {
		rolled[0] += fateDice * 21;
		rolled[1] += fateDice;
		rolled[2] += fateDice;
		rolled[3] += fateDice;
		rolled[4] += fateDice;
		rolled[5] += fateDice;
		rolled[6] += fateDice;
	}
	this.attack.roll = rolled[0];
	this.attack.spite = rolled[6];
	this.attack.vulnerable = rolled[1];
	this.attack.hpt = this.attack.roll + this.getAdds();
	this.attack.minimumDamage = 0;
	this.attack.spiteDamage = 0;
	this.attack.normalDamage = 0;
};

TntCreature.prototype.calculateMissileAttack = function() {
	var rolled = Adv.myrandom.dice(this.getMissileDice(), 6);
	this.attack.roll = rolled[0];
	this.attack.spite = rolled[6];
	this.attack.vulnerable = rolled[1];
	this.attack.hpt = this.attack.roll + this.getMissileAdds();
	this.attack.minimumDamage = 0;
	this.attack.spiteDamage = 0;
	this.attack.normalDamage = 0;
};

TntCreature.prototype.decrementEffects = function() {
	var i;
	var numEffects = this.effects.length;
	for (i=numEffects - 1; i>=0; --i) {
		this.effects[i].decrement();
		if (this.effects[i].getDuration() < 1) {
			this.removeEffect(i);
		}
	}
	if (this.summoned) this.duration--;
};

TntCreature.prototype.clearAttack = function() {
	this.attack.roll = 0;
	this.attack.spite = 0;
	this.attack.vulnerable = 0;
	this.attack.hpt = 0;
	this.attack.minimumDamage = 0;
	this.attack.spiteDamage = 0;
	this.attack.normalDamage = 0;
};

TntCreature.prototype.setHpt = function(amount) {
	this.attack.hpt = amount;
};

TntCreature.prototype.getHpt = function() {
	return this.attack.hpt;
};

TntCreature.prototype.getSpite = function() {
	return this.attack.spite;
};

TntCreature.prototype.setMinimumDamage = function(amount) {
	if (!amount || amount < 0) amount = 0;
	this.attack.minimumDamage = amount;
};

TntCreature.prototype.getMinimumDamage = function() {
	if (!this.attack.minimumDamage) this.attack.minimumDamage = 0;
	return this.attack.minimumDamage;
};

TntCreature.prototype.setNormalDamage = function(amount) {
	this.attack.normalDamage = amount;
};

TntCreature.prototype.addNormalDamage = function(amount) {
	this.attack.normalDamage += amount;
};

TntCreature.prototype.getNormalDamage = function(amount) {
	return this.attack.normalDamage;
};

TntCreature.prototype.addSpiteDamage = function(amount) {
	this.attack.spiteDamage += amount;
};

TntCreature.prototype.getSpiteDamage = function() {
	return this.attack.spiteDamage;
};

TntCreature.prototype.isAttacking = function(game) {
	if (this.getLife() <= 0) return false;
	if (!this.canAttack && !this.isShooting) return false;
	if (this.isChatting || this.isWaiting || this.isMoving || this.isDodging) {
		return false;
	}
	if (this.isParalyzed(game)) return false;
	if (this.distance && (this.distance > 0)) return false;
	return true;
};

TntCreature.prototype.isProtected = function() {
	var protected = 0;
	var numEffects = this.effects.length;
	var i;
	for (i=0; i<numEffects; ++i) {
		var effect = this.effects[i];
		if (effect.getName() == "Protective Pentagram") {
			if (effect.getDuration() > protected) {
				protected = effect.getDuration();
			}
		}
	}
	if (!protected && this.dodged) {
		protected = 1;
	}
	return protected;
};

TntCreature.prototype.isParalyzed = function(game) {
	var paralyzed = false;
	var numEffects = this.effects.length;
	var i;
	for (i=0; i<numEffects; ++i) {
		var effect = this.effects[i];
		if (effect.getName() == "Slush Yuck") {
			var srsuccess = effect.checkSR(this, game);
			if (!srsuccess) {
				effect.dealSpite = true;
				paralyzed = true;
			}
		}
		if ((effect.getName() == "HTP") && (effect.getDuration() > 0)) {
			paralyzed = true;
		} else if ((effect.getName() == "Protective Pentagram") && (effect.getDuration() > 0)) {
			paralyzed = true;
		}
	}
	return paralyzed;
};

TntCreature.prototype.attackMultiplier = function() {
	var i;
	var numEffects = this.effects.length;
	var multiplier = 1.0;
	var mults = [];
	for (i=0; i<numEffects; ++i) {
		var effect = this.effects[i];
		if (effect.getDuration() > 0) {
			var tmpMult = effect.getEffectAmount();
			var multBene = true;
			var effectName = effect.getName();
			if (effectName == "Slush Yuck") {
				tmpMult = 1.0 / tmpMult;
				multBene = false;
			}
			if (!mults[effectName]) mults[effectName] = 1;
			if (multBene && (mults[effectName] < tmpMult)) {
				mults[effectName] = tmpMult;
			} else if (!multBene && (mults[effectName] > tmpMult)) {
				mults[effectName] = tmpMult;
			}
		}
	}
	for (var effName in mults) {
		multiplier *= mults[effName];
	}
	if (this.isCharging && this.level) {
		if (this.type == "Warrior") {
			multiplier *= (1 + (this.level * 0.5));
		} else {
			multiplier *= (1 + (this.level * 0.2));
		}
	}
	return multiplier;
};

TntCreature.prototype.spdMultiplier = function() {
	var i;
	var numEffects = this.effects.length;
	var multiplier = 1.0;
	var mults = [];
	for (i=0; i<numEffects; ++i) {
		var effect = this.effects[i];
		if (effect.getDuration() > 0) {
			var tmpMult = effect.getEffectAmount();
			var multBene = true;
			var effectName = effect.getName();
			if (effectName == "Slush Yuck") {
				tmpMult = 1.0 / tmpMult;
				if (effect.checkSR(this)) tmpMult = 0;
				multBene = false;
			} else if (effectName == "HTP") {
				return 0;
			}
			if (!mults[effectName]) mults[effectName] = 1;
			if (multBene && (mults[effectName] < tmpMult)) {
				mults[effectName] = tmpMult;
			} else if (!multBene && (mults[effectName] > tmpMult)) {
				mults[effectName] = tmpMult;
			}
		}
	}
	for (var effName in mults) {
		multiplier *= mults[effName];
	}
	return multiplier;
};

TntCreature.prototype.clearTmpEffects = function() {
	var i;
	var numEffects = this.effects.length;
	for (i=numEffects - 1; i>=0; --i) {
		var effect = this.effects[i];
		if (!effect.isPermanent()) {
			this.removeEffect(i);
		}
	}
};

TntCreature.prototype.removeEffect = function(whichEffect) {
	Adv.removeFromArray(this.effects, whichEffect);
};

TntCreature.prototype.addEffect = function(effect) {
	this.effects[this.effects.length] = effect;
};

TntCreature.prototype.showEffects = function(adv) {
	var i;
	var plural;
	var numEffects = this.effects.length;
	var output = "";
	var maxEffectSpite = 0;
	if (this.isChatting) {
//		output += this.getName() + " is chatting.<" + "br />";
		this.isChatting = false;
	}
	if (this.isWaiting) {
//		output += this.getName() + " is waiting.<" + "br />";
		this.isWaiting = false;
	}
	for (i=0; i<numEffects; ++i) {
		var effect = this.effects[i];
		if (output) {
			output += "<" + "br />";
		}
		var duration = effect.getDuration();
		plural = "s";
		if (duration > 1) {
			if (duration == 2) plural = "";
			output += this.getName() + " will be affected by " + effect.getName() + " for " + (effect.getDuration() - 1) + " more combat turn" + plural + ".";
		} else {
			output += "The " + effect.getName() + " affecting " + this.getName() + " has run it's course.";
		}
		if (effect.dealSpite) {
			var effectSpite = Adv.myrandom.dice(effect.getEffectAmount(), 6)[0];
			if (effectSpite > maxEffectSpite) maxEffectSpite = effectSpite;
			effect.dealSpite = false;
		}
	}
	this.addSpiteDamage(maxEffectSpite);
	if (output) adv.addContent("<p>" + output + "</p>");
};

TntCreature.prototype.copyTo = function(newCreature) {
	for (var p in this) {
		var pv = this[p];
		if (typeof pv != "function") {
			newCreature[p] = pv;
		}
	}
	return;
};

TntCreature.prototype.modLife = function(pts) {
	var modPts = pts;
	var life = this.getLife();
	life += pts;
	var maxLife = this.getMaxLife();
	if (life > maxLife) {
		modPts = pts - life + maxLife;
		life = maxLife;
	}
	this.setLife(life);
	return modPts;
};

TntCreature.prototype.reduceAmmo = function() {
	if (this.ammo) {
		this.ammo.quantity--;
		this.displayAmmo();
		this.displayMissileDice();
		this.displayMissileAdds();
	}
};
