Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/Armour.js
function Armour() {} | function Armour() {} | ||||
Armour.prototype.Schema = | Armour.prototype.Schema = | ||||
"<a:help>Controls the damage resistance of the unit.</a:help>" + | "<a:help>Controls the damage resistance of the unit.</a:help>" + | ||||
"<a:example>" + | "<a:example>" + | ||||
"<Hack>10.0</Hack>" + | "<Hack>10.0</Hack>" + | ||||
"<Pierce>0.0</Pierce>" + | "<Pierce>0.0</Pierce>" + | ||||
"<Crush>5.0</Crush>" + | "<Crush>5.0</Crush>" + | ||||
"</a:example>" + | "</a:example>" + | ||||
DamageTypes.BuildSchema("damage protection") + | BuildDamageTypesSchema("damage protection") + | ||||
"<optional>" + | "<optional>" + | ||||
"<element name='Foundation' a:help='Armour given to building foundations'>" + | "<element name='Foundation' a:help='Armour given to building foundations'>" + | ||||
"<interleave>" + | "<interleave>" + | ||||
DamageTypes.BuildSchema("damage protection") + | BuildDamageTypesSchema("damage protection") + | ||||
"</interleave>" + | "</interleave>" + | ||||
"</element>" + | "</element>" + | ||||
"</optional>"; | "</optional>"; | ||||
Armour.prototype.Init = function() | Armour.prototype.Init = function() | ||||
{ | { | ||||
this.invulnerable = false; | this.invulnerable = false; | ||||
}; | }; | ||||
Show All 16 Lines | |||||
* Returns object of the form { "killed": false, "change": -12 }. | * Returns object of the form { "killed": false, "change": -12 }. | ||||
*/ | */ | ||||
Armour.prototype.TakeDamage = function(strengths, multiplier = 1) | Armour.prototype.TakeDamage = function(strengths, multiplier = 1) | ||||
{ | { | ||||
if (this.invulnerable) | if (this.invulnerable) | ||||
return { "killed": false, "change": 0 }; | return { "killed": false, "change": 0 }; | ||||
// Adjust damage values based on armour; exponential armour: damage = attack * 0.9^armour | // Adjust damage values based on armour; exponential armour: damage = attack * 0.9^armour | ||||
var armourStrengths = this.GetArmourStrengths(); | let armourStrengths = this.GetArmourStrengths(); | ||||
// Total is sum of individual damages | // Total is sum of individual damages | ||||
// Don't bother rounding, since HP is no longer integral. | // Don't bother rounding, since HP is no longer integral. | ||||
var total = 0; | let total = 0; | ||||
for (let type in strengths) | for (let type in strengths) | ||||
total += strengths[type] * multiplier * Math.pow(0.9, armourStrengths[type] || 0); | total += strengths[type] * multiplier * Math.pow(0.9, armourStrengths[type] || 0); | ||||
// Reduce health | // Reduce health | ||||
var cmpHealth = Engine.QueryInterface(this.entity, IID_Health); | let cmpHealth = Engine.QueryInterface(this.entity, IID_Health); | ||||
Stan: Shouldn't we check for cmpHealth ? | |||||
return cmpHealth.Reduce(total); | return cmpHealth.Reduce(total); | ||||
}; | }; | ||||
Armour.prototype.GetArmourStrengths = function() | Armour.prototype.GetArmourStrengths = function() | ||||
{ | { | ||||
Done Inline Actionsthe above should be moved to a separate diff wraitii: the above should be moved to a separate diff | |||||
Done Inline ActionsFreagarach: D2028. | |||||
// Work out the armour values with technology effects | // Work out the armour values with technology effects | ||||
var applyMods = (type, foundation) => { | let applyMods = (type, foundation) => { | ||||
var strength; | let strength; | ||||
if (foundation) | if (foundation) | ||||
{ | { | ||||
strength = +this.template.Foundation[type]; | strength = +this.template.Foundation[type]; | ||||
type = "Foundation/" + type; | type = "Foundation/" + type; | ||||
Done Inline ActionsWhy all the weird stuff with foundation, couldn't they add that in techs directly ? Stan: Why all the weird stuff with foundation, couldn't they add that in techs directly ? | |||||
Done Inline Actionsfoundations have separate armour damage. So we handle it specially here too. I have an idea on how to fix that cleanly but it'll need c++ code. wraitii: foundations have separate armour damage. So we handle it specially here too.
I have an idea on… | |||||
} | } | ||||
else | else | ||||
strength = +this.template[type]; | strength = +this.template[type]; | ||||
return ApplyValueModificationsToEntity("Armour/" + type, strength, this.entity); | return ApplyValueModificationsToEntity("Armour/" + type, strength, this.entity); | ||||
}; | }; | ||||
var foundation = Engine.QueryInterface(this.entity, IID_Foundation) && this.template.Foundation; | let foundation = Engine.QueryInterface(this.entity, IID_Foundation) && this.template.Foundation; | ||||
let ret = {}; | let ret = {}; | ||||
for (let damageType of DamageTypes.GetTypes()) | for (let damageType in this.template) | ||||
{ | |||||
if (damageType == "Foundation") | |||||
Done Inline ActionsSame here, invert condition, remove continue, remove braces :) Stan: Same here, invert condition, remove continue, remove braces :) | |||||
continue; | |||||
ret[damageType] = applyMods(damageType, foundation); | ret[damageType] = applyMods(damageType, foundation); | ||||
} | |||||
Done Inline Actionscan you apply the same as in Templates.js line 230? for another cases as well if it works ? Silier: can you apply the same as in Templates.js line 230? for another cases as well if it works ? | |||||
Done Inline ActionsWorked perfectly fine before. wraitii: Worked perfectly fine before. | |||||
return ret; | return ret; | ||||
}; | }; | ||||
Engine.RegisterComponentType(IID_DamageReceiver, "Armour", Armour); | Engine.RegisterComponentType(IID_DamageReceiver, "Armour", Armour); |
Wildfire Games · Phabricator
Shouldn't we check for cmpHealth ?