Module:表格/间歇泉

来自缺氧 Wiki
跳转到导航 跳转到搜索

可在Module:表格/间歇泉/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