2010-02-05 23:00:39 +01:00
|
|
|
function Armour() {}
|
|
|
|
|
2010-04-09 21:02:39 +02:00
|
|
|
Armour.prototype.Schema =
|
2010-04-23 18:09:03 +02:00
|
|
|
"<a:help>Controls the damage resistance of the unit.</a:help>" +
|
|
|
|
"<a:example>" +
|
|
|
|
"<Hack>10.0</Hack>" +
|
|
|
|
"<Pierce>0.0</Pierce>" +
|
|
|
|
"<Crush>5.0</Crush>" +
|
|
|
|
"</a:example>" +
|
|
|
|
"<element name='Hack' a:help='Hack damage protection'>" +
|
2010-04-09 21:02:39 +02:00
|
|
|
"<ref name='nonNegativeDecimal'/>" +
|
|
|
|
"</element>" +
|
2010-04-23 18:09:03 +02:00
|
|
|
"<element name='Pierce' a:help='Pierce damage protection'>" +
|
2010-04-09 21:02:39 +02:00
|
|
|
"<ref name='nonNegativeDecimal'/>" +
|
|
|
|
"</element>" +
|
2010-04-23 18:09:03 +02:00
|
|
|
"<element name='Crush' a:help='Crush damage protection'>" +
|
2010-04-09 21:02:39 +02:00
|
|
|
"<ref name='nonNegativeDecimal'/>" +
|
2012-08-23 23:22:49 +02:00
|
|
|
"</element>" +
|
|
|
|
"<optional>" +
|
|
|
|
"<element name='Foundation' a:help='Armour given to building foundations'>" +
|
|
|
|
"<interleave>" +
|
|
|
|
"<element name='Hack' a:help='Hack damage protection'>" +
|
|
|
|
"<ref name='nonNegativeDecimal'/>" +
|
|
|
|
"</element>" +
|
|
|
|
"<element name='Pierce' a:help='Pierce damage protection'>" +
|
|
|
|
"<ref name='nonNegativeDecimal'/>" +
|
|
|
|
"</element>" +
|
|
|
|
"<element name='Crush' a:help='Crush damage protection'>" +
|
|
|
|
"<ref name='nonNegativeDecimal'/>" +
|
|
|
|
"</element>" +
|
|
|
|
"</interleave>" +
|
|
|
|
"</element>" +
|
|
|
|
"</optional>";
|
2010-04-09 21:02:39 +02:00
|
|
|
|
2010-02-05 23:00:39 +01:00
|
|
|
Armour.prototype.Init = function()
|
|
|
|
{
|
2011-05-02 17:03:01 +02:00
|
|
|
this.invulnerable = false;
|
2010-02-05 23:00:39 +01:00
|
|
|
};
|
|
|
|
|
2011-05-02 17:03:01 +02:00
|
|
|
Armour.prototype.SetInvulnerability = function(invulnerability)
|
|
|
|
{
|
|
|
|
this.invulnerable = invulnerability;
|
|
|
|
};
|
|
|
|
|
2010-02-05 23:00:39 +01:00
|
|
|
Armour.prototype.TakeDamage = function(hack, pierce, crush)
|
|
|
|
{
|
2011-05-02 17:03:01 +02:00
|
|
|
if (this.invulnerable)
|
|
|
|
return { "killed": false };
|
2012-04-30 22:39:27 +02:00
|
|
|
|
2013-04-29 09:51:51 +02:00
|
|
|
// Adjust damage values based on armour; exponential armour: damage = attack * 0.9^armour
|
2012-04-30 22:39:27 +02:00
|
|
|
var armourStrengths = this.GetArmourStrengths();
|
2013-04-29 09:51:51 +02:00
|
|
|
var adjHack = hack * Math.pow(0.9, armourStrengths.hack);
|
|
|
|
var adjPierce = pierce * Math.pow(0.9, armourStrengths.pierce);
|
|
|
|
var adjCrush = crush * Math.pow(0.9, armourStrengths.crush);
|
2010-02-05 23:00:39 +01:00
|
|
|
|
|
|
|
// Total is sum of individual damages, with minimum damage 1
|
2012-02-01 05:11:47 +01:00
|
|
|
// Round to nearest integer, since HP is integral
|
|
|
|
var total = Math.max(1, Math.round(adjHack + adjPierce + adjCrush));
|
2010-02-05 23:00:39 +01:00
|
|
|
|
|
|
|
// Reduce health
|
|
|
|
var cmpHealth = Engine.QueryInterface(this.entity, IID_Health);
|
2010-11-12 23:24:49 +01:00
|
|
|
return cmpHealth.Reduce(total);
|
2010-02-05 23:00:39 +01:00
|
|
|
};
|
|
|
|
|
2010-02-28 22:45:09 +01:00
|
|
|
Armour.prototype.GetArmourStrengths = function()
|
|
|
|
{
|
2012-04-21 18:37:35 +02:00
|
|
|
// Work out the armour values with technology effects
|
|
|
|
var self = this;
|
2012-04-20 21:47:01 +02:00
|
|
|
|
2012-08-23 23:22:49 +02:00
|
|
|
var applyTechs = function(type, foundation)
|
2012-04-21 18:37:35 +02:00
|
|
|
{
|
2012-08-23 23:22:49 +02:00
|
|
|
var strength;
|
|
|
|
if (foundation)
|
|
|
|
{
|
|
|
|
strength = +self.template.Foundation[type];
|
|
|
|
type = "Foundation/" + type;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
strength = +self.template[type];
|
|
|
|
}
|
|
|
|
|
2013-01-08 01:00:21 +01:00
|
|
|
// All causes caching problems so disable it for now.
|
|
|
|
// var allComponent = ApplyTechModificationsToEntity("Armour/All", strength, self.entity) - self.template[type];
|
|
|
|
strength = ApplyTechModificationsToEntity("Armour/" + type, strength, self.entity);
|
2012-05-05 00:51:14 +02:00
|
|
|
return strength;
|
2012-04-21 18:37:35 +02:00
|
|
|
};
|
2012-04-20 21:47:01 +02:00
|
|
|
|
2012-08-23 23:22:49 +02:00
|
|
|
if (Engine.QueryInterface(this.entity, IID_Foundation) && this.template.Foundation)
|
|
|
|
{
|
|
|
|
return {
|
|
|
|
hack: applyTechs("Hack", true),
|
|
|
|
pierce: applyTechs("Pierce", true),
|
|
|
|
crush: applyTechs("Crush", true)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return {
|
|
|
|
hack: applyTechs("Hack"),
|
|
|
|
pierce: applyTechs("Pierce"),
|
|
|
|
crush: applyTechs("Crush")
|
|
|
|
};
|
|
|
|
}
|
2010-02-28 22:45:09 +01:00
|
|
|
};
|
|
|
|
|
2010-02-05 23:00:39 +01:00
|
|
|
Engine.RegisterComponentType(IID_DamageReceiver, "Armour", Armour);
|