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 = ApplyTechModificationsToEntity("Heal/Rate", repeat, this.entity); return { "prepare": prepare, "repeat": repeat }; }; Heal.prototype.GetRange = function() { var min = 0; var max = +this.template.Range; max = ApplyTechModificationsToEntity("Heal/Range", max, this.entity); return { "max": max, "min": min }; }; Heal.prototype.GetUnhealableClasses = function() { var classes = this.template.UnhealableClasses._string; // If we have no unhealable classes defined classes is undefined return classes ? classes.split(/\s+/) : []; }; Heal.prototype.GetHealableClasses = function() { var classes = this.template.HealableClasses._string; return 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 hp = +this.template.HP; hp = ApplyTechModificationsToEntity("Heal/HP", hp, this.entity); var targetState = cmpHealth.Increase(hp); // 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);