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 oldtime = {["ti"] = true, ["frozen"] = true, ["frozen2"] = true, ["nbc"] = true, ["mulan"] = true, ["batb"] = true, ["tlk"] = true, ["aladdin"] = true, ["aiw"] = true, ["aladdin"] = true, ["swatsd"] = true, ["wtp"] = true, ["l&s"] = true, ["bh6"] = true, ["tlm"] = true, ["wir"] = true, ["tpatf"] = true, ["moana"] = true, ["fn"] = true, ["coco"] = true, ["sw"] = true, ["sw2"] = true, ["sw3"] = true, ["onward"] = true, ["hercules"] = true, ["brave"] = true, ["ratld"] = true, ["luca"] = true, ["101d"] = true, ["pinocchio"] = true}

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				if k ~= "after" then reward = k					break end end end end

local tFunc = { -- Default (token rewards table row) ["D"] = function local tRet = {"|-\n| style=\"text-align: center;\"|", "", "\n|", "", "",									"", "", "", "", "", "", '\n|\n| nowrap data-sort-value="9000"|', "", "\n| nowrap|", "", "", "", ""					}					tRet[ 2] = " " tRet[ 6] = floatName tRet[ 7] = " Float" if data["R"][reward][1] ~= "" then if oldtime[reward] then tRet[13] = "2h (+ 6h)" else tRet[13] = "2h (± 8h)" end 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 fName = tArgs[1] or mw.title.getCurrentTitle.text fName = fName:gsub("%s*Float$", ""):gsub("^%s*(.-)%s*$", "%1") or '' local VL = mw.ext.VariablesLua

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			if k ~= "after" then reward = k				VL.vardefine("ltename", lte({k, nil, "K"})) break end end end

if data["R"][reward] then VL.vardefine("rewards")

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

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			if reward ~= data[2] then 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"}))) if oldtime[data[2]] then VL.vardefine("eventtime" .. data[1], "2h + 6h (Cooldown)") else VL.vardefine("eventtime" .. data[1], "2h ± 8h (Cooldown)") end end end end

return "" end

return p