function Heal() {}
Heal.prototype.Schema =
"Controls the healing abilities of the unit." +
"" +
"20" +
"5" +
"2000" +
"Cavalry" +
"Support Infantry" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"tokens" +
"" +
"" +
"" +
"" +
"" +
"tokens" +
"" +
"" +
"";
Heal.prototype.Init = function()
{
};
Heal.prototype.Serialize = null; // we have no dynamic state to save
Heal.prototype.GetTimers = function()
{
var prepare = 1000;
var repeat = +this.template.Rate;
repeat = ApplyValueModificationsToEntity("Heal/Rate", repeat, this.entity);
return { "prepare": prepare, "repeat": repeat };
};
Heal.prototype.GetRange = function()
{
var min = 0;
var max = +this.template.Range;
max = ApplyValueModificationsToEntity("Heal/Range", max, this.entity);
return { "max": max, "min": min };
};
Heal.prototype.GetUnhealableClasses = function()
{
var classes = this.template.UnhealableClasses._string;
return classes ? classes.split(/\s+/) : [];
};
Heal.prototype.GetHealableClasses = function()
{
var classes = this.template.HealableClasses._string;
return classes ? classes.split(/\s+/) : [];
};
/**
* Heal the target entity. This should only be called after a successful range
* check, and should only be called after GetTimers().repeat msec has passed
* since the last call to PerformHeal.
*/
Heal.prototype.PerformHeal = function(target)
{
var cmpHealth = Engine.QueryInterface(target, IID_Health);
if (!cmpHealth)
return;
var targetState = cmpHealth.Increase(ApplyValueModificationsToEntity("Heal/HP", +this.template.HP, this.entity));
// Add XP
var cmpLoot = Engine.QueryInterface(target, IID_Loot);
var cmpPromotion = Engine.QueryInterface(this.entity, IID_Promotion);
if (targetState !== undefined && cmpLoot && cmpPromotion)
{
// HP healed * XP per HP
cmpPromotion.IncreaseXp((targetState.new-targetState.old)*(cmpLoot.GetXp()/cmpHealth.GetMaxHitpoints()));
}
//TODO we need a sound file
// PlaySound("heal_impact", this.entity);
};
Engine.RegisterComponentType(IID_Heal, "Heal", Heal);