Disney Magic Kingdoms Wiki

The Sword in the Stone Part 3 Update has arrived! ✨
Visit this page to learn all about what's coming up in Disney Magic Kingdoms!

READ MORE

Disney Magic Kingdoms Wiki
No edit summary
 
(83 intermediate revisions by 2 users not shown)
Line 15: Line 15:
   
 
---[=[ For testing remove 1 '-' from start of line
 
---[=[ For testing remove 1 '-' from start of line
local attrData = mw.loadData('Module:Building/data')
+
local buildData = mw.loadData('Module:Building/data')
 
--[==[]=]
 
--[==[]=]
local attrData = {
+
local buildData = {
-- The Little Mermaid --
 
 
["Under the Sea"] = {
 
["Under the Sea"] = {
  +
["W"] = true,
 
["A"] = "Jamming with a Hot Crustacean Band",
 
["A"] = "Jamming with a Hot Crustacean Band",
 
["R"] = {
 
["R"] = {
["magic"] = {"4h", 12, 155, true},
+
["magic"] = {"4h", 12, 155, "IP-TLM", "Sebastian,3", "King triton,2", "Ariel,3", "Ursula,2", T=true},
["tlm"] = {"4h", 23, 32, true},
+
["tlm"] = {"4h", 23, 32, "", "", "", "", "", true},
["wir"] = {"4h", 12, 50},
+
["wir"] = {"4h", 12, 50, "IP-TLM", "Sebastian,2", "King triton,3", "Ariel,2", "Ursula,3"},
 
}
 
}
 
},
 
},
Line 30: Line 30:
 
--]==]
 
--]==]
   
local COLL = require("Module:ItemCollection").getCollection
 
local TOK = require("Module:CharacterToken").getToken
 
local collectionData = mw.loadData( 'Module:ItemCollection/data' )
 
 
local EC = require("Module:EC").getEC
 
local EC = require("Module:EC").getEC
local icon = require("Module:CharacterAvatar").getAvatar
+
local TOK = require("Module:CharacterToken").getTokenDirect
local npc = require("Module:NPC").getNPC
+
local NPC = require("Module:NPC").getNPC
 
local lte = require("Module:LTEvent").getLTE
 
local lte = require("Module:LTEvent").getLTE
 
local util = require("Module:Utility")
 
local util = require("Module:Utility")
   
  +
function oneBuilding(buildName, enchLvl, event, outType, pagename)
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 ''
 
buildName = buildName:gsub("^%s*(.-)%s*$", "%1") or ''
  +
if buildName == "" then
 
if buildName == "" then
+
buildName = mw.title.getCurrentTitle().text
  +
else
buildName = mw.title.getCurrentTitle().text
 
  +
buildName = mw.text.decode(buildName, false)
else
 
  +
end
buildName = mw.text.decode(buildName, false)
 
  +
enchLvl = tostring(enchLvl) or 0
end
 
 
 
enchLvl = enchLvl:upper():gsub("^%s*(.-)%s*$", "%1") or ''
 
enchLvl = enchLvl:upper():gsub("^%s*(.-)%s*$", "%1") or ''
event = event:lower():gsub("^%s*(.-)%s*$", "%1") or ''
+
enchLvl = enchLvl:gsub("[^0-5]", "")
   
  +
event = event:lower():gsub("^%s*(.-)%s*$", "%1") or ''
local outType = "D"
 
   
if enchLvl:match("^[ACRD]$") then
+
if not outType:match("^[DRM]$") and outType ~= "ME" then
outType = enchLvl
+
outType = "D"
enchLvl = ""
 
 
end
 
end
   
  +
local data = {}
enchLvl = enchLvl:gsub("[^0-5]", "")
 
 
local data = {}
 
   
if attrData[buildName] then
+
if buildData[buildName] then
data = attrData[buildName]
+
data = buildData[buildName]
 
else
 
else
data = {
+
data = {
["A"] = "?",
+
["A"] = "?",
["R"] = {
+
["R"] = {
["magic"] = {"?h", "?", "?"},
+
["magic"] = {"?h", "?", "?"},
}
+
}
}
+
}
buildName = "Unknown"
+
buildName = "?"
 
end
 
end
   
Line 90: Line 77:
 
if not data["R"]["magic"] then
 
if not data["R"]["magic"] then
 
for k, v in pairs(data["R"]) do
 
for k, v in pairs(data["R"]) do
reward = k
+
if k ~= "after" then
break
+
reward = k
  +
break
  +
end
 
end
 
end
 
end
 
end
 
end
 
end
   
  +
bData = data["R"][reward]
local tFunc = {
 
-- Activity
 
["A"] = function ()
 
return data["A"]
 
end,
 
-- Collection Time
 
["C"] = function ()
 
local retText = ""
 
local space = ""
 
   
  +
local tFunc = {
if event ~= "" then
 
  +
-- Magic Reward only
for k, v in pairs(data["R"]) do
 
if k ~= "magic" then
+
["M"] = function ()
local tRow = {
+
if bData[1] ~= "" then
space,
+
return bData[3]
v[1],
 
"", "",
 
" <small>(", lte({k, nil, "K"}), " Event)</small>"
 
}
 
retText = retText .. table.concat(tRow)
 
space = "<br />"
 
end
 
end
 
if space == "" then
 
retText = data["R"][reward][1]
 
end
 
else
 
retText = data["R"][reward][1]
 
 
end
 
end
return retText
 
 
end,
 
end,
 
-- Rewards only
 
-- Rewards only
 
["R"] = function ()
 
["R"] = function ()
local retText = ""
+
if data["R"][reward][1] ~= "" then
  +
local tRet = {"<small>Rewards <small>(Every ", data["R"][reward][1], ")</small></small><br/>'''", "", "", "", EC({reward}), data["R"][reward][3], "", "",
local space = ""
 
  +
"'''"
 
if event ~= "" then
 
for k, v in pairs(data["R"]) do
 
if k ~= "magic" then
 
local tRow = {
 
space,
 
EC({"XP"}), v[2], ", ",
 
EC({k}), v[3],
 
"", "",
 
" <small>(", lte({k, nil, "K"}), " Event)</small>"
 
 
}
 
}
if v[4] then
+
if bData[2] ~= 0 then
tRow[7] = ", "
+
tRet[4] = EC({"XP"})
tRow[8] = npc({"Gold Trophies", nil, nil, nil, k})
+
tRet[5] = data["R"][reward][2]
end
+
tRet[6] = ", "
retText = retText .. table.concat(tRow)
 
space = "<br />"
 
end
 
 
end
 
end
if space == "" then
+
if data["R"][reward]["T"] and event == "" then
if data["R"][reward][1] ~= "" then
+
tRet[ 9] = ", "
local tRow = {
+
if reward ~= "magic" then
"", EC({"XP"}), data["R"][reward][2], ", ",
+
tRet[10] = NPC({"Gold Trophies", nil, nil, nil, reward})
  +
else
EC({reward}), data["R"][reward][3],
 
  +
tRet[10] = NPC({"Gold Trophies", "G"})
}
 
retText = retText .. table.concat(tRow)
 
 
end
 
end
 
end
 
end
  +
return table.concat(tRet)
 
else
 
else
if data["R"][reward][1] ~= "" then
+
return ""
local tRow = {
 
"", EC({"XP"}), data["R"][reward][2], ", ",
 
EC({reward}), data["R"][reward][3],
 
"", "",
 
}
 
if data["R"][reward][4] then
 
tRow[7] = ", "
 
tRow[8] = npc({"Gold Trophies", "G"})
 
end
 
retText = retText .. table.concat(tRow)
 
end
 
 
end
 
end
return retText
 
 
end,
 
end,
 
-- Default (token rewards table row)
 
-- Default (token rewards table row)
 
["D"] = function()
 
["D"] = function()
local tRet = {"|-\n| style=\"text-align: center;\"|", "", "\n|", "", "[[",
+
local tRet = {"|-\n| style=\"text-align: center;\"|", "", "", "", "",
"", "]]: ", "", "", "",
+
"\n|[[", "", "]]: ", "", "\n|",
"", "\n|\n|", "", "\n| colspan=\"2\" nowrap|", "",
+
"", '\n| style="text-align: center;" data-sort-value="', "", '"|', "",
"", ", ", "", "", "",
+
"\n| nowrap style=\"text-align: center;\"|", "", "", ", ", "",
""
+
"", "", "", "", ""
}
+
}
tRet[ 2] = icon({"Kingdom", event or ""})
+
local buildType = "Ba"
tRet[ 6] = buildName
+
if data[1] then buildType = "Bc" end
  +
tRet[ 8] = data["A"]
 
  +
tRet[ 2] = "<span id=\"dmk-icon-plain\">[[File:" .. buildType .. "-" .. mw.ustring.gsub(mw.ustring.lower(buildName), "[':\"%,%.*]", "") .. ".png|60x60px|" .. buildName .. "|link=" .. buildName .. "]]</span>"
if data["R"][reward][1] ~= "" then
 
  +
if enchLvl ~= "" and enchLvl ~= "0" then
tRet[13] = data["R"][reward][1]
 
tRet[15] = EC({"XP"})
+
tRet[ 3] = "<small><br />''Ench. Level "
tRet[16] = data["R"][reward][2]
+
tRet[ 4] = tostring(enchLvl)
tRet[18] = EC({reward})
+
tRet[ 5] = "''</small>"
  +
end
tRet[19] = data["R"][reward][3]
 
  +
tRet[ 7] = buildName
  +
tRet[ 9] = data["A"]
  +
if data["W"] then
  +
tRet[11] = NPC({"Wish Granter"})
  +
end
  +
if bData[1] ~= "" then
  +
local durNumb, durHMS = string.match(bData[1], "^([%d%?]+)([hms])$")
  +
local durNumb = tonumber(durNumb)
  +
if durNumb then
  +
if durHMS == "h" then
  +
durNumb = durNumb * 3600
  +
elseif durHMS == "m" then
  +
durNumb = durNumb * 60
  +
end
  +
else
  +
durNumb = 99900
  +
end
  +
tRet[13] = durNumb
  +
tRet[15] = bData[1]
  +
if bData[2] ~= 0 then
  +
tRet[17] = EC({"XP"})
  +
tRet[18] = bData[2]
  +
end
  +
tRet[20] = EC({reward})
  +
tRet[21] = bData[3]
 
else
 
else
tRet[17] = ""
+
tRet[19] = ""
 
end
 
end
if data["R"][reward][4] then
+
if bData["T"] and event == "" then
tRet[20] = ", "
+
tRet[22] = ", "
if event then
+
if reward ~= "magic" then
tRet[21] = npc({"Gold Trophies", nil, nil, nil, event})
+
tRet[23] = NPC({"Gold Trophies", nil, nil, nil, event})
 
else
 
else
tRet[21] = npc({"Gold Trophies", "G"})
+
tRet[23] = NPC({"Gold Trophies", "G"})
 
end
 
end
 
end
 
end
if enchLvl ~= "" then
+
if event == "" and ((bData[4] and bData[4] ~= "") or (bData[5] and bData[5] ~= "")) then
tRet[ 9] = "<small><br />''* Enchantment Level "
+
tRet[24] = "\n| nowrap style=\"text-align: center;\"|"
tRet[10] = tostring(enchLvl)
+
local tokens = (bData[4] or "")
tRet[11] = "''</small>"
+
if enchLvl == "1" then
  +
tokens = (bData[4] or "") .. "$" .. (bData[5] or "")
  +
elseif enchLvl == "2" then
  +
tokens = (bData[4] or "") .. "$" .. (bData[5] or "") .. "$" .. (bData[6] or "")
  +
elseif enchLvl == "3" then
  +
tokens = (bData[4] or "") .. "$" .. (bData[5] or "") .. "$" .. (bData[6] or "") .. "$" .. (bData[7] or "")
  +
elseif enchLvl == "4" or enchLvl == "5" then
  +
tokens = (bData[4] or "") .. "$" .. (bData[5] or "") .. "$" .. (bData[6] or "") .. "$" .. (bData[7] or "") .. "$" .. (bData[8] or "")
  +
end
  +
tRet[25] = TOK(tokens, "", "B")
  +
end
  +
return table.concat(tRet)
  +
end,
  +
-- Mini Event (token rewards table row)
  +
["ME"] = function()
  +
local tRet = {"|-\n| style=\"text-align: center;\"|", "", "", "", "",
  +
"\n|[[", "", "]]: ", "", "\n|",
  +
"", '\n| style="text-align: center;" data-sort-value="', "", '"|', ""
  +
}
  +
local buildType = "Ba"
  +
if data[1] then buildType = "Bc" end
  +
  +
tRet[ 2] = "<span id=\"dmk-icon-plain\">[[File:" .. buildType .. "-" .. mw.ustring.gsub(mw.ustring.lower(buildName), "[':\"%,%.*]", "") .. ".png|60x60px|" .. buildName .. "|link=" .. buildName .. "]]</span>"
  +
if enchLvl ~= "" and enchLvl ~= "0" then
  +
tRet[ 3] = "<small><br />''Ench. Level "
  +
tRet[ 4] = tostring(enchLvl)
  +
tRet[ 5] = "''</small>"
  +
end
  +
tRet[ 7] = buildName
  +
tRet[ 9] = data["A"]
  +
if data["W"] then
  +
tRet[11] = NPC({"Wish Granter"})
  +
end
  +
if bData[1] ~= "" then
  +
local durNumb, durHMS = string.match(bData[1], "^([%d%?]+)([hms])$")
  +
local durNumb = tonumber(durNumb)
  +
if durNumb then
  +
if durHMS == "h" then
  +
durNumb = durNumb * 3600
  +
elseif durHMS == "m" then
  +
durNumb = durNumb * 60
  +
end
  +
else
  +
durNumb = 99900
  +
end
  +
tRet[13] = durNumb
  +
tRet[15] = bData[1]
  +
else
  +
tRet[19] = ""
 
end
 
end
 
return table.concat(tRet)
 
return table.concat(tRet)
Line 214: Line 230:
 
end
 
end
   
function p.getTrophies(frame)
+
function p.building(frame)
local tRet = {}
+
local tArgs = util.getArgs(frame)
  +
local pagename = tArgs["P"] or mw.title.getCurrentTitle().text or ""
local tAtt = {}
 
local tPrem = {}
+
local tOut = {}
  +
local attractions = {}
 
local reward = ""
+
local buildName = tArgs[1] or ""
  +
local enchLvl = tArgs[2] or ""
 
  +
local event = tArgs[3] or ""
for item, data in pairs(attrData) do
 
  +
local outType = tArgs[4] or ""
if not data["R"]["magic"] then
 
  +
for k, v in pairs(data["R"]) do
 
  +
if buildName ~= "" then
reward = k
 
  +
for build in mw.text.gsplit(buildName, "%s*$%s*") do
break
 
  +
table.insert(tOut, oneBuilding(build, enchLvl, event, outType, pagename))
end
 
else
 
reward = "magic"
 
 
end
 
end
  +
elseif outType ~= "" then
  +
local buildings = {}
  +
for item, data in pairs(buildData) 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
  +
local buildType = (data[1] and "0" or "1")
  +
  +
local durNumb, durHMS = string.match(data["R"][reward][1], "^([%d%?]+)([hms])$")
  +
if not durNumb or durNumb == "?" then
  +
durNumb = 0
  +
else
  +
durNumb = tonumber(durNumb)
  +
if durHMS == "m" then durNumb = durNumb / 60 end
  +
end
 
 
if data["R"][reward][4] then
+
if (outType == "G" and data["R"][reward]["T"]) or (outType == "W" and data["W"]) then
  +
table.insert(buildings, {buildType, durNumb, item})
local durNumb, durHMS = string.match(data["R"][reward][1], "^([%d%?]+)([hms])$")
 
  +
elseif outType == "T" then
local durNumb = tonumber(durNumb)
 
  +
for k, tokens in pairs(data["R"][reward]) do
if durHMS == "h" then
 
  +
if tonumber(k) and k > 3 then
durNumb = durNumb * 3600
 
  +
for token in mw.text.gsplit(tokens, "%s*$%s*") do
elseif durHMS == "m" then
 
  +
if pagename == TOK(token, "T") then
durNumb = durNumb * 60
 
  +
table.insert(buildings, {buildType, durNumb, item, k-4})
end
 
  +
end
table.insert(attractions, {durNumb, data, item})
 
end
+
end
  +
end
  +
end
  +
elseif outType == "E" then
  +
table.insert(buildings, {buildType, durNumb, item})
  +
end
  +
end
  +
end
  +
table.sort(buildings, function(a,b)
  +
if a[1] == b[1] then
  +
if a[2] == b[2] then
  +
return a[3] < b[3]
  +
else
  +
return a[2] < b[2]
  +
end
  +
else
  +
return a[1] < b[1]
  +
end
  +
end)
  +
for _, item in pairs(buildings) do
  +
table.insert(tOut, oneBuilding(item[3], (item[4] or ""), event, "D"))
  +
end
 
end
 
end
  +
 
  +
return table.concat(tOut, "\n")
table.sort(attractions, function(a,b) return a[1] < b[1] end)
 
  +
end
 
  +
for att, item in pairs(attractions) do
 
  +
function p.getBuildinginfo(frame)
if not item[2]["R"]["magic"] then
 
  +
local tArgs = util.getArgs(frame)
for k, v in pairs(item[2]["R"]) do
 
  +
  +
local buildName = tArgs[1] or mw.title.getCurrentTitle().text
  +
buildName = buildName:gsub("^%s*(.-)%s*$", "%1") or ''
  +
  +
local VL = mw.ext.VariablesLua
  +
local data = {}
  +
  +
if buildData[buildName] then
  +
data = buildData[buildName]
  +
else
  +
data = {
  +
["A"] = "?",
  +
["R"] = {
  +
["magic"] = {"?h", "?", "?"},
  +
}
  +
}
  +
end
  +
  +
local activity = data["A"]
  +
if data["W"] then activity = NPC({"Wish Granter"}) .. " " .. activity end
  +
VL.vardefine("activity", activity)
  +
  +
local reward = "magic"
  +
if not data["R"]["magic"] then
  +
for k, v in pairs(data["R"]) do
  +
if k ~= "after" then
 
reward = k
 
reward = k
  +
VL.vardefine("ltename", (k=="after" and "After" or k:upper()))
 
break
 
break
 
end
 
end
else
 
reward = "magic"
 
 
end
 
end
  +
end
 
tRet = {"|-\n| style=\"text-align: center;\"|", "", "\n|", "", "[[",
 
"", "]]: ", "", "", "",
 
"", "\n|\n|", "", "\n| colspan=\"2\" nowrap|", "",
 
"", ", ", "", "", "\n"
 
}
 
   
  +
local time = ""
tRet[ 2] = icon({"Kingdom"})
 
  +
local rewards = ""
tRet[ 6] = item[3]
 
  +
local chancerewards = ""
tRet[ 8] = item[2]["A"]
 
tRet[13] = item[2]["R"][reward][1]
 
tRet[15] = EC({"XP"})
 
tRet[16] = item[2]["R"][reward][2]
 
tRet[18] = EC({reward})
 
tRet[19] = item[2]["R"][reward][3]
 
 
local collectionData = mw.loadData( 'Module:ItemCollection/data' )
 
if collectionData["Items"][item[3]][3] and collectionData["Items"][item[3]][3] == true then
 
table.insert(tPrem, table.concat(tRet))
 
else
 
table.insert(tAtt, table.concat(tRet))
 
end
 
end
 
 
table.insert(tAtt, '|-\n! colspan="5"|Premium\n')
 
table.insert(tAtt, table.concat(tPrem))
 
 
return table.concat(tAtt)
 
end
 
   
  +
if data["R"][reward][1] ~= "" then
function p.getList(frame)
 
  +
time = data["R"][reward][1]
local tArgs = util.getArgs(frame)
 
  +
if data["R"][reward][2] ~= 0 then
local buildType = tArgs[1] or "Ba"
 
  +
rewards = EC({"XP"}) .. data["R"][reward][2] .. ", "
local buildings = {}
 
  +
end
local tOut = { '{| class="article-table sortable" style="width: 100%;"\n',
 
  +
rewards = rewards .. EC({reward}) .. data["R"][reward][3]
'! rowspan="2" class="unsortable" width="1"|\n',
 
  +
if data["R"][reward]["T"] then
'! rowspan="2" width="57%"|Name\n',
 
  +
rewards = rewards .. ", " .. NPC({"Gold Trophies", "G"})
'! rowspan="2" style="text-align: center;" width="1"|Premium\n',
 
  +
end
'! rowspan="2" style="text-align: center;" width="1"|Limited\n',
 
  +
'! colspan="3" style="text-align: center;"|Rewards\n',
 
  +
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 "")
'! rowspan="2" style="text-align: center;" width="10"|Magic per hour\n',
 
  +
chancerewards = TOK(tokens, "I")
'|-\n! width="10%"|Time\n! width="10%"|XP\n! width="10%"|Magic'
 
}
 
local tAtt = {}
 
 
for item, data in pairs(attrData) do
 
if item ~= ("\"it's a small world\"" or "Big Thunder Mountain Railroad" or "Expedition Everest") then
 
if collectionData["Items"][item] and collectionData["Items"][item][2] == buildType:lower() then
 
if data["A"] and data["R"]["magic"] and data["R"]["magic"][1] ~= "" then
 
table.insert(buildings, {mw.ustring.gsub(mw.ustring.lower(item), "[':\"%,%.]", ""), item, data})
 
end
 
end
 
end
 
 
end
 
end
 
table.sort(buildings, function(a,b) return a[1] < b[1] end)
 
 
for _, att in pairs(buildings) do
 
local premium = "[[File:m-cross.png|x20px|No]]"
 
if collectionData["Items"][att[2]] and collectionData["Items"][att[2]][3] and collectionData["Items"][att[2]][3] == true then
 
premium = "[[File:m-check.png|x20px|Yes]]"
 
end
 
local limited = "[[File:m-cross.png|x20px|No]]"
 
if collectionData["Items"][att[2]] and collectionData["Items"][att[2]][4] and collectionData["Items"][att[2]][4] == true then
 
limited = "[[File:m-check.png|x20px|Yes]]"
 
end
 
 
tAtt = {"\n|-\n| style=\"text-align: center;\"|", "",
 
"\n|[[", "", "]]:<br>''", "", "''",
 
"\n| style=\"text-align: center;\"|", premium,
 
"\n| style=\"text-align: center;\"|", limited,
 
"\n| nowrap data-sort-value=\"", "", "\"|", "",
 
"\n| nowrap data-sort-value=\"", "", "\"|", "",
 
"\n| nowrap data-sort-value=\"", "", "\"|", "",
 
"\n| nowrap data-sort-value=\"", "", "\"|", ""
 
}
 
   
  +
VL.vardefine("time", time)
tAtt[ 2] = "[[File:" .. buildType .. "-" .. att[1] .. ".png|50px|" .. att[2] .. "|link=" .. att[2] .. "]]"
 
  +
VL.vardefine("rewards", rewards)
 
  +
VL.vardefine("chancerewards", chancerewards)
tAtt[ 4] = att[2]
 
  +
tAtt[ 6] = att[3]["A"]
 
  +
local eventinfo = {}
 
  +
local durNumb, durHMS = string.match(att[3]["R"]["magic"][1], "^([%d%?]+)([hms])$")
 
  +
for k, v in pairs(data["R"]) do
local durNumb = tonumber(durNumb)
 
if durHMS == "h" then
+
if k ~= "magic" then
  +
table.insert(eventinfo, {(v["E"] or 1), k, v})
durNumb = durNumb * 60
 
 
end
 
end
  +
end
tAtt[13] = durNumb
 
tAtt[15] = att[3]["R"]["magic"][1]
 
 
tAtt[17] = att[3]["R"]["magic"][2]
 
tAtt[19] = EC({"XP"}) .. tAtt[17]
 
 
tAtt[21] = att[3]["R"]["magic"][3]
 
tAtt[23] = EC({"Magic"}) .. tAtt[21]
 
 
tAtt[25] = math.floor((tAtt[21] / (durNumb / 60)) + 0.5)
 
tAtt[27] = EC({"Magic"}) .. tAtt[25]
 
 
table.insert(tOut, table.concat(tAtt))
 
end
 
 
return table.concat(tOut)
 
end
 
   
  +
table.sort(eventinfo, function(a,b) return a[1] < b[1] end)
function p.getEnchList(frame)
 
local tArgs = util.getArgs(frame)
 
local tOut = { '{| class="article-table dmk-list2" style="width: 100%;"\n',
 
'! width="10%"|Collection\n',
 
'! width="20%"|Name\n',
 
'! colspan="2" width="10%"|Building\n',
 
'! colspan="2" width="10%"|Level 1\n',
 
'! colspan="2" width="10%"|Level 2\n',
 
'! colspan="2" width="10%"|Level 3\n',
 
'! colspan="2" width="10%"|Level 4\n',
 
'! colspan="2" width="10%"|Level 5',
 
}
 
local tEnch = {}
 
 
for att, data in pairs(tArgs) do
 
tEnch = {"\n|-\n|", "", "<br>''<small>[[:Category:", "", "|", "", "]]</small>''",
 
"\n|", "", "<br>''<small>[[", "", "]]</small>''",
 
"\n| nowrap|", "",
 
"\n| nowrap|", EC({"Magic"}), "",
 
"\n| nowrap|+", "",
 
"\n| nowrap|", EC({"Magic"}), "", "<br><small>''(+", EC({"Magic"}), "", ")''</small>",
 
"\n| nowrap|+", "",
 
"\n| nowrap|", EC({"Magic"}), "", "<br><small>''(+", EC({"Magic"}), "", ")''</small>",
 
"\n| nowrap|+", "",
 
"\n| nowrap|", EC({"Magic"}), "", "<br><small>''(+", EC({"Magic"}), "", ")''</small>",
 
"\n| nowrap|+", "",
 
"\n| nowrap|", EC({"Magic"}), "", "<br><small>''(+", EC({"Magic"}), "", ")''</small>",
 
"\n| nowrap|", TOK({"two chances"}),
 
"\n| nowrap|", EC({"Magic"}), "", "<br><small>''(+", EC({"Magic"}), "", ")''</small>",
 
}
 
   
  +
for _, data in pairs(eventinfo) do
tEnch[ 2] = COLL({att, "40"})
 
  +
if reward ~= data[2] then
tEnch[ 4] = COLL({att, "N"})
 
  +
VL.vardefine("ltename" .. data[1], (data[2]=="after" and "After" or data[2]:upper()))
tEnch[ 6] = COLL({att, "N"})
 
  +
VL.vardefine("eventtime" .. data[1], data[3][1])
 
  +
if data[3][2] ~= 0 then
tEnch[ 9] = "[[File:Ba-" .. mw.ustring.gsub(mw.ustring.lower(att), "[':\"%,%.]", "") .. ".png|50px|" .. att .. "|link=" .. att .. "]]"
 
  +
eventrewards = EC({"XP"}) .. data[3][2] .. ", "
tEnch[11] = att
 
+
end
  +
eventrewards = eventrewards .. EC({data[2]}) .. data[3][3]
local No = 0
 
  +
if data[3]["T"] then
local tMag = ""
 
  +
eventrewards = eventrewards .. ", " .. NPC({"Gold Trophies", nil, nil, nil, data[2]})
 
  +
end
if attrData[att] and attrData[att]["R"]["magic"] then
 
  +
VL.vardefine("eventrewards" .. data[1], eventrewards)
tMag = attrData[att]["R"]["magic"][3]
 
  +
if data[3][4] and data[3][4] ~= "" then
  +
local eventchancerewards = data[3][4] .. "$" .. (data[3][5] or "") .. "$" .. (data[3][6] or "") .. "$" .. (data[3][7] or "") .. "$" .. (data[3][8] or "")
  +
VL.vardefine("eventchancerewards" .. data[1], TOK(eventchancerewards, "I"))
  +
end
 
end
 
end
  +
end
 
  +
for item in mw.text.gsplit(data, "%s*%$%s*") do
 
  +
return ""
local iTok, iTok2, iMag = mw.ustring.match(item, "^([^,]-)%s*,%s*(%d+)%s*+*%s*([\/%d%?]*)$")
 
 
if iTok then
 
tMag = tMag + iMag
 
tEnch[19 + No] = TOK({(iTok .. "," .. iTok2)})
 
tEnch[22 + No] = tMag
 
tEnch[25 + No] = iMag
 
No = No + 9
 
else
 
if tonumber(item) then
 
tMag = tMag + item
 
tEnch[58] = tMag
 
tEnch[61] = item
 
else
 
tEnch[14] = TOK({item})
 
tEnch[17] = tMag
 
end
 
end
 
end
 
 
table.insert(tOut, table.concat(tEnch))
 
end
 
 
return table.concat(tOut)
 
 
end
 
end
   

Latest revision as of 14:25, 5 February 2024

Description

This module is the Lua back-end for {{Infobox attraction}}, {{Infobox concession}}, to display information about Attractions and Concessions.

Usage

{{#invoke:Building|building|<parameter list>}}


--[==[--
--------------------------------------
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 buildData = mw.loadData('Module:Building/data')
--[==[]=]
local buildData = {
    ["Under the Sea"] = {
        ["W"] = true,
        ["A"] = "Jamming with a Hot Crustacean Band",
        ["R"] = {
	        ["magic"] = {"4h", 12, 155, "IP-TLM", "Sebastian,3", "King triton,2", "Ariel,3", "Ursula,2", T=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").getTokenDirect
local NPC  = require("Module:NPC").getNPC
local lte = require("Module:LTEvent").getLTE
local util = require("Module:Utility")

function oneBuilding(buildName, enchLvl, event, outType, pagename)
	buildName = buildName:gsub("^%s*(.-)%s*$", "%1") or ''
	if buildName == "" then
		buildName = mw.title.getCurrentTitle().text
	else
		buildName = mw.text.decode(buildName, false)
	end
	enchLvl = tostring(enchLvl) or 0
	enchLvl = enchLvl:upper():gsub("^%s*(.-)%s*$", "%1") or ''
	enchLvl = enchLvl:gsub("[^0-5]", "")

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

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

	local data = {}

	if buildData[buildName] then
		data = buildData[buildName]
	else
		data = {
		        ["A"] = "?",
	        	["R"] = {
		        	["magic"] = {"?h", "?", "?"},
	    		}
		}
		buildName = "?"
	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

	bData = data["R"][reward]

	local tFunc = {
		-- Magic Reward only
		["M"] = function ()
					if bData[1] ~= "" then
						return bData[3]
					end
				end,
		-- Rewards only
		["R"] = function ()
					if data["R"][reward][1] ~= "" then
						local tRet = {"<small>Rewards <small>(Every ", data["R"][reward][1], ")</small></small><br/>'''", "", "", "", EC({reward}), data["R"][reward][3], "", "", 
								"'''"
								}
						if bData[2] ~= 0 then
							tRet[4] = EC({"XP"})
							tRet[5] = data["R"][reward][2]
							tRet[6] = ", "
						end
						if data["R"][reward]["T"] and event == "" then
							tRet[ 9] = ", "
							if reward ~= "magic" then
								tRet[10] = NPC({"Gold Trophies", nil, nil, nil, reward})
							else
								tRet[10] = NPC({"Gold Trophies", "G"})
							end
						end
						return table.concat(tRet)
					else
						return ""
					end
				end,
		-- Default (token rewards table row)
		["D"] = function()
					local tRet = {"|-\n| style=\"text-align: center;\"|", "", "", "", "", 
							"\n|[[", "", "]]: ", "", "\n|", 
							"", '\n| style="text-align: center;" data-sort-value="', "", '"|', "", 
							"\n| nowrap style=\"text-align: center;\"|", "", "", ", ", "", 
							"", "", "", "", ""
							}
					local buildType = "Ba"		
					if data[1] then buildType = "Bc" end

					tRet[ 2] = "<span id=\"dmk-icon-plain\">[[File:" .. buildType .. "-" .. mw.ustring.gsub(mw.ustring.lower(buildName), "[':\"%,%.*]", "") .. ".png|60x60px|" .. buildName .. "|link=" .. buildName .. "]]</span>"
					if enchLvl ~= "" and enchLvl ~= "0" then
						tRet[ 3] = "<small><br />''Ench. Level "
						tRet[ 4] = tostring(enchLvl)
						tRet[ 5] = "''</small>"
					end
					tRet[ 7] = buildName
					tRet[ 9] = data["A"]
					if data["W"] then
						tRet[11] = NPC({"Wish Granter"})
					end
					if bData[1] ~= "" then
						local durNumb, durHMS = string.match(bData[1], "^([%d%?]+)([hms])$")
						local durNumb = tonumber(durNumb)
						if durNumb then
							if durHMS == "h" then
								durNumb = durNumb * 3600
							elseif durHMS == "m" then
								durNumb = durNumb * 60
							end
						else
							durNumb = 99900
						end
						tRet[13] = durNumb
						tRet[15] = bData[1]
						if bData[2] ~= 0 then
							tRet[17] = EC({"XP"})
							tRet[18] = bData[2]
						end
						tRet[20] = EC({reward})
						tRet[21] = bData[3]
					else
						tRet[19] = ""
					end
					if bData["T"] and event == "" then
						tRet[22] = ", "
						if reward ~= "magic" then
							tRet[23] = NPC({"Gold Trophies", nil, nil, nil, event})
						else
							tRet[23] = NPC({"Gold Trophies", "G"})
						end
					end
					if event == "" and ((bData[4] and bData[4] ~= "") or (bData[5] and bData[5] ~= "")) then
						tRet[24] = "\n| nowrap style=\"text-align: center;\"|"
						local tokens = (bData[4] or "")
						if enchLvl == "1" then
							tokens = (bData[4] or "") .. "$" .. (bData[5] or "")
						elseif enchLvl == "2" then
							tokens = (bData[4] or "") .. "$" .. (bData[5] or "") .. "$" .. (bData[6] or "")
						elseif enchLvl == "3" then
							tokens = (bData[4] or "") .. "$" .. (bData[5] or "") .. "$" .. (bData[6] or "") .. "$" .. (bData[7] or "")
						elseif enchLvl == "4" or enchLvl == "5" then
							tokens = (bData[4] or "") .. "$" .. (bData[5] or "") .. "$" .. (bData[6] or "") .. "$" .. (bData[7] or "") .. "$" .. (bData[8] or "")
						end
						tRet[25] = TOK(tokens, "", "B")
					end
					return table.concat(tRet)
				end,
		-- Mini Event (token rewards table row)
		["ME"] = function()
					local tRet = {"|-\n| style=\"text-align: center;\"|", "", "", "", "", 
							"\n|[[", "", "]]: ", "", "\n|", 
							"", '\n| style="text-align: center;" data-sort-value="', "", '"|', ""
							}
					local buildType = "Ba"		
					if data[1] then buildType = "Bc" end

					tRet[ 2] = "<span id=\"dmk-icon-plain\">[[File:" .. buildType .. "-" .. mw.ustring.gsub(mw.ustring.lower(buildName), "[':\"%,%.*]", "") .. ".png|60x60px|" .. buildName .. "|link=" .. buildName .. "]]</span>"
					if enchLvl ~= "" and enchLvl ~= "0" then
						tRet[ 3] = "<small><br />''Ench. Level "
						tRet[ 4] = tostring(enchLvl)
						tRet[ 5] = "''</small>"
					end
					tRet[ 7] = buildName
					tRet[ 9] = data["A"]
					if data["W"] then
						tRet[11] = NPC({"Wish Granter"})
					end
					if bData[1] ~= "" then
						local durNumb, durHMS = string.match(bData[1], "^([%d%?]+)([hms])$")
						local durNumb = tonumber(durNumb)
						if durNumb then
							if durHMS == "h" then
								durNumb = durNumb * 3600
							elseif durHMS == "m" then
								durNumb = durNumb * 60
							end
						else
							durNumb = 99900
						end
						tRet[13] = durNumb
						tRet[15] = bData[1]
					else
						tRet[19] = ""
					end
					return table.concat(tRet)
				end,
	}
	return tFunc[outType]()
end

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

	local buildName = tArgs[1] or ""
	local enchLvl = tArgs[2] or ""
	local event = tArgs[3] or ""
	local outType = tArgs[4] or ""

	if buildName ~= "" then
		for build in mw.text.gsplit(buildName, "%s*$%s*") do
			table.insert(tOut, oneBuilding(build, enchLvl, event, outType, pagename))
		end
	elseif outType ~= "" then
		local buildings = {}
    		for item, data in pairs(buildData) 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
				local buildType = (data[1] and "0" or "1")

				local durNumb, durHMS = string.match(data["R"][reward][1], "^([%d%?]+)([hms])$")
				if not durNumb or durNumb == "?" then 
					durNumb = 0
				else
					durNumb = tonumber(durNumb)
					if durHMS == "m" then durNumb = durNumb / 60 end
				end
			
				if (outType == "G" and data["R"][reward]["T"]) or (outType == "W" and data["W"]) then
					table.insert(buildings, {buildType, durNumb, item})
				elseif 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(buildings, {buildType, durNumb, item, k-4})
								end
							end
						end
					end
				elseif outType == "E" then
					table.insert(buildings, {buildType, durNumb, item})
				end
			end
		end
		table.sort(buildings, function(a,b)
			if a[1] == b[1] then
				if a[2] == b[2] then
					return a[3] < b[3]
				else
					return a[2] < b[2]
				end
			else
				return a[1] < b[1]
			end
		end)
		for _, item in pairs(buildings) do
			table.insert(tOut, oneBuilding(item[3], (item[4] or ""), event, "D"))
		end
	end

	return table.concat(tOut, "\n")
end

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

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

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

	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", (k=="after" and "After" or k:upper()))
				break
			end
		end
	end

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

	if data["R"][reward][1] ~= "" then
		time = data["R"][reward][1]
		if data["R"][reward][2] ~= 0 then
			rewards = EC({"XP"}) .. data["R"][reward][2] .. ", "
		end
		rewards = rewards .. EC({reward}) .. data["R"][reward][3]
		if data["R"][reward]["T"] 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 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], (data[2]=="after" and "After" or data[2]:upper()))
			VL.vardefine("eventtime" .. data[1], data[3][1])
			if data[3][2] ~= 0 then
				eventrewards = EC({"XP"}) .. data[3][2] .. ", "
			end
			eventrewards = eventrewards .. EC({data[2]}) .. data[3][3]
			if data[3]["T"] then
				eventrewards = eventrewards .. ", " .. NPC({"Gold Trophies", nil, nil, nil, data[2]})
			end
			VL.vardefine("eventrewards" .. data[1], eventrewards)
			if data[3][4] and data[3][4] ~= "" then
				local eventchancerewards = data[3][4] .. "$" .. (data[3][5] or "") .. "$" .. (data[3][6] or "") .. "$" .. (data[3][7] or "") .. "$" .. (data[3][8] or "")
				VL.vardefine("eventchancerewards" .. data[1],  TOK(eventchancerewards, "I"))
			end
		end
	end

	return ""
end

return p