Module:DropRateCalc: Difference between revisions

From Roat Pkz
Jump to navigation Jump to search
(change colours)
(vote boost toggle handling)
 
(3 intermediate revisions by the same user not shown)
Line 13: Line 13:
local function getColor(rate)
local function getColor(rate)
     if rate == 1 then
     if rate == 1 then
         return "#afeeee"  -- always
         return "#0b5884"  -- always
     elseif rate <= 16 then
     elseif rate <= 16 then
         return "#56e156"  -- common
         return "#3c780a"  -- common  
     elseif rate <= 64 then
     elseif rate <= 64 then
         return "#ffed4c"  -- uncommon
         return "#a48900"  -- uncommon  
     elseif rate <= 128 then
     elseif rate <= 256 then
         return "#ff863c"  -- rare
         return "#b55e0c"  -- rare
    elseif rate <= 999 then
        return "#9f261e"  -- very rare  
     else
     else
         return "#ff6262"  -- very rare
         return "#5c1a1a"  -- extremely rare  
     end
     end
end
end
Line 28: Line 30:
     local base = tonumber(frame.args[1])
     local base = tonumber(frame.args[1])
     if not base then return "Invalid base rate" end
     if not base then return "Invalid base rate" end
    local noboost = frame.args[2] == "noboost"
     local cells = {}
     local cells = {}
     for _, tier in ipairs(buffs) do
     for _, tier in ipairs(buffs) do
         local rate = math.floor(base * (1 - tier.reduction) + 0.5)
        local reduction
        if noboost then
            reduction = 0
        else
            reduction = tier.reduction
        end
         local rate = math.floor(base * (1 - reduction))
         local color = getColor(rate)
         local color = getColor(rate)
         table.insert(cells, '<td style="background-color:' .. color .. '; color:#ffffff; text-align:center;">1/' .. rate .. '</td>')
        local attrs = ' data-baserate="' .. base .. '"'
                  .. ' data-reduction="' .. tier.reduction .. '"'
        if noboost then
            attrs = attrs .. ' data-noboost="1"'
        end
         table.insert(cells,
            '<td' .. attrs
            .. ' style="background-color:' .. color .. '; color:#ffffff; text-align:center;"'
            .. '>1/' .. rate .. '</td>'
        )
     end
     end
     return table.concat(cells, "")
     return table.concat(cells, "")
end
end


return p
return p

Latest revision as of 21:23, 18 July 2026

Need to test if Larran's keys are buffed, specifically for Template:CallistoDrops and the other bosses like that.


local p = {}

local buffs = {
    {label = "Base", reduction = 0},
    {label = "Donator", reduction = 0.15},
    {label = "Super donator", reduction = 0.25},
    {label = "Extreme donator", reduction = 0.30},
    {label = "Legendary donator", reduction = 0.35},
    {label = "Royal donator", reduction = 0.40},
    {label = "Divine donator", reduction = 0.45},
}
-- somewhat matches osrs wiki
local function getColor(rate)
    if rate == 1 then
        return "#0b5884"  -- always
    elseif rate <= 16 then
        return "#3c780a"  -- common 
    elseif rate <= 64 then
        return "#a48900"  -- uncommon 
    elseif rate <= 256 then
        return "#b55e0c"  -- rare 
    elseif rate <= 999 then
        return "#9f261e"  -- very rare 
    else
        return "#5c1a1a"  -- extremely rare 
    end
end

function p.calc(frame)
    local base = tonumber(frame.args[1])
    if not base then return "Invalid base rate" end
    local noboost = frame.args[2] == "noboost"
    local cells = {}
    for _, tier in ipairs(buffs) do
        local reduction
        if noboost then
            reduction = 0
        else
            reduction = tier.reduction
        end
        local rate = math.floor(base * (1 - reduction))
        local color = getColor(rate)
        local attrs = ' data-baserate="' .. base .. '"'
                   .. ' data-reduction="' .. tier.reduction .. '"'
        if noboost then
            attrs = attrs .. ' data-noboost="1"'
        end
        table.insert(cells,
            '<td' .. attrs
            .. ' style="background-color:' .. color .. '; color:#ffffff; text-align:center;"'
            .. '>1/' .. rate .. '</td>'
        )
    end
    return table.concat(cells, "")
end


return p