Created
May 13, 2025 20:06
-
-
Save efrec/ab397c30613437525cae995f8daf2cc5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Effect damage consists of scripted effects (which deal burst) and temporal effects (which change DPS). | |
-- This becomes a nebulous categorization when both effect types occur on the same weapon. Please do not. | |
-- The data presentation of effect damage is as extra/bonus damage, e.g. 120 + 40 with the "40" stylized. | |
local effectExplain | |
local effectBurst, effectRate = 0, 0 | |
if weaponDef.customParams.spark_basedamage then | |
effectExplain = i18n.explain_spark | |
local damage = weaponDef.customParams.spark_basedamage * weaponDef.customParams.spark_forkdamage | |
effectBurst = damage * weaponDef.customParams.spark_maxunits | |
elseif weaponDef.customParams.cluster then | |
effectExplain = i18n.explain_cluster | |
local munition = WeaponDefNames[weaponDef.customParams.cluster_def] | |
local damage = munition.damages[baseArmorTypeIndex] | |
local scatter = munition.range + munition.areaofeffect * (1 + munition.egdeEffectiveness) * 0.5 * 0.5 | |
effectBurst = damage * weaponDef.customParams.cluster_number | |
if areaOfEffect then | |
areaOfEffect = (areaOfEffect * baseDamage + scatter * effectBurst) / (baseDamage + effectBurst) | |
else | |
areaOfEffect = scatter | |
end | |
elseif weaponDef.customParams.area_onhit_damage then | |
effectExplain = i18n.explain_area_timed_damage | |
areaOfEffect = max(areaOfEffect or 0, weaponDef.customParams.area_onhit_range) | |
effectBurst = weaponDef.customParams.area_onhit_damage * weaponDef.customParams.area_onhit_time | |
elseif (weaponDefID == deathWeaponDefID or weaponDefID == selfDWeaponDefID) | |
and unitDef.customParams.area_ondeath_damage then | |
effectExplain = i18n.explain_area_timed_damage | |
areaOfEffect = max(areaOfEffect or 0, unitDef.customParams.area_ondeath_range) | |
effectBurst = unitDef.customParams.area_ondeath_damage * unitDef.customParams.area_ondeath_time | |
elseif baseDamage ~= 0 then | |
local temporalExplain, temporalRate | |
if burst and (burst - 1) * burstRate >= 0.5 and (burst - 1) * burstRate / reload >= 0.5 then | |
temporalExplain = i18n.explain_extended_burst | |
temporalRate = baseDamage / ((burst - 1) * burstRate) - baseDamage / reload | |
elseif stockpileTime and stockpileTime > reload and stockpileLimit > 1 then | |
temporalExplain = i18n.explain_extended_stockpile | |
temporalRate = baseDamage * (1 - reload / stockpileTime) | |
end | |
if temporalRate and temporalRate > 5 and temporalRate / baseDamage * reload >= 0.5 then | |
effectExplain = temporalExplain | |
effectRate = temporalRate | |
end | |
end | |
local damageBurst, damageRate = 0, 0 | |
local xpToDPS = true | |
if isExplodingUnit then | |
damageBurst = baseDamage | |
xpToDPS = false | |
else | |
if weaponDef.commandfire then | |
-- This is a third category of "effect" damage which complicates its description. | |
-- But it is more clear to present ability-like damage separate from base damage. | |
effectExplain = effectExplain or i18n.explain_commandfire | |
effectBurst, effectRate = effectBurst + baseDamage, effectRate + baseDamage / reload | |
else | |
damageBurst, damageRate = baseDamage, baseDamage / reload | |
end | |
if reload == stockpileTime then | |
xpToDPS = false | |
end | |
end | |
-- ... skipping ahead a bit ... | |
-- NB: Damage must be be entirely paralyzing or non-paralyzing per weapon. | |
-- Widgets are not the correct way to enforce anything/find errors though. | |
local empBurst, empRate = 0, 0 | |
local paralyzeDamageTime = positive(weaponDef.damages.paralyzeDamageTime) | |
if paralyzeDamageTime then | |
empBurst, empRate = damageBurst, damageRate | |
damageBurst, damageRate = 0, 0 | |
end | |
-- ... skipping ahead a bit ... | |
if addToTotals then | |
local countTotal = weapon.count * projectiles | |
damageBurstTotal = damageBurstTotal + damageBurst * countTotal | |
damageRateTotal = damageRateTotal + damageRate * countTotal | |
effectBurstTotal = effectBurstTotal + effectBurst * countTotal | |
effectRateTotal = effectRateTotal + effectRate * countTotal | |
empBurstTotal = empBurstTotal + empBurst * countTotal | |
empRateTotal = empRateTotal + empRate * countTotal | |
end | |
weaponSummary[#weaponSummary + 1] = weapon | |
-- ... skipping ahead a bit ... | |
-- to the unit summary after iterating all weapons: | |
if damageBurstTotal == 0 and empBurstTotal == 0 then | |
if effectBurstTotal == 0 then | |
damageBurstTotal, damageRateTotal = nil, nil | |
effectBurstTotal, effectRateTotal = nil, nil | |
empBurstTotal, empRateTotal = nil, nil | |
weaponSummary = nil | |
else | |
-- all weapon is "special" damage, so just display it normally: | |
for _, weapon in ipairs(weaponSummary) do | |
defaultDamage = effectBurst | |
baseDamage = effectBurst | |
weapon.damageBurst, weapon.damageRate = effectBurst, effectRate | |
weapon.effectBurst, weapon.effectRate = 0, 0 | |
end | |
damageBurstTotal, damageRateTotal = effectBurstTotal, effectRateTotal | |
effectBurstTotal, effectRateTotal = 0, 0 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment