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):match('^[0-9a-z]$') and temp or 'f'	end local function effectText(effect, level, variables, rarityTbl, durationOverride) local dt = potionData[effect] if dt then local dur, g_desc = dt.duration or unknownDisplay, dt.desc or unknownDisplay variables, rarityTbl = variables or toTable(dt.vars), rarityTbl or toTable(dt.rarity) local desc, rarity, color for i, var in ipairs(variables) do				desc = g_desc:gsub(('{%d}'):format(i-1), var[level] or unknownDisplay) end desc = desc:gsub('{%d}', unknownDisplay) rarity = rarityTbl[level] or 'C'			color = colorCode(dt.color or '&f') return ('&%s%s %s &f(%s&f)\n&r%s'):format(				color, effect, string._toRoman(level),				durationOverride or duration, desc				), rarity else return unknownDisplay, 'C'		end end local ret = {} for potionname, value in pairs(potionData) do		local name = ('%s Potion'):format(potionname) local effect = value.effect local vt, rt = toTable(value.vars), toTable(value.rarity) for level = 1, value.maxLevel, 1 do			local localret = {} local nameRoman = ('%s %s'):format(name, string._toRoman(level)) local tooltip, rarity if effect then for i, eff in ipairs(toTable(effect)) do					if eff == 'self' then tooltip, rarity = effectText(potionname, level, vt, rt) else local eff = toTable(eff) local e, l, d = eff[1], eff[2] or 1, eff[3] tooltip, rarity = effectText(e, l, nil, nil, d)					end table.push(localret, tooltip, '//') end else tooltip, rarity = unknownDisplay, 'C'				table.push(localret, tooltip, '//') end table.push(ret, { nameRoman, name, table.concat(localret), r = rarity }) end end return ret end

return p