local EventSystem = require('Event/EventSystem') local BattleES = EventSystem.CreateEventSystem(true) local SkillBaseSystem = require "Battle/Logic/Entity/System/SkillBaseSystem" local BattleEventListener = require"Battle/Logic/Event/BattleEventListener" local EBattleEventId = LuaConst.EBattleEventId local EntityExclusiveEventDic = LuaConst.EntityExclusiveEventDic local BattleEventSystem = {} local private = { } local table_remove = table.remove local table_clear = table.clear local paramsPool = {{}, {}, {}, {}, {}} local NEXT_LISTENER_ID = 54392 --随便写的起始ID --key是listener的id(动态分配的id),value是listener local allListenersDic = nil --key是eventId,valule是listener数组,把listener按照eventId分类储存 local eventId2ListenersDic = nil local entityId2skillRejectedFrameDic = nil local waitingRemoveListeners = nil local waitingValidateListeners = nil local waitingSetHostListeners = nil function BattleEventSystem.Init() allListenersDic = {} eventId2ListenersDic = {} waitingRemoveListeners = {} waitingValidateListeners = {} waitingSetHostListeners = {} entityId2skillRejectedFrameDic = {} private.dispatchingLayer = 0 end function BattleEventSystem.OnInitLevel() private.dispatchingLayer = 0 end --for debug↓ BattleEventSystem.LogListenerInfo = function() local total = 0 local totalActiveCount = 0 local sortedList = {} for eventId, listeners in pairs(eventId2ListenersDic) do local activeListenerCount = 0 for j,listener in ipairs(listeners) do if not listener.isPaused then activeListenerCount = activeListenerCount + 1 end end total = total + #listeners totalActiveCount = totalActiveCount + activeListenerCount sortedList[#sortedList + 1] = {eventId = eventId, count = #listeners, activeListenerCount = activeListenerCount} --logging.error(LTAG.ERROR, "HYW : 事件 : ", eventId, " listener数量 : ", #listeners, " 激活listener数量 : ", activeListenerCount)--for debug end table.sort(sortedList, function(a, b) return a.count > b.count end) for i,v in ipairs(sortedList) do logging.error(LTAG.ERROR, "HYW : 事件 : ", v.eventId, " listener数量 : ", v.count, " 激活listener数量 : ", v.activeListenerCount)--for debug end logging.error(LTAG.ERROR, "HYW : 总共listener数量 : ", total, " 总激活listener数量 : ", totalActiveCount)--for debug end --for debug↑ function BattleEventSystem.AddEventListener(eventId,callback,params,host) local listener = private.CreateEventListener(eventId,callback,params,host) private.ValidateListener(listener) return listener end function private.CreateEventListener(eventId,callback,params,host) local listener = BattleEventListener:new() listener:Init(NEXT_LISTENER_ID,eventId,callback,params,host) BattleEventSystem.RefreshRecordListenerCount(listener) NEXT_LISTENER_ID = NEXT_LISTENER_ID + 1 return listener end -- new↓ 底层改为用EventSystem function private.ValidateListener(listener) if private.isDispatching then --在Dispatch时收到的validate和remove请求都记录下来,延迟到Dispatch后处理。这样做副作用不大。改变的listener只是对于引发这个改变的事件的响应会延迟1帧生效,这种配置本身发生的概率就较小,即便发生对于玩家体验来说也通常不会产生显著影响 table.insert(waitingValidateListeners, listener) else allListenersDic[listener:GetId()] = listener local listeners = eventId2ListenersDic[listener:GetEventId()] if not listeners then listeners = {} eventId2ListenersDic[listener:GetEventId()] = listeners --new 不使用闭包 BattleES.Regist(listener:GetEventId(),private.OnEvent) end table.insert(listeners,listener) end end -- new↑ 底层改为用EventSystem function BattleEventSystem.SetHostOfListener(listener, host) if private.isDispatching then table.insert(waitingSetHostListeners, {listener = listener, host = host}) return end local oldEventId = listener:GetEventId() listener:SetHost(host) local newEventId = listener:GetEventId() if oldEventId ~= newEventId then local oldListeners = eventId2ListenersDic[oldEventId] if oldListeners then for i,v in ipairs(oldListeners) do if v == listener then table.remove(oldListeners, i) if #oldListeners == 0 then eventId2ListenersDic[oldEventId] = nil BattleES.UnRegist(oldEventId, private.OnEvent) end break end end end local newListeners = eventId2ListenersDic[newEventId] if not newListeners then newListeners = {} eventId2ListenersDic[newEventId] = newListeners --new 不使用闭包 BattleES.Regist(newEventId, private.OnEvent) end table.insert(newListeners, listener) end BattleEventSystem.RefreshRecordListenerCount(listener) end function BattleEventSystem.RefreshRecordListenerCount(listener) if listener.eventId == LuaConst.EBattleEventId.ENTITY_BEFORE_LOGIC_UPDATE then if listener.host then listener.host.components.record.logicUpdateEventListenerCount = (listener.host.components.record.logicUpdateEventListenerCount or 0) + 1 end elseif listener.eventId == LuaConst.EBattleEventId.ENTITY_BEFORE_FILTER then if listener.host then listener.host.components.record.beforeFilterEventListenerCount = (listener.host.components.record.beforeFilterEventListenerCount or 0) + 1 end end end function BattleEventSystem.RemoveEventListener(listener) if listener then if private.isDispatching then --在Dispatch时收到的validate和remove请求都记录下来,延迟到Dispatch后处理。这样做副作用不大。改变的listener只是对于引发这个改变的事件的响应会延迟1帧生效,这种配置本身发生的概率就较小,即便发生对于玩家体验来说也通常不会产生显著影响 table.insert(waitingRemoveListeners, listener) else local key = listener:GetId() if listener.host then if listener.eventId == LuaConst.EBattleEventId.ENTITY_BEFORE_LOGIC_UPDATE then listener.host.components.record.logicUpdateEventListenerCount = listener.host.components.record.logicUpdateEventListenerCount - 1 elseif listener.eventId == LuaConst.EBattleEventId.ENTITY_BEFORE_FILTER then listener.host.components.record.beforeFilterEventListenerCount = listener.host.components.record.beforeFilterEventListenerCount - 1 end end local listeners = eventId2ListenersDic[listener:GetEventId()] for i,v in ipairs(listeners) do if v == listener then table.remove(listeners,i) break end end listener:Dispose() allListenersDic[key] = nil end else logging.error(LTAG.ERROR, "HYW : 删除listener时发生异常") end end function BattleEventSystem.ExitLevel() for key, listener in pairs(allListenersDic) do listener:Pause() end end --subject:事件主语 function private.OnEvent(eventId,subject,params) if EntityExclusiveEventDic[eventId] then logging.error(LTAG.ERROR, "HYW : 抛出了单位专属的模板事件,可能是代码没有写完全! 模板事件ID : ", eventId) end local listeners = eventId2ListenersDic[eventId] if listeners then if type(params) == "table" and params.components == nil and params.BelongTo == nil then --现在展开了,之前是 BattleEventSystem.IsEventParams(params) params.eventId = eventId end local startCount = #listeners private.isDispatching = true private.dispatchingLayer = private.dispatchingLayer + 1 for index,listener in ipairs(listeners) do if not listener.isPaused then listener:OnEvent(subject,params) --这里面会pcall,不会产生exception end end private.dispatchingLayer = private.dispatchingLayer - 1 if startCount ~= #listeners then logging.error(LTAG.ERROR, "HYW : 遍历Dispatch有问题了 BattleEventSystem eventId : ", eventId) end if private.dispatchingLayer <= 0 then private.isDispatching = false for i=1,#waitingRemoveListeners do BattleEventSystem.RemoveEventListener(waitingRemoveListeners[i]) end table.clear(waitingRemoveListeners) for i=1,#waitingValidateListeners do private.ValidateListener(waitingValidateListeners[i]) end table.clear(waitingValidateListeners) for i=1,#waitingSetHostListeners do BattleEventSystem.SetHostOfListener(waitingSetHostListeners[i].listener, waitingSetHostListeners[i].host) end table.clear(waitingSetHostListeners) end end end function BattleEventSystem.Dispose() allListenersDic = nil eventId2ListenersDic = nil waitingRemoveListeners = nil waitingValidateListeners = nil end function BattleEventSystem.IsEntityEvent(eventId) return eventId > EBattleEventId.____ENTITY_EVENT_START___ and eventId < EBattleEventId.____ENTITY_EVENT_END____ end function BattleEventSystem.IsLevelNotifyEvent(eventId) return eventId > EBattleEventId.____LEVEL_NOTIFY_START____ and eventId < EBattleEventId.____LEVEL_NOTIFY_END____ end function BattleEventSystem.IsEventParams(obj) --是table,且不是entity(没有components),且不是skillData(没有BelongTo) return type(obj) == "table" and obj.components == nil and obj.BelongTo == nil end -------------------接受外部通知的接口 start ------------------------ function BattleEventSystem.OnEntityActive(entity) if eventId2ListenersDic[EBattleEventId.ENTITY_ACTIVE] == nil or #eventId2ListenersDic[EBattleEventId.ENTITY_ACTIVE] == 0 then return end BattleES.Dispatch(EBattleEventId.ENTITY_ACTIVE, entity) end function BattleEventSystem.OnBeforeSwitchHero(entity) if eventId2ListenersDic[EBattleEventId.ENTITY_SWITCH_HERO_BEFORE] == nil or #eventId2ListenersDic[EBattleEventId.ENTITY_SWITCH_HERO_BEFORE] == 0 then return end BattleES.Dispatch(EBattleEventId.ENTITY_SWITCH_HERO_BEFORE, entity) end function BattleEventSystem.OnAfterSwitchToEntity(toEntity, fromEntity) if eventId2ListenersDic[EBattleEventId.ENTITY_AFTER_SWITCH_TO] == nil or #eventId2ListenersDic[EBattleEventId.ENTITY_AFTER_SWITCH_TO] == 0 then return end local params = #paramsPool > 0 and table_remove(paramsPool) or {} table_clear(params) params.toEntity = toEntity params.fromEntity = fromEntity BattleES.Dispatch(EBattleEventId.ENTITY_AFTER_SWITCH_TO, toEntity, params) paramsPool[#paramsPool + 1] = params end function BattleEventSystem.OnEntityAfterRevive(entity) if eventId2ListenersDic[EBattleEventId.ENTITY_REVIVE_AFTER] == nil or #eventId2ListenersDic[EBattleEventId.ENTITY_REVIVE_AFTER] == 0 then return end local params = #paramsPool > 0 and table_remove(paramsPool) or {} table_clear(params) params.reviveEntity = entity BattleES.Dispatch(EBattleEventId.ENTITY_REVIVE_AFTER, entity, params) paramsPool[#paramsPool + 1] = params end function BattleEventSystem.BeforeLogicUpdate(entity) local logicUpdateEventListenerCount = entity.components.record.logicUpdateEventListenerCount if logicUpdateEventListenerCount and logicUpdateEventListenerCount > 0 then --加个判断减少dispatch次数 BattleES.Dispatch(EBattleEventId.ENTITY_BEFORE_LOGIC_UPDATE, entity) end if LogicUpdateManager._isIntegralSecond then BattleEventSystem.OnIntegralSecondUpdate(entity) end end function BattleEventSystem.BeforeFilter(entity ,command) if eventId2ListenersDic[EBattleEventId.ENTITY_BEFORE_FILTER] == nil or #eventId2ListenersDic[EBattleEventId.ENTITY_BEFORE_FILTER] == 0 then return end local beforeFilterEventListenerCount = entity.components.record.beforeFilterEventListenerCount if beforeFilterEventListenerCount and beforeFilterEventListenerCount > 0 then --加个判断减少dispatch次数 local params = #paramsPool > 0 and table_remove(paramsPool) or {} table_clear(params) params.command = command BattleES.Dispatch(EBattleEventId.ENTITY_BEFORE_FILTER, entity, params) paramsPool[#paramsPool + 1] = params end end function BattleEventSystem.OnIntegralSecondUpdate(entity) if eventId2ListenersDic[EBattleEventId.ENTITY_INTEGRAL_SECOND_UPDATE] ~= nil and #eventId2ListenersDic[EBattleEventId.ENTITY_INTEGRAL_SECOND_UPDATE] ~= 0 then BattleES.Dispatch(EBattleEventId.ENTITY_INTEGRAL_SECOND_UPDATE, entity) end local exclusiveBattleEvent_ENTITY_INTEGRAL_SECOND_UPDATE = entity.exclusiveBattleEventDic[EBattleEventId.ENTITY_INTEGRAL_SECOND_UPDATE] if eventId2ListenersDic[exclusiveBattleEvent_ENTITY_INTEGRAL_SECOND_UPDATE] ~= nil and #eventId2ListenersDic[exclusiveBattleEvent_ENTITY_INTEGRAL_SECOND_UPDATE] ~= 0 then BattleES.Dispatch(exclusiveBattleEvent_ENTITY_INTEGRAL_SECOND_UPDATE, entity) end end --entity是操作者(比如刘备上载具,那么这里的entity是刘备) function BattleEventSystem.OnEntityInteractStarted(entity, interactIndex) if eventId2ListenersDic[EBattleEventId.ENTITY_BE_INTERACT_STARTED] == nil or #eventId2ListenersDic[EBattleEventId.ENTITY_BE_INTERACT_STARTED] == 0 then return end local beInteractedEntity = entity.components.interact:GetCmdOpInteractEntity() -- 被操作的单位 if beInteractedEntity then local params = #paramsPool > 0 and table_remove(paramsPool) or {} table_clear(params) params.interactDoer = entity params.beInteractedEntity = beInteractedEntity params.interactIndex = interactIndex --logging.error(LTAG.ERROR, "HYW : 交互开始 entity.ID : ", entity.EntityID, " 交互物体 : ", entity.components.interact.InteractEntity.EntityID) BattleES.Dispatch(EBattleEventId.ENTITY_BE_INTERACT_STARTED, beInteractedEntity, params) if interactIndex then --支持多按钮的事件 BattleES.Dispatch(EBattleEventId.ENTITY_BE_INTERACT_1_STARTED + interactIndex - 1, beInteractedEntity, params) end paramsPool[#paramsPool + 1] = params --else --logging.error(LTAG.ERROR, "HYW : 被操作的单位为空!") end end --entity是操作者(比如刘备上载具,那么这里的entity是刘备) function BattleEventSystem.OnEntityInteractSucceed(entity, interactData, interactIndex) local beInteractedEntity = entity.components.interact:GetCmdOpInteractEntity() -- 被操作的单位 if beInteractedEntity then local params = #paramsPool > 0 and table_remove(paramsPool) or {} table_clear(params) params.interactDoer = entity params.beInteractedEntity = beInteractedEntity params.interactIndex = interactIndex --logging.error(LTAG.ERROR, "HYW : 交互成功 entity.ID : ", entity.EntityID, " 交互物体 : ", entity.components.interact.InteractEntity.EntityID) BattleES.Dispatch(EBattleEventId.ENTITY_BE_INTERACT_SUCCEED, beInteractedEntity, params) if interactIndex then --支持多按钮的事件 BattleES.Dispatch(EBattleEventId.ENTITY_BE_INTERACT_1_SUCCEED + interactIndex - 1, beInteractedEntity, params) end paramsPool[#paramsPool + 1] = params --else --logging.error(LTAG.ERROR, "HYW : 被操作的单位为空!") end end function BattleEventSystem.OnEntityInteractAbort(entity, beInteractedEntity, interactIndex) if eventId2ListenersDic[EBattleEventId.ENTITY_BE_INTERACT_ABORT] == nil or #eventId2ListenersDic[EBattleEventId.ENTITY_BE_INTERACT_ABORT] == 0 then return end -- beInteractedEntity 被操作的单位 if beInteractedEntity then local params = #paramsPool > 0 and table_remove(paramsPool) or {} table_clear(params) params.interactDoer = entity params.beInteractedEntity = beInteractedEntity params.interactIndex = interactIndex --logging.error(LTAG.ERROR, "HYW : 交互开始 entity.ID : ", entity.EntityID, " 交互物体 : ", entity.components.interact.InteractEntity.EntityID) BattleES.Dispatch(EBattleEventId.ENTITY_BE_INTERACT_ABORT, beInteractedEntity, params) if interactIndex then --支持多按钮的事件 BattleES.Dispatch(EBattleEventId.ENTITY_BE_INTERACT_1_ABORT + interactIndex - 1, beInteractedEntity, params) end paramsPool[#paramsPool + 1] = params --else --logging.error(LTAG.ERROR, "HYW : 被操作的单位为空!") end end function BattleEventSystem.OnEntityCancelJoystick(entity) BattleES.Dispatch(EBattleEventId.ENTITY_CANCEL_JOYSTICK, entity) end function BattleEventSystem.BeforeChangeAvatar(entity, recover) if recover then if eventId2ListenersDic[EBattleEventId.ENTITY_BEFORE_CHANGE_AVATAR] then BattleES.Dispatch(EBattleEventId.ENTITY_BEFORE_CHANGE_AVATAR, entity) end else if eventId2ListenersDic[EBattleEventId.ENTITY_BEFORE_RECOVER_AVATAR] then BattleES.Dispatch(EBattleEventId.ENTITY_BEFORE_RECOVER_AVATAR, entity) end end end function BattleEventSystem.AfterChangeAvatar(entity, recover) if recover then if eventId2ListenersDic[EBattleEventId.ENTITY_AFTER_RECOVER_AVATAR] then BattleES.Dispatch(EBattleEventId.ENTITY_AFTER_RECOVER_AVATAR, entity) end else if eventId2ListenersDic[EBattleEventId.ENTITY_AFTER_CHANGE_AVATAR] then BattleES.Dispatch(EBattleEventId.ENTITY_AFTER_CHANGE_AVATAR, entity) end end end function BattleEventSystem.OnBattlePropTimeUp(entity, battlePropId) if eventId2ListenersDic[EBattleEventId.ENTITY_BATTLEPROP_TIMEUP] then local params = #paramsPool > 0 and table_remove(paramsPool) or {} table_clear(params) params.battlePropId = battlePropId BattleES.Dispatch(EBattleEventId.ENTITY_BATTLEPROP_TIMEUP, entity, params) end end function BattleEventSystem.OnEntityAddBuffOrRefresh(entity, buffId, buffUpdateData, oldBuffLayer) local params if not oldBuffLayer or oldBuffLayer < buffUpdateData.BuffLayer then local exclusiveBattleEvent_ENTITY_ADD_BUFF = entity.exclusiveBattleEventDic[EBattleEventId.ENTITY_ADD_BUFF] local sourceEntityExclusiveBattleEvent_ENTITY_CAST_BUFF_ADDLAYER if buffUpdateData.SourceEntity then sourceEntityExclusiveBattleEvent_ENTITY_CAST_BUFF_ADDLAYER = buffUpdateData.SourceEntity.exclusiveBattleEventDic[EBattleEventId.ENTITY_CAST_BUFF_ADDLAYER] end if eventId2ListenersDic[EBattleEventId.ENTITY_ADD_BUFF] ~= nil and #eventId2ListenersDic[EBattleEventId.ENTITY_ADD_BUFF] ~= 0 or eventId2ListenersDic[EBattleEventId.ENTITY_CAST_BUFF_ADDLAYER] ~= nil and #eventId2ListenersDic[EBattleEventId.ENTITY_CAST_BUFF_ADDLAYER] ~= 0 or eventId2ListenersDic[exclusiveBattleEvent_ENTITY_ADD_BUFF] ~= nil and #eventId2ListenersDic[exclusiveBattleEvent_ENTITY_ADD_BUFF] ~= 0 or (sourceEntityExclusiveBattleEvent_ENTITY_CAST_BUFF_ADDLAYER and eventId2ListenersDic[sourceEntityExclusiveBattleEvent_ENTITY_CAST_BUFF_ADDLAYER] ~= nil and #eventId2ListenersDic[sourceEntityExclusiveBattleEvent_ENTITY_CAST_BUFF_ADDLAYER] ~= 0 ) then params = #paramsPool > 0 and table_remove(paramsPool) or {} table_clear(params) params.buffId = buffId params.eventBuffUpdateData = buffUpdateData params.buffReceiver = entity params.buffCaster = buffUpdateData.SourceEntity if eventId2ListenersDic[EBattleEventId.ENTITY_ADD_BUFF] ~= nil and #eventId2ListenersDic[EBattleEventId.ENTITY_ADD_BUFF] ~= 0 then BattleES.Dispatch(EBattleEventId.ENTITY_ADD_BUFF, entity, params) end if eventId2ListenersDic[exclusiveBattleEvent_ENTITY_ADD_BUFF] ~= nil and #eventId2ListenersDic[exclusiveBattleEvent_ENTITY_ADD_BUFF] ~= 0 then BattleES.Dispatch(exclusiveBattleEvent_ENTITY_ADD_BUFF, entity, params) end if buffUpdateData.SourceEntity then if eventId2ListenersDic[EBattleEventId.ENTITY_CAST_BUFF_ADDLAYER] ~= nil and #eventId2ListenersDic[EBattleEventId.ENTITY_CAST_BUFF_ADDLAYER] ~= 0 then BattleES.Dispatch(EBattleEventId.ENTITY_CAST_BUFF_ADDLAYER, buffUpdateData.SourceEntity, params) end if eventId2ListenersDic[sourceEntityExclusiveBattleEvent_ENTITY_CAST_BUFF_ADDLAYER] ~= nil and #eventId2ListenersDic[sourceEntityExclusiveBattleEvent_ENTITY_CAST_BUFF_ADDLAYER] ~= 0 then BattleES.Dispatch(sourceEntityExclusiveBattleEvent_ENTITY_CAST_BUFF_ADDLAYER, buffUpdateData.SourceEntity, params) end end end end if buffUpdateData.SourceEntity then if eventId2ListenersDic[EBattleEventId.ENTITY_CAST_BUFF_ADDLAYER_OR_REFRESH] ~= nil and #eventId2ListenersDic[EBattleEventId.ENTITY_CAST_BUFF_ADDLAYER_OR_REFRESH] ~= 0 then if params == nil then params = #paramsPool > 0 and table_remove(paramsPool) or {} table_clear(params) params.buffId = buffId params.eventBuffUpdateData = buffUpdateData params.buffReceiver = entity params.buffCaster = buffUpdateData.SourceEntity end BattleES.Dispatch(EBattleEventId.ENTITY_CAST_BUFF_ADDLAYER_OR_REFRESH, buffUpdateData.SourceEntity, params) end if eventId2ListenersDic[EBattleEventId.ENTITY_SLAVE_CAST_BUFF_ADDLAYER_OR_REFRESH] ~= nil and #eventId2ListenersDic[EBattleEventId.ENTITY_SLAVE_CAST_BUFF_ADDLAYER_OR_REFRESH] ~= 0 then local masterEntity = buffUpdateData.SourceEntity._logicInitData.RootMasterEntity if masterEntity then if params == nil then params = #paramsPool > 0 and table_remove(paramsPool) or {} table_clear(params) params.buffId = buffId params.eventBuffUpdateData = buffUpdateData params.buffReceiver = entity params.buffCaster = buffUpdateData.SourceEntity else params.masterEntity = masterEntity end BattleES.Dispatch(EBattleEventId.ENTITY_SLAVE_CAST_BUFF_ADDLAYER_OR_REFRESH, masterEntity, params) end end end if params then paramsPool[#paramsPool + 1] = params end end function BattleEventSystem.OnEntityAddBuffBefore(entity,buffId,buffCaster) if eventId2ListenersDic[EBattleEventId.ENTITY_ADD_BUFF_BEFORE] ~= nil and #eventId2ListenersDic[EBattleEventId.ENTITY_ADD_BUFF_BEFORE] ~= 0 then local params = #paramsPool > 0 and table_remove(paramsPool) or {} table_clear(params) params.buffId = buffId params.buffReceiver = entity params.buffCaster = buffCaster BattleES.Dispatch(EBattleEventId.ENTITY_ADD_BUFF_BEFORE, entity, params) paramsPool[#paramsPool + 1] = params end end function BattleEventSystem.OnEntityDeleteBuff(entity,buffId,buffUpdateData,layerBeforeDelete) local exclusiveBattleEvent_ENTITY_DELETE_BUFF = entity.exclusiveBattleEventDic[EBattleEventId.ENTITY_DELETE_BUFF] if eventId2ListenersDic[EBattleEventId.ENTITY_DELETE_BUFF] ~= nil and #eventId2ListenersDic[EBattleEventId.ENTITY_DELETE_BUFF] ~= 0 or (eventId2ListenersDic[EBattleEventId.ENTITY_CAST_BUFF_DELETED] ~= nil and #eventId2ListenersDic[EBattleEventId.ENTITY_CAST_BUFF_DELETED] ~= 0 ) or (eventId2ListenersDic[exclusiveBattleEvent_ENTITY_DELETE_BUFF] ~= nil and #eventId2ListenersDic[exclusiveBattleEvent_ENTITY_DELETE_BUFF] ~= 0 )then local params = #paramsPool > 0 and table_remove(paramsPool) or {} table_clear(params) params.buffId = buffId params.eventBuffUpdateData = buffUpdateData params.buffReceiver = entity params.buffCaster = buffUpdateData.SourceEntity params.layerBeforeDelete = layerBeforeDelete if eventId2ListenersDic[EBattleEventId.ENTITY_DELETE_BUFF] ~= nil and #eventId2ListenersDic[EBattleEventId.ENTITY_DELETE_BUFF] ~= 0 then BattleES.Dispatch(EBattleEventId.ENTITY_DELETE_BUFF, entity, params) end if eventId2ListenersDic[exclusiveBattleEvent_ENTITY_DELETE_BUFF] ~= nil and #eventId2ListenersDic[exclusiveBattleEvent_ENTITY_DELETE_BUFF] ~= 0 then BattleES.Dispatch(exclusiveBattleEvent_ENTITY_DELETE_BUFF, entity, params) end if buffUpdateData.SourceEntity then if eventId2ListenersDic[EBattleEventId.ENTITY_CAST_BUFF_DELETED] ~= nil and #eventId2ListenersDic[EBattleEventId.ENTITY_CAST_BUFF_DELETED] ~= 0 then BattleES.Dispatch(EBattleEventId.ENTITY_CAST_BUFF_DELETED, buffUpdateData.SourceEntity, params) end end paramsPool[#paramsPool + 1] = params end end function BattleEventSystem.OnEntityDeletePCBuff(entity,buffId,leftVal,totalVal)-- leftVal 剩余的pc值 ,totalVal 总值 if eventId2ListenersDic[EBattleEventId.ENTITY_DELETE_PC_BUFF] ~= nil and #eventId2ListenersDic[EBattleEventId.ENTITY_DELETE_PC_BUFF] ~= 0 then local params = #paramsPool > 0 and table_remove(paramsPool) or {} table_clear(params) params.buffId = buffId params.leftVal = leftVal params.totalVal = totalVal if eventId2ListenersDic[EBattleEventId.ENTITY_DELETE_PC_BUFF] ~= nil and #eventId2ListenersDic[EBattleEventId.ENTITY_DELETE_PC_BUFF] ~= 0 then BattleES.Dispatch(EBattleEventId.ENTITY_DELETE_PC_BUFF, entity, params) end paramsPool[#paramsPool + 1] = params end end function BattleEventSystem.OnEntityImmuneHardControl(entity)--暂时不传buffData参数了,因为目前用不上 if eventId2ListenersDic[EBattleEventId.ENTITY_IMMUNE_HARD_CONTROL_BUFF] == nil or #eventId2ListenersDic[EBattleEventId.ENTITY_IMMUNE_HARD_CONTROL_BUFF] == 0 then return end BattleES.Dispatch(EBattleEventId.ENTITY_IMMUNE_HARD_CONTROL_BUFF, entity) end --delta是number不是FP function BattleEventSystem.BeforeEntityAttrChange(delta, attrType, target, caster, missileData, changeParam1, changeParam2) if attrType == LuaConst.RealtimeAttrType.hp then BattleEventSystem.BeforeEntityHPChange(delta, target, caster, missileData, changeParam1, changeParam2) end local exclusiveBattleEvent_ENTITY_BEFORE_CAUSE_ATTR_CHANGE = caster.exclusiveBattleEventDic[EBattleEventId.ENTITY_BEFORE_CAUSE_ATTR_CHANGE] if eventId2ListenersDic[EBattleEventId.ENTITY_BEFORE_ATTR_CHANGE] and #eventId2ListenersDic[EBattleEventId.ENTITY_BEFORE_ATTR_CHANGE] > 0 or eventId2ListenersDic[EBattleEventId.ENTITY_BEFORE_CAUSE_ATTR_CHANGE] and #eventId2ListenersDic[EBattleEventId.ENTITY_BEFORE_CAUSE_ATTR_CHANGE] > 0 or eventId2ListenersDic[exclusiveBattleEvent_ENTITY_BEFORE_CAUSE_ATTR_CHANGE] and #eventId2ListenersDic[exclusiveBattleEvent_ENTITY_BEFORE_CAUSE_ATTR_CHANGE] > 0 then local params = #paramsPool > 0 and table_remove(paramsPool) or {} table_clear(params) params.attrType = attrType params.target = target params.caster = caster params.delta = delta params.missileData = missileData BattleES.Dispatch(EBattleEventId.ENTITY_BEFORE_ATTR_CHANGE, target, params) BattleES.Dispatch(EBattleEventId.ENTITY_BEFORE_CAUSE_ATTR_CHANGE, caster, params) BattleES.Dispatch(exclusiveBattleEvent_ENTITY_BEFORE_CAUSE_ATTR_CHANGE, caster, params) paramsPool[#paramsPool + 1] = params end --private.OnEvent(EBattleEventId.ENTITY_BEFORE_ATTR_CHANGE,target,params) end --delta是number不是FP function BattleEventSystem.AfterEntityAttrChange(delta,attrType,target,caster,changeParam1,changeParam2) if attrType == LuaConst.RealtimeAttrType.hp then BattleEventSystem.AfterEntityHPChange(delta,target,caster,changeParam1,changeParam2) elseif attrType == LuaConst.RealtimeAttrType.sa then BattleEventSystem.AfterEntitySAChange(delta,target,caster) end if eventId2ListenersDic[EBattleEventId.ENTITY_AFTER_ATTR_CHANGE] and #eventId2ListenersDic[EBattleEventId.ENTITY_AFTER_ATTR_CHANGE] > 0 or eventId2ListenersDic[EBattleEventId.ENTITY_AFTER_CAUSE_ATTR_CHANGE] and #eventId2ListenersDic[EBattleEventId.ENTITY_AFTER_CAUSE_ATTR_CHANGE] > 0 then local params = #paramsPool > 0 and table_remove(paramsPool) or {} table_clear(params) params.attrType = attrType params.target = target params.caster = caster params.delta = delta --params.changeParam1 = changeParam1 --目前不需要,就先注掉 --params.changeParam2 = changeParam2 --目前不需要,就先注掉 BattleES.Dispatch(EBattleEventId.ENTITY_AFTER_ATTR_CHANGE, target, params) BattleES.Dispatch(EBattleEventId.ENTITY_AFTER_CAUSE_ATTR_CHANGE, caster, params) --private.OnEvent(EBattleEventId.ENTITY_AFTER_ATTR_CHANGE,target,params) paramsPool[#paramsPool + 1] = params end end function BattleEventSystem.BeforeEntityPCChange(target, caster, delta) if eventId2ListenersDic[EBattleEventId.ENTITY_BEFORE_CAUSE_PC_LOSS] and #eventId2ListenersDic[EBattleEventId.ENTITY_BEFORE_CAUSE_PC_LOSS] > 0 then local params = #paramsPool > 0 and table_remove(paramsPool) or {} table_clear(params) params.delta = delta params.caster = caster params.target = target BattleES.Dispatch(EBattleEventId.ENTITY_BEFORE_CAUSE_PC_LOSS, caster, params) paramsPool[#paramsPool + 1] = params end end function BattleEventSystem.BeforeEntityHPChange(delta,target,caster,missileData,hpChangeType,buffId) local exclusiveBattleEvent_ENTITY_BEFORE_CAUSE_HP_LOSS = caster.exclusiveBattleEventDic[EBattleEventId.ENTITY_BEFORE_CAUSE_HP_LOSS] local exclusiveBattleEvent_ENTITY_BEFORE_HP_CHANGE = target.exclusiveBattleEventDic[EBattleEventId.ENTITY_BEFORE_HP_CHANGE] local exclusiveBattleEvent_ENTITY_BEFORE_GET_HP_LOSS = target.exclusiveBattleEventDic[EBattleEventId.ENTITY_BEFORE_GET_HP_LOSS] if eventId2ListenersDic[EBattleEventId.ENTITY_BEFORE_GET_HP_LOSS] and #eventId2ListenersDic[EBattleEventId.ENTITY_BEFORE_GET_HP_LOSS] > 0 or eventId2ListenersDic[EBattleEventId.ENTITY_BEFORE_CAUSE_HP_LOSS] and #eventId2ListenersDic[EBattleEventId.ENTITY_BEFORE_CAUSE_HP_LOSS] > 0 or eventId2ListenersDic[EBattleEventId.ENTITY_BEFORE_HP_CHANGE] and #eventId2ListenersDic[EBattleEventId.ENTITY_BEFORE_HP_CHANGE] > 0 or eventId2ListenersDic[EBattleEventId.ENTITY_BEFORE_GET_HP_HEAL] and #eventId2ListenersDic[EBattleEventId.ENTITY_BEFORE_GET_HP_HEAL] > 0 or eventId2ListenersDic[EBattleEventId.ENTITY_BEFORE_CAUSE_HP_HEAL] and #eventId2ListenersDic[EBattleEventId.ENTITY_BEFORE_CAUSE_HP_HEAL] > 0 or eventId2ListenersDic[exclusiveBattleEvent_ENTITY_BEFORE_CAUSE_HP_LOSS] and #eventId2ListenersDic[exclusiveBattleEvent_ENTITY_BEFORE_CAUSE_HP_LOSS] > 0 or eventId2ListenersDic[exclusiveBattleEvent_ENTITY_BEFORE_HP_CHANGE] and #eventId2ListenersDic[exclusiveBattleEvent_ENTITY_BEFORE_HP_CHANGE] > 0 or eventId2ListenersDic[exclusiveBattleEvent_ENTITY_BEFORE_GET_HP_LOSS] and #eventId2ListenersDic[exclusiveBattleEvent_ENTITY_BEFORE_GET_HP_LOSS] > 0 then local params = #paramsPool > 0 and table_remove(paramsPool) or {} table_clear(params) params.delta = delta --类型是number params.caster = caster params.target = target params.missileData = missileData params.hpChangeType = hpChangeType params.hpChangeBuffId = buffId if params.delta < 0 then BattleES.Dispatch(EBattleEventId.ENTITY_BEFORE_GET_HP_LOSS,target,params) BattleES.Dispatch(exclusiveBattleEvent_ENTITY_BEFORE_GET_HP_LOSS, target, params) BattleES.Dispatch(EBattleEventId.ENTITY_BEFORE_CAUSE_HP_LOSS,caster,params) BattleES.Dispatch(exclusiveBattleEvent_ENTITY_BEFORE_CAUSE_HP_LOSS, caster, params) elseif params.delta > 0 then BattleES.Dispatch(EBattleEventId.ENTITY_BEFORE_GET_HP_HEAL,target,params) BattleES.Dispatch(EBattleEventId.ENTITY_BEFORE_CAUSE_HP_HEAL,caster,params) end --private.OnEvent(EBattleEventId.ENTITY_BEFORE_HP_CHANGE,target,params) BattleES.Dispatch(EBattleEventId.ENTITY_BEFORE_HP_CHANGE,target,params) BattleES.Dispatch(exclusiveBattleEvent_ENTITY_BEFORE_HP_CHANGE,target,params) paramsPool[#paramsPool + 1] = params end end --dmgResult 应用最终伤害系数后的血量改变(负数表示损血),是number类型 --originDmg 应用最终伤害系数前的血量改变(负数表示损血),是number类型 --factor, 最终伤害系数,number类型 function BattleEventSystem.AfterApplyFinalDamageFactor(dmgResult, originDmg, factor, target, caster) local exclusiveBattleEvent_ENTITY_AFTER_APPLY_FINAL_DMG_FACTOR_AS_TARGET = target.exclusiveBattleEventDic[EBattleEventId.ENTITY_AFTER_APPLY_FINAL_DMG_FACTOR_AS_TARGET] if (eventId2ListenersDic[EBattleEventId.ENTITY_AFTER_APPLY_FINAL_DMG_FACTOR_AS_TARGET] == nil or #eventId2ListenersDic[EBattleEventId.ENTITY_AFTER_APPLY_FINAL_DMG_FACTOR_AS_TARGET] == 0) and (eventId2ListenersDic[exclusiveBattleEvent_ENTITY_AFTER_APPLY_FINAL_DMG_FACTOR_AS_TARGET] == nil or #eventId2ListenersDic[exclusiveBattleEvent_ENTITY_AFTER_APPLY_FINAL_DMG_FACTOR_AS_TARGET] == 0) then return end local params = #paramsPool > 0 and table_remove(paramsPool) or {} table_clear(params) params.damage = dmgResult params.factor = factor params.target = target params.caster = caster params.damageDelta = dmgResult - originDmg if eventId2ListenersDic[exclusiveBattleEvent_ENTITY_AFTER_APPLY_FINAL_DMG_FACTOR_AS_TARGET] and #eventId2ListenersDic[exclusiveBattleEvent_ENTITY_AFTER_APPLY_FINAL_DMG_FACTOR_AS_TARGET] > 0 then BattleES.Dispatch(exclusiveBattleEvent_ENTITY_AFTER_APPLY_FINAL_DMG_FACTOR_AS_TARGET, target, params) end if eventId2ListenersDic[EBattleEventId.ENTITY_AFTER_APPLY_FINAL_DMG_FACTOR_AS_TARGET] and #eventId2ListenersDic[EBattleEventId.ENTITY_AFTER_APPLY_FINAL_DMG_FACTOR_AS_TARGET] > 0 then BattleES.Dispatch(EBattleEventId.ENTITY_AFTER_APPLY_FINAL_DMG_FACTOR_AS_TARGET,target,params) end paramsPool[#paramsPool + 1] = params end function BattleEventSystem.BeforeFinalDmgOverride(delta,target,caster,missileData,hpChangeType,buffId) if eventId2ListenersDic[EBattleEventId.ENTITY_BEFORE_GET_HP_FINALLOSS] == nil or #eventId2ListenersDic[EBattleEventId.ENTITY_BEFORE_GET_HP_FINALLOSS] == 0 then return end local params = #paramsPool > 0 and table_remove(paramsPool) or {} table_clear(params) params.delta = delta --类型是number --数值是负数 params.caster = caster params.target = target params.missileData = missileData params.hpChangeType = hpChangeType params.hpChangeBuffId = buffId if params.delta < 0 then BattleES.Dispatch(EBattleEventId.ENTITY_BEFORE_GET_HP_FINALLOSS,target,params) end paramsPool[#paramsPool + 1] = params end function BattleEventSystem.OnEntityGetFatalHPLoss(entity,caster,delta) local params = #paramsPool > 0 and table_remove(paramsPool) or {} table_clear(params) params.delta = delta --类型是number --数值是负数 params.caster = caster params.target = entity BattleES.Dispatch(EBattleEventId.ENTITY_GET_FATAL_HP_LOSS,entity,params) paramsPool[#paramsPool + 1] = params end function BattleEventSystem.BeforeCalculateHurtResult(targetEntity, sourceEntity, missileData, missileHitCount, hpChangeType) local exclusiveBattleEvent_ENTITY_BEFORE_CALC_HURT_RESULT_AS_TARGET = targetEntity.exclusiveBattleEventDic[EBattleEventId.ENTITY_BEFORE_CALC_HURT_RESULT_AS_TARGET] local exclusiveBattleEvent_ENTITY_BEFORE_CALC_HURT_RESULT_AS_CASTER = sourceEntity.exclusiveBattleEventDic[EBattleEventId.ENTITY_BEFORE_CALC_HURT_RESULT_AS_CASTER] if eventId2ListenersDic[EBattleEventId.ENTITY_BEFORE_CALC_HURT_RESULT_AS_TARGET] ~= nil and #eventId2ListenersDic[EBattleEventId.ENTITY_BEFORE_CALC_HURT_RESULT_AS_TARGET] ~= 0 or eventId2ListenersDic[EBattleEventId.ENTITY_BEFORE_CALC_HURT_RESULT_AS_CASTER] ~= nil and #eventId2ListenersDic[EBattleEventId.ENTITY_BEFORE_CALC_HURT_RESULT_AS_CASTER] ~= 0 or eventId2ListenersDic[exclusiveBattleEvent_ENTITY_BEFORE_CALC_HURT_RESULT_AS_TARGET] ~= nil and #eventId2ListenersDic[exclusiveBattleEvent_ENTITY_BEFORE_CALC_HURT_RESULT_AS_TARGET] ~= 0 or eventId2ListenersDic[exclusiveBattleEvent_ENTITY_BEFORE_CALC_HURT_RESULT_AS_CASTER] ~= nil and #eventId2ListenersDic[exclusiveBattleEvent_ENTITY_BEFORE_CALC_HURT_RESULT_AS_CASTER] ~= 0 then local params = #paramsPool > 0 and table_remove(paramsPool) or {} table_clear(params) params.target = targetEntity params.caster = sourceEntity params.missileData = missileData params.missileHitCount = missileHitCount params.hpChangeType = hpChangeType BattleEventSystem.BeforeEntityCalcHurtResultAsTarget(targetEntity, params) BattleEventSystem.BeforeEntityCalcHurtResultAsCaster(sourceEntity, params) paramsPool[#paramsPool + 1] = params end end function BattleEventSystem.AfterCritBeforeApplyCritEff(targetEntity, sourceEntity, missileData) if (eventId2ListenersDic[EBattleEventId.ENTITY_AFTER_CRIT_BEFORE_APPLYCRITEFF_AS_CASTER] == nil or #eventId2ListenersDic[EBattleEventId.ENTITY_AFTER_CRIT_BEFORE_APPLYCRITEFF_AS_CASTER] == 0)then return end local params = #paramsPool > 0 and table_remove(paramsPool) or {} table_clear(params) params.target = targetEntity params.caster = sourceEntity params.missileData = missileData BattleES.Dispatch(EBattleEventId.ENTITY_AFTER_CRIT_BEFORE_APPLYCRITEFF_AS_CASTER, sourceEntity, params) paramsPool[#paramsPool + 1] = params end function BattleEventSystem.BeforeEntityCalcHurtResultAsTarget(entity, params) BattleES.Dispatch(EBattleEventId.ENTITY_BEFORE_CALC_HURT_RESULT_AS_TARGET, entity, params) local exclusiveBattleEvent_ENTITY_BEFORE_CALC_HURT_RESULT_AS_TARGET = entity.exclusiveBattleEventDic[EBattleEventId.ENTITY_BEFORE_CALC_HURT_RESULT_AS_TARGET] BattleES.Dispatch(exclusiveBattleEvent_ENTITY_BEFORE_CALC_HURT_RESULT_AS_TARGET, entity, params) end function BattleEventSystem.BeforeEntityCalcHurtResultAsCaster(entity, params) BattleES.Dispatch(EBattleEventId.ENTITY_BEFORE_CALC_HURT_RESULT_AS_CASTER, entity, params) local exclusiveBattleEvent_ENTITY_BEFORE_CALC_HURT_RESULT_AS_CASTER = entity.exclusiveBattleEventDic[EBattleEventId.ENTITY_BEFORE_CALC_HURT_RESULT_AS_CASTER] BattleES.Dispatch(exclusiveBattleEvent_ENTITY_BEFORE_CALC_HURT_RESULT_AS_CASTER, entity, params) end function BattleEventSystem.AfterEntityHPChange(delta, target, caster, hpChangeType, buffId, missileData) local exclusiveBattleEvent_ENTITY_AFTER_GET_HP_LOSS = target.exclusiveBattleEventDic[EBattleEventId.ENTITY_AFTER_GET_HP_LOSS] local exclusiveBattleEvent_ENTITY_AFTER_HP_CHANGE = target.exclusiveBattleEventDic[EBattleEventId.ENTITY_AFTER_HP_CHANGE] local exclusiveBattleEvent_ENTITY_AFTER_CAUSE_HP_LOSS = caster.exclusiveBattleEventDic[EBattleEventId.ENTITY_AFTER_CAUSE_HP_LOSS] if eventId2ListenersDic[EBattleEventId.ENTITY_AFTER_GET_HP_LOSS] and #eventId2ListenersDic[EBattleEventId.ENTITY_AFTER_GET_HP_LOSS] > 0 or eventId2ListenersDic[EBattleEventId.ENTITY_AFTER_CAUSE_HP_LOSS] and #eventId2ListenersDic[EBattleEventId.ENTITY_AFTER_CAUSE_HP_LOSS] > 0 or eventId2ListenersDic[EBattleEventId.ENTITY_AFTER_HP_CHANGE] and #eventId2ListenersDic[EBattleEventId.ENTITY_AFTER_HP_CHANGE] > 0 or eventId2ListenersDic[EBattleEventId.ENTITY_AFTER_SLAVE_CAUSE_HP_LOSS] and #eventId2ListenersDic[EBattleEventId.ENTITY_AFTER_SLAVE_CAUSE_HP_LOSS] > 0 or eventId2ListenersDic[exclusiveBattleEvent_ENTITY_AFTER_GET_HP_LOSS] and #eventId2ListenersDic[exclusiveBattleEvent_ENTITY_AFTER_GET_HP_LOSS] > 0 or eventId2ListenersDic[exclusiveBattleEvent_ENTITY_AFTER_HP_CHANGE] and #eventId2ListenersDic[exclusiveBattleEvent_ENTITY_AFTER_HP_CHANGE] > 0 or eventId2ListenersDic[exclusiveBattleEvent_ENTITY_AFTER_CAUSE_HP_LOSS] and #eventId2ListenersDic[exclusiveBattleEvent_ENTITY_AFTER_CAUSE_HP_LOSS] > 0 then local params = #paramsPool > 0 and table_remove(paramsPool) or {} table_clear(params) params.delta = delta params.caster = caster params.target = target params.hpChangeType = hpChangeType params.hpChangeBuffId = buffId params.missileData = missileData if params.delta < 0 then BattleES.Dispatch(EBattleEventId.ENTITY_AFTER_GET_HP_LOSS,target,params) BattleES.Dispatch(exclusiveBattleEvent_ENTITY_AFTER_GET_HP_LOSS,target,params) BattleES.Dispatch(EBattleEventId.ENTITY_AFTER_CAUSE_HP_LOSS,caster,params) BattleES.Dispatch(exclusiveBattleEvent_ENTITY_AFTER_CAUSE_HP_LOSS,caster,params) --elseif params.delta > 0 then end BattleES.Dispatch(EBattleEventId.ENTITY_AFTER_HP_CHANGE,target,params) BattleES.Dispatch(exclusiveBattleEvent_ENTITY_AFTER_HP_CHANGE,target,params) local masterEntity = params.caster._logicInitData.RootMasterEntity if masterEntity then BattleES.Dispatch(EBattleEventId.ENTITY_AFTER_SLAVE_CAUSE_HP_LOSS, masterEntity, params) end paramsPool[#paramsPool + 1] = params end end --delta要求传number function BattleEventSystem.BeforeEntityGetFinalLifeSteal(entity, delta) if not eventId2ListenersDic[EBattleEventId.ENTITY_BEFORE_GET_FINAL_LIFESTEAL] or #eventId2ListenersDic[EBattleEventId.ENTITY_BEFORE_GET_FINAL_LIFESTEAL] <= 0 then return end local params = #paramsPool > 0 and table_remove(paramsPool) or {} table_clear(params) params.delta = delta BattleES.Dispatch(EBattleEventId.ENTITY_BEFORE_GET_FINAL_LIFESTEAL,entity,params) paramsPool[#paramsPool + 1] = params end function BattleEventSystem.AfterEntitySAChange(delta,target,caster) if eventId2ListenersDic[EBattleEventId.ENTITY_AFTER_SA_CHANGE] == nil or #eventId2ListenersDic[EBattleEventId.ENTITY_AFTER_SA_CHANGE] == 0 then return end local params = #paramsPool > 0 and table_remove(paramsPool) or {} table_clear(params) params.delta = delta params.caster = caster params.target = target BattleES.Dispatch(EBattleEventId.ENTITY_AFTER_SA_CHANGE,target,params) paramsPool[#paramsPool + 1] = params end function BattleEventSystem.AfterEntityMissileSetHitMoveInfo(attacker, missileData, isHitHero, missile, hitMoveTime, hitDistance) local exclusiveBattleEvent_ENTITY_MISSILE_AFTER_SETHITMOVE = attacker.exclusiveBattleEventDic[EBattleEventId.ENTITY_MISSILE_AFTER_SETHITMOVE] if eventId2ListenersDic[EBattleEventId.ENTITY_MISSILE_AFTER_SETHITMOVE] and #eventId2ListenersDic[EBattleEventId.ENTITY_MISSILE_AFTER_SETHITMOVE] > 0 or eventId2ListenersDic[exclusiveBattleEvent_ENTITY_MISSILE_AFTER_SETHITMOVE] and #eventId2ListenersDic[exclusiveBattleEvent_ENTITY_MISSILE_AFTER_SETHITMOVE] > 0 then local params = #paramsPool > 0 and table_remove(paramsPool) or {} table_clear(params) params.missileData = missileData params.attacker = attacker params.isHitHero = isHitHero params.missile = missile params.hitMoveTime = hitMoveTime params.hitDistance = hitDistance BattleES.Dispatch(EBattleEventId.ENTITY_MISSILE_AFTER_SETHITMOVE, attacker, params) BattleES.Dispatch(exclusiveBattleEvent_ENTITY_MISSILE_AFTER_SETHITMOVE, attacker, params) paramsPool[#paramsPool + 1] = params end end function BattleEventSystem.AfterEntityHitByMissile(entity,missileData,attacker,missile) local attackerExclusiveBattleEvent_ENTITY_MISSILE_HIT_TARGET = attacker.exclusiveBattleEventDic[EBattleEventId.ENTITY_MISSILE_HIT_TARGET] local exclusiveBattleEvent_ENTITY_HIT_BY_MISSILE = entity.exclusiveBattleEventDic[EBattleEventId.ENTITY_HIT_BY_MISSILE] if eventId2ListenersDic[EBattleEventId.ENTITY_HIT_BY_MISSILE] and #eventId2ListenersDic[EBattleEventId.ENTITY_HIT_BY_MISSILE] > 0 or eventId2ListenersDic[EBattleEventId.ENTITY_MISSILE_HIT_TARGET] and #eventId2ListenersDic[EBattleEventId.ENTITY_MISSILE_HIT_TARGET] > 0 or eventId2ListenersDic[attackerExclusiveBattleEvent_ENTITY_MISSILE_HIT_TARGET] and #eventId2ListenersDic[attackerExclusiveBattleEvent_ENTITY_MISSILE_HIT_TARGET] > 0 or eventId2ListenersDic[exclusiveBattleEvent_ENTITY_HIT_BY_MISSILE] and #eventId2ListenersDic[exclusiveBattleEvent_ENTITY_HIT_BY_MISSILE] > 0 then local params = #paramsPool > 0 and table_remove(paramsPool) or {} table_clear(params) params.missileData = missileData params.attacker = attacker params.target = entity params.missile = missile BattleES.Dispatch(EBattleEventId.ENTITY_HIT_BY_MISSILE, entity, params) BattleES.Dispatch(exclusiveBattleEvent_ENTITY_HIT_BY_MISSILE, entity, params) BattleES.Dispatch(EBattleEventId.ENTITY_MISSILE_HIT_TARGET, attacker, params) BattleES.Dispatch(attackerExclusiveBattleEvent_ENTITY_MISSILE_HIT_TARGET, attacker, params) --2022年10月21日新增,自己召唤物(不包括载具)发射的子弹,也触发以自己为主语的事件 local originEntity = attacker:GetOriginEntity() if originEntity ~= attacker and attacker.components.drive and attacker.components.drive:GetLastDriver() ~= originEntity then params.attacker = originEntity BattleES.Dispatch(EBattleEventId.ENTITY_HIT_BY_MISSILE, entity, params) BattleES.Dispatch(exclusiveBattleEvent_ENTITY_HIT_BY_MISSILE, entity, params) BattleES.Dispatch(EBattleEventId.ENTITY_MISSILE_HIT_TARGET, originEntity, params) BattleES.Dispatch(originEntity.exclusiveBattleEventDic[EBattleEventId.ENTITY_MISSILE_HIT_TARGET], originEntity, params) end paramsPool[#paramsPool + 1] = params end end function BattleEventSystem.AfterEntityMissileHitOnce(attacker, missileData, firstHitEntity, missile) local exclusiveBattleEvent_ENTITY_MISSILE_HIT_ONCE = attacker.exclusiveBattleEventDic[EBattleEventId.ENTITY_MISSILE_HIT_ONCE] if eventId2ListenersDic[EBattleEventId.ENTITY_MISSILE_HIT_ONCE] and #eventId2ListenersDic[EBattleEventId.ENTITY_MISSILE_HIT_ONCE] > 0 or eventId2ListenersDic[exclusiveBattleEvent_ENTITY_MISSILE_HIT_ONCE] and #eventId2ListenersDic[exclusiveBattleEvent_ENTITY_MISSILE_HIT_ONCE] > 0 then local params = #paramsPool > 0 and table_remove(paramsPool) or {} table_clear(params) params.missileData = missileData params.attacker = attacker params.target = firstHitEntity params.missile = missile BattleES.Dispatch(EBattleEventId.ENTITY_MISSILE_HIT_ONCE, attacker, params) if eventId2ListenersDic[EBattleEventId.ENTITY_MISSILE_HIT_ONCE] and #eventId2ListenersDic[EBattleEventId.ENTITY_MISSILE_HIT_ONCE] > 0 then BattleES.Dispatch(EBattleEventId.ENTITY_MISSILE_HIT_ONCE, attacker, params) end if eventId2ListenersDic[exclusiveBattleEvent_ENTITY_MISSILE_HIT_ONCE] and #eventId2ListenersDic[exclusiveBattleEvent_ENTITY_MISSILE_HIT_ONCE] > 0 then BattleES.Dispatch(exclusiveBattleEvent_ENTITY_MISSILE_HIT_ONCE, attacker, params) end paramsPool[#paramsPool + 1] = params end end function BattleEventSystem.OnEntityMissileStart(missile) local exclusiveBattleEvent_ENTITY_MISSILE_BORN = missile.Attacker.exclusiveBattleEventDic[EBattleEventId.ENTITY_MISSILE_BORN] if eventId2ListenersDic[EBattleEventId.ENTITY_MISSILE_BORN] and #eventId2ListenersDic[EBattleEventId.ENTITY_MISSILE_BORN] > 0 or eventId2ListenersDic[exclusiveBattleEvent_ENTITY_MISSILE_BORN] and #eventId2ListenersDic[exclusiveBattleEvent_ENTITY_MISSILE_BORN] > 0 then local params = #paramsPool > 0 and table_remove(paramsPool) or {} table_clear(params) params.missileData = missile.MissileData params.attacker = missile.Attacker params.missile = missile BattleES.Dispatch(EBattleEventId.ENTITY_MISSILE_BORN, missile.Attacker, params) BattleES.Dispatch(exclusiveBattleEvent_ENTITY_MISSILE_BORN, missile.Attacker, params) paramsPool[#paramsPool + 1] = params end end function BattleEventSystem.OnEntityMissileCancel(attacker, missileData, missile) local exclusiveBattleEvent_ENTITY_MISSILE_CANCEL = attacker.exclusiveBattleEventDic[EBattleEventId.ENTITY_MISSILE_CANCEL] if eventId2ListenersDic[EBattleEventId.ENTITY_MISSILE_CANCEL] and #eventId2ListenersDic[EBattleEventId.ENTITY_MISSILE_CANCEL] > 0 or eventId2ListenersDic[exclusiveBattleEvent_ENTITY_MISSILE_CANCEL] and #eventId2ListenersDic[exclusiveBattleEvent_ENTITY_MISSILE_CANCEL] > 0 then local params = #paramsPool > 0 and table_remove(paramsPool) or {} table_clear(params) params.missileData = missileData params.attacker = attacker params.missile = missile BattleES.Dispatch(EBattleEventId.ENTITY_MISSILE_CANCEL, attacker, params) BattleES.Dispatch(exclusiveBattleEvent_ENTITY_MISSILE_CANCEL, attacker, params) paramsPool[#paramsPool + 1] = params end end function BattleEventSystem.OnEntityAttackStateIn(entity,skillData) if eventId2ListenersDic[EBattleEventId.ENTITY_SKILL_ENTERATTACK] and #eventId2ListenersDic[EBattleEventId.ENTITY_SKILL_ENTERATTACK] > 0 then local params = #paramsPool > 0 and table_remove(paramsPool) or {} table_clear(params) params.skillData = skillData BattleES.Dispatch(EBattleEventId.ENTITY_SKILL_ENTERATTACK, entity, params) paramsPool[#paramsPool + 1] = params end end function BattleEventSystem.OnEntitySkillStart(entity,skillData) if not skillData then return end local eventId if skillData.ID == entity.components.record.BtnSkillId then if(SkillBaseSystem.IsNormalAttack(skillData)) then eventId = EBattleEventId.ENTITY_NORMAL_ATTACK_START elseif SkillBaseSystem.IsDodgeSkill(skillData) then eventId = EBattleEventId.ENTITY_DODGE_START else --由按钮触发的 非普攻非闪避技能 开始释放的时间点 --private.OnEvent(EBattleEventId.ENTITY_SKILL_START,entity,skillData) eventId = EBattleEventId.ENTITY_SKILL_START end elseif skillData.ID == entity.components.record.LastAutoNextSkillId then eventId = EBattleEventId.ENTITY_AUTONEXT_SKILL_START end if eventId then if eventId2ListenersDic[eventId] and #eventId2ListenersDic[eventId] > 0 then local params = #paramsPool > 0 and table_remove(paramsPool) or {} table_clear(params) params.skillData = skillData BattleES.Dispatch(eventId, entity, params) paramsPool[#paramsPool + 1] = params end end end function BattleEventSystem.OnEntityStratagemSkill(entity) if eventId2ListenersDic[EBattleEventId.ENTITY_STRATAGEM_SKILL_START] and #eventId2ListenersDic[EBattleEventId.ENTITY_STRATAGEM_SKILL_START] > 0 then BattleES.Dispatch(EBattleEventId.ENTITY_STRATAGEM_SKILL_START, entity) end end function BattleEventSystem.OnEntitySkillQuit(entity, skillData) if eventId2ListenersDic[EBattleEventId.ENTITY_SKILL_QUIT] and #eventId2ListenersDic[EBattleEventId.ENTITY_SKILL_QUIT] > 0 then local params = #paramsPool > 0 and table_remove(paramsPool) or {} table_clear(params) params.skillData = skillData BattleES.Dispatch(EBattleEventId.ENTITY_SKILL_QUIT, entity, params) paramsPool[#paramsPool + 1] = params end end function BattleEventSystem.OnEntitySkillEnterCDOrCharge(entity, skillData) if eventId2ListenersDic[EBattleEventId.ENTITY_SKILL_ENTER_CD_OR_CHARGE] and #eventId2ListenersDic[EBattleEventId.ENTITY_SKILL_ENTER_CD_OR_CHARGE] > 0 then if skillData then local params = #paramsPool > 0 and table_remove(paramsPool) or {} table_clear(params) params.skillData = skillData BattleES.Dispatch(EBattleEventId.ENTITY_SKILL_ENTER_CD_OR_CHARGE, entity, params) paramsPool[#paramsPool + 1] = params end end end function BattleEventSystem.OnForceRandomSkillEnterOrFillCD(entity, keyPos, skillData) if eventId2ListenersDic[EBattleEventId.ENTITY_SKILL_FORCE_ENTER_OR_FILL_CD] and #eventId2ListenersDic[EBattleEventId.ENTITY_SKILL_FORCE_ENTER_OR_FILL_CD] > 0 then local params = #paramsPool > 0 and table_remove(paramsPool) or {} table_clear(params) params.skillData = skillData params.keyPos = keyPos BattleES.Dispatch(EBattleEventId.ENTITY_SKILL_FORCE_ENTER_OR_FILL_CD, entity, params) paramsPool[#paramsPool + 1] = params end end function BattleEventSystem.OnEntityTimeUpSkillSwitchAll(entity, skillData) if eventId2ListenersDic[EBattleEventId.ENTITY_SKILL_TIMEUP_SWITCHALL] and #eventId2ListenersDic[EBattleEventId.ENTITY_SKILL_TIMEUP_SWITCHALL] > 0 then local params = #paramsPool > 0 and table_remove(paramsPool) or {} table_clear(params) params.skillData = skillData BattleES.Dispatch(EBattleEventId.ENTITY_SKILL_TIMEUP_SWITCHALL, entity, params) paramsPool[#paramsPool + 1] = params end end function BattleEventSystem.OnEntitySkillMeetTarget(entity,skillData) if eventId2ListenersDic[EBattleEventId.ENTITY_SKILL_MEET_TARGET] and #eventId2ListenersDic[EBattleEventId.ENTITY_SKILL_MEET_TARGET] > 0 then if skillData then BattleES.Dispatch(EBattleEventId.ENTITY_SKILL_MEET_TARGET, entity, skillData) end end end function BattleEventSystem.OnEntitySkillCommandFilterRejected(entity, skillID) if eventId2ListenersDic[EBattleEventId.ENTITY_SKILL_COMMAND_FILTER_REJECTED] and #eventId2ListenersDic[EBattleEventId.ENTITY_SKILL_COMMAND_FILTER_REJECTED] > 0 then local lastSkillCommandRejectedFrame = entityId2skillRejectedFrameDic[entity.EntityID] or -999 if LogicUpdateManager._clientHandleFrame - lastSkillCommandRejectedFrame > 2 then -- 做个这个判断减少粘滞现象,因为现在click一次技能会有连续粘滞两帧有释放技能的命令产生,加个判断减少一次事件的dispatch local params = #paramsPool > 0 and table_remove(paramsPool) or {} table_clear(params) params.skillID = skillID BattleES.Dispatch(EBattleEventId.ENTITY_SKILL_COMMAND_FILTER_REJECTED, entity, params) entityId2skillRejectedFrameDic[entity.EntityID] = LogicUpdateManager._clientHandleFrame paramsPool[#paramsPool + 1] = params end end end function BattleEventSystem.OnRideHorse(entity) if eventId2ListenersDic[EBattleEventId.ENTITY_RIDE] and #eventId2ListenersDic[EBattleEventId.ENTITY_RIDE] > 0 then BattleES.Dispatch(EBattleEventId.ENTITY_RIDE, entity) end end function BattleEventSystem.OnOffHorse(entity) if eventId2ListenersDic[EBattleEventId.ENTITY_OFFRIDE] and #eventId2ListenersDic[EBattleEventId.ENTITY_OFFRIDE] > 0 then BattleES.Dispatch(EBattleEventId.ENTITY_OFFRIDE, entity) end end function BattleEventSystem.OnUseAdjutantSkill(entity, adjutantEntity, adjutantSkillData) if eventId2ListenersDic[EBattleEventId.ENTITY_USE_ADJUTANT_SKILL] and #eventId2ListenersDic[EBattleEventId.ENTITY_USE_ADJUTANT_SKILL] > 0 then local params = #paramsPool > 0 and table_remove(paramsPool) or {} table_clear(params) params.entity = entity params.adjutantEntity = adjutantEntity params.skillData = adjutantSkillData BattleES.Dispatch(EBattleEventId.ENTITY_USE_ADJUTANT_SKILL, entity, params) paramsPool[#paramsPool + 1] = params end end function BattleEventSystem.OnUseBuffSkill(entity, buffSkillId) if eventId2ListenersDic[EBattleEventId.ENTITY_USE_BUFF_SKILL] and #eventId2ListenersDic[EBattleEventId.ENTITY_USE_BUFF_SKILL] > 0 then local params = #paramsPool > 0 and table_remove(paramsPool) or {} table_clear(params) params.buffSkillId = buffSkillId BattleES.Dispatch(EBattleEventId.ENTITY_USE_BUFF_SKILL, entity, params) paramsPool[#paramsPool + 1] = params end end function BattleEventSystem.OnUsePetSkill(entity) if eventId2ListenersDic[EBattleEventId.ENTITY_USE_PET_SKILL] and #eventId2ListenersDic[EBattleEventId.ENTITY_USE_PET_SKILL] > 0 then BattleES.Dispatch(EBattleEventId.ENTITY_USE_PET_SKILL, entity) end end function BattleEventSystem.OnUsePetNormalAttack(entity) if eventId2ListenersDic[EBattleEventId.ENTITY_USE_PET_NORMAL_ATTACK] and #eventId2ListenersDic[EBattleEventId.ENTITY_USE_PET_NORMAL_ATTACK] > 0 then BattleES.Dispatch(EBattleEventId.ENTITY_USE_PET_NORMAL_ATTACK, entity) end end function BattleEventSystem.OnEntitySkillExitCD(entity, skillID) if eventId2ListenersDic[EBattleEventId.ENTITY_SKILL_EXIT_CD] and #eventId2ListenersDic[EBattleEventId.ENTITY_SKILL_EXIT_CD] > 0 then local params = #paramsPool > 0 and table_remove(paramsPool) or {} table_clear(params) params.skillID = skillID BattleES.Dispatch(EBattleEventId.ENTITY_SKILL_EXIT_CD, entity, params) paramsPool[#paramsPool + 1] = params end end function BattleEventSystem.AfterHookMissileHooked(missile) if eventId2ListenersDic[EBattleEventId.ENTITY_HOOK_MISSILE_HOOKED] and #eventId2ListenersDic[EBattleEventId.ENTITY_HOOK_MISSILE_HOOKED] > 0 then local params = #paramsPool > 0 and table_remove(paramsPool) or {} table_clear(params) params.missile = missile BattleES.Dispatch(EBattleEventId.ENTITY_HOOK_MISSILE_HOOKED, missile.hookStartEntity, params) BattleES.Dispatch(EBattleEventId.ENTITY_HOOK_MISSILE_HOOKED, missile.hookEntity, params) paramsPool[#paramsPool + 1] = params end end function BattleEventSystem.AfterHookMissileBreak(missile) if eventId2ListenersDic[EBattleEventId.ENTITY_HOOK_MISSILE_TOO_BREAK] and #eventId2ListenersDic[EBattleEventId.ENTITY_HOOK_MISSILE_TOO_BREAK] > 0 then local params = #paramsPool > 0 and table_remove(paramsPool) or {} table_clear(params) params.missile = missile params.originEntity = missile.Attacker:GetOriginEntity() BattleES.Dispatch(EBattleEventId.ENTITY_HOOK_MISSILE_TOO_BREAK, missile.hookStartEntity, params) BattleES.Dispatch(EBattleEventId.ENTITY_HOOK_MISSILE_TOO_BREAK, missile.hookEntity, params) paramsPool[#paramsPool + 1] = params end end function BattleEventSystem.AfterHookMissileTooFarBreak(missile) if eventId2ListenersDic[EBattleEventId.ENTITY_HOOK_MISSILE_TOO_FAR_BREAK] and #eventId2ListenersDic[EBattleEventId.ENTITY_HOOK_MISSILE_TOO_FAR_BREAK] > 0 then local params = #paramsPool > 0 and table_remove(paramsPool) or {} table_clear(params) params.missile = missile BattleES.Dispatch(EBattleEventId.ENTITY_HOOK_MISSILE_TOO_FAR_BREAK, missile.hookStartEntity, params) BattleES.Dispatch(EBattleEventId.ENTITY_HOOK_MISSILE_TOO_FAR_BREAK, missile.hookEntity, params) paramsPool[#paramsPool + 1] = params end end function BattleEventSystem.AfterHookMissileUpdate(missile) if eventId2ListenersDic[EBattleEventId.ENTITY_HOOK_MISSILE_UPDATE] and #eventId2ListenersDic[EBattleEventId.ENTITY_HOOK_MISSILE_UPDATE] > 0 then local params = #paramsPool > 0 and table_remove(paramsPool) or {} table_clear(params) params.missile = missile BattleES.Dispatch(EBattleEventId.ENTITY_HOOK_MISSILE_UPDATE, missile.hookStartEntity, params) BattleES.Dispatch(EBattleEventId.ENTITY_HOOK_MISSILE_UPDATE, missile.hookEntity, params) paramsPool[#paramsPool + 1] = params end end function BattleEventSystem.OnEntityDecisionReturnOut(entity) if eventId2ListenersDic[EBattleEventId.ENTITY_DECISION_RETURN_OUT] and #eventId2ListenersDic[EBattleEventId.ENTITY_DECISION_RETURN_OUT] > 0 then BattleES.Dispatch(EBattleEventId.ENTITY_DECISION_RETURN_OUT, entity) end end function BattleEventSystem.OnEntityImmunoPosAnchorRecover(entity) if eventId2ListenersDic[EBattleEventId.ENTITY_IMMUNO_ANCHOR_RECOVER] and #eventId2ListenersDic[EBattleEventId.ENTITY_IMMUNO_ANCHOR_RECOVER] > 0 then local params = #paramsPool > 0 and table_remove(paramsPool) or {} table_clear(params) params.recoverEntity = entity BattleES.Dispatch(EBattleEventId.ENTITY_IMMUNO_ANCHOR_RECOVER, entity, params) paramsPool[#paramsPool + 1] = params end end function BattleEventSystem.BeforeEntityDead(entity, missileID) if eventId2ListenersDic[EBattleEventId.ENTITY_BEFORE_DEAD] and #eventId2ListenersDic[EBattleEventId.ENTITY_BEFORE_DEAD] > 0 then --private.OnEvent(EBattleEventId.ENTITY_BEFORE_DEAD,entity) local params = #paramsPool > 0 and table_remove(paramsPool) or {} table_clear(params) params.deadEntity = entity params.killer = entity.components.record.KillerEntity params.missileID = missileID or -1 BattleES.Dispatch(EBattleEventId.ENTITY_BEFORE_DEAD, entity, params) paramsPool[#paramsPool + 1] = params end end function BattleEventSystem.AfterEntityDead(entity) if (eventId2ListenersDic[EBattleEventId.ENTITY_AFTER_DEAD] and #eventId2ListenersDic[EBattleEventId.ENTITY_AFTER_DEAD] > 0) or (eventId2ListenersDic[EBattleEventId.ENTITY_AFTER_KILL] and #eventId2ListenersDic[EBattleEventId.ENTITY_AFTER_KILL] > 0) then local params = #paramsPool > 0 and table_remove(paramsPool) or {} table_clear(params) params.deadEntity = entity params.killer = entity.components.record.KillerEntity --private.OnEvent(EBattleEventId.ENTITY_AFTER_DEAD,entity) BattleES.Dispatch(EBattleEventId.ENTITY_AFTER_DEAD, entity, params) BattleES.Dispatch(EBattleEventId.ENTITY_AFTER_KILL, params.killer, params) paramsPool[#paramsPool + 1] = params end if (eventId2ListenersDic[EBattleEventId.ENTITY_AFTER_SLAVE_DEAD] and #eventId2ListenersDic[EBattleEventId.ENTITY_AFTER_SLAVE_DEAD] > 0) then if entity:GetMasterEntity() then local params = #paramsPool > 0 and table_remove(paramsPool) or {} table_clear(params) params.slave = entity params.master = entity:GetMasterEntity() BattleES.Dispatch(EBattleEventId.ENTITY_AFTER_SLAVE_DEAD, params.master, params) paramsPool[#paramsPool + 1] = params end end end function BattleEventSystem.AfterEntityDrived(carEntity, driverEntity) if eventId2ListenersDic[EBattleEventId.ENTITY_AFTER_DRIVE] and #eventId2ListenersDic[EBattleEventId.ENTITY_AFTER_DRIVE] > 0 or eventId2ListenersDic[EBattleEventId.ENTITY_AFTER_BE_DRIVE ] and #eventId2ListenersDic[EBattleEventId.ENTITY_AFTER_BE_DRIVE ] > 0 then local params = #paramsPool > 0 and table_remove(paramsPool) or {} table_clear(params) params.vehicle = carEntity params.driver = driverEntity BattleES.Dispatch(EBattleEventId.ENTITY_AFTER_DRIVE, driverEntity, params) BattleES.Dispatch(EBattleEventId.ENTITY_AFTER_BE_DRIVE, carEntity, params) paramsPool[#paramsPool + 1] = params end end function BattleEventSystem.AfterEntityOffDrived(carEntity, driverEntity) if eventId2ListenersDic[EBattleEventId.ENTITY_AFTER_OFFDRIVE] and #eventId2ListenersDic[EBattleEventId.ENTITY_AFTER_OFFDRIVE] > 0 or eventId2ListenersDic[EBattleEventId.ENTITY_AFTER_DRIVER_OFF_CAR] and #eventId2ListenersDic[EBattleEventId.ENTITY_AFTER_DRIVER_OFF_CAR] > 0 then local params = #paramsPool > 0 and table_remove(paramsPool) or {} table_clear(params) params.vehicle = carEntity params.driver = driverEntity BattleES.Dispatch(EBattleEventId.ENTITY_AFTER_OFFDRIVE, carEntity, params) BattleES.Dispatch(EBattleEventId.ENTITY_AFTER_DRIVER_OFF_CAR, driverEntity, params) -- 给司机发司机下车 paramsPool[#paramsPool + 1] = params end end function BattleEventSystem.AfterDrivedVehicleDead(vehicleEntity, driver) --载具死亡后 if eventId2ListenersDic[EBattleEventId.ENTITY_DRIVED_VEHICLE_AFTER_DEAD] and #eventId2ListenersDic[EBattleEventId.ENTITY_DRIVED_VEHICLE_AFTER_DEAD] > 0 then local params = #paramsPool > 0 and table_remove(paramsPool) or {} table_clear(params) params.vehicle = vehicleEntity params.driver = driver BattleES.Dispatch(EBattleEventId.ENTITY_DRIVED_VEHICLE_AFTER_DEAD, vehicleEntity, params) paramsPool[#paramsPool + 1] = params end end function BattleEventSystem.AfterSelectOneRevive(entity) if (eventId2ListenersDic[EBattleEventId.ENTITY_AFTER_SELECTONEREVIVE] and #eventId2ListenersDic[EBattleEventId.ENTITY_AFTER_SELECTONEREVIVE] > 0) then local curEntity = LevelPlayerManager.GetPlayerActiveEntity(entity:GetPlayerID()) BattleES.Dispatch(EBattleEventId.ENTITY_AFTER_SELECTONEREVIVE, curEntity) end end function BattleEventSystem.AfterSelectOneReviveCurHero(entity) if (eventId2ListenersDic[EBattleEventId.ENTITY_AFTER_SELECTONEREVIVE_CURHERO] and #eventId2ListenersDic[EBattleEventId.ENTITY_AFTER_SELECTONEREVIVE_CURHERO] > 0) then BattleES.Dispatch(EBattleEventId.ENTITY_AFTER_SELECTONEREVIVE_CURHERO, entity) end end function BattleEventSystem.AfterEntityBorn(entity) if eventId2ListenersDic[EBattleEventId.ENTITY_AFTER_BORN] and #eventId2ListenersDic[EBattleEventId.ENTITY_AFTER_BORN] > 0 then local params = #paramsPool > 0 and table_remove(paramsPool) or {} table_clear(params) params.bornEntity = entity BattleES.Dispatch(EBattleEventId.ENTITY_AFTER_BORN, entity, params) paramsPool[#paramsPool + 1] = params end if eventId2ListenersDic[EBattleEventId.ENTITY_AFTER_SLAVE_BORN] then if entity:GetMasterEntity() then local params = #paramsPool > 0 and table_remove(paramsPool) or {} table_clear(params) params.slave = entity params.master = entity:GetMasterEntity() BattleES.Dispatch(EBattleEventId.ENTITY_AFTER_SLAVE_BORN, params.master, params) paramsPool[#paramsPool + 1] = params end end end function BattleEventSystem.OnBuffAddLayerOrRefresh(buff, buffId, buffUpdateData, oldBuffLayer) if not oldBuffLayer or oldBuffLayer < buffUpdateData.BuffLayer then if eventId2ListenersDic[EBattleEventId.BUFF_ADD_LAYER] and #eventId2ListenersDic[EBattleEventId.BUFF_ADD_LAYER] > 0 then local params = #paramsPool > 0 and table_remove(paramsPool) or {} table_clear(params) params.buffId = buffId params.eventBuffUpdateData = buffUpdateData BattleES.Dispatch(EBattleEventId.BUFF_ADD_LAYER, buff, params) paramsPool[#paramsPool + 1] = params end end if eventId2ListenersDic[EBattleEventId.BUFF_ADD_LAYER_OR_REFRESH] and #eventId2ListenersDic[EBattleEventId.BUFF_ADD_LAYER_OR_REFRESH] > 0 then local params = #paramsPool > 0 and table_remove(paramsPool) or {} table_clear(params) params.buffId = buffId params.eventBuffUpdateData = buffUpdateData BattleES.Dispatch(EBattleEventId.BUFF_ADD_LAYER_OR_REFRESH, buff, params) paramsPool[#paramsPool + 1] = params end end function BattleEventSystem.OnNotifyBuff(id) if BattleEventSystem.IsLevelNotifyEvent(id) then BattleES.Dispatch(id,LevelManager) else logging.error(LTAG.ERROR, "HYW : 通知buff的事件ID不正确,应该为 " , EBattleEventId.____LEVEL_NOTIFY_START____ , " 和 " , EBattleEventId.____LEVEL_NOTIFY_END____ , " 之间") end end --关卡据点元素占领完成时(据点所属改变时) function BattleEventSystem.OnStrongholdCompleteOccupy(campsitePos, occupierID, occupyRule) if eventId2ListenersDic[EBattleEventId.STRONGHOLD_COMPLETE_OCCUPY] and #eventId2ListenersDic[EBattleEventId.STRONGHOLD_COMPLETE_OCCUPY] > 0 then local params = #paramsPool > 0 and table_remove(paramsPool) or {} table_clear(params) params.pos = campsitePos params.occupierID = occupierID params.occupierType = occupyRule BattleES.Dispatch(EBattleEventId.STRONGHOLD_COMPLETE_OCCUPY, LevelManager, params) paramsPool[#paramsPool + 1] = params end end function BattleEventSystem.AfterEntityCreateIllusion(entity, illusionEntity) if eventId2ListenersDic[EBattleEventId.ENTITY_AFTER_CREATE_ILLUSION] and #eventId2ListenersDic[EBattleEventId.ENTITY_AFTER_CREATE_ILLUSION] > 0 then local params = #paramsPool > 0 and table_remove(paramsPool) or {} table_clear(params) params.master = entity params.illusion = illusionEntity BattleES.Dispatch(EBattleEventId.ENTITY_AFTER_CREATE_ILLUSION, entity, params) paramsPool[#paramsPool + 1] = params end end -------------------接受外部通知的接口 over ------------------------ return BattleEventSystem