Module:NPCTables

-- Lua script to get NPC Tables --

local p = {}

local util = require("Module:Utility") local storylineData = mw.loadData( 'Module:Storyline/data' ) local EC = require("Module:EC").getEC local TOK = require("Module:CharacterToken").getToken local NPC = require("Module:NPC").getNPC local ICON = require("Module:CharacterAvatar").getAvatar

local tArgs = {} local ch   = {} local qn   = {} local tok  = {} local npcname = mw.title.getCurrentTitle.baseText

local function processArgs(frame) tArgs = util.getArgs(frame) if tArgs["npcname"] then npcname = tArgs["npcname"] end

for arg, value in pairs(tArgs) do		local cat, q, n = tostring(arg):match('^(%a+)([1-9]-)_?([1-9]%d*)$') local num = tonumber(n) local qNo = tonumber(q) if not qNo then qNo = 1 end if num then if cat == "qn" then qn[num] = mw.text.split(value, "%s*%$%s*") elseif cat == "tok" then tok[num] = value elseif cat == "ch" then if not ch[qNo] then ch[qNo] = {} end ch[qNo][num] = mw.text.split(value, "%s*%$%s*") end end end end

local function npcTable(qstdata, chdata) local tOut = {'|-|', (qstdata[1] or "Character Tasks"), '=\n', ' \n', , , , , , , , , , 			}

if qstdata[1] then tOut[5 ] = '==="		tOut[8 ] = qstdata[1]		tOut[9 ] = ' ('		tOut[10] = NPC({npcname})		tOut[11] = (qstdata[2] or "?")		tOut[12] = ') Spawn Rate: ' tOut[13] = (qstdata[3] or "? every ? hours") tOut[14] = ' ===\n' if tOut[8]:match("^.+%#Part %d+$") then tOut[8] = mw.ustring.gsub(tOut[8], "#Part ", ", Pt. ") end local i = 1 local tIn = mw.text.split(tOut[8], "%s*%-%s*") for idx = 0, #tIn do i = idx end if tIn[i] and storylineData["Colors"][tIn[i]:lower] then tOut[8] = mw.ustring.gsub(tOut[8], "-" .. tIn[i]:upper .. "$", "") end if tOut[8]:match("^.+%-%d+$") then tOut[8] = tOut[8]:match("(.+)%-%d+$") end tOut[2] = tOut[8] end

for _, char in ipairs(chdata) do		local rewards = "" local space = ""

for idx = 5, #char do			if char[idx]:match("^EC") then rewards = rewards .. space .. EC({char[idx]}) space = ", " else rewards = rewards .. space .. TOK({char[idx], nil, "B"}) space = ", " end end

table.insert(tOut, table.concat({'{| class="npccard"', '\n| class="Part_1"|', ICON({char[1], nil, 75}), '\n|-\n| class="Part_2"|', (" " .. char[1] .. " "), '\n|-\n| class="Part_3"|', (char[2] or "?h"), (char[3]~="" and " | " .. TOK({(npcname .. ",1 #" .. (char[3] or "1") .. "$" .. npcname .. ",2 #" .. (char[4] or "1"))}) or ""), '\n|-\n| class="Part_4"|', ' ', '\n|}\n'})) end

if tok[1] then table.insert(tOut, table.concat({'If you want to see the different conflicts for each activity, go directly to the token page \n', '{| style="width:100%;"\n', '| style="width:50%; vertical-align: top;"|\n', '==', TOK({(npcname .. ",1"), "I"}), '==\n', '{| class="article-table act" style="width: 100%;"\n', '! width="1" style="padding: 3px"|Character\n', '! width="100%"|Activity\n', '! style="text-align: center;" width="1" nowrap|+\n', '! width="5%"|Time\n', (tok[1] or ""), '\n|}\n| style="width:50%; vertical-align: top;"|\n', '==', TOK({(npcname .. ",2"), "I"}), '==\n', '{| class="article-table act" style="width: 100%;"\n', '! width="1" style="padding: 3px"|Character\n', '! width="100%"|Activity\n', '! style="text-align: center;" width="1" nowrap|+\n', '! width="5%"|Time\n', (tok[2] or ""), '\n|}\n|}\n'})) end

table.insert(tOut, ' \n')

return table.concat(tOut) end

function p.getTables(frame) processArgs(frame)

local allTables = {}

for qNo, chD in ipairs(ch) do		table.insert(allTables, npcTable((qn[qNo] or {}), chD)) end

return table.concat(allTables) end

return p