Module:DropRateCalc
Jump to navigation
Jump to search
Need to test if Larran's keys are buffed, specifically for Template:CallistoDrops and the other bosses like that.
local p = {}
-- Donator rank drop rate bonuses, shown in the "My drop bonuses" bar (MediaWiki:VoteBoostToggle.js)
local RANK_REDUCTION = { royal = 0.40, divine = 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
-- pass rank like {{DropRateCalc|512||d}} or {{DropRateCalc|512||r}}. The two || between rate and rank are necessary, otherwise the arg is matched as noboost.
-- fallback to title to save edits on all pre-existing div pages (hopefully)
local function npcRank(frame)
local f = frame.args[3] and frame.args[3]:lower() or ""
if f == "d" then return "divine" end
if f == "r" then return "royal" end
local title = mw.title.getCurrentTitle().text:lower()
if title:find("divine", 1, true) then return "divine" end
if title:find("royal", 1, true) then return "royal" end
end
-- One drop rate cell. Monsters that need a Royal or Divine rank start at that rank's rate;
-- the bar then applies the reader's own rank and bonuses.
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 rank = npcRank(frame)
local rate = base
if not noboost and rank then
rate = math.floor(base * (1 - RANK_REDUCTION[rank]))
end
local attrs = ' data-baserate="' .. base .. '" data-reduction="0"'
if rank then attrs = attrs .. ' data-npcrank="' .. rank .. '"' end
if noboost then attrs = attrs .. ' data-noboost="1"' end
return '<td' .. attrs
.. ' style="background-color:' .. getColor(rate) .. '; color:#ffffff; text-align:center;"'
.. '>1/' .. rate .. '</td>'
end
return p