- 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
|
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()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+8
-2
@@ -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,18 +68,22 @@ 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
|
||||||
|
if math.random(1,10) <= 4 then
|
||||||
self:redAlarm_On()
|
self:redAlarm_On()
|
||||||
world.removeEventHandler(redAlarmEvent)
|
world.removeEventHandler(redAlarmEvent)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if objectCategory == Object.Category.STATIC then
|
if objectCategory == Object.Category.STATIC then
|
||||||
|
if math.random(1,10) == 1 then
|
||||||
self:redAlarm_On()
|
self:redAlarm_On()
|
||||||
world.removeEventHandler(redAlarmEvent)
|
world.removeEventHandler(redAlarmEvent)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
world.addEventHandler(redAlarmEvent)
|
world.addEventHandler(redAlarmEvent)
|
||||||
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
|
||||||
|
|||||||
Reference in New Issue
Block a user