Changeset View
Standalone View
binaries/data/mods/public/simulation/components/Resistance.js
- This file was moved from binaries/data/mods/public/simulation/components/Armour.js.
function Armour() {} | class Resistance | |||||||||
bb: I have noticed some sim components have been implemented in class syntax, however I have my… | ||||||||||
{ | ||||||||||
Armour.prototype.DamageResistanceSchema = "" + | Init() | |||||||||
"<oneOrMore>" + | ||||||||||
"<element a:help='Resistance against any number of damage types'>" + | ||||||||||
"<anyName>" + | ||||||||||
"<except><name>Foundation</name></except>" + | ||||||||||
"</anyName>" + | ||||||||||
"<ref name='nonNegativeDecimal' />" + | ||||||||||
"</element>" + | ||||||||||
"</oneOrMore>"; | ||||||||||
Armour.prototype.Schema = | ||||||||||
"<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>" + | ||||||||||
Armour.prototype.DamageResistanceSchema + | ||||||||||
"<optional>" + | ||||||||||
"<element name='Foundation' a:help='Armour given to building foundations'>" + | ||||||||||
Armour.prototype.DamageResistanceSchema + | ||||||||||
"</element>" + | ||||||||||
"</optional>"; | ||||||||||
Armour.prototype.Init = function() | ||||||||||
{ | { | |||||||||
this.invulnerable = false; | this.invulnerable = false; | |||||||||
}; | } | |||||||||
Armour.prototype.IsInvulnerable = function() | IsInvulnerable() | |||||||||
{ | { | |||||||||
return this.invulnerable; | return this.invulnerable; | |||||||||
}; | } | |||||||||
Armour.prototype.SetInvulnerability = function(invulnerability) | SetInvulnerability(invulnerability) | |||||||||
{ | { | |||||||||
this.invulnerable = invulnerability; | this.invulnerable = invulnerability; | |||||||||
StanUnsubmitted Done Inline ActionsShould not happen often, but one might not want to send a message if it didn't change? As done because it's likely out of scope. Stan: Should not happen often, but one might not want to send a message if it didn't change? As done… | ||||||||||
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) | /** | |||||||||
* Calculate the effective resistance of an entity to a particular effect. | ||||||||||
* @param {string} effectType - The type of attack effect the resistance has to be calculated for (e.g. "Damage", "Capture"). | ||||||||||
* @return {object} - An object of the type { "Damage": { "Crush": 10, "Hack": 2 }, "Capture": 2 } | ||||||||||
bbUnsubmitted Done Inline Actionsperiod bb: period | ||||||||||
*/ | ||||||||||
GetEffectiveResistanceAgainst(effectType) | ||||||||||
{ | { | |||||||||
// Work out the armour values with technology effects. | let ret = {}; | |||||||||
let applyMods = (type, foundation) => { | ||||||||||
let strength; | ||||||||||
if (foundation) | ||||||||||
{ | ||||||||||
strength = +this.template.Foundation[type]; | ||||||||||
type = "Foundation/" + type; | ||||||||||
} | ||||||||||
else | ||||||||||
strength = +this.template[type]; | ||||||||||
return ApplyValueModificationsToEntity("Armour/" + type, strength, this.entity); | // ToDo: Support resistance against status effects. | |||||||||
}; | if (effectType == "StatusEffects") | |||||||||
return ret; | ||||||||||
let foundation = Engine.QueryInterface(this.entity, IID_Foundation) && this.template.Foundation; | let foundation = Engine.QueryInterface(this.entity, IID_Foundation) && this.template.Foundation; | |||||||||
for (let resistanceType in this.template) | ||||||||||
{ | ||||||||||
if (foundation ? resistanceType != "Foundation" : resistanceType == "Foundation") | ||||||||||
Done Inline ActionsWhy the tab? bb: Why the tab? | ||||||||||
continue; | ||||||||||
let template = this.template[resistanceType][effectType]; | ||||||||||
if (!template) | ||||||||||
continue; | ||||||||||
Done Inline ActionsSplit from attacking, make own schema here. Freagarach: Split from attacking, make own schema here. | ||||||||||
if (effectType == "Capture") | ||||||||||
{ | ||||||||||
if (!ret.Capture) | ||||||||||
ret.Capture = 0; | ||||||||||
ret.Capture += ApplyValueModificationsToEntity("Resistance/" + resistanceType + "/Capture", +this.template[resistanceType].Capture, this.entity); | ||||||||||
bbUnsubmitted Done Inline ActionsUnderstand why, you do it like this. But why do we need the loop here? Seems like we can access the correct form immediately bb: Understand why, you do it like this. But why do we need the loop here? Seems like we can access… | ||||||||||
} | ||||||||||
else if (effectType == "Damage") | ||||||||||
for (let damageType in template) | ||||||||||
{ | ||||||||||
if (!ret[damageType]) | ||||||||||
ret[damageType] = 0; | ||||||||||
ret[damageType] += ApplyValueModificationsToEntity("Resistance/" + resistanceType + "/" + effectType + "/" + damageType, +(this.template[resistanceType][effectType][damageType] || 0), this.entity); | ||||||||||
} | ||||||||||
} | ||||||||||
return ret; | ||||||||||
} | ||||||||||
/** | ||||||||||
* Get all separate resistances for showing in the GUI. | ||||||||||
* @return {Object} - All resistances ordered by type. | ||||||||||
*/ | ||||||||||
Done Inline ActionsSince strength can be inlined, applyMods is a oneliner which is used only once => double inline bb: Since `strength` can be inlined, `applyMods` is a oneliner which is used only once => double… | ||||||||||
GetFullResistance() | ||||||||||
Done Inline ActionsI really fail to see the purpose of having several resistanceTypes, yes we should have foundation and 1 other, but more doesn't make sense right? We seem to simply add up all the values, so this doesn't give any new functionality in the template. (K you gain a very small amount of flexibility with techs and auras, but I don't think we need that) bb: I really fail to see the purpose of having several resistanceTypes, yes we should have… | ||||||||||
{ | ||||||||||
let ret = {}; | let ret = {}; | |||||||||
for (let resistanceType in this.template) | ||||||||||
ret[resistanceType] = this.GetResistanceOfType(resistanceType); | ||||||||||
if (effectType != "Damage") | return ret; | |||||||||
Done Inline Actions!#R@$@@!$@$%@ but that is probably just my opinion bb: !#R@$@@!$@$%@ but that is probably just my opinion | ||||||||||
} | ||||||||||
/** | ||||||||||
* Get the resistance of a particular type, i.e. Foundation or Entity. | ||||||||||
* @param {String} resistanceType - The type to query. | ||||||||||
* @return {Object} - An object containing the resistances. | ||||||||||
*/ | ||||||||||
Not Done Inline ActionsI suppose these need to generalized somewhat too bb: I suppose these need to generalized somewhat too | ||||||||||
Not Done Inline ActionsEach receiving cmp could have their own implementation and one generalised one here? Freagarach: Each receiving cmp could have their own implementation and one generalised one here? | ||||||||||
Not Done Inline ActionsEach attackType should get their own here. A general one doesn't seem useful than anymore (since one can set all individually) bb: Each attackType should get their own here. A general one doesn't seem useful than anymore… | ||||||||||
GetResistanceOfType(resistanceType) | ||||||||||
{ | ||||||||||
let ret = {} | ||||||||||
let template = this.template[resistanceType]; | ||||||||||
if (!template) | ||||||||||
return ret; | return ret; | |||||||||
for (let damageType in this.template) | if (template.Damage) | |||||||||
if (damageType != "Foundation") | { | |||||||||
Done Inline ActionsI guess we should remove any reference that damagetypes may not be foundations bb: I guess we should remove any reference that damagetypes may not be foundations | ||||||||||
ret[damageType] = applyMods(damageType, foundation); | ret.Damage = {}; | |||||||||
for (let damageType in template.Damage) | ||||||||||
Done Inline ActionsChange. Freagarach: Change. | ||||||||||
Done Inline Actions
bb: | ||||||||||
ret.Damage[damageType] = ApplyValueModificationsToEntity("Resistance/" + resistanceType + "/Damage/" + damageType, +this.template[resistanceType].Damage[damageType], this.entity); | ||||||||||
} | ||||||||||
if (template.Capture) | ||||||||||
ret.Capture = ApplyValueModificationsToEntity("Resistance/" + resistanceType + "/Capture", +this.template[resistanceType].Capture, this.entity); | ||||||||||
return ret; | return ret; | |||||||||
} | ||||||||||
} | ||||||||||
/** | ||||||||||
Done Inline Actions
(yes, we should teach this to the linter) bb: (yes, we should teach this to the linter) | ||||||||||
* Builds a RelaxRNG schema of possible attack effects. | ||||||||||
Done Inline ActionsI always wonder if merging early continues is faster ? Stan: I always wonder if merging early continues is faster ? | ||||||||||
Done Inline ActionsLess readable. Freagarach: Less readable. | ||||||||||
* ToDo: Resistance to StatusEffects. | ||||||||||
* | ||||||||||
* @return {string} - RelaxNG schema string | ||||||||||
bbUnsubmitted Done Inline Actionsperiod bb: period | ||||||||||
*/ | ||||||||||
Done Inline Actionstab? bb: tab? | ||||||||||
Resistance.prototype.BuildResistanceSchema = function() | ||||||||||
{ | ||||||||||
return "" + | ||||||||||
Done Inline Actionsif !template continue ? Stan: if !template continue ? | ||||||||||
"<oneOrMore>" + | ||||||||||
"<choice>" + | ||||||||||
"<element name='Damage'>" + | ||||||||||
"<oneOrMore>" + | ||||||||||
"<element a:help='Resistance against any number of damage types affecting health.'>" + | ||||||||||
Done Inline ActionsoneOrMore is correct over zeroOrMore since not having a damage note is preferred over zeroOrMore bb: oneOrMore is correct over zeroOrMore since not having a damage note is preferred over zeroOrMore | ||||||||||
"<anyName/>" + | ||||||||||
"<ref name='nonNegativeDecimal'/>" + | ||||||||||
"</element>" + | ||||||||||
Done Inline Actionsspace? bb: space? | ||||||||||
"</oneOrMore>" + | ||||||||||
"</element>" + | ||||||||||
"<element name='Capture' a:help='Resistance against Capture attacks.'>" + | ||||||||||
"<ref name='nonNegativeDecimal'/>" + | ||||||||||
"</element>" + | ||||||||||
"</choice>" + | ||||||||||
"</oneOrMore>"; | ||||||||||
}; | }; | |||||||||
Engine.RegisterComponentType(IID_Resistance, "Armour", Armour); | Resistance.prototype.Schema = | |||||||||
"<a:help>Controls the damage resistance of the unit.</a:help>" + | ||||||||||
"<a:example>" + | ||||||||||
"<Foundation>" + | ||||||||||
"<Damage>" + | ||||||||||
"<Hack>10.0</Hack>" + | ||||||||||
"<Pierce>0.0</Pierce>" + | ||||||||||
"<Crush>5.0</Crush>" + | ||||||||||
"</Damage>" + | ||||||||||
"<Capture>10</Capture>" + | ||||||||||
"</Foundation>" + | ||||||||||
Done Inline ActionsA foundation should have the same armour schema available (except that it can have a foundation). This is violated in the current proposed schema bb: A foundation should have the same armour schema available (except that it can have a… | ||||||||||
"<Entity>" + | ||||||||||
"<StatusEffects>" + | ||||||||||
Done Inline Actionsdependency Stan: dependency | ||||||||||
"<Poison>" + | ||||||||||
"<Duration>0.5</Duration>" + | ||||||||||
"<BlockChance>0.75</BlockChance>" + | ||||||||||
"</Poison>" + | ||||||||||
"</StatusEffects>" + | ||||||||||
bbUnsubmitted Done Inline ActionsNot implemented yet, so shouldn't be in the help yet bb: Not implemented yet, so shouldn't be in the help yet | ||||||||||
"</Entity>" + | ||||||||||
"</a:example>" + | ||||||||||
"<zeroOrMore>" + | ||||||||||
"<choice>" + | ||||||||||
"<element name='Foundation' a:help='Resistance of an unfinished structure (i.e. a foundation).'>" + | ||||||||||
Resistance.prototype.BuildResistanceSchema() + | ||||||||||
"</element>" + | ||||||||||
"<element name='Entity' a:help='Resistance of an entity.'>" + | ||||||||||
Resistance.prototype.BuildResistanceSchema() + | ||||||||||
"</element>" + | ||||||||||
"</choice>" + | ||||||||||
"</zeroOrMore>"; | ||||||||||
Engine.RegisterComponentType(IID_Resistance, "Resistance", Resistance); | ||||||||||
Done Inline ActionsSince this is just a health-thing, it can perhaps be moved thereto? Freagarach: Since this is just a health-thing, it can perhaps be moved thereto? | ||||||||||
Done Inline ActionsDidn't it use to be there? I think it's better in Health yeah. wraitii: Didn't it use to be there? I think it's better in Health yeah. | ||||||||||
Done Inline ActionsFreagarach: D2941. |
I have noticed some sim components have been implemented in class syntax, however I have my doubts about it. I certainly won't start rewriting stuff into class syntax.