Module:Enchantment

local loader = require('Module:Loader') local string, table, yesno = loader.require('String', 'Table', 'Yesno') local enchData = loader.require('Enchantment/Data')

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

--- -- Generates table for Module:Inventory slot/Templates --- function p.getEnchantedBooksTemplate local function toDoubleTable(v) local t = type(v) == 'table' and table.deepCopy(v, true) or {v} t = type(t[1]) == 'table' and t or {t} return t	end local function toTable(v) local t = type(v) == 'table' and table.deepCopy(v, true) or {v} return t	end local ret = { id = 'Enchanted Book ($o)' } for enchname, value in pairs(enchData) do		local g_desc, ultimate, nocombine = value.desc or unknownDisplay, value.isUltimate, value.noCombine local variables, costTbl, upgradesTbl, rarityTbl = toDoubleTable(value.vars), toTable(value.cost), toTable(value.upgrades), toTable(value.rarity) for tier = 1, value.max, 1 do			local name, arabicname, link, displayname, upgradeType, toUpgrade, ultWarning, cost, combineWarning, requirement, rarity local desc = g_desc name = ('%s %s'):format(enchname, string._toRoman(tier)) arabicname = ('%s %s'):format(enchname, tier) link = ('%sEnchantments#%s'):format(ultimate and 'Ultimate ' or '', mw.uri.anchorEncode(enchname)) displayname = (ultimate and '&d&l' or '&9') .. (name) for i, var in ipairs(variables) do				desc = desc:gsub(('{%d}'):format(i-1), var[tier] or unknownDisplay) end desc = desc:gsub('{%d}', unknownDisplay) toUpgrade = (string._toNumber(upgradesTbl[tier]) or 0) > 0 and table.concat{ '&r&8', upgradesTbl[tier], '&r &8', value.upgradeType, ('&r&8 to tier up!/'):format(string._toNumber(upgradesTbl[tier])) } 			or '' ultWarning = ultimate and '&cYou can only have 1 Ultimate/Enchantment on an item!//' or '' cost = costTbl[tier] or unknownDisplay combineWarning = nocombine and '&e▲ ' .. (ultimate and '&d&l' or '&7') .. (enchname) .. ' cannot be combined!/' or ''--Overflow text color is intentional requirement = (tonumber(value.req) or 0) > 0 and ('&cRequires Enchanting %d to/apply.//'):format(tonumber(value.req)) or '' rarity = rarityTbl[tier] or 'common' table.push(ret, {name, link, displayname, desc, toUpgrade, ultWarning, cost, combineWarning, requirement, r = rarity}) table.push(ret, {arabicname, link, displayname, desc, toUpgrade, ultWarning, cost, combineWarning, requirement, r = rarity}) end end return ret end

return p