local FuncNode_ActiveNum = class("FuncNode_ActiveNum") local private = {} --[[ 初始化 --]] function FuncNode_ActiveNum:initialize(entity) self.LimitChildCount = 3 self.Type = LuaConst.ConditionFuncType.ActiveNum end function FuncNode_ActiveNum:GetEntityListOfLevelItemByID(levelItemID) local levelItem = LevelItemManager.GetItemByID(levelItemID) if levelItem then if levelItem._allEntityDict then local list = {} for k,entity in pairs(levelItem._allEntityDict) do --pairs safe 因为只是统计数量 table.insert(list, entity) end return list else logging.error(LTAG.ERROR, "HYW : 关卡元素的_allEntityDict为空!!! 元素ID :", levelItemID, " @FuncNode_ActiveNum:GetEntityListOfLevelItemByID ") end else logging.error(LTAG.ERROR, "HYW : 找不到指定的关卡元素!! 元素ID :", levelItemID, " @FuncNode_ActiveNum:GetEntityListOfLevelItemByID ") end end --[[ 执行 --]] function FuncNode_ActiveNum:Run(conditionDataNode, entity, missile) local type = conditionDataNode.FirstNode:Run(entity, missile) local disSqr = conditionDataNode.SecondNode:Run(entity, missile) local characterIdFilter = nil if conditionDataNode.ThirdNode then characterIdFilter = conditionDataNode.ThirdNode:Run(entity, missile) end local dontAddNumIfHasCanNotBeTargetBuff = false if type == FP.Const.Zero then --组内成员 --TODO else local num = FP.newV1(0) --new local list2d = nil if type == FP.Const.One then --范围友方 list2d = TargetManager.Get2DFriendList(entity) elseif type == FP.Const.Two or type == FP.Const.Six then --范围敌方 list2d = TargetManager.Get2DEnemyList(entity) dontAddNumIfHasCanNotBeTargetBuff = type == FP.Const.Six elseif type == FP.Const.Three then list2d = {LogicUpdateManager.EntityList_Sync, LogicUpdateManager.EntityList_Normal} elseif type == FP.Const.Four then if characterIdFilter then local levelItemID = FP.tonumberV1(characterIdFilter) local list = self:GetEntityListOfLevelItemByID(levelItemID) if list then list2d = {} table.insert(list2d, list) end else logging.error(LTAG.ERROR, "HYW : 没有指定元素ID @FuncNode_ActiveNum:Run CharacterID :", entity:GetCharacterID()) end characterIdFilter = nil --这里设characterIdFilter为nil,表示在AddNumber里不再过滤ID了,因为在此处已经过滤完毕了 elseif type == FP.Const.Five then if characterIdFilter then local levelItemGroupID = FP.tonumberV1(characterIdFilter) local levelItemIDList = LevelItemManager.GetItemIDListByGroup(levelItemGroupID, LuaConst.LevelItemType.Monster) if levelItemIDList then list2d = {} for i,levelItemID in ipairs(levelItemIDList) do local list = self:GetEntityListOfLevelItemByID(levelItemID) if list then table.insert(list2d, list) end end end else logging.error(LTAG.ERROR, "HYW : 没有指定元素组ID @FuncNode_ActiveNum:Run CharacterID :", entity:GetCharacterID()) end characterIdFilter = nil --这里设characterIdFilter为nil,表示在AddNumber里不再过滤ID了,因为在此处已经过滤完毕了 end if list2d then for i,list in ipairs(list2d) do private.AddNumber(list,entity,disSqr,num,characterIdFilter,dontAddNumIfHasCanNotBeTargetBuff) end end return num end end function private.AddNumber(list,entity,disSqr,num,characterIdFilter,dontAddNumIfHasCanNotBeTargetBuff) for i,value in ipairs(list) do if value._logicInitData.EntityID ~= entity._logicInitData.EntityID and private.MatchState(value) and private.MatchDis(entity, value, disSqr) then if not dontAddNumIfHasCanNotBeTargetBuff or not value.components.buff:HasBuff(LuaConst.SpecialBuffs.CanNotBeTarget) then if characterIdFilter == nil or characterIdFilter == FP.Const.Zero then num:Add(FP.Const.One) else if characterIdFilter > FP.Const.Zero then if value._logicInitData.CharacterID == FP.tonumberV1(characterIdFilter) then num:Add(FP.Const.One) end else --单位类型过滤 1=英雄 2=怪物 if characterIdFilter == FP.Const.NegOne then if value:IsHero() then num:Add(FP.Const.One) end elseif characterIdFilter == FP.Const.NegTwo then if value:IsMonster() then num:Add(FP.Const.One) end end end end end end end end function private.MatchState(tempEntity) if tempEntity._logicInitData.CharacterType == LuaConst.CharacterType.Adjutant then --副将 return false end local comp_Base = tempEntity.components.base if not comp_Base.IsActive then --未激活 return false end if not tempEntity.components.attr:IsAlive() then return false end return true end function private.MatchDis(entity, tempEntity, disSqr) if disSqr == FP.Const.Zero then return true else return not FP.V2.IsDistanceSqrGreater(entity.components.move.LogicPos, tempEntity.components.move.LogicPos, disSqr) end end return FuncNode_ActiveNum