Module:MultiItems

local p = {}

local util = require("Module:Utility") local EC = require("Module:EC").getEC local TOK = require("Module:CharacterToken").getTokenDirect local CHEST = require("Module:EnchantedChest").getChest local cData = mw.loadData( 'Module:ItemCollection/data' )

local tItem = {}

local function ITEM(iData, iName, count, size) local conv = { ["ch"] = "cp", ["cos"] = "cp", }

local iDisp = iName:gsub("^([^%(]-)%/([^%(]-)$", "%2")

if size=="L" then return table.concat({"", (iDisp or iName), ""}) else size = size + 5 local fname = mw.ustring.gsub(mw.ustring.lower(iName), "[':\"%,%.*]", "")		fname = fname:gsub(" ", "_")		if iData[2] == "pf" then			fname = fname:gsub("_float$", "")		else			fname = fname:gsub("^([^%(]-)%/([^%(]-)$", "%1-%2")			fname = mw.ustring.gsub(fname, "^([^%(]-) *%(([^%(]-)%)$", "%1_%2")		end

local tItemData = {	"", "", "" }

if iData["C"] and cData["Categories"][iData["C"]] then local category = iData["C"] tItemData[1] = '' tItemData[16] = ' ' if tostring(count):match("^%+%d$") then tItemData[16] = tItemData[16] .. ' ' end tItem[3] = ' ' end

return table.concat(tItemData) end end

function p.getOneItem(item, count, size, withName, tRewards, type) if not item or not count or count=="" then return "" end local nCount = 2 local sCount = count if not tostring(count):match("%d[,/-]%d") then nCount = tonumber(count) or 0 sCount = util.th_comma(nCount) end

tItem = {"", (type and "" or (" " .. sCount)), (withName and " " or ""), "", "",			(withName and " " or ""), }

local iName = item local iData = cData.Items[iName] if iData == nil then iData = cData["Items"][iName:match("(.+)%-%d+$")] end

if iName:match("Chests") and not iName:match("Wacky Lunch Chests") then tItem = {CHEST({item .. ("#" .. count), "P"})} item = "CHEST-" .. item elseif iData and iData[2] then tItem[1] = ITEM(iData, iName, count, (size or 42)) tItem[2] = "" if withName then tItem[4] = ITEM(iData, item, nCount, "L") end item = "ZITM-" .. item elseif item:match("^EC") then tItem[1] = EC({item, nil, nil, (size and "I" or "E"), (size or 35)}) if withName then tItem[4] = EC({item, "L", S=(nCount==1)}) end else tItem[1] = TOK(item, (size or 35)) if withName then tItem[4] = TOK(item, "L") if nCount > 1 then tItem[5] = "s" end end item = "TOK-" .. item end

if nCount == 0 then tItem[2] = " ?" end

if tRewards and type then if not tRewards[item] then tRewards[item] = {I = table.concat(tItem)} end if not tRewards[item][type] then tRewards[item][type] = nCount else tRewards[item][type] = (tRewards[item][type] + nCount) end return tRewards end

return table.concat(tItem) end

function p.getCost(costData, cardFormat) local tOut = {} local space = ""

for costItem in mw.text.gsplit(costData, "%s*$%s*") do		local costName, costNumb = mw.ustring.match(costItem, "^(.-)%s*^%s*(.-)$") if not costName then costName = costItem end

table.insert(tOut, space) if costName:match("^EC-") then local curName, curNumb = mw.ustring.match(costName, "^([^,]-)%s*#%s*(.-)$") if not curName then curName = costName end if not curNumb then curNumb = "1" end

local cNumb, sNumb = mw.ustring.match(curNumb, "^([^,]-)%s*-%s*(.-)$") if not cNumb then cNumb = count end

if sNumb then cNumb = tonumber((string.gsub(cNumb or "", "[,]", ""))) sNumb = tonumber((string.gsub(sNumb or "", "[,]", "")))

if cardFormat then table.insert(tOut, " ") end table.insert(tOut, EC({(curName .. " #" .. util.th_comma(sNumb)), nil, nil, nil, 30})) if cardFormat then table.insert(tOut, " ") end if cardFormat then table.insert(tOut, ' ') else table.insert(tOut, ' ') end table.insert(tOut, util.th_comma(cNumb)) table.insert(tOut, '  -') table.insert(tOut, (100-(string.format("%.2f", (sNumb/cNumb))*100))) table.insert(tOut, '% ') else if cardFormat then table.insert(tOut, " ") end table.insert(tOut, EC({costName, nil, nil, nil, 30})) if cardFormat then table.insert(tOut, " ") end end else table.insert(tOut, costName) end table.insert(tOut, (costNumb and (" (" .. costNumb .. ") ") or "")) space = " " end

return table.concat(tOut) end

return p