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 npcname = mw.title.getCurrentTitle.baseText

local function processArgs(frame) tArgs = util.getArgs(frame) if tArgs["P"] then npcname = tArgs["P"] 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 eNo = 1 end if num then if cat == "qn" then qn[num] = mw.text.split(value, "%s*%$%s*") 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 "?"), '=\n', ' \n', '===", (qstdata[1] or "?"), ' (', NPC({npcname}), (qstdata[2] or "?"), ') Spawn Rate: ', (qstdata[3] or "? every ? hours"), ' ===\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]

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="card old" style="text-align: center; line-height: normal; border-spacing: 0px; color: white; text-shadow: 2.2px 2.2px 2px #020596; display: inline-table; margin: 0 3px 10px 0;"', '\n| style="width: 210px; height: 65px; background-size: cover; background-position: top; padding: 0 9px 0 4px; vertical-align: bottom;"|', ICON({char[1], nil, 75}), '\n|-\n| style="width: 210px; height: 17px; background-size: cover; background-position: 0 -65px; padding: 0 9px 0 4px;"|', (" " .. char[1] .. " "), '\n|-\n| style="width: 210px; height: 40px; background-size: cover; background-position: 0 -82px; padding: 0 9px 0 4px;"|', char[2], (char[3]~="" and " | " .. TOK({(npcname .. ",1 #" .. char[3] .. "$" .. npcname .. ",2 #" .. char[4])}) or ""), '\n|-\n| style="width: 210px; height: 70px; background-size: cover; background-position: 0 -240px; padding: 0 9px 0 4px; vertical-align: top;"|', ' ', '\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		if qn[qNo] then table.insert(allTables, npcTable(qn[qNo], chD)) end end

return table.concat(allTables) end

return p