Module:StreetBrawlAbilities: Difference between revisionsGive feedback
Jump to navigation
Jump to search
Fix hero lookup: ability slot keys decode as numbers, not strings (with help from vergir-bot LLM) |
Add change() to describe a Street Brawl property change as reduced/increased by a percentage (with help from vergir-bot LLM) |
||
| Line 64: | Line 64: | ||
end | end | ||
end | end | ||
end | |||
-- Reads a property both ways, returning its Street Brawl value and its normal one. | |||
local function both_values(frame, ability, prop) | |||
local sb = frame:expandTemplate{ title = "DataProp", args = { ability, prop, "streetbrawl" } } | |||
local base = frame:expandTemplate{ title = "DataProp", args = { ability, prop } } | |||
return tonumber(sb), tonumber(base) | |||
end | end | ||
| Line 74: | Line 81: | ||
return "* <code>" .. mw.text.nowiki(call) .. "</code> → '''" .. sb | return "* <code>" .. mw.text.nowiki(call) .. "</code> → '''" .. sb | ||
.. "''' ''(default " .. base .. ")''" | .. "''' ''(default " .. base .. ")''" | ||
end | |||
-- {{#invoke:StreetBrawlAbilities|change|ABILITY|PROP}} describes how far a property moved | |||
-- in Street Brawl, as "reduced by 45%" or "increased by 44%". | |||
function p.change(frame) | |||
local ability = mw.text.trim(frame.args[1] or "") | |||
local prop = mw.text.trim(frame.args[2] or "") | |||
local sb, base = both_values(frame, ability, prop) | |||
-- DataProp answers a failed lookup with a red notice rather than a number. | |||
if not sb or not base or base == 0 then | |||
return '<span style="color:red;">No change for ' .. ability .. '/' .. prop .. '</span>' | |||
end | |||
-- Properties Street Brawl leaves alone fall back to the base value, so two equal | |||
-- numbers mean this property was never in the overlay. | |||
if sb == base then | |||
return '<span style="color:red;">Street Brawl does not change ' .. ability .. '/' .. prop .. '</span>' | |||
end | |||
-- Purely a comparison of the two numbers; whether that helps or hurts the hero is | |||
-- for the surrounding prose to say. | |||
local direction = sb > base and "increased" or "reduced" | |||
local percent = math.abs(sb - base) / math.abs(base) * 100 | |||
return direction .. " by " .. string.format("%.0f", percent) .. "%" | |||
end | end | ||