function Armour() {} Armour.prototype.Schema = "Controls the damage resistance of the unit." + "" + "10.0" + "0.0" + "5.0" + "" + "" + "" + "" + "" + "" + "" + "" + "" + ""; Armour.prototype.Init = function() { this.invulnerable = false; }; Armour.prototype.Serialize = null; // we have no dynamic state to save Armour.prototype.SetInvulnerability = function(invulnerability) { this.invulnerable = invulnerability; }; Armour.prototype.TakeDamage = function(hack, pierce, crush) { if (this.invulnerable) return { "killed": false }; // Adjust damage values based on armour var adjHack = Math.max(0, hack - this.template.Hack); var adjPierce = Math.max(0, pierce - this.template.Pierce); var adjCrush = Math.max(0, crush - this.template.Crush); // Total is sum of individual damages, with minimum damage 1 // Round to nearest integer, since HP is integral var total = Math.max(1, Math.round(adjHack + adjPierce + adjCrush)); // Reduce health var cmpHealth = Engine.QueryInterface(this.entity, IID_Health); return cmpHealth.Reduce(total); }; Armour.prototype.GetArmourStrengths = function() { // Convert attack values to numbers return { hack: +this.template.Hack, pierce: +this.template.Pierce, crush: +this.template.Crush }; }; Engine.RegisterComponentType(IID_DamageReceiver, "Armour", Armour);