--死亡 local DeadSystem = {} local private = {} --加载需要的模块 local EventSystem = require 'Event/EventSystem' function DeadSystem.OnDead(entity, levelConditionIgnoreCount, deadParams, missileID) if not entity.isPickupItem then entity.components.attr.hp:Reset() if entity.components.move.ShovePriority > 50 then LuaShoveManager.ReSetGridDataOfEntity(entity,true) end local masterEntity = entity:GetMasterEntity() if masterEntity then masterEntity.components.base:OnDominatedEntityDead(entity) end --投技(Grab)处理↓ if entity.components.base.GrabbedEntity then SystemManager.StopGrab(entity, entity.components.base.GrabbedEntity) end if entity.components.base.Graber then SystemManager.StopGrab(entity.components.base.Graber, entity) --被抓取的单位死亡时,解除抓取 end --↑↑↑↑↑↑↑ entity.components.record:OnDead() end LevelManager.CurLevelFunc:OnEntityDead(entity, deadParams, missileID) EventSystem.Dispatch(entity.Event_EntityDead,entity, levelConditionIgnoreCount) if entity:IsPlayerSelf() then EventSystem.Dispatch(EventID.Player_Dead) end entity.ExpEntity:OnDead() BattleEventSystem.AfterEntityDead(entity) --这个要放BuffSystem.OnDead、AttrSystem.OnDead、DriveSystem.OnDead等的前面,因为后面这些会清除数据,所以要在清除数据前抛事件,否则会缺少信息量以至于无法发动一些效果 end function DeadSystem.OnLogicUpdate(entity) if entity.isPickupItem then entity.pickUpItemLifeFrameLeft = entity.pickUpItemLifeFrameLeft - 1 if entity.pickUpItemLifeFrameLeft <= 0 then SystemManager.DeadQuit(entity) end return --这里必须return 因为 pickupItem 没有 record Comp end local comp_Record = entity.components.record if not comp_Record.IsUnload then return end SystemManager.OnUnload(entity) end function DeadSystem.BindDead(fatherEntity,sonEntity) fatherEntity.components.dead:BindDead(sonEntity) end function DeadSystem.FollowDead(entity,deadFunc) -- 尝试让我的子孙陪葬 local dead = entity.components.dead if dead then local followList = dead:GetFollowDeadList() if followList then for i,sonEntity in ipairs(followList) do sonEntity._logicInitData.MasterEntity = nil deadFunc = deadFunc or SystemManager.OnDead deadFunc(sonEntity) -- 形成了递归 end dead:ResetFollowDeadList() end end --告诉自己父亲,不能陪葬了 gws:不会和上面形成了递归 ,因为上面已经设置myFather=nil 。这段代码只有在父亲没死子孙死的时候才发生 local myFather = entity:GetDirectMasterEntity() if myFather then local fatherDead = myFather.components.dead fatherDead:UnBindDead(entity) end end function DeadSystem.FollowDeadQuit(entity) DeadSystem.FollowDead(entity,SystemManager.DeadQuit) end function DeadSystem.OnMove(entity) if entity.components.move.isInCliff then if entity:IsAlive() then DeadSystem.OnDead(entity) end end end return DeadSystem