<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="zh-Hans">
	<id>https://wum.hetonger.cn/index.php?action=history&amp;feed=atom&amp;title=%E6%A8%A1%E5%9D%97%3A%E5%9C%B0%E7%82%B9%E8%A7%A3%E9%94%81</id>
	<title>模块:地点解锁 - 版本历史</title>
	<link rel="self" type="application/atom+xml" href="https://wum.hetonger.cn/index.php?action=history&amp;feed=atom&amp;title=%E6%A8%A1%E5%9D%97%3A%E5%9C%B0%E7%82%B9%E8%A7%A3%E9%94%81"/>
	<link rel="alternate" type="text/html" href="https://wum.hetonger.cn/index.php?title=%E6%A8%A1%E5%9D%97:%E5%9C%B0%E7%82%B9%E8%A7%A3%E9%94%81&amp;action=history"/>
	<updated>2026-11-27T20:45:39Z</updated>
	<subtitle>本wiki上该页面的版本历史</subtitle>
	<generator>MediaWiki 1.46.0</generator>
	<entry>
		<id>https://wum.hetonger.cn/index.php?title=%E6%A8%A1%E5%9D%97:%E5%9C%B0%E7%82%B9%E8%A7%A3%E9%94%81&amp;diff=2009&amp;oldid=prev</id>
		<title>NotBot：​VisualJSON：地点解锁迁移为 and/or 条件树，支持 use；校正太阳持有条件</title>
		<link rel="alternate" type="text/html" href="https://wum.hetonger.cn/index.php?title=%E6%A8%A1%E5%9D%97:%E5%9C%B0%E7%82%B9%E8%A7%A3%E9%94%81&amp;diff=2009&amp;oldid=prev"/>
		<updated>2026-11-12T01:59:24Z</updated>

		<summary type="html">&lt;p&gt;VisualJSON：地点解锁迁移为 and/or 条件树，支持 use；校正太阳持有条件&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新页面&lt;/b&gt;&lt;/p&gt;&lt;div&gt;-- Offline implementation of the proposed 模块:地点解锁.&lt;br /&gt;
-- Uses Lua 5.1-compatible syntax and the existing 模块:物品通用 contract.&lt;br /&gt;
-- No network, page edits, game state, or mutation of the input record.&lt;br /&gt;
local C = require(&amp;#039;模块:物品通用&amp;#039;)&lt;br /&gt;
local p = { MAX_DEPTH = 8, MAX_NODES = 200 }&lt;br /&gt;
&lt;br /&gt;
local function fail(code, path, message)&lt;br /&gt;
    error({ code = code, path = path, message = message }, 0)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function protect(callback)&lt;br /&gt;
    local ok, value = pcall(callback)&lt;br /&gt;
    if ok then return value end&lt;br /&gt;
    if type(value) == &amp;#039;table&amp;#039; and value.code then&lt;br /&gt;
        return { status = &amp;#039;error&amp;#039;, code = value.code, path = value.path, message = value.message }&lt;br /&gt;
    end&lt;br /&gt;
    return { status = &amp;#039;error&amp;#039;, code = &amp;#039;internal-error&amp;#039;, path = &amp;#039;$&amp;#039;, message = &amp;#039;解锁解析发生内部错误&amp;#039; }&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function finite(value)&lt;br /&gt;
    return type(value) == &amp;#039;number&amp;#039; and value == value and value &amp;gt; -math.huge and value &amp;lt; math.huge&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function nonempty(value)&lt;br /&gt;
    return type(value) == &amp;#039;string&amp;#039; and C.trim(value) ~= &amp;#039;&amp;#039;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function requireName(value, path)&lt;br /&gt;
    if not nonempty(value) then fail(&amp;#039;invalid-item&amp;#039;, path, &amp;#039;物品名称必须是非空文本&amp;#039;) end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function requireCount(value, path)&lt;br /&gt;
    if not finite(value) or value &amp;lt; 1 or value % 1 ~= 0 then&lt;br /&gt;
        fail(&amp;#039;invalid-count&amp;#039;, path, &amp;#039;持有数量必须是正整数&amp;#039;)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function requirePercent(value, path)&lt;br /&gt;
    if not finite(value) or value &amp;lt; 0 then fail(&amp;#039;invalid-percent&amp;#039;, path, &amp;#039;收集度必须是有限的非负百分比数值&amp;#039;) end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function fields(value, allowed, path)&lt;br /&gt;
    for key in pairs(value) do&lt;br /&gt;
        if type(key) ~= &amp;#039;string&amp;#039; or not allowed[key] then&lt;br /&gt;
            fail(&amp;#039;unknown-field&amp;#039;, path .. &amp;#039;.&amp;#039; .. tostring(key), &amp;#039;条件包含未知或不适用的字段&amp;#039;)&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function list(value, path)&lt;br /&gt;
    if type(value) ~= &amp;#039;table&amp;#039; then fail(&amp;#039;invalid-list&amp;#039;, path, &amp;#039;条件组必须是列表&amp;#039;) end&lt;br /&gt;
    local count = 0&lt;br /&gt;
    for key in pairs(value) do&lt;br /&gt;
        if type(key) ~= &amp;#039;number&amp;#039; or key &amp;lt; 1 or key % 1 ~= 0 then&lt;br /&gt;
            fail(&amp;#039;invalid-list&amp;#039;, path, &amp;#039;列表不能包含命名字段&amp;#039;)&lt;br /&gt;
        end&lt;br /&gt;
        count = count + 1&lt;br /&gt;
    end&lt;br /&gt;
    if count &amp;gt; p.MAX_NODES then fail(&amp;#039;node-limit&amp;#039;, path, &amp;#039;条件节点过多&amp;#039;) end&lt;br /&gt;
    for index = 1, count do&lt;br /&gt;
        if value[index] == nil then fail(&amp;#039;invalid-list&amp;#039;, path, &amp;#039;列表不能包含空洞&amp;#039;) end&lt;br /&gt;
    end&lt;br /&gt;
    if count == 0 then fail(&amp;#039;empty-group&amp;#039;, path, &amp;#039;条件组至少需要一条条件&amp;#039;) end&lt;br /&gt;
    return count&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function validate(condition)&lt;br /&gt;
    if condition == nil then return end&lt;br /&gt;
    local seen, count = {}, 0&lt;br /&gt;
    local function walk(node, path, depth)&lt;br /&gt;
        count = count + 1&lt;br /&gt;
        if count &amp;gt; p.MAX_NODES then fail(&amp;#039;node-limit&amp;#039;, path, &amp;#039;条件节点过多&amp;#039;) end&lt;br /&gt;
        if depth &amp;gt; p.MAX_DEPTH then fail(&amp;#039;depth-limit&amp;#039;, path, &amp;#039;条件嵌套过深&amp;#039;) end&lt;br /&gt;
        if type(node) ~= &amp;#039;table&amp;#039; then fail(&amp;#039;invalid-node&amp;#039;, path, &amp;#039;每条条件必须是对象&amp;#039;) end&lt;br /&gt;
        if seen[node] then fail(&amp;#039;cyclic-condition&amp;#039;, path, &amp;#039;条件不能循环引用&amp;#039;) end&lt;br /&gt;
        seen[node] = true&lt;br /&gt;
        local shapes = (node[&amp;#039;and&amp;#039;] ~= nil and 1 or 0) + (node[&amp;#039;or&amp;#039;] ~= nil and 1 or 0) + (node.type ~= nil and 1 or 0)&lt;br /&gt;
        if shapes &amp;gt; 1 then fail(&amp;#039;conflicting-shapes&amp;#039;, path, &amp;#039;一个节点只能使用 and、or 或一种基本条件&amp;#039;) end&lt;br /&gt;
        for _, name in ipairs({ &amp;#039;text&amp;#039;, &amp;#039;addition&amp;#039; }) do&lt;br /&gt;
            if node[name] ~= nil and type(node[name]) ~= &amp;#039;string&amp;#039; then&lt;br /&gt;
                fail(&amp;#039;invalid-text&amp;#039;, path .. &amp;#039;.&amp;#039; .. name, &amp;#039;说明字段必须是文本&amp;#039;)&lt;br /&gt;
            end&lt;br /&gt;
        end&lt;br /&gt;
        local allowed = { text = true, addition = true }&lt;br /&gt;
        if node[&amp;#039;and&amp;#039;] ~= nil or node[&amp;#039;or&amp;#039;] ~= nil then&lt;br /&gt;
            local operator = node[&amp;#039;and&amp;#039;] ~= nil and &amp;#039;and&amp;#039; or &amp;#039;or&amp;#039;&lt;br /&gt;
            allowed[operator] = true&lt;br /&gt;
            fields(node, allowed, path)&lt;br /&gt;
            local size = list(node[operator], path .. &amp;#039;.&amp;#039; .. operator)&lt;br /&gt;
            for index = 1, size do walk(node[operator][index], path .. &amp;#039;.&amp;#039; .. operator .. &amp;#039;[&amp;#039; .. index .. &amp;#039;]&amp;#039;, depth + 1) end&lt;br /&gt;
        elseif node.type ~= nil then&lt;br /&gt;
            allowed.type, allowed.item = true, true&lt;br /&gt;
            if node.type == &amp;#039;have&amp;#039; then&lt;br /&gt;
                allowed.count = true&lt;br /&gt;
                if node.count ~= nil then requireCount(node.count, path .. &amp;#039;.count&amp;#039;) end&lt;br /&gt;
            elseif node.type == &amp;#039;collection&amp;#039; then&lt;br /&gt;
                allowed.percent = true&lt;br /&gt;
                requirePercent(node.percent, path .. &amp;#039;.percent&amp;#039;)&lt;br /&gt;
            elseif node.type ~= &amp;#039;equipment&amp;#039; and node.type ~= &amp;#039;use&amp;#039; then&lt;br /&gt;
                fail(&amp;#039;unknown-type&amp;#039;, path .. &amp;#039;.type&amp;#039;, &amp;#039;不支持的解锁条件类型&amp;#039;)&lt;br /&gt;
            end&lt;br /&gt;
            fields(node, allowed, path)&lt;br /&gt;
            requireName(node.item, path .. &amp;#039;.item&amp;#039;)&lt;br /&gt;
        else&lt;br /&gt;
            fields(node, allowed, path)&lt;br /&gt;
            if not nonempty(node.text) then fail(&amp;#039;empty-node&amp;#039;, path, &amp;#039;节点必须有结构条件或非空 text&amp;#039;) end&lt;br /&gt;
        end&lt;br /&gt;
        seen[node] = nil&lt;br /&gt;
    end&lt;br /&gt;
    walk(condition, &amp;#039;$&amp;#039;, 1)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function numberText(value)&lt;br /&gt;
    return string.format(&amp;#039;%.15g&amp;#039;, value)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function bracket(text)&lt;br /&gt;
    return &amp;#039;（&amp;#039; .. text .. &amp;#039;）&amp;#039;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function complexText(text)&lt;br /&gt;
    return text:find(&amp;#039;且&amp;#039;, 1, true) ~= nil or text:find(&amp;#039;或&amp;#039;, 1, true) ~= nil or text:find(&amp;#039;\n&amp;#039;, 1, true) ~= nil&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function render(condition)&lt;br /&gt;
    if condition == nil then return &amp;#039;无需解锁&amp;#039; end&lt;br /&gt;
    local function walk(node)&lt;br /&gt;
        local result&lt;br /&gt;
        if nonempty(node.text) then&lt;br /&gt;
            result = { text = C.literal(node.text), kind = &amp;#039;atom&amp;#039;, opaque = complexText(node.text) }&lt;br /&gt;
        elseif node.type then&lt;br /&gt;
            local item = C.link(node.item)&lt;br /&gt;
            if node.type == &amp;#039;have&amp;#039; then&lt;br /&gt;
                local count = node.count or 1&lt;br /&gt;
                result = { text = count == 1 and (&amp;#039;持有&amp;#039; .. item) or (&amp;#039;持有至少&amp;#039; .. C.literal(numberText(count)) .. &amp;#039;个&amp;#039; .. item), kind = &amp;#039;atom&amp;#039;, simple = count == 1 and &amp;#039;have&amp;#039; or nil, item = item }&lt;br /&gt;
            elseif node.type == &amp;#039;collection&amp;#039; then&lt;br /&gt;
                result = { text = item .. &amp;#039;收集度达到&amp;#039; .. C.literal(numberText(node.percent)) .. &amp;#039;%&amp;#039;, kind = &amp;#039;atom&amp;#039; }&lt;br /&gt;
            elseif node.type == &amp;#039;use&amp;#039; then&lt;br /&gt;
                result = { text = &amp;#039;使用&amp;#039; .. item, kind = &amp;#039;atom&amp;#039;, simple = &amp;#039;use&amp;#039;, item = item }&lt;br /&gt;
            else&lt;br /&gt;
                result = { text = &amp;#039;装备有&amp;#039; .. item, kind = &amp;#039;atom&amp;#039;, simple = &amp;#039;equipment&amp;#039;, item = item }&lt;br /&gt;
            end&lt;br /&gt;
        else&lt;br /&gt;
            local operator = node[&amp;#039;and&amp;#039;] ~= nil and &amp;#039;and&amp;#039; or &amp;#039;or&amp;#039;&lt;br /&gt;
            local children, simple, sameSimple = {}, nil, true&lt;br /&gt;
            for index, child in ipairs(node[operator]) do&lt;br /&gt;
                children[index] = walk(child)&lt;br /&gt;
                if index == 1 then simple = children[index].simple end&lt;br /&gt;
                if simple == nil or children[index].simple ~= simple then sameSimple = false end&lt;br /&gt;
            end&lt;br /&gt;
            if #children == 1 then&lt;br /&gt;
                result = children[1]&lt;br /&gt;
            elseif sameSimple then&lt;br /&gt;
                local names = {}&lt;br /&gt;
                for index, child in ipairs(children) do names[index] = child.item end&lt;br /&gt;
                local verbs = { have = &amp;#039;持有&amp;#039;, equipment = &amp;#039;装备有&amp;#039;, use = &amp;#039;使用&amp;#039; }&lt;br /&gt;
                result = { text = verbs[simple] .. table.concat(names, operator == &amp;#039;and&amp;#039; and &amp;#039;和&amp;#039; or &amp;#039;或&amp;#039;), kind = operator }&lt;br /&gt;
            else&lt;br /&gt;
                local phrases = {}&lt;br /&gt;
                for index, child in ipairs(children) do&lt;br /&gt;
                    phrases[index] = (child.kind ~= &amp;#039;atom&amp;#039; or child.opaque) and bracket(child.text) or child.text&lt;br /&gt;
                end&lt;br /&gt;
                result = { text = table.concat(phrases, operator == &amp;#039;and&amp;#039; and &amp;#039;且&amp;#039; or &amp;#039;或&amp;#039;), kind = operator }&lt;br /&gt;
            end&lt;br /&gt;
        end&lt;br /&gt;
        if nonempty(node.addition) then&lt;br /&gt;
            local base = (result.kind == &amp;#039;or&amp;#039; or result.opaque) and bracket(result.text) or result.text&lt;br /&gt;
            local addition = C.literal(node.addition)&lt;br /&gt;
            if complexText(node.addition) then addition = bracket(addition) end&lt;br /&gt;
            result = { text = base .. &amp;#039;且&amp;#039; .. addition, kind = &amp;#039;and&amp;#039; }&lt;br /&gt;
        end&lt;br /&gt;
        return result&lt;br /&gt;
    end&lt;br /&gt;
    return walk(condition).text&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.validate(condition)&lt;br /&gt;
    return protect(function()&lt;br /&gt;
        validate(condition)&lt;br /&gt;
        return { status = condition == nil and &amp;#039;none&amp;#039; or &amp;#039;known&amp;#039; }&lt;br /&gt;
    end)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.render(condition)&lt;br /&gt;
    return protect(function()&lt;br /&gt;
        validate(condition)&lt;br /&gt;
        return { status = condition == nil and &amp;#039;none&amp;#039; or &amp;#039;known&amp;#039;, text = render(condition) }&lt;br /&gt;
    end)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.describe(record, version)&lt;br /&gt;
    return protect(function()&lt;br /&gt;
        if type(record) ~= &amp;#039;table&amp;#039; then fail(&amp;#039;invalid-record&amp;#039;, &amp;#039;$&amp;#039;, &amp;#039;地点记录必须是对象&amp;#039;) end&lt;br /&gt;
        if version ~= 2 then fail(&amp;#039;unsupported-version&amp;#039;, &amp;#039;schemaVersion&amp;#039;, &amp;#039;仅支持地点数据版本 2，旧数据应在部署前转换&amp;#039;) end&lt;br /&gt;
        for _, key in ipairs({ &amp;#039;entryEquipment&amp;#039;, &amp;#039;entryDisabled&amp;#039; }) do&lt;br /&gt;
            if record[key] ~= nil then fail(&amp;#039;obsolete-field&amp;#039;, &amp;#039;$.&amp;#039; .. key, &amp;#039;进入条件必须统一放在 unlock 中，不接受旧字段&amp;#039;) end&lt;br /&gt;
        end&lt;br /&gt;
        validate(record.unlock)&lt;br /&gt;
        return { status = record.unlock == nil and &amp;#039;none&amp;#039; or &amp;#039;known&amp;#039;, condition = record.unlock, text = render(record.unlock) }&lt;br /&gt;
    end)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>NotBot</name></author>
	</entry>
</feed>