Module:NPC

--[=[ Lua script to get NPC Detail

getNPC: get generic NPC infomation Parameters: 1: NPC = NPC name 2: Include Name/Text Link (Optional) N = NPC Name with image F = File Name E = NPC Name only L = NPC Name Link only D = Descriptive/Display Name (Text Only) G = Curent Gold Trophies Icon T = Text Only NPC Name A = Alternate Text (Parameter 3) 3: Alternate Text (Optional) 4: Size in pixels (Optional) default 25 5: Event Version (Optional)

-- The list of available NPCs is kept in the module data -- Unknown is returned if NPC is not in data.

getNPCList: get a List of NPC in horizontal format Parameters: None

getFirstUse: get the fixed format text about first LTE using the NPC Parameters: 1:	NPC Name --]=]

local p = {}

local npcData = mw.loadData( 'Module:NPC/data' ) local util = require('Module:Utility')

function p.getNPC(frame) local tArgs = util.getArgs(frame) local npcName = tArgs[1] or "" local inclName = tArgs[2] or "" local altText = tArgs[3] or "" local size    = tArgs[4] or "" local version = string.lower(tArgs[5] or "")

local keyName = string.lower(npcName)

if inclName ~= "" then if not inclName:match("^[NEATGDLF]$") then inclName = "N" end end

if size == "" then size = "25" end

local outText = "" local tFile = "work_in_progress" local tSize = ".png|x" .. size .. "px|" local tDisp = npcName local tLink = "Work In Progress"

if npcData[keyName] then local npcItem = npcData[keyName]

if npcItem["A"] and npcItem["A"][1] and npcData[npcItem["A"][1]] then if not version or version == "" then version = npcItem["A"][2] or "" end npcItem = npcData[npcItem["A"][1]] end if npcItem["N"] then tLink = npcItem["N"] tDisp = tLink end if npcItem["D"] then tDisp = npcItem["D"] end if npcItem["F"] then tDisp = npcItem["E"] end

if npcItem["I"] then tFile = npcItem["I"] end

if version ~= "" and npcItem["E"] and npcItem["E"][version] then local text = "" text = npcItem["E"][version][1] if inclName == "F" then if npcItem["E"][version][4] and npcItem["E"][version][4] == true then tDisp = string.gsub(text, "%%(%d)", "") else tDisp = ":Category:" .. string.gsub(text, "%%(%d)", "") .. "|" .. string.gsub(text, "%%(%d)", "") end elseif text and text ~= "" then tDisp = string.gsub(text, "%%(%d)",                       function(v)                            return npcItem["V"..v] or ""                        end                    ) end

text = npcItem["E"][version][2] if text and text ~= "" then tFile = string.gsub(text, "%%(%d)",                       function(v)                            return npcItem["V"..v] or ""                        end                    ) end

text = npcItem["E"][version][3] if text and text ~= "" then tLink = string.gsub(text, "%%(%d)",                       function(v)                            return npcItem["V"..v] or ""                        end                    ) end end end

local nameLink = "" local bracket = ""

if inclName == "N" then nameLink = "" .. tLink .. " ("       bracket = ")" elseif inclName == "L" then nameLink = "" .. tDisp       end        nameLink = nameLink .. "" elseif inclName == "A" then nameLink = "" .. altText       end        nameLink = nameLink .. " ("        bracket = ")" elseif inclName == "E" then nameLink = tLink elseif inclName == "T" then nameLink = tLink .. " ("       bracket = ")" elseif inclName == "D" then nameLink = tDisp .. " ("       bracket = ")" elseif inclName == "G" then tFile = npcData[keyName]["C"] elseif inclName == "F" then return tFile .. ".png|" .. tDisp .. " themed trophy\n" end

if inclName ~= "L" then if inclName ~= "E" then nameLink = nameLink .. ""       .. tFile .. tSize .. tDisp        .. "" .. bracket end end return nameLink end

-- return all NPC in horizontal format

function p.getNPCList local tIndex = {}

for _, v in pairs(npcData) do       if not v["X"] then -- include lower case name for sort comparison -- so that ALL CAPS names sort properly table.insert(tIndex, {string.lower(v["N"]), v["N"]}) end end

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

local outText = "" local sDot = ""

for _, name in ipairs(tIndex) do       outText = outText .. sDot .. "" .. name[2] .. ""

sDot = " · " end

return outText end

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

local npcName = tArgs[1] or "" npcName = npcName:lower:gsub("^%s*(.-)%s*$", "%1") or ''

local outText = {}

if npcData[npcName] then local npcItem = npcData[npcName] -- check for alias if npcItem["A"] and npcItem["A"][1] and npcData[npcItem["A"][1]] then npcItem = npcData[npcItem["A"][1]] end -- assemble output string if LTE name present if npcData[npcName]["L"] then outText = { "* " or "",			   	npcItem["D"] or "",			    	" first appeared during the ", require("Module:LTEvent").getLTE({npcItem["L"], "N", "D"}), ".\n", }		end end return table.concat(outText) end

return p

-- --