-- hanle miscellaneous mission events --Red alarm when under attack do local redAlarmEvent = { redAlarm = false, ignoreList = { ['Red-RescueInf-1'] = true, ['Red-Scud'] = true, } } function redAlarmEvent:redAlarm_On() Utils.Debug('==================\n\n敌人因为受到攻击, 拉响了警报!\n\n==================') self.redAlarm = true local redGrounds = coalition.getGroups(1,Group.Category.GROUND) for i, group in ipairs(redGrounds) do local groupIsActivate = true for i,unit in ipairs(group:getUnits()) do if not unit:isActive() then groupIsActivate = false end end if not groupIsActivate and not redAlarmEvent.ignoreList[group:getName()] then timer.scheduleFunction(function (group) group:activate() end,group,timer.getTime()+math.random(120,600)) end end end function redAlarmEvent:onEvent(event) if not self.redAlarm then if event.id == world.event.S_EVENT_HIT or event.id == world.event.S_EVENT_KILL or event.id == world.event.S_EVENT_DEAD then local object = event.initiator if not object:getCoalition() == 1 then return end if object:getName() == 'Red-PowerStation-1' then return end local objectCategory, unitCategory = Unit.getCategory(object) if objectCategory == Object.Category.UNIT then if unitCategory == Unit.Category.GROUND_UNIT or unitCategory == Unit.Category.STRUCTURE then self:redAlarm_On() world.removeEventHandler(redAlarmEvent) end end if objectCategory == Object.Category.STATIC then self:redAlarm_On() world.removeEventHandler(redAlarmEvent) end end end end world.addEventHandler(redAlarmEvent) end -- Power Station do local PowerStationEvent = { connectedGroupList = { 'Red-EWR-CRAM-1', 'Red-CWStorage-CRAM-1', 'Red-SAMSite-CRAM-1', 'Red-EWR-1', 'Red-Rescue-SAM-1', }, replaceStatics = { ['Static M92 Container watchtower lights-1'] = { ori = 'Container_watchtower_lights', replace = 'Container_watchtower', }, ['Static M92 Container watchtower lights-2-1'] = { ori = 'Container_watchtower_lights', replace = 'Container_watchtower', }, ['Static M92 Container watchtower lights-3-1'] = { ori = 'Container_watchtower_lights', replace = 'Container_watchtower', }, ['Static M92 Container watchtower lights-4-1'] = { ori = 'Container_watchtower_lights', replace = 'Container_watchtower', }, ['Static M92 Container watchtower lights-5-1'] = { ori = 'Container_watchtower_lights', replace = 'Container_watchtower', }, ['静态 M92 集装箱瞭望塔(有灯光)-1-1'] = { ori = 'Container_watchtower_lights', replace = 'Container_watchtower', }, ['静态 M92 集装箱瞭望塔(有灯光)-2-1'] = { ori = 'Container_watchtower_lights', replace = 'Container_watchtower', }, ['Static M92 NF-2 LightOn-1-1'] = { ori = 'NF-2_LightOn', replace = 'NF-2_LightOff01', }, ['Static M92 NF-2_LightOn-2-1'] = { ori = 'NF-2_LightOn', replace = 'NF-2_LightOff01', }, ['静态 M92 NF-2 泛光灯组(打开)-1-1'] = { ori = 'NF-2_LightOn', replace = 'NF-2_LightOff01', }, ['静态 M92 NF-2 泛光灯组(打开)-2-1'] = { ori = 'NF-2_LightOn', replace = 'NF-2_LightOff01', }, ['静态 M92 NF-2 泛光灯组(打开)-3-1'] = { ori = 'NF-2_LightOn', replace = 'NF-2_LightOff01', }, ['静态 M92 NF-2 泛光灯组(打开)-4-1'] = { ori = 'NF-2_LightOn', replace = 'NF-2_LightOff01', }, ['静态 M92 NF-2 泛光灯组(打开)-5-1'] = { ori = 'NF-2_LightOn', replace = 'NF-2_LightOff01', }, ['静态 M92 NF-2 泛光灯组(打开)-6-1'] = { ori = 'NF-2_LightOn', replace = 'NF-2_LightOff01', }, ['静态 M92 NF-2 泛光灯组(打开)-7-1'] = { ori = 'NF-2_LightOn', replace = 'NF-2_LightOff01', }, ['静态 M92 NF-2 泛光灯组(打开)-8-1'] = { ori = 'NF-2_LightOn', replace = 'NF-2_LightOff01', }, }, newStaticObjs = {}, } function PowerStationEvent:onEvent(event) if event.id == world.event.S_EVENT_KILL or event.id == world.event.S_EVENT_DEAD then local object = event.initiator if object:getName() == 'Red-PowerStation-1' then -- 关闭防空 for i, groupName in ipairs(PowerStationEvent.connectedGroupList) do local group = Group.getByName(groupName) if group then if group:isExist() and group:getUnits() then local groupIsAlive = false for i, unit in ipairs(group:getUnits()) do if unit:getLife() >= 1 then groupIsAlive= true end end if not groupIsAlive then group = nil end end end --关闭 timer.scheduleFunction(function (group) if not group 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 trigger.action.setGroupAIOn(group) end,group,timer.getTime()+math.random(180,900)) end -- 关闭静态物体灯光 local objectIndex = 1 for groupName, staticData in pairs(PowerStationEvent.replaceStatics) do local staticLight = StaticObject.getByName(groupName) if staticLight then local staticPoint = staticLight:getPoint() local staticType_Ori = staticLight:getTypeName() local staticType_Replace = PowerStationEvent.replaceStatics[groupName].replace -- local staticeHeading = math.deg(Utils.getObjHeading(staticLight)) local staticeHeading = Utils.getObjHeading(staticLight) local countryId = staticLight:getCountry() --- 记录初始状态 local staticData = {} -- 记录位置 staticData.name = 'lightsOff-'..objectIndex objectIndex = objectIndex + 1 staticData.type = staticType_Replace staticData.x = staticPoint.x staticData.y = staticPoint.z -- 记录方向 staticData.heading = staticeHeading --关闭 timer.scheduleFunction(function (args) -- 删除旧物体 args.staticLight:destroy() -- 刷新新物体 timer.scheduleFunction(function (vars) local newStaticObj = coalition.addStaticObject(vars.countryId,vars.staticData) if newStaticObj then PowerStationEvent.replaceStatics[vars.groupName].newObj = newStaticObj end end,{groupName = args.groupName,staticData = args.staticData,countryId = args.countryId},timer.getTime()+0.1) end,{groupName = groupName,staticLight = staticLight,staticData = staticData,countryId = countryId},timer.getTime()+math.random(3,10)*0.1) --开启 timer.scheduleFunction(function (args) -- 删除旧物体 PowerStationEvent.replaceStatics[groupName].newObj:destroy() -- 刷新新物体. timer.scheduleFunction(function (vars) vars.staticData.name = vars.groupName vars.staticData.type = PowerStationEvent.replaceStatics[vars.groupName].ori local newStaticObj = coalition.addStaticObject(vars.countryId,vars.staticData) end,{groupName = args.groupName,staticData = args.staticData,countryId = args.countryId},timer.getTime()+0.1) end,{groupName = groupName,staticData = staticData,countryId = countryId},timer.getTime()+math.random(180,900)) end end world.removeEventHandler(PowerStationEvent) end end end world.addEventHandler(PowerStationEvent) end --Debug local PowerStation = StaticObject.getByName('Red-PowerStation-1') if not PowerStation then return end timer.scheduleFunction(function (PowerStation) Utils.Debug('触发电厂被炸event') event = { id = world.event.S_EVENT_DEAD, initiator = PowerStation, } world.onEvent(event) end,PowerStation,timer.getTime()+10)