Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/Armour.js
Show All 21 Lines | "<optional>" + | ||||
"<element name='Foundation' a:help='Armour given to building foundations'>" + | "<element name='Foundation' a:help='Armour given to building foundations'>" + | ||||
Armour.prototype.DamageResistanceSchema + | Armour.prototype.DamageResistanceSchema + | ||||
"</element>" + | "</element>" + | ||||
"</optional>"; | "</optional>"; | ||||
Armour.prototype.Init = function() | Armour.prototype.Init = function() | ||||
{ | { | ||||
this.invulnerable = false; | this.invulnerable = false; | ||||
this.UpdateProperties(); | |||||
}; | }; | ||||
Armour.prototype.IsInvulnerable = function() | Armour.prototype.IsInvulnerable = function() | ||||
{ | { | ||||
return this.invulnerable; | return this.invulnerable; | ||||
}; | }; | ||||
Armour.prototype.SetInvulnerability = function(invulnerability) | Armour.prototype.SetInvulnerability = function(invulnerability) | ||||
{ | { | ||||
this.invulnerable = invulnerability; | this.invulnerable = invulnerability; | ||||
Engine.PostMessage(this.entity, MT_InvulnerabilityChanged, { "entity": this.entity, "invulnerability": invulnerability }); | Engine.PostMessage(this.entity, MT_InvulnerabilityChanged, { "entity": this.entity, "invulnerability": invulnerability }); | ||||
}; | }; | ||||
Armour.prototype.GetArmourStrengths = function(effectType) | /** | ||||
* Cache properties that are expensive to compute and are used often. | |||||
*/ | |||||
Armour.prototype.UpdateProperties = function() | |||||
{ | { | ||||
// Work out the armour values with technology effects. | // Work out the armour values with technology effects. | ||||
let applyMods = (type, foundation) => { | let applyMods = (type, foundation) => { | ||||
let strength; | let strength; | ||||
if (foundation) | if (foundation) | ||||
{ | { | ||||
strength = +this.template.Foundation[type]; | strength = +this.template.Foundation[type]; | ||||
type = "Foundation/" + type; | type = "Foundation/" + type; | ||||
} | } | ||||
else | else | ||||
strength = +this.template[type]; | strength = +this.template[type]; | ||||
return ApplyValueModificationsToEntity("Armour/" + type, strength, this.entity); | return ApplyValueModificationsToEntity("Armour/" + type, strength, this.entity); | ||||
}; | }; | ||||
let foundation = Engine.QueryInterface(this.entity, IID_Foundation) && this.template.Foundation; | let foundation = Engine.QueryInterface(this.entity, IID_Foundation) && this.template.Foundation; | ||||
let ret = {}; | this.armourStrengths = {}; | ||||
if (effectType != "Damage") | |||||
return ret; | |||||
for (let damageType in this.template) | for (let damageType in this.template) | ||||
if (damageType != "Foundation") | if (damageType != "Foundation") | ||||
ret[damageType] = applyMods(damageType, foundation); | this.armourStrengths[damageType] = applyMods(damageType, foundation); | ||||
}; | |||||
Armour.prototype.GetArmourStrengths = function(effectType) | |||||
{ | |||||
if (effectType != "Damage") | |||||
return {}; | |||||
return this.armourStrengths; | |||||
}; | |||||
Armour.prototype.OnValueModification = function(msg) | |||||
{ | |||||
if (msg.component == "Armour") | |||||
this.UpdateProperties(); | |||||
}; | |||||
Armour.prototype.OnOwnershipChanged = function(msg) | |||||
{ | |||||
if (msg.to == INVALID_PLAYER) | |||||
return; | |||||
this.UpdateProperties(); | |||||
}; | |||||
return ret; | Armour.prototype.OnGlobalInitGame = function(msg) | ||||
{ | |||||
this.UpdateProperties(); | |||||
}; | |||||
Armour.prototype.OnMultiplierChanged = function(msg) | |||||
{ | |||||
if (msg.player == QueryOwnerInterface(this.entity, IID_Player).GetPlayerID()) | |||||
this.UpdateProperties(); | |||||
}; | }; | ||||
Engine.RegisterComponentType(IID_Resistance, "Armour", Armour); | Engine.RegisterComponentType(IID_Resistance, "Armour", Armour); |
Wildfire Games · Phabricator