#ZONE - Trigger added OnAfterZoneEmpty and OnAfterObjectDead

This commit is contained in:
Applevangelist 2025-03-13 10:50:15 +01:00
parent 31d0410284
commit 32f0bb33c3
2 changed files with 48 additions and 2 deletions

View File

@ -605,10 +605,13 @@ function ZONE_BASE:Trigger(Objects)
self:AddTransition("TriggerStopped","TriggerStart","TriggerRunning")
self:AddTransition("*","EnteredZone","*")
self:AddTransition("*","LeftZone","*")
self:AddTransition("*","ZoneEmpty","*")
self:AddTransition("*","ObjectDead","*")
self:AddTransition("*","TriggerRunCheck","*")
self:AddTransition("*","TriggerStop","TriggerStopped")
self:TriggerStart()
self.checkobjects = Objects
self.ObjectsInZone = false
if UTILS.IsInstanceOf(Objects,"SET_BASE") then
self.objectset = Objects.Set
else
@ -646,6 +649,22 @@ function ZONE_BASE:Trigger(Objects)
-- @param #string Event Event.
-- @param #string To To state.
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The controllable leaving the zone.
--- On After "ObjectDead" event. An observed object has left the zone.
-- @function [parent=#ZONE_BASE] OnAfterObjectDead
-- @param #ZONE_BASE self
-- @param #string From From state.
-- @param #string Event Event.
-- @param #string To To state.
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The controllable which died. Might be nil.
--- On After "ZoneEmpty" event. All observed objects have left the zone or are dead.
-- @function [parent=#ZONE_BASE] OnAfterZoneEmpty
-- @param #ZONE_BASE self
-- @param #string From From state.
-- @param #string Event Event.
-- @param #string To To state.
end
--- (Internal) Check the assigned objects for being in/out of the zone
@ -659,9 +678,13 @@ function ZONE_BASE:_TriggerCheck(fromstart)
-- just earmark everyone in/out
for _,_object in pairs(objectset) do
local obj = _object -- Wrapper.Controllable#CONTROLLABLE
if not obj.TriggerInZone then obj.TriggerInZone = {} end
if not obj.TriggerInZone then
obj.TriggerInZone = {}
obj.TriggerZoneDeadNotification = false
end
if obj and obj:IsAlive() and self:IsCoordinateInZone(obj:GetCoordinate()) then
obj.TriggerInZone[self.ZoneName] = true
self.ObjectsInZone = true
else
obj.TriggerInZone[self.ZoneName] = false
end
@ -669,6 +692,7 @@ function ZONE_BASE:_TriggerCheck(fromstart)
end
else
-- Check for changes
local objcount = 0
for _,_object in pairs(objectset) do
local obj = _object -- Wrapper.Controllable#CONTROLLABLE
if obj and obj:IsAlive() then
@ -683,11 +707,20 @@ function ZONE_BASE:_TriggerCheck(fromstart)
-- is obj in zone?
local inzone = self:IsCoordinateInZone(obj:GetCoordinate())
--self:I("Object "..obj:GetName().." is in zone: "..tostring(inzone))
if inzone and obj.TriggerInZone[self.ZoneName] then
-- just count
objcount = objcount + 1
self.ObjectsInZone = true
obj.TriggerZoneDeadNotification = false
end
if inzone and not obj.TriggerInZone[self.ZoneName] then
-- wasn't in zone before
--self:I("Newly entered")
self:__EnteredZone(0.5,obj)
obj.TriggerInZone[self.ZoneName] = true
objcount = objcount + 1
self.ObjectsInZone = true
obj.TriggerZoneDeadNotification = false
elseif (not inzone) and obj.TriggerInZone[self.ZoneName] then
-- has left the zone
--self:I("Newly left")
@ -696,8 +729,21 @@ function ZONE_BASE:_TriggerCheck(fromstart)
else
--self:I("Not left or not entered, or something went wrong!")
end
else
-- object dead
if not obj.TriggerZoneDeadNotification == true then
obj.TriggerInZone = nil
self:__ObjectDead(0.5,obj)
obj.TriggerZoneDeadNotification = true
end
end
end
-- zone empty?
if objcount == 0 and self.ObjectsInZone == true then
-- zone was not but is now empty
self.ObjectsInZone = false
self:__ZoneEmpty(0.5)
end
end
return self
end

View File

@ -2816,7 +2816,7 @@ do -- Event Handling
self:EventDispatcher():Reset( self )
for UnitID, UnitData in pairs( self:GetUnits() ) do
for UnitID, UnitData in pairs( self:GetUnits() or {}) do
UnitData:ResetEvents()
end