openwf/Scripts/自定义节点等级.pluto

80 lines
2.3 KiB
Plaintext

-- 自定义节点等级
local regionNames = loadfile("OpenWF/Scripts/RegionNameMapping.pluto")()
local function launchNode(nodeId, minLevel, maxLevel, hardMode)
local args = Engine.OpenLevelArgs()
local info = gStarChart:BuildMissionForLocation(Symbol(nodeId))
local infoStr = info:EncodeAsString()
if hardMode then
infoStr = infoStr:gsub("levelAuras={[^}]+}", [[levelAuras={
/Lotus/Upgrades/Mods/DirectorMods/HardModeEnemyLevelAura,
/Lotus/Upgrades/Mods/DirectorMods/HardModeLevelAura
}]])
end
if not infoStr:find("tier=") then
infoStr = infoStr:gsub("}", " tier=1\r\n}")
end
if minLevel then
infoStr = infoStr:gsub("minEnemyLevel=%d+", $"minEnemyLevel={minLevel}")
end
if maxLevel then
infoStr = infoStr:gsub("maxEnemyLevel=%d+", $"maxEnemyLevel={maxLevel}")
end
args:SetLevel(info.levelOverride:GetFullName())
args:AddContextTag(infoStr)
for info:GetEnemies() as enemy do
args:AddContextObject(enemy.agent)
end
for info:GetAdvancedAiDirectorSpawns() as spawner do
args:AddContextObject(spawner)
end
Engine.OpenLevel(args)
end
local function parseCommand(text, hardMode)
local parts = text:split(" ")
local nodeId = regionNames[parts[2]] or parts[2]
local min = parts[3]
local max = parts[4]
local minLevel = (min and min ~= "-" and min ~= "x") ? tonumber(min) : nil
local maxLevel = (max and max ~= "-" and max ~= "x") ? tonumber(max) : nil
launchNode(nodeId, minLevel, maxLevel, hardMode)
end
local commands = {}
commands["节点"] = |text| -> parseCommand(text, false)
commands["钢铁"] = |text| -> parseCommand(text, true)
for prefix in commands do
chat_subscribe_prefix("/" .. prefix, true)
end
repeat
while evt := owf_next_event() do
if evt.type == OWF_EVT_SUBMIT_CHAT_MESSAGE and evt.text and evt.text:sub(1,1) == "/" then
for prefix, handler in commands do
if evt.text:sub(2, #prefix + 1) == prefix then
handler(evt.text)
break
end
end
end
end
until yield()
-- 示例:
-- /钢铁 赛德娜-Kappa 9999 只设置最低
-- /节点 赛德娜-Kappa 9999 10000 同时设置
-- /钢铁 赛德娜-Kappa - 10000 只设置最高