mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
Cargo is now respawning correctly when:
The cargo is destroyed The carrier crashes with cargo on board The player exits the carrier with cargo on board.
This commit is contained in:
parent
71da9933d7
commit
532a311db6
@ -581,6 +581,7 @@ end -- CARGO_REPRESENTABLE
|
||||
end
|
||||
|
||||
local CargoObject = self.CargoObject -- Wrapper.Group#GROUP
|
||||
CargoObject:Destroy()
|
||||
local Template = CargoObject:GetTemplate()
|
||||
CargoObject:Respawn( Template )
|
||||
|
||||
@ -632,16 +633,16 @@ function CARGO_UNIT:New( CargoUnit, Type, Name, Weight, NearRadius )
|
||||
|
||||
self:T( self.ClassName )
|
||||
|
||||
self:HandleEvent( EVENTS.Dead,
|
||||
--- @param #CARGO Cargo
|
||||
-- @param Core.Event#EVENTDATA EventData
|
||||
function( Cargo, EventData )
|
||||
if Cargo:GetObjectName() == EventData.IniUnit:GetName() then
|
||||
self:E( { "Cargo destroyed", Cargo } )
|
||||
Cargo:Destroyed()
|
||||
end
|
||||
end
|
||||
)
|
||||
-- self:HandleEvent( EVENTS.Dead,
|
||||
-- --- @param #CARGO Cargo
|
||||
-- -- @param Core.Event#EVENTDATA EventData
|
||||
-- function( Cargo, EventData )
|
||||
-- if Cargo:GetObjectName() == EventData.IniUnit:GetName() then
|
||||
-- self:E( { "Cargo destroyed", Cargo } )
|
||||
-- Cargo:Destroyed()
|
||||
-- end
|
||||
-- end
|
||||
-- )
|
||||
|
||||
self:SetEventPriority( 5 )
|
||||
|
||||
@ -984,6 +985,7 @@ function CARGO_GROUP:New( CargoGroup, Type, Name, ReportRadius )
|
||||
|
||||
self.CargoObject = CargoGroup
|
||||
self:SetDeployed( false )
|
||||
self.CargoGroup = CargoGroup
|
||||
|
||||
local WeightGroup = 0
|
||||
|
||||
@ -1002,33 +1004,44 @@ function CARGO_GROUP:New( CargoGroup, Type, Name, ReportRadius )
|
||||
-- Cargo objects are added to the _DATABASE and SET_CARGO objects.
|
||||
_EVENTDISPATCHER:CreateEventNewCargo( self )
|
||||
|
||||
self:HandleEvent( EVENTS.Dead,
|
||||
--- @param #CARGO Cargo
|
||||
-- @param Core.Event#EVENTDATA EventData
|
||||
function( Cargo, EventData )
|
||||
|
||||
local Destroyed = true
|
||||
for CargoID, CargoData in pairs( self.CargoSet:GetSet() ) do
|
||||
local Cargo = CargoData -- #CARGO
|
||||
if Cargo:IsAlive() then
|
||||
Destroyed = false
|
||||
else
|
||||
Cargo:Destroyed()
|
||||
end
|
||||
end
|
||||
|
||||
if Destroyed then
|
||||
self:Destroyed()
|
||||
self:E( { "Cargo destroyed", Cargo } )
|
||||
end
|
||||
end
|
||||
)
|
||||
self:HandleEvent( EVENTS.Dead, self.OnEventCargoDead )
|
||||
self:HandleEvent( EVENTS.Crash, self.OnEventCargoDead )
|
||||
self:HandleEvent( EVENTS.PlayerLeaveUnit, self.OnEventCargoDead )
|
||||
|
||||
self:SetEventPriority( 4 )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- @param #CARGO Cargo
|
||||
-- @param Core.Event#EVENTDATA EventData
|
||||
function CARGO_GROUP:OnEventCargoDead( EventData )
|
||||
|
||||
local Destroyed = false
|
||||
|
||||
if self:IsDestroyed() or self:IsUnLoaded() then
|
||||
Destroyed = true
|
||||
for CargoID, CargoData in pairs( self.CargoSet:GetSet() ) do
|
||||
local Cargo = CargoData -- #CARGO
|
||||
if Cargo:IsAlive() then
|
||||
Destroyed = false
|
||||
else
|
||||
Cargo:Destroyed()
|
||||
end
|
||||
end
|
||||
else
|
||||
if self.CargoCarrier:GetName() == EventData.IniUnitName then
|
||||
Destroyed = true
|
||||
end
|
||||
end
|
||||
|
||||
if Destroyed then
|
||||
self:Destroyed()
|
||||
self:E( { "Cargo group destroyed" } )
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--- Enter Boarding State.
|
||||
-- @param #CARGO_GROUP self
|
||||
-- @param Wrapper.Unit#UNIT CargoCarrier
|
||||
@ -1070,7 +1083,7 @@ function CARGO_GROUP:onenterLoaded( From, Event, To, CargoCarrier, ... )
|
||||
end
|
||||
end
|
||||
|
||||
self.CargoObject:Destroy()
|
||||
--self.CargoObject:Destroy()
|
||||
self.CargoCarrier = CargoCarrier
|
||||
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user