Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Foundry

From Teriock

Documentation for this module may be created at Module:Foundry/doc

local p = {}

function p.data(frame)
    local args = frame.args
    local data = {
        base = {},
        proficient = {},
        fluent = {}
    }
    
    -- Parse base consequences
    for key, value in pairs(args) do
        local parts = {}
        for part in key:gmatch("[^_]+") do
            table.insert(parts, part)
        end
        
        if #parts >= 3 then
            local level = parts[1] -- base, proficient, fluent
            local target = parts[2] -- hit, miss, etc.
            local property = table.concat(parts, "_", 3) -- damage, crit_double, etc.
            
            if not data[level][target] then
                data[level][target] = createEmptyConsequence()
            end
            
            setConsequenceProperty(data[level][target], property, value)
        end
    end
    
    local json = mw.text.jsonEncode(data)
    return "<!-- FOUNDRY_DATA_START\n" .. json .. "\nFOUNDRY_DATA_END -->"
end

function createEmptyConsequence()
    return {
        default = {
            instant = { rolls = {}, hacks = {} },
            ongoing = {
                statuses = {},
                changes = {},
                duration = nil,
                expirations = {
                    turn = { who = "target", when = "end", how = "auto" },
                    movement = false,
                    dawn = false,
                    sustained = false
                }
            }
        },
        crit = {
            overrides = {},
            mutations = { double = false }
        }
    }
end

function setConsequenceProperty(consequence, property, value)
    if property == "damage" then
        consequence.default.instant.rolls.damage = {value}
    elseif property == "crit_double" then
        consequence.crit.mutations.double = (value == "true")
    elseif property == "heightened_damage" then
        if not consequence.heightened then
            consequence.heightened = {
                overrides = {},
                scaling = { rolls = {}, duration = { value = 0, rounding = 1 } }
            }
        end
        consequence.heightened.scaling.rolls.damage = {value}
    end
    -- Add more property mappings as needed
end

return p