Module:Activity-2

--[=[

Temporary Lua Module for Character Activities Templates Functions

--]=]

local p = {} local util = require("Module:Utility") local LTE = require("Module:LTEvent").getLTE local TOK = require("Module:CharacterToken").getToken local ICON = require("Module:CharacterAvatar").getAvatar 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 'style="border: 3px solid #595358; border-style: dashed;'			elseif type == "T" then				return " * Unavailable during the " .. LTE({event, nil, "A", "Event"}) .. " "			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.main(frame) local tArgs = util.getArgs(frame) local today = os.date("%Y/%m/%d %H:%M:%S") local fullpagename = tArgs["F"] or mw.title.getCurrentTitle.prefixedText or "" local pagename = tArgs["P"] or mw.title.getCurrentTitle.text or ""

local char1 = tArgs["ch1"] or "? #0" local ch1name, ch1lvl = mw.ustring.match(char1, "^([^#]-)%s*#*%s*([%d%,]*)$") if not ch1name then ch1name = char1 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 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 trophy = tArgs["trophy"] local notokens = tArgs["notok"] local tokens = tArgs["tok"]

local event = tArgs["event"] if event and LTE({event, nil, "SD"}) > today then event = nil end local eventtokens = tArgs["eventtok"]

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

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

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

if pagename == ch1name then tOut[4] = ch1lvl elseif ch2name and pagename == ch2name then tOut[4] = ch2lvl tOut[7] = actaltname tOut[11] = ICON({ch1name, nil, 30}) .. ' ' .. " ''Lvl " .. ch1lvl .. "'' "	else tOut[4] = ICON({ch1name, event}) .. " ''Level " .. ch1lvl .. "'' "	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 not notokens then if event and eventtokens then if LTE({event, nil, "SD"}) < today and today < LTE({event, nil, "ED"}) 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 else tOut[15] = "" tOut[16] = "" end return table.concat(tOut) end

return p