缺氧 wiki 编辑团队提示:注册账号并登录后体验更佳,且可通过参数设置定制优化您的浏览体验!

该站点为镜像站点,如果你想帮助这个由玩家志愿编辑的 wiki 站点,请前往原站点参与编辑,
同时欢迎加入编辑讨论群 851803695 与其他编辑者一起参与建设!

全站通知:

模块:表格/间歇泉

来自缺氧WIKI_BWIKI_哔哩哔哩
跳到导航 跳到搜索

此模块的文档可以在模块:表格/间歇泉/doc创建

local p = {}
local getArgs = require([[Module:Arguments]]).getArgs
local utils = require([[Module:Utils]])
local K0 = utils.K0
local geyserData = mw.loadData([[Module:Data/Geysers]])
local getTable = require([[Module:表格]]).table

local function countsinbasegame() -- 计算本体游戏可用的间歇泉个数
	local num = 0
	for _, geyser in pairs(geyserData) do
		num = num + (geyser.geyserType.DlcID == "" and 1 or 0)
	end
	return num
end

function p.probcalc(args) -- 计算本体游戏中成功生成 PICKS 次 Generic_geyser 时,至少有 wanted 个间歇泉属于人为划定为 preferred 的一组间歇泉的概率
	local prob = {}
	local PICKS = 9
	local GROUP_SIZE = countsinbasegame() or 20

	local function combination(n, m)
	    if n == m or m == 0 then return 1 end
	    local out = 1
	    for i = 1, m do
	        out = out * (n-i+1) / i
	    end
	    return out
	end

	for preferred = 1, GROUP_SIZE do
	    prob[preferred] = {}
	    for wanted = 0, PICKS do
	        if wanted == 0 then
	            prob[preferred][wanted] = 1
	        else
	            local probWantedMinusOne = combination(PICKS, wanted - 1) * math.pow(preferred, wanted - 1) * math.pow(GROUP_SIZE - preferred, PICKS - wanted + 1)/math.pow(GROUP_SIZE, PICKS)
	            prob[preferred][wanted] = prob[preferred][wanted - 1] - probWantedMinusOne
	        end
	    end
	end
	
	local out = {}
	for wanted = 1, PICKS do
		local row = {wanted}
		for preferred = 1, GROUP_SIZE do
			row[#row + 1] = ("%.2f%%"):format(100 * prob[preferred][wanted])
		end
		out[#out + 1] = row
	end
	
	return getTable(out, args)
end

function p.geysers(args)
    local out = {}
    local ks = {}

    for k in pairs(geyserData) do
        ks[#ks+1] = k
    end

    table.sort(ks, function(a,b) --按形状排序,相同形状的 DLC 间歇泉放后面
    return geyserData[a].geyserType.shape ==  geyserData[b].geyserType.shape and 
            geyserData[a].geyserType.DlcID < geyserData[b].geyserType.DlcID or
            geyserData[a].geyserType.shape < geyserData[b].geyserType.shape
    end
    )

    for _, k in ipairs(ks) do
        local _name = utils.getEntry(k)
        local icon_name = ("[[File:%s.png|x48px|center|link=%s]][[%s]]"):format(_name, _name, _name)

        local geyser = geyserData[k]
        if not geyser.geyserType then break end
        local mGeyserType = geyser.geyserType
        local dlcIcon = mGeyserType.DlcID ~= "" and utils.DLC_ICONS[mGeyserType.DlcID] or ""
        icon_name = icon_name .. dlcIcon
        local output = ("%s°C 的 {{物品|%s}}"):format(utils.float2str(mGeyserType.temperature + K0), utils.getEntry(mGeyserType.element))
        local germs = mGeyserType.diseaseId and mGeyserType.diseaseCount
        	and ("<br>(含[[%s病菌]] %s 个)"):format(utils.getEntry(mGeyserType.diseaseId), mGeyserType.diseaseCount)
        	or ""
        output = output .. germs
        
        local maxPressure = mGeyserType.maxPressure

        local range = "%s ~ %s"
        local ratePerCycle = mGeyserType.minRatePerCycle < mGeyserType.maxRatePerCycle
        	and range:format(mGeyserType.minRatePerCycle, mGeyserType.maxRatePerCycle)
        	or mGeyserType.minRatePerCycle
        local iterationLength = mGeyserType.minIterationLength < mGeyserType.maxIterationLength
        	and range:format(mGeyserType.minIterationLength, mGeyserType.maxIterationLength)
        	or mGeyserType.minIterationLength
        local iterationPercent = mGeyserType.minIterationPercent < mGeyserType.maxIterationPercent
        	and range:format(utils.float2str(mGeyserType.minIterationPercent, 4) * 100 .. "%", utils.float2str(mGeyserType.maxIterationPercent, 4) * 100 .. "%")
        	or utils.float2str(mGeyserType.minIterationPercent, 4) * 100 .. "%"
        local yearLength = mGeyserType.minYearLength < mGeyserType.maxYearLength
        	and range:format(mGeyserType.minYearLength, mGeyserType.maxYearLength)
        	or mGeyserType.minYearLength
        local yearPercent = mGeyserType.minYearPercent < mGeyserType.maxYearPercent
        	and range:format(utils.float2str(mGeyserType.minYearPercent, 4) * 100 .."%", utils.float2str(mGeyserType.maxYearPercent, 4) * 100 .. "%")
        	or utils.float2str(mGeyserType.minYearPercent, 4) * 100 .."%"

        table.insert(out, {icon_name, output, maxPressure, ratePerCycle, iterationLength, iterationPercent, yearLength, yearPercent})
    end

    return getTable(out, args)
end

function p._main(args)
	args = args or {""}
	local f = p[args[1]]
    return f(args)
end

function p.main(frame)
    return p._main(getArgs(frame))
end

return p