Module:Building

--[[ LUA script to get Building Template for Token Pages

getbuildToken: get Building Template based on input parameters 1 = Building Name 2 = Enchantment Number 3 = Event Name / IP Short Name

Unknown Building is returned if Building is not in data. --]]

local p = {}

local buildData = mw.loadData('Module:TokenBuilding/data') local currency = require("Module:EC").getEC local icon = require("Module:CharacterAvatar").getAvatar

function p.getBuilding(frame) local tArgs

if frame == mw.getCurrentFrame then fParent = frame:getParent tArgs = fParent.args

if (fParent.args[1]) then tArgs = fParent.args else tArgs = frame.args end else tArgs = frame end local bName = tArgs[1] or "Unknown Building" local eNumb = tArgs[2] local event = tArgs[3] bName = mw.ustring.gsub(mw.ustring.lower(bName),               "^%s*(.-)%s*$", "%1") or '' if event then event = mw.ustring.gsub(mw.ustring.lower(event),               "^%s*(.-)%s*$", "%1") or '' end local buildTemplate = "" for build in mw.text.gsplit(bName, "%s*%$%s*") do    	local cName = mw.ustring.match(build,                             "^([^,]-)%s*,%s*([%/%,%d%?%-]*)$") if not cName then cName = build end if buildData[bName] then local data 	= buildData[bName] local buildName 	= data["Name"] local buildActivity = data["Activity"] local buildTime 	= data["N"][1] local xpReward		= data["N"][2] local ecReward		= data["N"][3] if data["E"][4] == event then buildTime = data["E"][1] or "?h" xpReward = data["E"][2] or "?" ecReward = data["E"][3] or "?" eventName = data["E"][4] elseif data["E2"][4] == event then buildTime = data["E2"][1] or "?h" xpReward = data["E2"][2] or "?" ecReward = data["E2"][3] or "?" eventName = data["E2"][4] end buildTemplate = "|-\n|" .. "|"       		if event then buildTemplate = buildTemplate .. icon({"Kingdom", event}) else buildTemplate = buildTemplate .. icon({"Kingdom"}) end buildTemplate = buildTemplate .. "\n" .. "|"       				     .. buildName        				     .. ": " .. buildActivity if eNumb then buildTemplate = buildTemplate .. " ''* Enchantment Level " .. eNumb .. "'' "       		end buildTemplate = buildTemplate .. "\n" .. "|\n" .. "|"       				     .. buildTime .. "\n" .. "| nowrap|" .. currency({"XP"}) .. xpReward .. ", "       		if eventName then buildTemplate = buildTemplate .. currency({eventName}) else buildTemplate = buildTemplate .. currency({"Magic"}) end buildTemplate = buildTemplate .. ecReward else buildTemplate = "|-\n|" .. "|\n" .. "|?|Unknown Building: ?\n" .. "|\n" .. "|?h\n" .. "| nowrap|?, ?" end end return buildTemplate end

return p

-- --