Module:Potion

local loader = require('Module:Loader') local string, table, yesno, uitext = loader.require('String', 'Table', 'Yesno', 'UIText') local potionData = loader.loadData('Potion/Data')

local p = {} local unknownDisplay = '&r&f&l???&r'

--- -- Generates table for Module:Inventory slot/Templates --- function p.getPotionsTemplate local function toTable(v) local t = type(v) == 'table' and table.deepCopy(v, true) or {v} return t	end local function colorCode(col) local temp = uitext.getFormatting(col):match('^[0-9a-z]$') and uitext.getFormatting(col) or uitext.getColorCode(col) return (temp or ''):match('^[0-9a-z]$') and temp or 'f'	end local function effectText(effect, level, duration) if not level or level < 0 then return end local dt = potionData[effect] if dt then local g_desc = dt.desc or unknownDisplay variables = toTable(dt.vars) local desc local color = dt.ttColor or colorCode(dt.color or '&f') desc = g_desc if level > 0 then for i, var in ipairs(variables) do					desc = desc:gsub(('{%d}'):format(i-1), var[level] or unknownDisplay) end end desc = desc:gsub('{%d+}', unknownDisplay) return ('&%s%s %s &r&f(%s&f)/&r%s//&r'):format(				color, effect, level > 0 and string._toRoman(level) or '?',				duration or unknownDisplay, desc				) else return unknownDisplay end end local ret = {} for potionname, value in pairs(potionData) do		local name = ('%s Potion'):format(potionname) for level = 1, value.maxLevel, 1 do			local localret = {} local nameRoman = ('%s %s Potion'):format(potionname, string._toRoman(level)) local nameArabic = ('%s %s Potion'):format(potionname, level) local duration, composite = value.duration, value.composite if type(duration) == 'table' then duration = duration[level] end local tooltip local rarityTbl = toTable(value.rarity) local rarity = rarityTbl[level > 0 and level or 1] or 'C'			if composite then for i, eff in ipairs(toTable(composite)) do					if eff == 'self' then tooltip = effectText(potionname, level, duration) else local eff = toTable(eff) local e, l = eff[1], eff[2] or 1 if type(l) == 'table' then l = l[level] end tooltip = effectText(e, l, duration) end table.push(localret, tooltip) end else tooltip = effectText(potionname, level, duration) table.push(localret, tooltip) end table.push(ret, { nameRoman, name, table.concat(localret), '{l}', r = rarity }) table.push(ret, { nameArabic, name, table.concat(localret), '{l}', r = rarity, title = '{r}'..nameRoman }) end local tooltip0, rarity0 = effectText(potionname, 0) table.push(ret, { name, name, tooltip0, '{r}&l???', r = rarity0, title = ('{r}%s ? Potion'):format(potionname) }) end return ret end

return p