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 = { ["Star Wars"] = { ["A"] = "500", ["R"] = { ["magic"] = {"250", 5, "500", "Luke Skywalker,3$Leia Organa,2$Leia Organa,3$Chewbacca,2$Chewbacca,3"}, ["sw"] = {"450", 5, "", E=1}, ["sw2"] = {"450", 5, "", E=2}, ["sw3"] = {"450", 5, "", E=3}, },	}, } --]==]

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 eventinfo = {}

for k, v in pairs(data["R"]) do		if k ~= "magic" then table.insert(eventinfo, {(v["E"] or 1), k, v}) end end

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

for _, data in pairs(eventinfo) do VL.vardefine("ltename" .. data[1], lte({data[2], nil, "K"})) VL.vardefine("eventrewards" .. data[1], (EC({data[2]}) .. data[3][1])) VL.vardefine("eventchancerewards" .. data[1], (EC({"Gems"}) .. data[3][2] .. " " .. EC({data[2]}) .. data[3][3] .. " " .. TOK({(data[3][4] or ""), "I"}))) end

return "" end

return p