Add first version of PowerStationEvent effect(Ver1.0)

This commit is contained in:
2025-04-02 00:42:56 +08:00
parent 094a79d317
commit d1cdac51a8
2 changed files with 165 additions and 15 deletions
Binary file not shown.
+164 -14
View File
@@ -26,10 +26,8 @@ do
if not groupIsActivate and not redAlarmEvent.ignoreList[group:getName()] then if not groupIsActivate and not redAlarmEvent.ignoreList[group:getName()] then
Utils.Debug('Activate: '..group:getName())
timer.scheduleFunction(function (group) timer.scheduleFunction(function (group)
group:activate() group:activate()
Utils.Debug('Activated: '..group:getName())
end,group,timer.getTime()+math.random(120,600)) end,group,timer.getTime()+math.random(120,600))
end end
@@ -42,20 +40,17 @@ do
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 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 local object = event.initiator
if not object:getCoalition() == 1 then return end if not object:getCoalition() == 1 then return end
Utils.Debug('redAlarmEvent') if object:getName() == 'Red-PowerStation-1' then return end
local objectCategory, unitCategory = Unit.getCategory(object) local objectCategory, unitCategory = Unit.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
Utils.Debug('call redAlarm_On')
self:redAlarm_On() self:redAlarm_On()
world.removeEventHandler(redAlarmEvent) world.removeEventHandler(redAlarmEvent)
end end
end end
if objectCategory == Object.Category.STATIC then if objectCategory == Object.Category.STATIC then
if object:getName() == 'Red-PowerStation-1' then return end
Utils.Debug('call redAlarm_On')
self:redAlarm_On() self:redAlarm_On()
world.removeEventHandler(redAlarmEvent) world.removeEventHandler(redAlarmEvent)
end end
@@ -69,7 +64,7 @@ end
-- Power Station -- Power Station
do do
local PowerStationEvent = { local PowerStationEvent = {
connectedUnitList = { connectedGroupList = {
'Red-EWR-CRAM-1', 'Red-EWR-CRAM-1',
'Red-CWStorage-CRAM-1', 'Red-CWStorage-CRAM-1',
'Red-SAMSite-CRAM-1', 'Red-SAMSite-CRAM-1',
@@ -81,20 +76,160 @@ do
ori = 'Container_watchtower_lights', ori = 'Container_watchtower_lights',
replace = 'Container_watchtower', replace = 'Container_watchtower',
}, },
['Static M92 NF-2 LightOn-1'] = { ['Static M92 Container watchtower lights-2-1'] = {
ori = 'NF-2 LightOn', ori = 'Container_watchtower_lights',
replace = 'NF-2 LightOff 01', 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) function PowerStationEvent:onEvent(event)
if event.id == world.event.S_EVENT_KILL or event.id == world.event.S_EVENT_DEAD then if event.id == world.event.S_EVENT_KILL or event.id == world.event.S_EVENT_DEAD then
local object = event.initiator 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
local objectCategory, unitCategory = Unit.getCategory(object) if not groupIsAlive then
if objectCategory == Object.Category.STATIC then group = nil
if object:getName() == 'Red-PowerStation-1' then return end 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) world.removeEventHandler(PowerStationEvent)
end end
@@ -103,3 +238,18 @@ do
world.addEventHandler(PowerStationEvent) world.addEventHandler(PowerStationEvent)
end 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)