Module:AbilityTable/ComplexRenderers: Difference between revisionsGive feedback
strip trailing periods from auto-generated notes, period is now handled by main module ensure_period (with help from vergir-bot LLM) |
add base damage column to melee list |
||
| Line 225: | Line 225: | ||
end | end | ||
-- Renders | -- Renders base damage and melee scaling. | ||
-- Special case for upgrades that | -- Special case for upgrades that switch from Light to Heavy Melee scaling. | ||
function p.RenderMelee(ability) | function p.RenderMelee(ability) | ||
local melee_types = {} | |||
for _, t in ipairs(Lists.lists["melee"]) do melee_types[t] = true end | |||
-- Find the base property with active melee/heavy_melee scaling (Scale.Value > 0) | |||
local base_prop, base_damage, base_scale, base_type | |||
for k, v in pairs(ability) do | |||
if k ~= "Upgrades" and type(v) == "table" then | |||
local scale = v["Scale"] | |||
if type(scale) == "table" and melee_types[scale["Type"]] | |||
and type(scale["Value"]) == "number" and scale["Value"] > 0 then | |||
base_prop = k | |||
base_damage = v["Value"] or 0 | |||
base_scale = scale["Value"] | |||
base_type = scale["Type"] | |||
break | |||
end | |||
end | |||
end | |||
local cells = {} | local cells = {} | ||
cells["Base Damage"] = tostring(base_damage or 0) | |||
if base_scale then cells["Light Melee Scaling"] = "×" .. base_scale end | if base_scale then | ||
cells["Light Melee Scaling"] = "×" .. base_scale | |||
end | |||
local upgrades = ability["Upgrades"] | local upgrades = ability["Upgrades"] | ||
if type(upgrades) ~= "table" then return cells end | if type(upgrades) ~= "table" then return cells end | ||
local notes = {} | local notes = {} | ||
local running_damage = base_damage or 0 | |||
local running_scale = base_scale or 0 | |||
local running_type = base_type | |||
for i, tier in ipairs(upgrades) do | for i, tier in ipairs(upgrades) do | ||
if type(tier) == "table" then | if type(tier) == "table" then | ||
for | local damage_delta = 0 | ||
local new_scale = nil | |||
local new_type = nil | |||
for k, v in pairs(tier) do | |||
if type(v) == "table" then | if type(v) == "table" then | ||
local scale = v["Scale"] | local scale = v["Scale"] | ||
if type(scale) == "table" and | if type(scale) == "table" and melee_types[scale["Type"]] then | ||
damage_delta = damage_delta + (v["Value"] or 0) | |||
if scale["Value"] > 0 then | |||
new_scale = scale["Value"] | |||
new_type = scale["Type"] | |||
end | end | ||
end | end | ||
end | end | ||
end | |||
local flat_delta = 0 | |||
if base_prop and type(tier[base_prop]) == "number" then | |||
flat_delta = tier[base_prop] | |||
end | |||
local tier_parts = {} | |||
if new_type and new_type ~= running_type then | |||
running_damage = running_damage + damage_delta | |||
running_scale = new_scale | |||
running_type = new_type | |||
local type_label = new_type == "heavy_melee" and "'''Heavy Melee'''" or "Light Melee" | |||
local parts = {} | |||
if running_damage > 0 then | |||
table.insert(parts, running_damage .. " base damage") | |||
end | |||
table.insert(parts, "×" .. new_scale .. " " .. type_label .. " scaling") | |||
table.insert(tier_parts, "on T" .. i .. " becomes " .. table.concat(parts, " with ")) | |||
elseif new_scale then | |||
running_damage = running_damage + damage_delta | |||
running_scale = running_scale + new_scale | |||
local parts = {} | |||
if damage_delta ~= 0 then | |||
table.insert(parts, "+" .. damage_delta .. " base damage") | |||
end | |||
table.insert(parts, "+×" .. new_scale .. " scaling (total ×" .. running_scale .. ")") | |||
table.insert(tier_parts, "on T" .. i .. " gets " .. table.concat(parts, ", ")) | |||
end | |||
if flat_delta ~= 0 and not new_scale then | |||
running_damage = running_damage + flat_delta | |||
table.insert(tier_parts, "on T" .. i .. " gets +" .. flat_delta .. " base damage (total " .. running_damage .. ")") | |||
end | |||
if #tier_parts > 0 then | |||
table.insert(notes, table.concat(tier_parts, ", ")) | |||
end | end | ||
end | end | ||
end | end | ||
if #notes > 0 then cells["Notes"] = table.concat(notes, " ") end | |||
if #notes > 0 then cells["Notes"] = table.concat(notes, ". ") end | |||
return cells | return cells | ||
end | end | ||