Module:Activity

--[==[-- -- Lua script to get Character Activities --

PLEASE DO NOT USE/EDIT YET, AS THE MODULE AND DATA STRUCTURE IS STILL CHANGING AND NOT FINALIZED.

Parameters: Numbered Parameters 1 .. n = Character Name + Activity (Format: Character$Activity) Named Parameters Boolean (true if present) collection = Numbered Parameters are Collection names icon = Include Owner-Character Icon notoken = do not include token drops trophy = Include trophy icon for trophy tasks wish = Include Wish icon for wishable tasks Text event = LTE short name me = Mini-Event short name/reference display = output type blank = normal output character = Character Page tasks list(s) attraction = Attraction Page token tasks list currency = event (EC) tasks (only for 'event' if specified) animated = Animated Tasks Page trophy = trophy tasks conflict = Current Token Name (for conflict check) --]==]

local p = {}

--[===[ structure of data file (data file not to be created yet, till module is almost finished,	because the structure might need to be fine-tuned if it can help	in simplifying/speed-up code) Table Key: owner character (short name) Key: activity	(activity name) data: Table with fields as below numbered fields 1	= owner level 2	= duration 3	= sidekick character (short name) 4	= sidekick level keyed fields (only present when needed) alias	= points to activity this is an alias of   						Other fields are ignored if 'alias' is present Table of Character, Activity-Name pair. 1	= Character (if nil, another activity of same character) 2	= Activity (if nil, same activity of another character) tok		= possible token drops (table) toknpc = possible NPC token drops (table) attr	= requires attraction (table) 1 = Attraction Name 2 = Enchantment Level (nil if not needed) cstm1	= requires Costume 1 cstm2	= requires Costume 2 act		= owner activity (if different from activity-key) act2	= sidekick activity (if differnet from activity-key/act) anim	= present if activity is animated text description of activity wish	= present if task is wishable trophy	= present if task currently drops a trophy ver		= table: activity versions with fields (Not finalized yet) 1 = From version (e.g. 4.1.0) 2 = To version  (e.g. 4.2.0) optional fields (override the current values if present) dur = duration act act2 wish trophy tok toknpc event	= table of LTEs where activity produced EC. other changes (if any) during the LTE will be reflected in the ver(sions) above. key: "eventid" (LTE ID) data: Table with fields as below numbered fields 1	= generates EC 2	= table of tokens during event. 3  = table of npc tokens during event. (optional) --]===]

local actData = { ---[==[	-- Sample content of data file Module:Activity/mandf ["MAF"] = { -- Mickey Mouse ["Mickey Mouse"] = { ["High Five!"] = { 2, 21600, "Goofy", 1, tok = {"Daisy Duck,2","Aladdin,3","Sebastian,2","Ralph,2"}, anim = "Goofy and Mickey high five", },			["Search for Friends"]	= { 1, "60s", tok = {"IP-MAF"}, wish = 1, anim = "Mickey Searches around the Kingdom", },			["Dance"] = { alias = {nil, "Dance with Minnie"}, },			["Dance with Minnie"] = { 8, "2h", "Minnie Mouse", 8, act2 = "Dance with Mickey", anim = "Mickey and Minnie dance together", },			["Review"] = { 3, 7200,				act = "Review Pete's Complaints", attr = {"Mickey's House"}, tok = {"Pumbaa,3"}, event = { nbc = {true,nil}, }			},			["Mistletoe"] = { alias = {"Minnie Mouse"}, },		},		-- Minnie Mouse ["Minnie Mouse"] = { ["Dance"] = { alias = {"Mickey Mouse"}, },			["Mistletoe"] = { 1, 7200, "Mickey Mouse", 1, cstm1 = "Mickey Mouse/Holiday", cstm2 = "Minnie Mouse/Holiday", tok  = {"Hans,3"}, anim = "Minnie and Mickey, in their Holiday costumes, share a tender moment under the mistletoe", },		},		-- Goofy ["Goofy"] = { ["High Five!"] = { alias = {"Mickey Mouse"}, },			["Check the Fun Wheel"] = { 1, "60m", req = "[Mickey's Fun Wheel]", tok = {"IP-MI","Mickey Mouse,3","Woody,2"}, },			["Run in Panic"] = { 1, "60s", tok = {"IP-MAF"}, anim = "Goofy runs in panic", },		},	},	-- end of sample content --]==] }

local icon = require("Module:CharacterAvatar").getAvatar local token = require("Module:CharacterToken").getTokenDirect local task = require("Module:Tasks").getData local NPC = require("Module:NPC").getNPC local coll = require("Module:ItemCollection").getCollection local util = require("Module:Utility")

local tArgs = {} local tTasks = {} local badAct = {"?", "?h"}

-- Generate the ouput list of tasks from data provided in a table. local function genOut(tActList, wIcon, animPage, evtID) if type(tActList) ~= "table" then return "" end local tRet = {} for _, oneTask in ipairs(tActList) do       local data = oneTask[3] local actChar = oneTask[1] local actChar2 = data[3] or "" local asChar2 = 0 local actText = data.act or oneTask[2] if oneTask[4] and data[3] then asChar2 = 3 actChar = data[3] actChar2 = oneTask[1] actText = data.act2 or data.act or oneTask[2] end local evt, ECtype local tokens = data.tok local toknpc = data.toknpc if (data.event and data.event[evtID]) then evt = evtID ECtype = data.event[evtID][1] and evtID tokens = data.event[evtID][2] toknpc = data.event[evtID][3] end

local tRow = { "|-\n| style=\"text-align:center;\"|", "", "", "", "", -- Char1 (2-5) "\n|", -- (6) "", "", "", "", "", -- Animation (7-11) "", -- Happiness (12) actText, -- Activity (13) "", -- blank (14) "", -- Requirements start (15) "", "", "", "", "", "", -- Attraction/level (16-21) "", "", "", "", -- Costume 1 (22-25) "", "", "", "", -- Costume 2 (26-29) "", -- Requirements end (30) "\n|", -- (31) "", "", "", "", "", -- Char2 (32-36) "\n", -- (37) "", -- Task (duration / rewards) (38) "", "", -- Trophy (39-40) "", "", -- Tokens / Trophy (41-42) "\n" -- (43) }

if wIcon then tRow[2] = icon({actChar, evt}) tRow[3] = " ''Level " tRow[5] = "'' " end tRow[4] = data[1 + asChar2] or "?"

if data["anim"] then tRow[ 7] = " " end

if data["wish"] then tRow[12] = " " end

local hasReq = 0 if data.attr then tRow[16] = ""			tRow[17] = data.attr[1]			tRow[18] = "" if (data.attr[2]) then tRow[19] = " (Ench. Lvl "				tRow[20] = data.attr[2]				tRow[21] = ")" end hasReq = hasReq + 1 end if data.cstm1 then tRow[23] = ""			tRow[24] = data.cstm1			tRow[25] = "" hasReq = hasReq + 1 end if data.cstm2 then tRow[27] = ""			tRow[28] = data.cstm2			tRow[29] = "" hasReq = hasReq + 1 end if hasReq > 0 then tRow[15] = " ''" tRow[30] = "'' " if hasReq == 2 then if tRow[28] ~= "" then tRow[26] = " & " else tRow[22] = " & " end elseif hasReq == 3 then tRow[22] = ", " tRow[26] = " & " end end

if data[3] then tRow[32] = " align=\"center\" nowrap|" tRow[33] = icon({actChar2, nil, "25"}) tRow[34] = " ''Lvl " tRow[35] = data[4 - asChar2] tRow[36] = "'' " end

tRow[38] = task({data[2], data[3] and "J" or nil, ECtype}) if data["trophy"] then tRow[39] = ", " tRow[40] = NPC({"Gold Trophies"}) end

if tokens then local temp = token(tokens, nil, true) if temp ~= "" then tRow[41] = "\n| nowrap|" tRow[42] = token(tokens, nil, true) end end

table.insert(tRet, table.concat(tRow)) end return table.concat(tRet) end

local function getDataFile(ch) local sName = coll({ch, "S"}) if (not actData[sName]) then actData[sName] = mw.loadData( 'Module:Activity/' .. sName ) end

return actData[sName] end

local function srchAct(tChAct) local ch = tChAct[1] local act = tChAct[2] local tChActData = getDataFile(ch) local actData = nil

if tChActData[ch] then actData = tChActData[ch][act]

while (actData and actData.alias) do			local aliasCh = actData.alias[1] or ch			local aliasAct = actData.alias[2] or act if (aliasCh == ch and aliasAct == act) then actData = nil else ch = aliasCh act = aliasAct tChActData = getDataFile(ch) if tChActData[ch] then actData = tChActData[ch][act] end end end end if actData then tChAct[1] = ch		tChAct[2] = act tChAct[3] = actData return true else return false end end

local function normalDisplay local tList = {}

for _, inAct in ipairs(tTasks) do		local tChAct = {inAct[1], inAct[2]} if (srchAct(tChAct)) then table.insert(tList, {tChAct[1], tChAct[2], tChAct[3]}) else table.insert(tList, {tChAct[1], tChAct[2], badAct}) end end return genOut(tList, true, nil, tArgs.event) end

local function characterPage return "Not Finished Yet\nCharacter Page Format\n" end

local function attractionPage return "Not Finished Yet\nAttraction Page Format\n" end

local function ECPage return "Not Finished Yet\nEvent Currency Page Format\n" end

local function animatedTasks return "Not Finished Yet\nAnimated Tasks Page Format\n" end

local function trophyTasks return "Not Finished Yet\nTrophy Tasks List\n" end

local function processArgs(frame) tArgs = util.getArgs(frame)

-- ensure blank table tTasks = {}

-- Loop over all numbered args to get Character/Activity Pairs for _, value in ipairs(tArgs) do		table.insert(tTasks, mw.text.split(value, "%s*%$%s*")) end end

function p.main(frame) processArgs(frame)

local tFunc = { normal = normalDisplay, character = characterPage, attraction = attractionPage, currency = ECPage, animated = animatedTasks, trophy = trophyTasks, }

local display = string.lower(tArgs.display or "normal")

if tFunc[display] then return tFunc[display] else return normalDisplay end

--	return "Not Finished Yet\nStill finalising data table structure\n" end

return p --