bayuMIR/Mirserver/Mir200/Envir/QuestDiary/游戏功能/A0_通用类/BOSS查询.lua
2026-06-18 01:11:06 +08:00

103 lines
2.6 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- BOSS查询模块
-- 负责定时缓存BOSS存活状态 + 响应客户端查询请求
BOSSqueryOBJ = Up_BaseClass:new()
BOSSqueryOBJ._name = "BOSSqueryOBJ"
-- BOSS存活状态缓存
BOSSqueryOBJ.bossCache = {}
-- 配置文件
BOSSqueryOBJ.cfg = Func.require("cfg_BOSS查询")
---* 刷新BOSS缓存由全局定时器每60秒调用
function BOSSqueryOBJ:reloadBossCache()
local cache = {}
for _, info in ipairs(self.cfg) do
-- mapbossinfo 返回格式: {[1] = "怪物名#血量%#复活倒计时秒#X#Y#未知"}
-- 例: "奴隶统帅#0#10687#100#99#无" → HP=0(死亡), 10687秒后复活
-- 例: "洪荒·祖玛教皇#100#0#20#22#无" → HP=100(存活)
local monStatus = mapbossinfo(info.mapname, info.name, 0, 0)
local alive = false
local respawnTime = 0
LOGDump(monStatus,info.name)
if monStatus and type(monStatus) == "table" then
for _, v in pairs(monStatus) do
if type(v) == "string" and v ~= "" then
local parts = Func.splitString(v, "#")
-- parts[1]=怪物名, parts[2]=血量百分比, parts[3]=复活倒计时秒
local hpPercent = tonumber(parts[2]) or 0
if hpPercent > 0 then
alive = true
end
respawnTime = tonumber(parts[3]) or 0
break
end
end
end
table.insert(cache, {
map = info.mapname,
name = info.name,
level = info.level or "S级",
alive = alive,
reviveStamp = (not alive and respawnTime > 0) and (os.time() + respawnTime) or 0,
appr = info.Appr or 0,
})
end
-- -- 存活BOSS置顶
-- table.sort(cache, function(a, b)
-- if a.alive ~= b.alive then
-- return a.alive -- true在前
-- end
-- return false
-- end)
self.bossCache = cache
end
---* 获取存活BOSS数量
function BOSSqueryOBJ:getAliveCount()
local count = 0
for _, v in ipairs(self.bossCache) do
if v.alive then
count = count + 1
end
end
return count
end
BOSSqueryOBJ:reloadBossCache()
---* 客户端请求入口(由 Message.dispatch 自动调用)
---@param actor any 玩家对象
function BOSSqueryOBJ:main(actor)
-- 首次调用时缓存可能为空,立即刷新一次
if not self.bossCache or #self.bossCache == 0 then
self:reloadBossCache()
end
-- 客户端用 SL:Get_SERVER_TIME() 与 reviveStamp 自行计算剩余倒计时
Message:SubLink(actor, self._name .. "_main", {cfg = self.bossCache})
end
-- 允许客户端调用的方法白名单(安全校验)
BOSSqueryOBJ.allowFunc = {"main"}
return BOSSqueryOBJ