- fix bugs for event listener
- change redalarm triggered by random(seems not work as expected)
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -108,7 +108,11 @@ do
|
||||
end
|
||||
|
||||
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()
|
||||
|
||||
|
||||
|
||||
+8
-2
@@ -45,13 +45,13 @@ do
|
||||
|
||||
function redAlarmEvent:onEvent(event)
|
||||
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
|
||||
if not object then return end
|
||||
if not object:isExist() 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
|
||||
|
||||
@@ -68,18 +68,22 @@ do
|
||||
local objectCategory, unitCategory = Object.getCategory(object)
|
||||
if objectCategory == Object.Category.UNIT then
|
||||
if unitCategory == Unit.Category.GROUND_UNIT or unitCategory == Unit.Category.STRUCTURE then
|
||||
if math.random(1,10) <= 4 then
|
||||
self:redAlarm_On()
|
||||
world.removeEventHandler(redAlarmEvent)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if objectCategory == Object.Category.STATIC then
|
||||
if math.random(1,10) == 1 then
|
||||
self:redAlarm_On()
|
||||
world.removeEventHandler(redAlarmEvent)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
world.addEventHandler(redAlarmEvent)
|
||||
end
|
||||
@@ -194,12 +198,14 @@ do
|
||||
--关闭
|
||||
timer.scheduleFunction(function (group)
|
||||
if not group then return end
|
||||
if not group:isExist() then return end
|
||||
trigger.action.setGroupAIOff(group)
|
||||
end,group,timer.getTime()+math.random(1,10))
|
||||
|
||||
--开启
|
||||
timer.scheduleFunction(function (group)
|
||||
if not group then return end
|
||||
if not group:isExist() then return end
|
||||
trigger.action.setGroupAIOn(group)
|
||||
end,group,timer.getTime()+math.random(180,900))
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user