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() {} | function Resistance() {} | |||||||||
bb: I have noticed some sim components have been implemented in class syntax, however I have my… | ||||||||||
Armour.prototype.DamageResistanceSchema = "" + | /** | |||||||||
* Builds a RelaxRNG schema of possible attack effects. | ||||||||||
* Currently harcoded to "Damage", "Capture" and "StatusEffects". | ||||||||||
* | ||||||||||
* @return {string} - RelaxNG schema string | ||||||||||
Done Inline ActionsWhy the tab? bb: Why the tab? | ||||||||||
*/ | ||||||||||
Resistance.prototype.BuildResistanceSchema = function() | ||||||||||
{ | ||||||||||
return "" + | ||||||||||
"<oneOrMore>" + | ||||||||||
"<choice>" + | ||||||||||
"<element name='Damage'>" + | ||||||||||
"<oneOrMore>" + | "<oneOrMore>" + | |||||||||
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… | ||||||||||
"<element a:help='Resistance against any number of damage types'>" + | "<element a:help='Resistance against any number of damage types.'>" + | |||||||||
"<anyName>" + | "<anyName/>" + | |||||||||
"<except><name>Foundation</name></except>" + | "<ref name='nonNegativeDecimal' />" + | |||||||||
"</anyName>" + | "</element>" + | |||||||||
"</oneOrMore>" + | ||||||||||
"</element>" + | ||||||||||
"<element name='Capture' a:help='Resistance against Capture attacks.'>" + | ||||||||||
Done Inline Actionsperiod bb: period | ||||||||||
"<ref name='nonNegativeDecimal' />" + | "<ref name='nonNegativeDecimal'/>" + | |||||||||
"</element>" + | "</element>" + | |||||||||
"<element name='StatusEffects' a:help='Resistance against effects like poisoning or burning.'>" + | ||||||||||
"<oneOrMore>" + | ||||||||||
"<element>" + | ||||||||||
"<anyName/>" + | ||||||||||
"<interleave>" + | ||||||||||
"<element name='Duration' a:help='The duration of the status while the effect occurs.'><ref name='nonNegativeDecimal'/></element>" + | ||||||||||
"<element name='Interval' a:help='Interval between the occurances of the effect.'><ref name='nonNegativeDecimal'/></element>" + | ||||||||||
"<element name='Damage' a:help='Damage caused by the effect.'><ref name='nonNegativeDecimal'/></element>" + | ||||||||||
"</interleave>" + | ||||||||||
"</element>" + | ||||||||||
"</oneOrMore>" + | ||||||||||
"</element>" + | ||||||||||
"</choice>" + | ||||||||||
"</oneOrMore>"; | "</oneOrMore>"; | |||||||||
}; | ||||||||||
Armour.prototype.Schema = | Resistance.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>" + | |||||||||
"<Foundation>" + | ||||||||||
"<Damage>" + | ||||||||||
"<Hack>10.0</Hack>" + | "<Hack>10.0</Hack>" + | |||||||||
"<Pierce>0.0</Pierce>" + | "<Pierce>0.0</Pierce>" + | |||||||||
"<Crush>5.0</Crush>" + | "<Crush>5.0</Crush>" + | |||||||||
"</Damage>" + | ||||||||||
"<Capture>10</Capture>" + | ||||||||||
"</Foundation>" + | ||||||||||
"<MagicShield>" + | ||||||||||
"<StatusEffects>" + | ||||||||||
"<Poison>" + | ||||||||||
"<Duration>10</Duration>" + | ||||||||||
"<Interval>0</Interval>" + | ||||||||||
"<Damage>5.0</Damage>" + | ||||||||||
"</Poison>" + | ||||||||||
"</StatusEffects>" + | ||||||||||
"</MagicShield>" + | ||||||||||
"</a:example>" + | "</a:example>" + | |||||||||
Armour.prototype.DamageResistanceSchema + | "<oneOrMore>" + | |||||||||
"<optional>" + | "<element a:help='Resistance with name (e.g. shield, armour, foundation etc.).'>" + | |||||||||
"<element name='Foundation' a:help='Armour given to building foundations'>" + | "<anyName/>" + | |||||||||
Armour.prototype.DamageResistanceSchema + | Resistance.prototype.BuildResistanceSchema() + | |||||||||
Done Inline ActionsSplit from attacking, make own schema here. Freagarach: Split from attacking, make own schema here. | ||||||||||
"</element>" + | "</element>" + | |||||||||
"</optional>"; | "</oneOrMore>"; | |||||||||
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… | ||||||||||
Armour.prototype.Init = function() | Resistance.prototype.Init = function() | |||||||||
{ | { | |||||||||
this.invulnerable = false; | this.invulnerable = false; | |||||||||
}; | }; | |||||||||
Armour.prototype.IsInvulnerable = function() | Resistance.prototype.IsInvulnerable = function() | |||||||||
Done Inline Actions!#R@$@@!$@$%@ but that is probably just my opinion bb: !#R@$@@!$@$%@ but that is probably just my opinion | ||||||||||
{ | { | |||||||||
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… | ||||||||||
return this.invulnerable; | return this.invulnerable; | |||||||||
}; | }; | |||||||||
Armour.prototype.SetInvulnerability = function(invulnerability) | Resistance.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 }); | |||||||||
}; | }; | |||||||||
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… | ||||||||||
Armour.prototype.GetArmourStrengths = function(effectType) | /** | |||||||||
{ | * Calculate the resistance of an entity. | |||||||||
// Work out the armour values with technology effects. | * @param {string} effectType - The type of attack effect the resistance has to be calculated for (e.g. "Damage", "Capture"). | |||||||||
let applyMods = (type, foundation) => { | * @param {string} circumvent - An optional array consisting of the resistance types not to use in calculation (e.g. "Shield"). | |||||||||
let strength; | * @return {object} - An object of the type { "Damage": { "Crush": 10, "Hack": 2 }, "Capture": 2 } | |||||||||
Done Inline ActionsChange. Freagarach: Change. | ||||||||||
Done Inline Actions
bb: | ||||||||||
if (foundation) | */ | |||||||||
Resistance.prototype.GetResistanceStrengths = function(effectType, circumvent = []) | ||||||||||
{ | { | |||||||||
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… | ||||||||||
strength = +this.template.Foundation[type]; | // Work out the resistance values with technology effects. | |||||||||
type = "Foundation/" + type; | let applyMods = (resistanceType, damageType) => { | |||||||||
} | let strength = +this.template[resistanceType][effectType][damageType]; | |||||||||
else | ||||||||||
strength = +this.template[type]; | ||||||||||
return ApplyValueModificationsToEntity("Armour/" + type, strength, this.entity); | return ApplyValueModificationsToEntity("Resistance/" + resistanceType + "/" + effectType + "/" + damageType, 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 = {}; | let ret = {}; | |||||||||
if (effectType != "Damage") | // ToDo: Support resistance against status effects. | |||||||||
if (effectType == "StatusEffects") | ||||||||||
return ret; | return ret; | |||||||||
for (let damageType in this.template) | for (let resistanceType in this.template) | |||||||||
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 | ||||||||||
Done Inline Actions
(yes, we should teach this to the linter) bb: (yes, we should teach this to the linter) | ||||||||||
ret[damageType] = applyMods(damageType, foundation); | if (circumvent.length && circumvent.indexOf(resistanceType) != -1) | |||||||||
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. | ||||||||||
continue; | ||||||||||
if (!foundation && resistanceType == "Foundation") | ||||||||||
continue; | ||||||||||
if (foundation && resistanceType != "Foundation") | ||||||||||
continue; | ||||||||||
let template = this.template[resistanceType][effectType]; | ||||||||||
if (template) | ||||||||||
Done Inline Actionsif !template continue ? Stan: if !template continue ? | ||||||||||
{ | ||||||||||
if (effectType == "Capture") | ||||||||||
{ | ||||||||||
if (!ret.Capture) | ||||||||||
ret.Capture = 0; | ||||||||||
ret.Capture += ApplyValueModificationsToEntity("Resistance/" + resistanceType + "/Capture", +this.template[resistanceType].Capture, this.entity); | ||||||||||
} | ||||||||||
else if (effectType == "Damage") | ||||||||||
{ | ||||||||||
if (!ret.Damage) | ||||||||||
ret.Damage = {}; | ||||||||||
for (let damageType in template) | ||||||||||
{ | ||||||||||
if (!ret.Damage[damageType]) | ||||||||||
ret.Damage[damageType] = 0; | ||||||||||
ret.Damage[damageType] += applyMods(resistanceType, damageType); | ||||||||||
} | ||||||||||
} | ||||||||||
} | ||||||||||
} | ||||||||||
return ret; | return ret; | |||||||||
}; | }; | |||||||||
Engine.RegisterComponentType(IID_Resistance, "Armour", Armour); | Engine.RegisterComponentType(IID_Resistance, "Resistance", Resistance); | |||||||||
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 | ||||||||||
Done Inline Actionstab? bb: tab? | ||||||||||
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… | ||||||||||
Done Inline Actionsspace? bb: space? | ||||||||||
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 | ||||||||||
Done Inline Actionsperiod bb: period | ||||||||||
Done Inline Actionsdependency Stan: dependency | ||||||||||
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.