- fix bugs for event listener

- change redalarm triggered by random(seems not work as expected)
This commit is contained in:
2025-04-10 21:13:11 +08:00
parent ec3178c2d6
commit c55b615554
4 changed files with 17 additions and 7 deletions
Binary file not shown.
Binary file not shown.
+5 -1
View File
@@ -108,7 +108,11 @@ do
end end
function PatrolUnit:Remove() function PatrolUnit:Remove()
if self.group then self.group:destroy() end if self.group then
if self.group:isExist() then
self.group:destroy()
end
end
self:stop() self:stop()
+12 -6
View File
@@ -45,13 +45,13 @@ do
function redAlarmEvent:onEvent(event) function redAlarmEvent:onEvent(event)
if not self.redAlarm then if not self.redAlarm then
if event.id == world.event.S_EVENT_HIT then if event.id == world.event.S_EVENT_KILL then
local object = event.target local object = event.target
if not object then return end if not object then return end
if not object:isExist() then return end if not object:isExist() then return end
if not object.getCoalition then return end if not object.getCoalition then return end
if object:getCoalition() == 2 then return end if object:getCoalition() ~= coalition.side.RED then return end
for groupName, value in pairs(redAlarmEvent.alarmOffGroups) do for groupName, value in pairs(redAlarmEvent.alarmOffGroups) do
@@ -68,14 +68,18 @@ do
local objectCategory, unitCategory = Object.getCategory(object) local objectCategory, unitCategory = Object.getCategory(object)
if objectCategory == Object.Category.UNIT then if objectCategory == Object.Category.UNIT then
if unitCategory == Unit.Category.GROUND_UNIT or unitCategory == Unit.Category.STRUCTURE then if unitCategory == Unit.Category.GROUND_UNIT or unitCategory == Unit.Category.STRUCTURE then
self:redAlarm_On() if math.random(1,10) <= 4 then
world.removeEventHandler(redAlarmEvent) self:redAlarm_On()
world.removeEventHandler(redAlarmEvent)
end
end end
end end
if objectCategory == Object.Category.STATIC then if objectCategory == Object.Category.STATIC then
self:redAlarm_On() if math.random(1,10) == 1 then
world.removeEventHandler(redAlarmEvent) self:redAlarm_On()
world.removeEventHandler(redAlarmEvent)
end
end end
end end
end end
@@ -194,12 +198,14 @@ do
--关闭 --关闭
timer.scheduleFunction(function (group) timer.scheduleFunction(function (group)
if not group then return end if not group then return end
if not group:isExist() then return end
trigger.action.setGroupAIOff(group) trigger.action.setGroupAIOff(group)
end,group,timer.getTime()+math.random(1,10)) end,group,timer.getTime()+math.random(1,10))
--开启 --开启
timer.scheduleFunction(function (group) timer.scheduleFunction(function (group)
if not group then return end if not group then return end
if not group:isExist() then return end
trigger.action.setGroupAIOn(group) trigger.action.setGroupAIOn(group)
end,group,timer.getTime()+math.random(180,900)) end,group,timer.getTime()+math.random(180,900))
end end