Module:Potions

-- -- Generates tables comparing different types of potions

local price = require("Module:RecursiveExchange")._price

local p = {}

function ifnan(n, _then, _else) _else = _else or n	return n ~= n and _then or _else end

-- Compares different potions restoring prayer points function p.prayerpoints(frame) local restore_types = { regular = { instant_99 = 317, instant_formula = "level * 2.5 + 70" },		super_restore = { instant_99 = 327, instant_formula = "level * 2.5 + 80" },		super_prayer = { instant_99 = 416, instant_formula = "level * 3.6 + 70" },		renewal = { overtime_99 = 545, overtime_formula = "level * 4.3 + 120" },		super_renewal = { instant_99 = 317, instante_formula = "level * 2.5 + 70", overtime_99 = 595, overtime_formula = "level * 4.7 + 130.5" }	}	local pots = { {			name = "Prayer potion", herblore_level = 38, restore_type = "regular" },		{			name = "Prayer flask", herblore_level = 38, restore_type = "regular" },		{			name = "Super restore", herblore_level = 63, restore_type = "super_restore" },		{			name = "Super restore flask", herblore_level = 63, restore_type = "super_restore", doses = 6 },		{			name = "Sanfew serum", herblore_level = 65, restore_type = "super_restore" },		{			name = "Sanfew serum flask", herblore_level = 65, restore_type = "super_restore", doses = 6 },		{			name = "Super prayer", herblore_level = 94, restore_type = "super_prayer" },		{			name = "Super prayer flask", herblore_level = 94, restore_type = "super_prayer", doses = 6 },		{			name = "Prayer renewal", herblore_level = 94, restore_type = "renewal" },		{			name = "Prayer renewal flask", herblore_level = 94, restore_type = "renewal", doses = 6 },		{			name = "Replenishment potion", herblore_level = 87, restore_type = "super_restore", doses = 6 },		{			name = "Brightfire potion", herblore_level = 94, restore_type = "renewal", doses = 6 },		{			name = "Super prayer renewal potion", herblore_level = 96, restore_type = "super_renewal", doses = 6 },		{			name = "Holy overload potion", herblore_level = 97, restore_type = "renewal", doses = 6 },		{			name = "Overload salve", herblore_level = 97, restore_type = "super_renewal", doses = 6 },		{			name = "Supreme overload salve", herblore_level = 99, restore_type = "super_renewal", doses = 6 }	}	local t = mw.html.create("table") :addClass("wikitable sortable") :tag("tr") :tag("th"):wikitext("Potion"):done :tag("th"):wikitext("Herblore level"):done :tag("th"):wikitext("Points restored per dose"):done :tag("th"):wikitext("... at 99 Prayer"):done :tag("th"):wikitext("Restored over time"):done :tag("th"):wikitext("... at 99 Prayer"):done :tag("th"):wikitext("Price per dose"):done :tag("th"):wikitext("Price per instant prayer point"):done :tag("th"):wikitext("Price per prayer point"):done :done for _, pot in ipairs(pots) do		local row = t:tag("tr") local nan = 0 / 0 local na = "-" local name = pot["name"] local doses = pot["doses"] or 4 local full_name = name .. " (" .. doses .. ")" local icon = frame:expandTemplate({title = "Pic link plain", args = {full_name}}) local restore_type = restore_types[pot["restore_type"]] local instant_formula = restore_type["instant_formula"] or na		local overtime_formula = restore_type["overtime_formula"] or na		local instant_99 = restore_type["instant_99"] or nan local overtime_99 = restore_type["overtime_99"] or nan local price_per_dose = price(full_name) / doses local price_per_point = price_per_dose / instant_99 local price_per_point_total = price_per_dose / (ifnan(instant_99, 0) + ifnan(overtime_99, 0)) row:tag("td"):wikitext(icon .. " " .. name .. "") row:tag("td"):wikitext(pot["herblore_level"]) row:tag("td"):wikitext(instant_formula) row:tag("td"):wikitext(ifnan(instant_99, na)) row:tag("td"):wikitext(overtime_formula) row:tag("td"):wikitext(ifnan(overtime_99, na)) row:tag("td"):wikitext(frame:expandTemplate({title = 'Coins', args = {price_per_dose}})) row:tag("td"):wikitext(ifnan(price_per_point, na, frame:expandTemplate({title = 'Coins', args = {math.floor(price_per_point * 10) / 10}}))) row:tag("td"):wikitext(frame:expandTemplate({title = 'Coins', args = {math.floor(price_per_point_total * 10) / 10}})) end return t end

return p