Module:WillpowerCooldownTable

From Caves of Qud Wiki
Jump to navigation Jump to search

Creates a willpower-to-cooldown table, given a base cooldown value. For more information, refer to Template:Willpower_cooldown_table.


local WillpowerCooldownTable = {}

local ProcessArgs = require'Module:ProcessArgs'

function WillpowerCooldownTable.calcCooldown(willpower, basecooldown)
    local internalCooldown = basecooldown * 10.0
    local wpAdjustedCooldown = math.floor((internalCooldown * (100.0 - ((willpower - 16.0) * 5.0))) / 100.0)
    local minimumCooldown = math.max(math.floor(internalCooldown * 0.2 + 0.5), math.min(50.0, internalCooldown))
    local calculatedCooldown = math.max(wpAdjustedCooldown, minimumCooldown)
    local finalCooldown = math.ceil(calculatedCooldown / 10.0)
    return finalCooldown
end

function WillpowerCooldownTable.makeTable(frame)
    local args = ProcessArgs.merge(true)
    local baseCooldown = args.basecooldown

    local result = "<table class=\"willpower-cooldown-table\"><tr>"

    for c=0,3 do  --header row
        result = result .. "<th class=\"cd-wi-header\">WI</th>"
        result = result .. "<th class=\"cd-cd-header\">CD</th>"
    end

    result = result .. "</tr>"

    local rowWP = 9
    for r=0,5 do  --rows
        result = result .. "<tr>"
        for c=0,3 do  --column groups
            local wp = rowWP + (c * 6)
            local cd = WillpowerCooldownTable.calcCooldown(wp, baseCooldown)
            local wiClass = "cd-wi-cell"
            if wp == 32 then
            	wiClass = wiClass .. " cd-wi-32-cell"
            end
            result = result .. "<td class=\"" .. wiClass .. "\">" .. wp .. "</td>"
            result = result .. "<td class=\"cd-cd-cell\">" .. cd .. "</td>"
        end
        result = result .. "</tr>"
        rowWP = rowWP + 1
    end

    result = result .. "</table>"

    return result
end

return WillpowerCooldownTable