Module:Float

--[==[-- -- Lua script to get Float Information -- float: get Float data based on input parameters 1 = Float Name 3 = Event Name / IP Short Name

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

local p = {}

---[=[ For testing remove 1 '-' from start of line local floatData = mw.loadData('Module:Float/data') --[==[]=] local floatData = { ["The Little Mermaid"] = { ["A"] = "500", ["R"] = { ["magic"] = {"250", 5, "500", "IP-TLM$Sebastian,2$Scuttle,2$King Triton,2$Ursula,2"}, ["tlm"] = {"450", 5, ""}, }	}, } --]==]

local EC = require("Module:EC").getEC local TOK = require("Module:CharacterToken").getToken local lte = require("Module:LTEvent").getLTE local util = require("Module:Utility")

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

local floatName = tArgs[1] or "" local event = tArgs[2] or "" local outType = tArgs[3] or "D"

floatName = floatName:gsub("^%s*(.-)%s*$", "%1") or '' if floatName == "" then floatName = mw.title.getCurrentTitle.text else floatName = mw.text.decode(floatName, false) end floatName = floatName:gsub("%s*Float$", "")

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

if not outType:match("^[D]$") then outType = "" end

local data = {}

if floatData[floatName] then data = floatData[floatName] else data = { ["A"] = "?", ["R"] = { ["magic"] = {"?", "?", "?", "?"}, }		}		floatName = "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 = { -- Default (token rewards table row) ["D"] = function local tRet = {"|-\n| style=\"text-align: center;\"|", "", "\n|", "", "",									"", "", "", "", "", "", "\n|\n| nowrap|", "", "\n| nowrap|", "", "", "", ""					}					tRet[ 2] = " " tRet[ 6] = floatName tRet[ 7] = " Float" if data["R"][reward][1] ~= "" then tRet[13] = "2h (+ 6h)" tRet[15] = EC({reward}) tRet[16] = data["R"][reward][1] if event == "" and data["R"][reward][4] then tRet[17] = "\n| nowrap|" tRet[18] = TOK({data["R"][reward][4], "", "B"}) end else tRet[17] = "" tRet[23] = "" end return table.concat(tRet) end, }	return tFunc[outType] end

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

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

fName = fName:gsub("%s*Float$", "") VL.vardefine("file", ("pf-" .. mw.ustring.gsub(mw.ustring.lower(fName), "[':\"%,%.]", "") .. ".png"))

local data = {}

if floatData[fName] then data = floatData[fName] else data = { ["A"] = "?", ["R"] = { ["magic"] = {"?", "?", "?", "?"}, }		}	end

VL.vardefine("assigncost", (EC({"Magic"}) .. data["A"]))

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

VL.vardefine("rewards")

VL.vardefine("rewards", (EC({reward}) .. data["R"][reward][1])) VL.vardefine("chancerewards", (EC({"Gems"}) .. data["R"][reward][2] .. " " .. EC({reward}) .. data["R"][reward][3] .. " " .. TOK({(data["R"][reward][4] or ""), "I"})))

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

for k, v in pairs(data["R"]) do		if k ~= "magic" then local tRew = {	space, EC({k}), v[1], " (", lte({k, nil, "K"}), " Event) " }			eventrewards = eventrewards .. table.concat(tRew) local tRewC = {	space, " ", lte({k, nil, "K"}), " Event: ", EC({"Gems"}), v[2], " ", EC({k}), v[3], " ", TOK({(v[4] or ""), "I"}), " " }			eventchancerewards = eventchancerewards .. table.concat(tRewC) space = " " end end VL.vardefine("eventrewards", eventrewards) VL.vardefine("eventchancerewards", eventchancerewards)

return "" end

return p