/// <summary>
 /// 创建任务节点
 /// </summary>
 /// <param name="unitId">行为树归属的UnitID</param>
 /// <param name="runtimeTree">运行时归属的行为树</param>
 /// <returns></returns>
 public virtual Task CreateTask(long unitId, NP_RuntimeTree runtimeTree)
 {
     return(null);
 }
Exemplo n.º 2
0
 /// <summary>
 /// 取得Buff,Buff流程是Acquire->OnInit(CalculateTimerAndOverlay)->AddTemp->经过筛选->AddReal
 /// </summary>
 /// <param name="npDataSupportor">Buff数据归属的数据块</param>
 /// <param name="buffNodeId">Buff节点的Id</param>
 /// <param name="theUnitFrom">Buff来源者</param>
 /// <param name="theUnitBelongTo">Buff寄生者</param>
 /// <returns></returns>
 public static ABuffSystemBase AcquireBuff(NP_DataSupportor npDataSupportor, long buffNodeId, Unit theUnitFrom, Unit theUnitBelongTo,
                                           NP_RuntimeTree theSkillCanvasBelongTo)
 {
     return(AcquireBuff((npDataSupportor.BuffNodeDataDic[buffNodeId] as NormalBuffNodeData).BuffData, theUnitFrom, theUnitBelongTo,
                        theSkillCanvasBelongTo));
 }
 /// <summary>
 /// 创建装饰结点
 /// </summary>
 /// <param name="unitId">行为树归属的UnitID</param>
 /// <param name="runtimeTree">运行时归属的行为树</param>
 /// <param name="node">所装饰的结点</param>
 /// <returns></returns>
 public virtual Decorator CreateDecoratorNode(long unitId, NP_RuntimeTree runtimeTree, Node node)
 {
     return(null);
 }
 public override Decorator CreateDecoratorNode(long unitId, NP_RuntimeTree runtimeTree, Node node)
 {
     this.m_BlackboardMultipleConditions = new BlackboardMultipleConditions(this.MatchInfos, this.MatchType, this.Stop, node);
     //此处的value参数可以随便设,因为我们在游戏中这个value是需要动态改变的
     return(this.m_BlackboardMultipleConditions);
 }
Exemplo n.º 5
0
 public override Task CreateTask(long unitId, NP_RuntimeTree runtimeTree)
 {
     this.m_WaitUntilStopped = new WaitUntilStopped();
     return(this.m_WaitUntilStopped);
 }
Exemplo n.º 6
0
        /// <summary>
        /// 创建一个行为树实例,默认存入Unit的NP_RuntimeTreeManager中
        /// </summary>
        /// <param name="unit">行为树所归属unit</param>
        /// <param name="nPDataId">行为树数据id</param>
        /// <returns></returns>
        public static NP_RuntimeTree CreateNpRuntimeTree(Unit unit, long nPDataId)
        {
            NP_DataSupportor npDataSupportor =
                Game.Scene.GetComponent <NP_TreeDataRepository>().GetNP_TreeData_DeepCopyBBValuesOnly(nPDataId);

            NP_RuntimeTree runTimeTree =
                ComponentFactory.Create <NP_RuntimeTree, NP_DataSupportor, long>(npDataSupportor, unit.Id);

            long treeId = npDataSupportor.NpDataSupportorBase.NPBehaveTreeDataId;

            unit.GetComponent <NP_RuntimeTreeManager>().AddTree(runTimeTree.Id, treeId, runTimeTree);

            //Log.Info($"运行时id为{theRuntimeTreeID}");
            //配置节点数据
            foreach (var nodeDateBase in npDataSupportor.NpDataSupportorBase.NP_DataSupportorDic)
            {
                switch (nodeDateBase.Value.NodeType)
                {
                case NodeType.Task:
                    try
                    {
                        nodeDateBase.Value.CreateTask(unit.Id, runTimeTree);
                    }
                    catch (Exception e)
                    {
                        Log.Error($"{e}-----{nodeDateBase.Value.NodeDes}");
                        throw;
                    }

                    break;

                case NodeType.Decorator:
                    try
                    {
                        nodeDateBase.Value.CreateDecoratorNode(unit.Id, runTimeTree,
                                                               npDataSupportor.NpDataSupportorBase.NP_DataSupportorDic[nodeDateBase.Value.LinkedIds[0]].NP_GetNode());
                    }
                    catch (Exception e)
                    {
                        Log.Error($"{e}-----{nodeDateBase.Value.NodeDes}");
                        throw;
                    }

                    break;

                case NodeType.Composite:
                    try
                    {
                        List <Node> temp = new List <Node>();
                        foreach (var linkedId in nodeDateBase.Value.LinkedIds)
                        {
                            temp.Add(npDataSupportor.NpDataSupportorBase.NP_DataSupportorDic[linkedId].NP_GetNode());
                        }

                        nodeDateBase.Value.CreateComposite(temp.ToArray());
                    }
                    catch (Exception e)
                    {
                        Log.Error($"{e}-----{nodeDateBase.Value.NodeDes}");
                        throw;
                    }

                    break;
                }
            }

            //配置根结点
            runTimeTree.SetRootNode(npDataSupportor.NpDataSupportorBase.NP_DataSupportorDic[treeId].NP_GetNode() as Root);

            //配置黑板数据
            Dictionary <string, ANP_BBValue> bbvaluesManager = runTimeTree.GetBlackboard().GetDatas();

            foreach (var bbValues in npDataSupportor.NpDataSupportorBase.NP_BBValueManager)
            {
                bbvaluesManager.Add(bbValues.Key, bbValues.Value);
            }

            return(runTimeTree);
        }
Exemplo n.º 7
0
 /// <summary>
 /// 添加行为树
 /// </summary>
 /// <param name="runTimeID">行为树运行时ID</param>
 /// <param name="treeId">行为树在预配置中的id,即根节点id</param>
 /// <param name="npRuntimeTree">要添加的行为树</param>
 public void AddTree(long runTimeID, long treeId, NP_RuntimeTree npRuntimeTree)
 {
     RuntimeTrees.Add(runTimeID, npRuntimeTree);
     this.m_HasAddedTrees.Add(treeId, runTimeID);
 }
        /// <summary>
        /// 取得Buff,Buff流程是Acquire->OnInit(CalculateTimerAndOverlay)->AddTemp->经过筛选->AddReal
        /// </summary>
        /// <param name="buffDataBase">Buff数据</param>
        /// <param name="theUnitFrom">Buff来源者</param>
        /// <param name="theUnitBelongTo">Buff寄生者</param>
        /// <returns></returns>
        public ABuffSystemBase AcquireBuff(BuffDataBase buffDataBase, Unit theUnitFrom, Unit theUnitBelongTo, NP_RuntimeTree theSkillCanvasBelongTo)
        {
            Queue <ABuffSystemBase> buffBase;
            Type            targetBuffSystemType = AllBuffSystemTypes[buffDataBase.BelongBuffSystemType];
            ABuffSystemBase resultBuff;

            if (this.BuffSystems.TryGetValue(targetBuffSystemType, out buffBase))
            {
                if (buffBase.Count > 0)
                {
                    resultBuff = buffBase.Dequeue();
                    resultBuff.BelongtoRuntimeTree = theSkillCanvasBelongTo;
                    resultBuff.OnInit(buffDataBase, theUnitFrom, theUnitBelongTo);
                    return(resultBuff);
                }
            }

            resultBuff = (ABuffSystemBase)Activator.CreateInstance(targetBuffSystemType);
            resultBuff.BelongtoRuntimeTree = theSkillCanvasBelongTo;
            resultBuff.OnInit(buffDataBase, theUnitFrom, theUnitBelongTo);
            return(resultBuff);
        }