Changeset View
Standalone View
binaries/data/mods/public/globalscripts/Templates.js
Show First 20 Lines • Show All 159 Lines • ▼ Show 20 Lines | let getEntityValue = function(value_path, mod_key) { | ||||
return GetModifiedTemplateDataValue(template, value_path, mod_key, player, modifiers); | return GetModifiedTemplateDataValue(template, value_path, mod_key, player, modifiers); | ||||
}; | }; | ||||
let ret = {}; | let ret = {}; | ||||
if (template.Armour) | if (template.Armour) | ||||
{ | { | ||||
ret.armour = {}; | ret.armour = {}; | ||||
for (let damageType of damageTypes.GetTypes()) | for (let damageType in template.Armour) | ||||
if (damageType != "Foundation") | |||||
Silier: you could switch this, go with for through AllDamageTypes and then ret.armour[damageType] =… | |||||
Done Inline ActionsThe ": 0" is not necessary, so I guess with the comment by @Stan below, this is not needed anymore? Freagarach: The ": 0" is not necessary, so I guess with the comment by @Stan below, this is not needed… | |||||
Done Inline ActionsMaybe you could write it as : for (let damageType in template.Armour) if (damageType != "Foundation") ret.armour[damageType] = getEntityValue("Armour/" + damageType); Stan: Maybe you could write it as :
```lang=js
for (let damageType in template.Armour)
if… | |||||
Done Inline ActionsI thought I had that already (was probably lost in one of many reverts ;) ). Freagarach: I thought I had that already (was probably lost in one of many reverts ;) ). | |||||
ret.armour[damageType] = getEntityValue("Armour/" + damageType); | ret.armour[damageType] = getEntityValue("Armour/" + damageType); | ||||
} | } | ||||
if (template.Attack) | if (template.Attack) | ||||
{ | { | ||||
ret.attack = {}; | ret.attack = {}; | ||||
for (let type in template.Attack) | for (let type in template.Attack) | ||||
{ | { | ||||
let getAttackStat = function(stat) { | let getAttackStat = function(stat) { | ||||
return getEntityValue("Attack/" + type + "/" + stat); | return getEntityValue("Attack/" + type + "/" + stat); | ||||
}; | }; | ||||
if (type == "Capture") | if (type == "Capture") | ||||
ret.attack.Capture = { | ret.attack.Capture = { | ||||
"value": getAttackStat("Value") | "value": getAttackStat("Value") | ||||
}; | }; | ||||
else | else | ||||
{ | { | ||||
ret.attack[type] = { | ret.attack[type] = { | ||||
"minRange": getAttackStat("MinRange"), | "minRange": getAttackStat("MinRange"), | ||||
"maxRange": getAttackStat("MaxRange"), | "maxRange": getAttackStat("MaxRange"), | ||||
"elevationBonus": getAttackStat("ElevationBonus"), | "elevationBonus": getAttackStat("ElevationBonus"), | ||||
"damage": {} | "damage": {} | ||||
}; | }; | ||||
for (let damageType of damageTypes.GetTypes()) | for (let damageType in template.Attack[type].Damage) | ||||
Done Inline ActionsWill not that retake the other values as MinRange, MaxRange, etc.. ? Polakrity: Will not that retake the other values as MinRange, MaxRange, etc.. ? | |||||
Done Inline ActionsIt does, thanks, I re-incorporated the check. Freagarach: It does, thanks, I re-incorporated the check. | |||||
ret.attack[type].damage[damageType] = getAttackStat("Damage/" + damageType); | ret.attack[type].damage[damageType] = getAttackStat("Damage/" + damageType); | ||||
Done Inline ActionsInstead use for (let damageType of template.Attack[type]) wraitii: Instead use `for (let damageType of template.Attack[type])` | |||||
Done Inline ActionsDoes writing if(!!AllDamageTypes[damageType]) work ? Instead of iterating through the whole collection ? Stan: Does writing if(!!AllDamageTypes[damageType]) work ? Instead of iterating through the whole… | |||||
ret.attack[type].elevationAdaptedRange = Math.sqrt(ret.attack[type].maxRange * | ret.attack[type].elevationAdaptedRange = Math.sqrt(ret.attack[type].maxRange * | ||||
(2 * ret.attack[type].elevationBonus + ret.attack[type].maxRange)); | (2 * ret.attack[type].elevationBonus + ret.attack[type].maxRange)); | ||||
} | } | ||||
ret.attack[type].repeatTime = getAttackStat("RepeatTime"); | ret.attack[type].repeatTime = getAttackStat("RepeatTime"); | ||||
if (template.Attack[type].Splash) | if (template.Attack[type].Splash) | ||||
{ | { | ||||
ret.attack[type].splash = { | ret.attack[type].splash = { | ||||
// true if undefined | // true if undefined | ||||
"friendlyFire": template.Attack[type].Splash.FriendlyFire != "false", | "friendlyFire": template.Attack[type].Splash.FriendlyFire != "false", | ||||
"shape": template.Attack[type].Splash.Shape, | "shape": template.Attack[type].Splash.Shape, | ||||
"damage": {} | "damage": {} | ||||
}; | }; | ||||
for (let damageType of damageTypes.GetTypes()) | for (let damageType in template.Attack[type].Splash.Damage) | ||||
ret.attack[type].splash.damage[damageType] = getAttackStat("Splash/Damage/" + damageType); | ret.attack[type].splash.damage[damageType] = getAttackStat("Splash/Damage/" + damageType); | ||||
} | } | ||||
Done Inline ActionsSame here in all the occurences below. Stan: Same here in all the occurences below. | |||||
} | } | ||||
} | } | ||||
if (template.DeathDamage) | if (template.DeathDamage) | ||||
{ | { | ||||
ret.deathDamage = { | ret.deathDamage = { | ||||
"friendlyFire": template.DeathDamage.FriendlyFire != "false", | "friendlyFire": template.DeathDamage.FriendlyFire != "false", | ||||
"damage": {} | "damage": {} | ||||
}; | }; | ||||
for (let damageType of damageTypes.GetTypes()) | for (let damageType in template.DeathDamage.Damage) | ||||
ret.deathDamage.damage[damageType] = getEntityValue("DeathDamage/Damage/" + damageType); | ret.deathDamage.damage[damageType] = getEntityValue("DeathDamage/Damage/" + damageType); | ||||
Done Inline ActionsWorked perfectly fine before. wraitii: Worked perfectly fine before. | |||||
} | } | ||||
Done Inline ActionsMight want to cache GetTypes() instead of calling it a lot of times. Also why do you need to check if the damagetype exists ? If it doesn't it will throw a warning and the modder will know something is up no ? Stan: Might want to cache GetTypes() instead of calling it a lot of times. Also why do you need to… | |||||
Done Inline ActionsYou're right, this is left over from my nigh endless fiddling to get this working. Freagarach: You're right, this is left over from my nigh endless fiddling to get this working. | |||||
Done Inline ActionsOops, you were not right, see comment above. Freagarach: Oops, you were not right, see comment above. | |||||
if (template.Auras && auraTemplates) | if (template.Auras && auraTemplates) | ||||
{ | { | ||||
ret.auras = {}; | ret.auras = {}; | ||||
for (let auraID of template.Auras._string.split(/\s+/)) | for (let auraID of template.Auras._string.split(/\s+/)) | ||||
{ | { | ||||
let aura = auraTemplates[auraID]; | let aura = auraTemplates[auraID]; | ||||
ret.auras[auraID] = { | ret.auras[auraID] = { | ||||
▲ Show 20 Lines • Show All 313 Lines • Show Last 20 Lines |
you could switch this, go with for through AllDamageTypes and then ret.armour[damageType] = template.Armour[damageType] ? getEntityValue("Armour/" + damageType) : 0;