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"] = { ["after"] = {"250", 5, "500", "Luke Skywalker,3$Leia Organa,2$Leia Organa,3$Chewbacca,2$Chewbacca,3"}, ["sw"] = {"450", 5, "750", "Luke Skywalker,3$Leia Organa,2$Leia Organa,3$Chewbacca,2$Chewbacca,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")

local function unavailable(tokens, type, pagename, event) if not tokens or tokens == "" then return "" end for _, k in ipairs(tokens) do		if pagename == TOK({k, "T"}) then if type == "S" then return ' class="dmk-act-unavailable"' elseif type == "T" then return " '* Unavailable during " .. LTE({event, "N", "S"}) .. "' "			end end end return "" end

local function eventchanges(afterevent, duringevent) if afterevent == duringevent then return nil end if not (type(afterevent) == "table" and type(duringevent) == "table") then return {from = afterevent, to = duringevent} end

local result = {} for k, v in pairs(afterevent) do		result[k] = eventchanges(v, duringevent[k]) end for k, v in pairs(duringevent) do		if afterevent[k] == nil then result[k] = eventchanges(nil, v)		end end

return next(result) and result end

function oneFloat(floatName, event, outType, pagename) 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 outType == "ME" and not pagename:match(" Token$") then outType = "ME" else outType = "D" end

local data = {}

if floatData[floatName] then data = floatData[floatName] else data = { ["A"] = "?", ["R"] = { ["magic"] = {"?", "?", "?", "?"}, }		}		floatName = "?" 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" and not v["E"] 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|', floatName, ' Float', '', "", '\n|\n| nowrap style="text-align: center;" data-sort-value="9000"|', "2h (± 8h)", '\n| nowrap style="text-align: center;"|', EC({reward}), "?", "", ""					}

if data["R"][reward][1] ~= "?" then tRet[ 4] = ""

if oldtime[reward] then tRet[12] = "2h (+ 6h)" end

tRet[15] = data["R"][reward][1]

if event == "" and data["R"]["after"] and data["R"][reward][4] then tRet[16] = "\n| nowrap style=\"text-align: center;\"|"

if data["R"]["after"][4] ~= data["R"][reward][4] then local alltokens = {} alltokens["After"] = mw.text.split(data["R"]["after"][4], "%s*%$%s*") alltokens["During"] = mw.text.split(data["R"][reward][4], "%s*%$%s*")

local unavtokens = {} for _, data in pairs(eventchanges(alltokens["After"], alltokens["During"])) do									for y, v in pairs(data) do										if y == "from" then table.insert(unavtokens, v) end end end

tRet[ 2] = unavailable(unavtokens, "S", pagename, reward) tRet[10] = unavailable(unavtokens, "T", pagename, reward) end

tRet[17] = TOK({data["R"][reward][4], nil, "B"}) elseif event == "" and data["R"][reward][4] then tRet[16] = "\n| nowrap style=\"text-align: center;\"|" tRet[17] = TOK({data["R"][reward][4], nil, "B"}) end else tRet[ 4] = "" tRet[ 8] = "|Unknown Float" end

return table.concat(tRet) end, -- Mini Events (token rewards table row) ["ME"] = function local tRet = {	'|-', "", '\n| style="text-align: center;"| ', "", ' ', '\n|', floatName, ' Float', '', "", '\n|\n| nowrap style="text-align: center;" data-sort-value="9000"|', "2h (± 8h)" }

if data["R"][reward][1] ~= "?" then tRet[ 4] = ""

if oldtime[reward] then tRet[12] = "2h (+ 6h)" end else tRet[ 4] = "" tRet[ 8] = "|Unknown Float" end

return table.concat(tRet) end, }

return tFunc[outType] end

function p.float(frame) local tArgs = util.getArgs(frame) local pagename = tArgs["P"] or mw.title.getCurrentTitle.text or "" local tOut = {}

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

if floatName ~= "" then for float in mw.text.gsplit(floatName, "%s*$%s*") do			table.insert(tOut, oneFloat(float, event, outType, pagename)) end elseif outType ~= "" then local floats = {} for item, data in pairs(floatData) do			local reward = (event~="" and event or "magic")

if (event == "" or event == "T") and not data["R"][reward] then for k, v in pairs(data["R"]) do					if k ~= "after" then reward = k						break end end end

if data["R"][reward] then if outType == "T" then for k, tokens in pairs(data["R"][reward]) do						if tonumber(k) and k > 3 then for token in mw.text.gsplit(tokens, "%s*$%s*") do								if pagename == TOK({token, "T"}) then table.insert(floats, item) end end end end elseif outType == "E" then table.insert(floats, item) end end end table.sort(floats, function(a,b) return a < b end) for _, item in pairs(floats) do			table.insert(tOut, oneFloat(item, event, "D")) end end

return table.concat(tOut, "\n") 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" and not v["E"] 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", "B"}))) 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", "B"}))) 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