Example #1
0
        public static void AutoAddBuff(this VTD_BuffInfo self, NP_DataSupportor npDataSupportor, long buffNodeId, Unit theUnitFrom,
                                       Unit theUnitBelongTo,
                                       NP_RuntimeTree theSkillCanvasBelongTo)
        {
            int Layers = 0;

            if (self.LayersDetermindByBBValue)
            {
                Layers = theSkillCanvasBelongTo.GetBlackboard().Get <int>(self.LayersThatDetermindByBBValue.BBKey);
            }
            else
            {
                Layers = self.Layers;
            }

            if (self.LayersIsAbs)
            {
                ABuffSystemBase nextBuffSystemBase = BuffFactory.AcquireBuff(npDataSupportor, buffNodeId, theUnitFrom, theUnitBelongTo,
                                                                             theSkillCanvasBelongTo);
                if (nextBuffSystemBase.CurrentOverlay < nextBuffSystemBase.BuffData.MaxOverlay && nextBuffSystemBase.CurrentOverlay < Layers)
                {
                    Layers -= nextBuffSystemBase.CurrentOverlay;
                }
                else
                {
                    return;
                }
            }

            for (int i = 0; i < Layers; i++)
            {
                BuffFactory.AcquireBuff(npDataSupportor, buffNodeId, theUnitFrom, theUnitBelongTo,
                                        theSkillCanvasBelongTo);
            }
        }
Example #2
0
        public override void Dispose()
        {
            if (IsDisposed)
            {
                return;
            }
            base.Dispose();

            this.Finish();
            BelongToUnitId              = 0;
            this.m_RootNode             = null;
            this.BelongNP_DataSupportor = null;
        }
        /// <summary>
        /// 获取一棵树的所有数据(仅深拷贝黑板数据内容,而忽略例如BuffNodeDataDic的数据内容)
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public NP_DataSupportor GetNP_TreeData_DeepCopyBBValuesOnly(long id)
        {
            NP_DataSupportor result = new NP_DataSupportor();

            if (this.m_NpRuntimeTreesDatas.ContainsKey(id))
            {
                result.BuffNodeDataDic     = this.m_NpRuntimeTreesDatas[id].BuffNodeDataDic;
                result.NpDataSupportorBase = this.m_NpRuntimeTreesDatas[id].NpDataSupportorBase.DeepCopy();
                return(result);
            }

            Log.Error($"请求的行为树id不存在,id为{id}");
            return(null);
        }
Example #4
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));
 }
Example #5
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 tempTree =
                ComponentFactory.Create <NP_RuntimeTree, NP_DataSupportor, long>(npDataSupportor, unit.Id);

            long rootId = npDataSupportor.NpDataSupportorBase.NPBehaveTreeDataId;

            unit.GetComponent <NP_RuntimeTreeManager>().AddTree(tempTree.Id, rootId, tempTree);

            //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, tempTree);
                    }
                    catch (Exception e)
                    {
                        Log.Error($"{e}-----{nodeDateBase.Value.NodeDes}");
                        throw;
                    }

                    break;

                case NodeType.Decorator:
                    try
                    {
                        nodeDateBase.Value.CreateDecoratorNode(unit.Id, tempTree,
                                                               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;
                }
            }

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

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

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

            return(tempTree);
        }
        public void Awake()
        {
            Type[] types = typeof(NodeType).Assembly.GetTypes();
            foreach (Type type in types)
            {
                if (type.IsSubclassOf(typeof(NP_NodeDataBase)) || type.IsSubclassOf(typeof(NP_ClassForStoreAction)) ||
                    type.IsSubclassOf(typeof(BuffNodeDataBase)) || type.IsSubclassOf(typeof(BuffDataBase)) ||
                    type.IsSubclassOf(typeof(ListenBuffEvent_Normal)) || type.IsSubclassOf(typeof(NP_DataSupportorBase)))
                {
                    BsonClassMap.LookupClassMap(type);
                }
            }

            BsonClassMap.LookupClassMap(typeof(NP_BBValue_Int));
            BsonClassMap.LookupClassMap(typeof(NP_BBValue_Bool));
            BsonClassMap.LookupClassMap(typeof(NP_BBValue_Float));
            BsonClassMap.LookupClassMap(typeof(NP_BBValue_String));
            BsonClassMap.LookupClassMap(typeof(NP_BBValue_Vector3));
            BsonClassMap.LookupClassMap(typeof(NP_BBValue_Long));
            BsonClassMap.LookupClassMap(typeof(NP_BBValue_List_Long));
#if SERVER
            DirectoryInfo directory = new DirectoryInfo(NPDataPath);
            FileInfo[]    fileInfos = directory.GetFiles();

            foreach (var fileInfo in fileInfos)
            {
                byte[] mfile = File.ReadAllBytes(fileInfo.FullName);

                if (mfile.Length == 0)
                {
                    Log.Info("没有读取到文件");
                }

                try
                {
                    NP_DataSupportor MnNpDataSupportor = BsonSerializer.Deserialize <NP_DataSupportor>(mfile);

                    Log.Info($"反序列化行为树:{fileInfo.FullName}完成");

                    NpRuntimeTreesDatas.Add(MnNpDataSupportor.RootId, MnNpDataSupportor);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    throw;
                }
            }
#else
            ResourcesComponent resourcesComponent = Game.Scene.GetComponent <ResourcesComponent>();
            GameObject         skillConfigs       = resourcesComponent.LoadAsset <GameObject>(ABPathUtilities.GetSkillConfigPath("SkillConfigs"));
            foreach (var referenceCollectorData in skillConfigs.GetComponent <ReferenceCollector>().data)
            {
                TextAsset textAsset = skillConfigs.GetTargetObjectFromRC <TextAsset>(referenceCollectorData.key);

                if (textAsset.bytes.Length == 0)
                {
                    Log.Info("没有读取到文件");
                }

                try
                {
                    NP_DataSupportor MnNpDataSupportor = BsonSerializer.Deserialize <NP_DataSupportor>(textAsset.bytes);

                    Log.Info($"反序列化行为树:{referenceCollectorData.key}完成");

                    this.m_NpRuntimeTreesDatas.Add(MnNpDataSupportor.NpDataSupportorBase.NPBehaveTreeDataId, MnNpDataSupportor);
                }
                catch (Exception e)
                {
                    Log.Error(e);
                    throw;
                }
            }
#endif
        }
Example #7
0
 public void Awake(NP_DataSupportor m_BelongNP_DataSupportor, long belongToUnitId)
 {
     BelongToUnitId = belongToUnitId;
     this.BelongNP_DataSupportor = m_BelongNP_DataSupportor;
 }