local Base = require("Battle/Logic/AI/Decision/Decision_Base") local Decision_SetLeader = class("Decision_SetLeader", Base) --[[ 初始化 --]] function Decision_SetLeader:initialize(entity) --类型 self.Type = LuaConst.DecisionType.SetLeader --瞬时 self.IsOnce = true end --[[ 输出指令 --]] function Decision_SetLeader:SetCommand(entity, decisionData, command) command.DecisionID = decisionData.ID return command end --[[ 执行 --]] function Decision_SetLeader:Handle(entity, decisionData, stateType, animName) -- 解除旧的leader关系 local oldGroupID = entity._logicInitData.LeaderID if oldGroupID then local oldLeaderEntity = LogicUpdateManager.GroupAIEntityDir[oldGroupID] SystemManager.OnGroupRemoveEntity(oldLeaderEntity, entity) end -- 设置新的leader local itemData = LevelItemManager.GetItemDataByID(decisionData.IntParam1) if itemData.IsLeader then local groupID = itemData.LevelItemID if groupID and groupID ~= 0 then entity._logicInitData.LeaderID = groupID local leader = LogicUpdateManager.GroupAIEntityDir[groupID] if leader == nil then logging.error(LTAG.ERROR, "[关卡策划]:在设置自身的兵长时,并没发现兵长的entity 。AI配置的关卡元素ID = ",decisionData.IntParam1 , " 出错的AI =", entity.components.aiBase.CurDecisionID) end SystemManager.OnGroupAddEntity(groupID, leader, entity) end else logging.error(LTAG.ERROR, "[关卡策划]:在设置自身的兵长时,发现AI配置的Leader元素并不是Leader 。AI配置的关卡元素ID = ",decisionData.IntParam1 , " 出错的AI =", entity.components.aiBase.CurDecisionID) end return LuaConst.StateType.None,nil end return Decision_SetLeader