1
0
forked from 0ad/0ad
0ad/binaries/data/mods/public/simulation/components/Armour.js
Ykkrosh c8c10a4871 # Extensions and cleanups to session GUI files.
Add various GUI pieces (exit button, resource counts, unit details).
Clean up implementation of button panels.
Split some content out of 'common' and into page-specific files.
Delete some obsolete content.

This was SVN commit r7337.
2010-02-28 21:45:09 +00:00

34 lines
955 B
JavaScript

function Armour() {}
Armour.prototype.Init = function()
{
};
Armour.prototype.TakeDamage = function(hack, pierce, crush)
{
// Adjust damage values based on armour
// (Default armour values to 0 if undefined)
var adjHack = Math.max(0, hack - (this.template.Hack || 0));
var adjPierce = Math.max(0, pierce - (this.template.Pierce || 0));
var adjCrush = Math.max(0, crush - (this.template.Crush || 0));
// Total is sum of individual damages, with minimum damage 1
var total = Math.max(1, adjHack + adjPierce + adjCrush);
// Reduce health
var cmpHealth = Engine.QueryInterface(this.entity, IID_Health);
cmpHealth.Reduce(total);
};
Armour.prototype.GetArmourStrengths = function()
{
// Convert attack values to numbers, default 0 if unspecified
return {
hack: +(this.template.Hack || 0),
pierce: +(this.template.Pierce || 0),
crush: +(this.template.Crush || 0)
};
};
Engine.RegisterComponentType(IID_DamageReceiver, "Armour", Armour);