Module:BDR

From Fallen London Wiki

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

-- Based on stuff from the original 'Module:Item' by [[User:Adnoam]]
local p = {}

function quality_from_effect(effect)
    local quality, sign, value = string.match(effect, "%[%[File:.*link=([^%|]*)%|alt=%]%] %[%[%1%]%]%<%/span%>%s+([%+-])(%d+)")
    value = tonumber(value)
    if sign == '-' then
        value = value * -1
    end
    return quality, value
end

function p.get_bdr(frame)
	targs = frame:getParent().args
	list = {}
	total_bdr = 0
	
	for k, v in pairs(targs) do
        num = string.match(k, "^Effects(%d+)$")
        if (num) then
            table.insert(list, tonumber(num))
        end
	end
	
	bdr = {
		["Bizarre"] = true,
		["Dreaded"] = true,
       	["Respectable"] = true
    }

	for _, num in ipairs(list) do
    	local effect = targs["Effects" .. num]
  	    local quality, value = quality_from_effect(effect)
    	
    	if (bdr[quality]) then
            total_bdr = total_bdr + value
        end
	end
	
	return total_bdr
end

return p