模块:EquipOnlineTimeConstructor

来自PRTS
跳转到导航 跳转到搜索

此模块的文档可以在模块:EquipOnlineTimeConstructor/doc创建

local p = {}
local query = mw.ext.cargo.query

function compare(x, y)
	if x["time"] ~= y["time"] then
		return x["time"] < y["time"]
	end
	if x["rarity"] ~= y["rarity"] then
		return x["rarity"] < y["rarity"]
	end
	if x["ind"] ~= y["ind"] then
		return tonumber(x["ind"]) < tonumber(y["ind"])
	end
end

function p.equip()
	local tables = "chara,char_mod=mod"
	local fields = "chara._pageName=char,chara.charIndex=ind,chara.rarity=rarity,chara.subProfession=sub,mod.type=type,mod.name=equip"
	local args = {
		join = "mod._pageName=chara._pageName",
		limit = 5000
	}
	local time = mw.text.jsonDecode(mw.title.new( '干员模组一览/time' ):getContent())
	local data = query(tables, fields, args)
	local result = [[{|class="wikitable sortable"style="text-align:center"
!干员!!稀有度!!职业分支!!模组类型!!专属模组名称!!实装日期]]
	for k,v in ipairs(data) do
		for kt, vt in ipairs(time) do
			for ke, ve in ipairs(vt["equips"]) do
				if ve["char"] == v["char"] and ve["name"]==v["equip"] then
					data[k]["time"] = vt["time"]
				end
			end
		end
	end
	table.sort(data, compare)
	for k,v in ipairs(data) do
		result = result .. "\n|-\n" .. "|[[" .. v["char"] .. "]] || " .. v["rarity"] + 1 .. " || "
			.. v["sub"] .. " || " .. v["type"] .. " || " .. v["equip"] .. " || "
			.. mw.language.getContentLanguage():formatDate("Y-m-d", "@" ..v["time"], true)
	end
	result = result .. "\n|}"
	return result
end

return p