Module:Activity-2

--[=[

Temporary Lua Module for Character Activities Templates Functions

--]=]

local p = {} local util = require("Module:Utility")

local EC = require("Module:EC").getEC local LTE = require("Module:LTEvent").getLTE local TOK = require("Module:CharacterToken").getToken local ICON = require("Module:CharacterAvatar").getAvatar local COLL = require("Module:ItemCollection").getCollection local TASK = require("Module:Tasks").getData local NPC = require("Module:NPC").getNPC

local function unavailable(tokens, type, pagename, event) if not tokens or tokens == "" then return "" end local tOut = {} for _, k in ipairs(tokens) do		if pagename == TOK({k, "T"}) then if type == "S" then return 'class="dmk-act-unavailable"' elseif type == "T" then return " '* Unavailable during " .. LTE({event, "N", "S"}) .. "' "			end end end return "" end

local function eventchanges(afterevent, duringevent) if afterevent == duringevent then return nil end if not (type(afterevent) == "table" and type(duringevent) == "table") then return {from = afterevent, to = duringevent} end

local result = {} for k, v in pairs(afterevent) do		result[k] = eventchanges(v, duringevent[k]) end for k, v in pairs(duringevent) do		if afterevent[k] == nil then result[k] = eventchanges(nil, v)		end end

return next(result) and result end

function p.getconflicts(tokens, event) if type(tokens) ~= "table" then return "" end local allcharacters = – local tOut = {'{| class="article-table" style="text-align: center; line-height: 1.0; width: fit-content;"'} local i = 6

for _, data in ipairs(tokens) do		if type(TOK({data, "X"})) == "table" then for _, v in ipairs(TOK({data, "X"})) do				if not allcharacters[v] then if v:match("^IP-") then table.insert(allcharacters[1], 'AAAA-' .. v)					elseif v:match("^Fabric ") then table.insert(allcharacters[1], 'ZZZZ-' .. v)					else table.insert(allcharacters[1], v)					end allcharacters[v] = v				end end end end

table.sort(allcharacters[1], function(a, b) return a < b end)

for k, name in pairs(allcharacters[1]) do		if i == 6 then i = 0 table.insert(tOut, '\n|-') end if name:match("^AAAA-") then table.insert(tOut, ('\n| style="width: 15%; padding: 5px;"|' .. COLL({mw.ustring.lower(name):match("^aaaa%-ip%-(.+)$"), "P"}))) i = i + 1 elseif name:match("^ZZZZ-") then table.insert(tOut, ('\n| style="width: 15%; padding: 5px;"|' .. TOK({name:match("^ZZZZ%-(.+)$"), "50"}) .. ' ' .. TOK({name:match("^ZZZZ%-(.+)$"), "L"}) .. ' '))			i = i + 1 elseif name ~= "" then table.insert(tOut, ('\n| style="width: 15%; padding: 5px;"|' .. ICON({name, (event or '')}) .. ' ' .. name .. ' ')) i = i + 1 end end

table.insert(tOut, "\n|}\n Note: if the collection icon is displayed, it means that this token conflicts with the whole collection") return table.concat(tOut) end

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

local today = os.date("%Y/%m/%d %H:%M:%S") local eventstart = today local eventend = today

local fullpagename = tArgs["F"] or mw.title.getCurrentTitle.prefixedText or "" local pagename = tArgs["P"] or mw.title.getCurrentTitle.text or "" pagename = pagename:gsub("^([^,]-)%s*/%s*(.-)$", "%1")

local char1 = tArgs["ch1"] or "? #0" local ch1name, ch1lvl = mw.ustring.match(char1, "^(.-)%s*#%s*([%d%,]*)$") if not ch1name then ch1name = char1 end if ch1lvl == "0" then ch1lvl = "?" end

local char2 = tArgs["ch2"] local ch2name = nil local ch2lvl = nil if char2 then ch2name, ch2lvl = mw.ustring.match(char2, "^(.-)%s*#%s*([%d%,]*)$") if not ch2name then ch2name = char2 end if ch2lvl == "0" then ch2lvl = "?" end end

local actanim = tArgs["anim"] local actname = tArgs["name"] or "?" local actaltname = tArgs["altname"] or actname local actreq = tArgs["req"] local acttime = tArgs["time"] or "?h"

local wish = tArgs["wish"] local trophy = tArgs["trophy"] local notokens = tArgs["notok"] local tokens = tArgs["tok"] or ""

local event = tArgs["event"] if event then eventstart = LTE({event, nil, "SD"}) eventend = LTE({event, nil, "ED"}) if eventstart >= today then event = nil end end local noec = tArgs["noec"] local eventtokens = tArgs["eventtok"] or ""

local tOut = {	'|-', "", '\n|', "", '\n| style="text-align: left;"|', (actanim and (" ") or ""), actname, "", "", '\n| nowrap|', (wish and NPC({"Wish Granter"}) or ""), '\n', TASK({acttime, (ch2name and "J" or ""), event}), "", '\n| nowrap|', TOK({tokens, nil, "B"}), ("\n"), "" }

if ch2name then tOut[11] = ' ' .. ICON({ch2name, nil, 30}) .. '  ' .. (ch2lvl and (" ''Lvl " .. ch2lvl .. "'' ") or "") tOut[18] = "" end

if noec and event and noec == event then tOut[13] = TASK({acttime, (ch2name and "J" or "")}) end

if not fullpagename:match("^Template") or fullpagename:match("%-Event%-") then tOut[17] = "" tOut[18] = "" end

if pagename == ch1name and fullpagename == ch1name then tOut[4] = ch1lvl or "" elseif ch2name and pagename == ch2name and fullpagename == ch2name then tOut[4] = ch2lvl or "" tOut[7] = actaltname tOut[11] = ' ' .. ICON({ch1name, nil, 30}) .. '  ' .. (ch1lvl and (" ''Lvl " .. ch1lvl .. "'' ") or "") elseif ch2name and pagename == ch2name then tOut[4] = ICON({ch2name}) .. (ch2lvl and (" ''Level " .. ch2lvl .. "'' ") or "") tOut[7] = actaltname tOut[11] = ' ' .. ICON({ch1name, nil, 30}) .. '  ' .. (ch1lvl and (" ''Lvl " .. ch1lvl .. "'' ") or "") else tOut[4] = ICON({ch1name}) .. (ch1lvl and (" ''Level " .. ch1lvl .. "'' ") or "") end if actreq then local sep = "" local rOut = "" local requirements = mw.text.split(actreq, "%s*%$%s*") for idx = #requirements, 1, -1 do			local reqname, reqlvl = mw.ustring.match(requirements[idx], "^(.-)%s*#%s*([%d%,]*)$") if not reqname then reqname = requirements[idx] reqlvl = nil end if reqlvl and reqlvl == "" then reqlvl = nil end rOut = " " .. reqname .. "" .. (reqlvl and (" (Ench. Lvl. " .. reqlvl .. ")") or "") .. sep .. rOut if sep == "" then sep = " &" else sep = "," end end tOut[8] = " ''*" .. rOut .. "'' "	end if trophy and not event then tOut[14] = ", " .. NPC({"Gold Trophies", "G"}) end

if tArgs["reward"] then if tArgs["alttext"] then tOut[8] = " ''* " .. tArgs["alttext"] .. "'' " end if acttime == "Instant" then tOut[13] = '| data-sort-value="0"|Instant' else local durNumb, durHMS = string.match(acttime, "^([%d%?]+)([hms])$") local durNumb = tonumber(durNumb) if durNumb then if durHMS == "h" then durNumb = durNumb * 3600 elseif durHMS == "m" then durNumb = durNumb * 60 end end tOut[13] = '| data-sort-value="' .. (durNumb or 99900) .. '"|' .. acttime end tOut[14] = "\n| nowrap|" .. (tArgs["reward"]~="X" and tArgs["reward"] or "") if tArgs["reward"]:match("^EC%-") then tOut[14] = "\n| nowrap|" .. EC({tArgs["reward"]}) end end if notokens and ((notokens == "ME" and not pagename:match(" Token$")) or notokens ~= "ME") then if notokens == "ME" then if tOut[11] == "" then tOut[10] = "" tOut[5] = '\n| colspan="2" style="text-align: left;"|' end tOut[13] = "| nowrap|" tOut[14] = acttime tOut[15] = "" tOut[16] = "" elseif notokens == "O" then if event and eventtokens ~= tokens then if eventstart > today then return "" elseif eventstart <= today then if today <= eventend then tOut[2] = 'class="dmk-act-available"' tOut[9] = " '* Available only during " .. LTE({event, "N", "S"}) .. "' "						tOut[16] = TOK({eventtokens, nil, "B"}) end end end else tOut[15] = "" tOut[16] = "" end else if event and eventtokens ~= tokens then if eventstart <= today then if today <= eventend then local alltokens = {} alltokens["After"] = mw.text.split(tokens, "%s*%$%s*") alltokens["During"] = mw.text.split(eventtokens, "%s*%$%s*") local unavtokens = {}

for _, data in pairs(eventchanges(alltokens["After"], alltokens["During"])) do					for y, v in pairs(data) do						if y == "from" then table.insert(unavtokens, v) end end end

tOut[2] = unavailable(unavtokens, "S", pagename, event) tOut[9] = unavailable(unavtokens, "T", pagename, event)

tOut[16] = TOK({eventtokens, nil, "B"}) end end end end return table.concat(tOut) end

return p