bayuMIR/Mirserver/Mir200/Envir/QuestDiary/系统类/定时器任务.lua
2026-06-24 21:00:14 +08:00

134 lines
3.3 KiB
Lua

OntimerOBJ = {}
function OntimerOBJ:hasPickupDrop(actor)
local mapid = getbaseinfo(actor, ConstCfg.gbase.mapid)
local x = getbaseinfo(actor, ConstCfg.gbase.x)
local y = getbaseinfo(actor, ConstCfg.gbase.y)
if not mapid or mapid == "" or not x or not y then
return false
end
local items = getobjectinmap(mapid, x, y, 10, 8)
return items and next(items) ~= nil
end
function OntimerOBJ:refreshPickupSprite(actor)
local timerId = VarCfg.Timer["拾取精灵巡检"]
if getflagstatus(actor, VarCfg.Falg_shiqujinlin) ~= 1 then
pickupitems(actor, -1)
releasesprite(actor)
setofftimer(actor, timerId)
return
end
local hasDrop = self:hasPickupDrop(actor)
local hasSprite = checkspritelevel(actor, "嗷嗷虎")
if hasDrop then
if not hasSprite then
createsprite(actor, "嗷嗷虎")
pickupitems(actor, 3, 10, 1000)
end
else
if hasSprite then
pickupitems(actor, -1)
releasesprite(actor)
end
end
end
function OntimerOBJ:startPickupSpriteTimer(actor)
local timerId = VarCfg.Timer["拾取精灵巡检"]
if getflagstatus(actor, VarCfg.Falg_shiqujinlin) ~= 1 then
self:stopPickupSpriteTimer(actor)
return
end
if not hastimer(actor, timerId) then
setontimer(actor, timerId, 3, 0)
end
self:refreshPickupSprite(actor)
end
function OntimerOBJ:stopPickupSpriteTimer(actor)
local timerId = VarCfg.Timer["拾取精灵巡检"]
if hastimer(actor, timerId) then
setofftimer(actor, timerId)
end
pickupitems(actor, -1)
releasesprite(actor)
end
OntimerOBJ.ontimer = {
[20] = function(actor)
-- LOGDump(ShabaKeOBJ.SBK._state())
local _state = ShabaKeOBJ.SBK._state()
if not _state then
setofftimer(actor, VarCfg.Timer["攻沙定时器"])
return
end
local _guild = getbaseinfo(actor, ConstCfg.gbase.guild)
if _guild == "" then
setofftimer(actor, VarCfg.Timer["攻沙定时器"])
return
end
local _relevel = getbaseinfo(actor, ConstCfg.gbase.renew_level)
if _relevel < ShabaKeOBJ.cfg.minRelevel then
return
end
local _sbkrange = getbaseinfo(actor, ConstCfg.gbase.sbkrange)
if not _sbkrange then
return
end
local _min = Player.getTLint(actor, VarCfg.Player.TL.int["攻城区域计秒"]) or 0
Player.setTLint(actor, VarCfg.Player.TL.int["攻城区域计秒"], _min + 1)
-- LOGDump("攻城区域计秒: " .. _min)
end,
[21] = function(actor)
OntimerOBJ:refreshPickupSprite(actor)
end,
[22] = function(actor)
if AutoXunHangOBJ and AutoXunHangOBJ.onTimer then
AutoXunHangOBJ:onTimer(actor)
end
end,
[23] = function(actor)
if NPCGotoMapOBJ and NPCGotoMapOBJ.onLimitedTimer then
NPCGotoMapOBJ:onLimitedTimer(actor)
end
end
}
for i, v in pairs(VarCfg.Timer or {}) do
_G["ontimer" .. v] = function(actor)
if OntimerOBJ.ontimer[v] then
OntimerOBJ.ontimer[v](actor)
end
end
end
GameEvent.add(EventCfg.onExitGame, function(actor)
OntimerOBJ:stopPickupSpriteTimer(actor)
end, OntimerOBJ)
return OntimerOBJ