Module:Card

--[=[

Lua Module for Item Cards

--]=]

local p = {} local util = require("Module:Utility") local cData = mw.loadData("Module:ItemCollection/data") local storylineData = mw.loadData( 'Module:Storyline/data' ) local EC = require("Module:EC").getEC local CHEST = require("Module:EnchantedChest").getChest local RARITY = require("Module:Rarity").rarity local TOK = require("Module:CharacterToken").getToken local date = require('Dev:Date')

local function costTable(cost, sale, alttext) local iCost = ' " end

function p.getCost(frame) local tArgs = util.getArgs(frame) return costTable(tArgs[1], nil, tArgs[2]) end

function getCard(name, rewards, requirements, cost, sale, duration, lte, smallcard) local cType = "default"

local iFile = "" local iLink = "" local iRequ = "" local iReward = nil local iCost = "" local iDur = ""

local event = {"default", ""} if lte then event = mw.text.split(lte, "%s*%$%s*") event[1] = event[1]:lower if not storylineData["Colors"][(event[2]=="T" and "ttc" or event[1])] and not event[1]:match("^ts") then event[1] = "default" elseif event[1]~="ms" and event[1]~="old" then cType = "event" end end

if smallcard then cType = "small" end

local span = "" local space = ""

if name then local conv = {["ch"] = "cp", ["cos"] = "cp"}

local iName, iDisp = mw.ustring.match(name, "^([^,]-)%s*#%s*(.-)$") if not iName then iName = name end

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

if name:match(" Chests") then if event[1]~="default" then name = name .. "-" .. event[1]:upper .. (event[2]=="T" and " TC Event" or " Event") end iFile = CHEST({name, (cType=="event" and "120" or "100")}) iLink = CHEST({name, "L"}) elseif name:match("^EC%-") then iFile = EC({iName, nil, nil, "C", (cType=="small" and 60 or 120)}) iLink = iDisp or EC({iName, "L"}) elseif iData and iData[2] then 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			if not cData["Items"][iName] and iName:match("^.+%-%d+$") then iName = iName:match("(.+)%-%d+$") end			local iDisp = (iDisp or iName):gsub("^([^%(]-)%/([^%(]-)$", "%2")

iFile = "" if iData["C"] and cData["Categories"][iData["C"]] then local category = iData["C"] iFile = ' ' .. iFile .. '  '			end

iLink =  .. (iDisp or iName) ..  else iFile = TOK({name, (cType=="small" and 55 or 120)}) iLink = TOK({name, "S"}) if cType == "small" then iFile = ' ' .. iFile .. ' ' .. TOK({name, "C"}) .. ' '			end end end

if requirements then local qstLink = require("Module:Storyline").getLink for rName in mw.text.gsplit(requirements, "%s*$%s*") do			local tRequ = {space, "", rName, ""} if rName:match("-" .. (event[2]=="T" and "TTC" or event[1]:upper)) then tRequ[3] = qstLink(rName) end iRequ = iRequ .. table.concat(tRequ) space = " " end elseif rewards then iReward = ' ' end

if cost then iCost = costTable(cost, sale) end

if duration then local bDur1, bDur2 = mw.ustring.match(duration, "^([^,]-)%s*#%s*(%d+)$") if not bDur1 then bDur1 = "0001/01/01" end

if bDur2 then local today = os.date("%Y/%m/%d %H:%M:%S") local UnlockDate = bDur1 .. util.dayStart local LockDate = date(bDur1):adddays(tonumber(bDur2)):fmt("%Y/%m/%d")

if today <= UnlockDate then iCost = ": " .. util.countdown(UnlockDate, " in ", " on ", true) iCost = "" duration = util.countdown(UnlockDate, " in ", " on ", true) elseif today <= LockDate then duration = util.countdown(LockDate, " for ", " until ", true) elseif today > LockDate then duration = util.strDate(bDur1, tonumber(bDur2)) end end

iDur = ' ' end

if cType == "small" then return table.concat({'{| class="smallcard ', (event[2]=="T" and "ttc" or event[1]), '"', 			'\n| class="Part_1"|', iFile, 			'\n|-\n| class="Part_2"|', (iRequ~="" and (" " .. iRequ .. " ") or RARITY({TOK({name, "R"}), "S", 15})), 			'\n|-\n| class="Part_3"|', (" '''" .. iLink .. "''' "), 			'\n|-\n| class="Part_4"|', (iReward or iCost), 			'\n|-\n| class="Part_5"|', iDur, 			'\n|}'		}) elseif cType == "event" then return table.concat({'{| class="ltecard ', (event[2]=="T" and "ttc" or event[1]), '"', 			'\n| class="Part_1"|', ("'''" .. iLink .. "'''"), 			'\n|-\n| class="Part_2"|', (' ' .. iFile .. ' '), 			'\n|-\n| class="Part_3"|', iRequ, 			'\n|-\n| class="Part_4"|', iCost, 			'\n|-\n| class="Part_5"|', iDur, 			'\n|}'		}) else return table.concat({'{| class="card ', (event[2]=="T" and "ttc" or event[1]), '"', 			'\n| class="Part_1|', (' ' .. iFile .. ' '), 			'\n|-\n| class="Part_2"|', (" " .. iLink .. " "), 			'\n|-\n| class="Part_3"|', (iReward or iRequ), 			'\n|-\n| class="Part_4"|', iCost, 			'\n|-\n| class="Part_5"|', iDur, 			'\n|}'		})	end end

function getTSCards(tArgs) local tOut = {}

for arg, value in pairs(tArgs) do		if arg ~= "event" then local tRow = {"===", arg, " Tokens===\n"} for token in mw.text.gsplit(value, "%s*$%s*") do if arg == "Fabric" or arg == "Relic" then token = arg .. " " .. token end table.insert(tRow, getCard(token, nil, nil, ("EC-Elixirs #" .. TOK({token, "E"})), nil, nil, ("ts" .. TOK({token, "R"})), true)) table.insert(tRow, "\n") end table.insert(tOut, table.concat(tRow)) end end

return " \n" .. table.concat(tOut) .. " \n" end

function p.main(frame) local tArgs = util.getArgs(frame)

if tArgs["event"] and tArgs["event"] == "ts" then return getTSCards(tArgs) else return getCard(tArgs["name"], tArgs["reward"], tArgs["requirement"], tArgs["cost"], tArgs["sale"], tArgs["duration"], tArgs["event"], tArgs["small"]) end end

return p