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
(Test)
No edit summary
Line 391: Line 391:
   
 
tEnch[ 2] = COLL({att, "40"})
 
tEnch[ 2] = COLL({att, "40"})
tEnch[ 4] = COLL({att, "T"})
+
tEnch[ 4] = COLL({att, "S"})
tEnch[ 6] = COLL({att, "T"})
+
tEnch[ 6] = COLL({att, "S"})
 
 
 
tEnch[ 9] = "[[File:Ba-" .. mw.ustring.gsub(mw.ustring.lower(att), "[':\"%,%.]", "") .. ".png|50px|" .. att .. "|link=" .. att .. "]]"
 
tEnch[ 9] = "[[File:Ba-" .. mw.ustring.gsub(mw.ustring.lower(att), "[':\"%,%.]", "") .. ".png|50px|" .. att .. "|link=" .. att .. "]]"
Line 405: Line 405:
 
 
 
for item in mw.text.gsplit(data, "%s*%$%s*") do
 
for item in mw.text.gsplit(data, "%s*%$%s*") do
local iTok, iMag = mw.ustring.match(item, "^([^,]-)%s*^%s*(.-)$")
+
local iTok, iMag = mw.ustring.match(item, "^([^,]-)%s*/%s*(.-)$")
 
 
if not iTok then
+
if iTok then
 
tMag = tMag + iMag
 
tEnch[19 + No] = TOK({iTok})
 
tEnch[22 + No] = tMag
 
tEnch[25 + No] = iMag
 
else
 
if tonumber(item) then
 
if tonumber(item) then
 
tMag = tMag + item
 
tMag = tMag + item
Line 416: Line 421:
 
tEnch[17] = tMag
 
tEnch[17] = tMag
 
end
 
end
else
 
tMag = tMag + iMag
 
tEnch[19 + No] = TOK({iTok})
 
tEnch[22 + No] = tMag
 
tEnch[25 + No] = iMag
 
 
end
 
end
 
 

Revision as of 09:39, 26 July 2021

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>}}


--[==[-- <nowiki>
--------------------------------------
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 attrData = mw.loadData('Module:Building/data')
--[==[]=]
local attrData = {
-- The Little Mermaid  --
    ["Under the Sea"] = {
        ["A"] = "Jamming with a Hot Crustacean Band",
        ["R"] = {
	        ["magic"] = {"4h", 12, 155, true},
	        ["tlm"] = {"4h", 23, 32, true},
	        ["wir"] = {"4h", 12, 50},
    	}
    },
}
--]==]

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 icon = require("Module:CharacterAvatar").getAvatar
local npc = require("Module:NPC").getNPC
local lte = require("Module:LTEvent").getLTE
local util = require("Module:Utility")

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 ''

    if buildName == "" then
        buildName = mw.title.getCurrentTitle().text
    else
        buildName = mw.text.decode(buildName, false)
    end
	
	enchLvl = enchLvl:upper():gsub("^%s*(.-)%s*$", "%1") or ''
    event = event:lower():gsub("^%s*(.-)%s*$", "%1") or ''

	local outType = "D"

	if enchLvl:match("^[ACRD]$") then
		outType = enchLvl
		enchLvl = ""
	end

	enchLvl = enchLvl:gsub("[^0-5]", "")

    local data = {}

    if attrData[buildName] then
		data = attrData[buildName]
	else
	    data = {
	        ["A"] = "?",
	        ["R"] = {
		        ["magic"] = {"?h", "?", "?"},
	    	}
	    }
	    buildName = "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 = {
		-- Activity
		["A"] = function ()
					return data["A"]
				end,
		-- Collection Time
		["C"] = function ()
					local retText = ""
					local space = ""

					if event ~= "" then
						for k, v in pairs(data["R"]) do
							if k ~= "magic" then
								local tRow = {
									space,
									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
					return retText
				end,
		-- Rewards only
		["R"] = function ()
					local retText = ""
					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
									tRow[7] = ", "
									tRow[8] = npc({"Gold Trophies", nil, nil, nil, k})
								end
								retText = retText .. table.concat(tRow)
								space = "<br />"
							end
						end
						if space == "" then
							if data["R"][reward][1] ~= "" then
								local tRow = {
									"", EC({"XP"}), data["R"][reward][2], ", ",
									EC({reward}), data["R"][reward][3],
								}
								retText = retText .. table.concat(tRow)
							end
						end
					else
						if data["R"][reward][1] ~= "" then
							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
					return retText
				end,
		-- Default (token rewards table row)
		["D"] = function()
					local tRet = {"|-\n| style=\"text-align: center;\"|", "", "\n|", "", "[[",
									"", "]]: ", "", "", "",
									"", "\n|\n|", "", "\n| colspan=\"2\" nowrap|", "",
									"", ", ", "", "", "",
									""
					}
					tRet[ 2] = icon({"Kingdom", event or ""})
					tRet[ 6] = buildName
					tRet[ 8] = data["A"]
					if data["R"][reward][1] ~= "" then
						tRet[13] = data["R"][reward][1]
						tRet[15] = EC({"XP"})
						tRet[16] = data["R"][reward][2]
						tRet[18] = EC({reward})
						tRet[19] = data["R"][reward][3]
					else
						tRet[17] = ""
					end
					if data["R"][reward][4] then
						tRet[20] = ", "
						if event then
							tRet[21] = npc({"Gold Trophies", nil, nil, nil, event})
						else
							tRet[21] = npc({"Gold Trophies", "G"})
						end
					end
					if enchLvl ~= "" then
						tRet[ 9] = "<small><br />''* Enchantment Level "
						tRet[10] = tostring(enchLvl)
						tRet[11] = "''</small>"
					end
					return table.concat(tRet)
				end,
	}
	return tFunc[outType]()
end

function p.getTrophies(frame)
	local tRet = {}
	local tAtt = {}
	local tPrem = {}
	local attractions = {}
	local reward = ""
    		
    for item, data in pairs(attrData) do
		if not data["R"]["magic"] then
			for k, v in pairs(data["R"]) do
				reward = k
				break
			end
		else
			reward = "magic"
		end
			
    	if data["R"][reward][4] then
			local durNumb, durHMS = string.match(data["R"][reward][1], "^([%d%?]+)([hms])$")
			local durNumb = tonumber(durNumb)
			if durHMS == "h" then
			    durNumb = durNumb * 3600
			elseif durHMS == "m" then
		        durNumb = durNumb * 60
		    end
       		table.insert(attractions, {durNumb, data, item})
       	end
	end
		
	table.sort(attractions, function(a,b) return a[1] < b[1] end)
		
    for att, item in pairs(attractions) do
		if not item[2]["R"]["magic"] then
			for k, v in pairs(item[2]["R"]) do
				reward = k
				break
			end
		else
			reward = "magic"
		end
		
		tRet = {"|-\n| style=\"text-align: center;\"|", "", "\n|", "", "[[",
				"", "]]: ", "", "", "",
				"", "\n|\n|", "", "\n| colspan=\"2\" nowrap|", "",
				"", ", ", "", "", "\n"
				}

		tRet[ 2] = icon({"Kingdom"})
		tRet[ 6] = item[3]
		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

function p.getList(frame)
    local tArgs = util.getArgs(frame)
	local buildType = tArgs[1] or "Ba"
	local buildings = {}
	local tOut = {	'{| class="article-table sortable" style="width: 100%;"\n',
					'! rowspan="2" class="unsortable" width="1"|\n',
					'! rowspan="2" width="57%"|Name\n',
					'! rowspan="2" style="text-align: center;" width="1"|Premium\n',
					'! rowspan="2" style="text-align: center;" width="1"|Limited\n',
					'! colspan="3" style="text-align: center;"|Rewards\n',
					'! rowspan="2" style="text-align: center;" width="10"|Magic per hour\n',
					'|-\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
		
	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=\"", "", "\"|", ""
				}

		tAtt[ 2] = "[[File:" .. buildType .. "-" .. att[1] .. ".png|50px|" .. att[2] .. "|link=" .. att[2] .. "]]"
		
		tAtt[ 4] = att[2]
		tAtt[ 6] = att[3]["A"]
		
		local durNumb, durHMS = string.match(att[3]["R"]["magic"][1], "^([%d%?]+)([hms])$")
		local durNumb = tonumber(durNumb)
		if durHMS == "h" then
			durNumb = durNumb * 60
		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

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>",
				}

		tEnch[ 2] = COLL({att, "40"})
		tEnch[ 4] = COLL({att, "S"})
		tEnch[ 6] = COLL({att, "S"})
		
		tEnch[ 9] = "[[File:Ba-" .. mw.ustring.gsub(mw.ustring.lower(att), "[':\"%,%.]", "") .. ".png|50px|" .. att .. "|link=" .. att .. "]]"
		tEnch[11] = att
		
		local No = 0
		local tMag = ""
		
		if attrData[att] and attrData[att]["R"]["magic"] then
			tMag = attrData[att]["R"]["magic"][3]
		end
		
    	for item in mw.text.gsplit(data, "%s*%$%s*") do
    		local iTok, iMag = mw.ustring.match(item, "^([^,]-)%s*/%s*(.-)$")
	    	
	    	if iTok then
	    		tMag = tMag + iMag
	    		tEnch[19 + No] = TOK({iTok})
	    		tEnch[22 + No] = tMag
	    		tEnch[25 + No] = iMag
	    	else
	    		if tonumber(item) then
	    			tMag = tMag + item
		    		tEnch[58] = tMag
		    		tEnch[61] = item
	    		else
		    		tEnch[14] = TOK({item})
		    		tEnch[17] = tMag
		    	end
	    	end
	    	
	    	No = No + 9
	    end
       	
       	table.insert(tOut, table.concat(tEnch))
    end
	
    return table.concat(tOut)
end

return p