Module:Building

--[==[-- -- Lua script to get Building Information -- building: get Building data based on input parameters 1 = Building Name 2 = Enchantment Number 3 = Event Name / IP Short Name

Unknown is returned if building is not in data. --]==]

local p = {}

---[=[ For testing remove 1 '-' from start of line local attrData = mw.loadData('Module:Building/data') --[==[]=] local attrData = { -- The Little Mermaid -- ["Under the Sea"] = { ["A"] = "Jamming with a Hot Crustacean Band", ["R"] = { ["magic"] = {"4h", 12, 155, true}, ["tlm"] = {"4h", 23, 32, true}, ["wir"] = {"4h", 12, 50}, }   }, } --]==]

local EC = require("Module:EC").getEC local icon = require("Module:CharacterAvatar").getAvatar local npc = require("Module:NPC").getNPC local lte = require("Module:LTEvent").getLTE local util = require("Module:Utility")

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

local buildName = tArgs[1] or "" local enchLvl = tArgs[2] or "" local event = tArgs[3] or ""

buildName = buildName:gsub("^%s*(.-)%s*$", "%1") or ''

if buildName == "" then buildName = mw.title.getCurrentTitle.text else buildName = mw.text.decode(buildName, false) end enchLvl = enchLvl:upper:gsub("^%s*(.-)%s*$", "%1") or '' event = event:lower:gsub("^%s*(.-)%s*$", "%1") or ''

local outType = "D"

if enchLvl:match("^[ACRD]$") then outType = enchLvl enchLvl = "" end

enchLvl = enchLvl:gsub("[^0-5]", "")

local data = {}

if attrData[buildName] then data = attrData[buildName] else data = { ["A"] = "?", ["R"] = { ["magic"] = {"?h", "?", "?"}, }	   }	    buildName = "Unknown" end

local reward = ""

if event ~= "" and data["R"][event] then reward = event else reward = "magic" -- current event (no magic entry yet) -- pick the first reward key (should be for current event) if not data["R"]["magic"] then for k, v in pairs(data["R"]) do				reward = k				break end end end

local tFunc = { -- Activity ["A"] = function return data["A"] end, -- Collection Time ["C"] = function local retText = "" local space = ""

if event ~= "" then for k, v in pairs(data["R"]) do							if k ~= "magic" then local tRow = { space, v[1], "", "",									" (", lte({k, nil, "K"}), " Event) " }								retText = retText .. table.concat(tRow) space = " " end end if space == "" then retText = data["R"][reward][1] end else retText = data["R"][reward][1] end return retText end, -- Rewards only ["R"] = function local retText = "" local space = ""

if event ~= "" then for k, v in pairs(data["R"]) do							if k ~= "magic" then local tRow = { space, EC({"XP"}), v[2], ", ", EC({k}), v[3], "", "",									" (", lte({k, nil, "K"}), " Event) " }								if v[4] then tRow[7] = ", " tRow[8] = npc({"Gold Trophies", nil, nil, nil, k}) end retText = retText .. table.concat(tRow) space = " " end end if space == "" then if data["R"][reward][1] ~= "" then local tRow = { "", EC({"XP"}), data["R"][reward][2], ", ", EC({reward}), data["R"][reward][3], }								retText = retText .. table.concat(tRow) end end else if data["R"][reward][1] ~= "" then local tRow = { "", EC({"XP"}), data["R"][reward][2], ", ", EC({reward}), data["R"][reward][3], "", "",							}							if data["R"][reward][4] then tRow[7] = ", " tRow[8] = npc({"Gold Trophies", "G"}) end retText = retText .. table.concat(tRow) end end return retText end, -- Default (token rewards table row) ["D"] = function local tRet = {"|-\n| style=\"text-align: center;\"|", "", "\n|", "", "",									"", ": ", "", "", "", "", "\n|\n|", "", "\n| colspan=\"2\" nowrap|", "", "", ", ", "", "", "",									""					}					tRet[ 2] = icon({"Kingdom", event or ""}) tRet[ 6] = buildName tRet[ 8] = data["A"] if data["R"][reward][1] ~= "" then tRet[13] = data["R"][reward][1] tRet[15] = EC({"XP"}) tRet[16] = data["R"][reward][2] tRet[18] = EC({reward}) tRet[19] = data["R"][reward][3] else tRet[17] = "" end if data["R"][reward][4] and event then tRet[20] = ", " tRet[21] = npc({"Gold Trophies", nil, nil, nil, event}) elseif data["R"][reward][4] then tRet[20] = ", " tRet[21] = npc({"Gold Trophies", "G"}) end if enchLvl ~= "" then tRet[ 9] = " ''* Enchantment Level " tRet[10] = tostring(enchLvl) tRet[11] = "'' " end return table.concat(tRet) end, }	return tFunc[outType] end

function p.getTrophies(frame) local tRet = {} local tAtt = {} local tPrem = {} local attractions = {} local reward = "" for item, data in pairs(attrData) do		if not data["R"]["magic"] then for k, v in pairs(data["R"]) do				reward = k				break end else reward = "magic" end if data["R"][reward][4] then local durNumb, durHMS = string.match(data["R"][reward][1], "^([%d%?]+)([hms])$") local durNumb = tonumber(durNumb) if durHMS == "h" then durNumb = durNumb * 3600 elseif durHMS == "m" then durNumb = durNumb * 60 end table.insert(attractions, {durNumb, data, item}) end end table.sort(attractions, function(a,b) return a[1] < b[1] end) for att, item in pairs(attractions) do		if not item[2]["R"]["magic"] then for k, v in pairs(item[2]["R"]) do				reward = k				break end else reward = "magic" end tRet = {"|-\n| style=\"text-align: center;\"|", "", "\n|", "", "",				"", ": ", "", "", "", "", "\n|\n|", "", "\n| colspan=\"2\" nowrap|", "", "", ", ", "", "", "\n" }

tRet[ 2] = icon({"Kingdom"}) tRet[ 6] = item[3] tRet[ 8] = item[2]["A"] tRet[13] = item[2]["R"][reward][1] tRet[15] = EC({"XP"}) tRet[16] = item[2]["R"][reward][2] tRet[18] = EC({reward}) tRet[19] = item[2]["R"][reward][3] local collectionData = mw.loadData( 'Module:ItemCollection/data' ) if collectionData["Items"][item[3]][3] and collectionData["Items"][item[3]][3] == true then table.insert(tPrem, table.concat(tRet)) else table.insert(tAtt, table.concat(tRet)) end end table.insert(tAtt, '|-\n! colspan="5"|Premium\n') table.insert(tAtt, table.concat(tPrem)) return table.concat(tAtt) end

return p