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 = { ["Under the Sea"] = { ["W"] = true, ["A"] = "Jamming with a Hot Crustacean Band", ["S"] = "12x12", ["R"] = { ["magic"] = {"4h", 12, 155, "IP-TLM", "Sebastian,3", "King triton,2", "Ariel,3", "Ursula,2", true}, ["tlm"] = {"4h", 23, 32, "", "", "", "", "", true}, ["wir"] = {"4h", 12, 50, "IP-TLM", "Sebastian,2", "King triton,3", "Ariel,2", "Ursula,3"}, }   }, } --]==]

local EC = require("Module:EC").getEC local TOK = require("Module:CharacterToken").getToken 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("^[DM]$") then outType = enchLvl enchLvl = "" end

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

local data = {}

if attrData[buildName] then data = attrData[buildName] else data = { ["S"] = "?x?", ["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 = { -- Magic Reward only ["M"] = function if data["R"][reward][1] ~= "" then return data["R"][reward][3] end end, -- Default (token rewards table row) ["D"] = function local tRet = {"|-\n| style=\"text-align: center;\"|", "", "\n|", "", ": ", "", "", "", "", "\n|", "", "\n|", "", "\n| nowrap|", "", "", ", ", "", "", "", 							"", "", ""							}					local buildType = "Bc" if data["S"] then buildType = "Ba" end

bData = data["R"][reward]

tRet[ 2] = " " tRet[ 4] = buildName tRet[ 6] = data["A"] if enchLvl ~= "" then tRet[ 7] = " ''* Enchantment Level " tRet[ 8] = tostring(enchLvl) tRet[ 9] = "'' " end if data["W"] then tRet[11] = npc({"Happiness"}) end if bData[1] ~= "" then tRet[13] = bData[1] tRet[15] = EC({"XP"}) tRet[16] = bData[2] tRet[18] = EC({reward}) tRet[19] = bData[3] else tRet[17] = "" end if bData[9] then tRet[20] = ", " if reward ~= "magic" then tRet[21] = npc({"Gold Trophies", nil, nil, nil, event}) else tRet[21] = npc({"Gold Trophies", "G"}) end end if event == "" and bData[4] and bData[4] ~= "" then tRet[22] = "\n| nowrap|" local tokens = bData[4] if enchLvl == "1" then tokens = bData[4] .. "$" .. (bData[5] or "") elseif enchLvl == "2" then tokens = bData[4] .. "$" .. (bData[5] or "") .. "$" .. (bData[6] or "") elseif enchLvl == "3" then tokens = bData[4] .. "$" .. (bData[5] or "") .. "$" .. (bData[6] or "") .. "$" .. (bData[7] or "") elseif enchLvl == "4" or enchLvl == "5" then tokens = bData[4] .. "$" .. (bData[5] or "") .. "$" .. (bData[6] or "") .. "$" .. (bData[7] or "") .. "$" .. (bData[8] or "") end tRet[23] = TOK({tokens, "", "B"}) end return table.concat(tRet) end, }	return tFunc[outType] end

function p.getBuildinginfo(frame) local tArgs = util.getArgs(frame) local coll = require("Module:ItemCollection") local buildName = tArgs[1] or mw.title.getCurrentTitle.text buildName = buildName:gsub("^%s*(.-)%s*$", "%1") or '' local VL = mw.ext.VariablesLua

if tArgs[1] then VL.vardefine("premium", coll.getPremium({buildName})) VL.vardefine("limited", coll.getPremium({buildName})) else VL.vardefine("premium", coll.getPremium({})) VL.vardefine("limited", coll.getPremium({})) end

VL.vardefine("collection", coll.getCollection({buildName, "T"}))

local data = {}

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

local buildType = "Bc-" if data["S"] then buildType = "Ba-" end VL.vardefine("file", (buildType .. mw.ustring.gsub(mw.ustring.lower(buildName), "[':\"%,%.]", "") .. ".png"))

local activity = data["A"] if data["W"] then activity = npc({"Happiness"}) .. " " .. activity end VL.vardefine("activity", activity)

VL.vardefine("size", (data["S"] or "5x5"))

local reward = "magic" if not data["R"]["magic"] then for k, v in pairs(data["R"]) do			reward = k			break end end

local time = "" local rewards = "" local chancerewards = ""

if data["R"][reward][1] ~= "" then time = data["R"][reward][1] rewards = EC({"XP"}) .. data["R"][reward][2] .. ", " .. EC({reward}) .. data["R"][reward][3] if data["R"][reward][9] then rewards = rewards .. ", " .. npc({"Gold Trophies", "G"}) end

local tokens = (data["R"][reward][4] or "") .. "$" .. (data["R"][reward][5] or "") .. "$" .. (data["R"][reward][6] or "") .. "$" .. (data["R"][reward][7] or "") .. "$" .. (data["R"][reward][8] or "") chancerewards = TOK({tokens, "I"}) end

VL.vardefine("time", time) VL.vardefine("rewards", rewards) VL.vardefine("chancerewards", chancerewards)

local eventtime = "" local eventrewards = "" local eventchancerewards = "" local space = ""

for k, v in pairs(data["R"]) do		if k ~= "magic" then local tTime = {	space, v[1], " (", lte({k, nil, "K"}), " Event) " }			eventtime = eventtime .. table.concat(tTime)

local tRew = {	space, EC({"XP"}), v[2], ", ", EC({k}), v[3], "", "",					" (", lte({k, nil, "K"}), " Event) " }			if v[9] then tRew[7] = ", " tRew[8] = npc({"Gold Trophies", nil, nil, nil, k}) end eventrewards = eventrewards .. table.concat(tRew)

if v[4] ~= "" then local tokens = v[4] .. "$" .. (v[5] or "") .. "$" .. (v[6] or "") .. "$" .. (v[7] or "") .. "$" .. (v[8] or "")			local tRewC = {	space, " ", lte({k, nil, "K"}), " Event: ", TOK({tokens, "I"}), " " }				eventchancerewards = eventchancerewards .. table.concat(tRewC) end space = " " end end if space == "" then eventtime = time eventrewards = rewards end

VL.vardefine("eventtime", eventtime) VL.vardefine("eventrewards", eventrewards) VL.vardefine("eventchancerewards", eventchancerewards)

return "" end

return p