Exemplo n.º 1
0
        private void SelTarget()
        {
            WarServerNpcMgr npcMgr = WarServerManager.Instance.npcMgr;

            List <ServerLifeNpc> buildList = npcMgr.GetBuildByType(myHero.Camp, BuildNPCType.Tower);

            if (buildList == null || buildList.Count == 0)
            {
                ConsoleEx.DebugError("no tower find ");
            }

            int len = buildList.Count;

            float minDis = Mathf.Infinity;

            for (int i = 0; i < len; i++)
            {
                if (buildList[i].IsAlive)
                {
                    float dis = AITools.GetSqrDis(mTrans.position, buildList[i].transform.position);
                    if (dis < minDis)
                    {
                        minDis = dis;
                        target = buildList[i];
                    }
                }
            }

            mTargetTrans = target.transform;
            targetPos    = target.transform.forward * target.data.configData.seekRange * -1;

            distance = myHero.data.configData.radius + target.data.configData.radius + 2.0f;
        }
Exemplo n.º 2
0
        /// <summary>
        /// 加载子弹型npc
        /// </summary>
        /// <returns>The bullet npc.</returns>
        /// <param name="num">Number.</param>
        /// <param name="camp">Camp.</param>
        /// <param name="pos">Position.</param>
        /// <param name="rot">Rot.</param>
        public GameObject LoadBulletNpc(int num, CAMP camp, Vector3 pos, Quaternion rot)
        {
            if (NpcModel == null)
            {
                NpcModel = Core.Data.getIModelConfig <NPCModel>();
            }

            NPCConfigData configData = NpcModel.get(num);

            #if DEBUG
            Utils.Assert(configData == null, "Virtual Npc load can't find npc configure. NPC id = " + num);
            #endif

            string path = SPath.Combine(ResourceSetting.PACKROOT, NPC);
            path = SPath.Combine(path, "ServerBulletNpc");

            UObj obj = URes.Load(path);

            GameObject go = GameObject.Instantiate(obj) as GameObject;
            go.transform.position = pos;
            go.transform.rotation = rot;

            ServerNPC npc = go.GetComponent <ServerNPC>();
            if (npc != null)
            {
                DynamicDataInit(npc, configData, camp);
            }

            return(go);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 数据的初始化
        /// </summary>
        /// <param name="go">Go.</param>
        /// <param name="num">Number.</param>
        /// <param name="id">Identifier.</param>
        /// <param name="camp">Camp.</param>
        void DynamicDataInit(ServerNPC curHero, NPCConfigData econfig, CAMP camp)
        {
            ///
            /// 填充阵营
            ///
            curHero.Camp = camp;

            ///
            /// 填充NPC数据
            ///
            NPCData dynamicData = new NPCData();

            dynamicData.rtData     = new NPCRuntimeData(econfig);
            dynamicData.configData = econfig;
            dynamicData.btData     = new NPCBattleData();
            curHero.data           = dynamicData;

            ///
            /// 向WarManager注册
            ///
            serNpcMgr.SignID(curHero);

            WarServerManager warMgr = WarServerManager.Instance;
            ///
            /// 填充技能数据
            ///
            RtNpcSkillModel skMd = new RtNpcSkillModel(econfig.ID, curHero.UniqueID);
            ServerLifeNpc   life = curHero as ServerLifeNpc;

            if (life != null)
            {
                life.runSkMd = skMd;
            }

            ///
            /// 填充默认的buff
            ///
            for (short i = 0; i < Consts.MAX_SKILL_COUNT; ++i)
            {
                RtSkData sk = skMd.getRuntimeSkill(i);
                if (sk != null)
                {
                    int passive = sk.skillCfg.PassiveBuff;
                    if (passive > 0)
                    {
                        BuffCtorParam ctor = new BuffCtorParam()
                        {
                            bufNum    = passive,
                            fromNpcId = curHero.UniqueID,
                            toNpcId   = curHero.UniqueID,
                            origin    = OriginOfBuff.BornWithSkill,
                            initLayer = 1,
                            duration  = Consts.USE_BUFF_CONFIG_DURATION,
                        };
                        warMgr.bufMgr.createBuff(ctor);
                    }
                }
            }
        }
Exemplo n.º 4
0
 //发送hp消息
 void SendHpMsg(ServerNPC newNpc)
 {
     hpMsg.srcID    = newNpc.UniqueID;
     hpMsg.uniqueId = newNpc.UniqueID;
     hpMsg.deltaHp  = newNpc.data.rtData.totalHp;
     hpMsg.isDamage = false;
     WarServerManager.Instance.realServer.proxyCli.NPChp(hpMsg);
 }
Exemplo n.º 5
0
 public void RegisterNPC(ServerNPC npc)
 {
     npc.Init(networking.GetNextEntityID(), networking);
     lock (newNPCLock)
     {
         newNPCs.Add(npc);
     }
 }
Exemplo n.º 6
0
 //发送创建npc消息
 void SendCreateNpcMsg(ServerNPC newNpc)
 {
     crtMsg.npclist[0].npcID    = newNpc.data.configData.ID;
     crtMsg.npclist[0].uniqueId = newNpc.UniqueID;
     crtMsg.npclist[0].camp     = (int)newNpc.Camp;
     crtMsg.npclist[0].pos      = VectorWrap.ToVector(newNpc.transform.position);
     crtMsg.npclist[0].rotation = VectorWrap.ToVector(newNpc.transform.eulerAngles);
     WarServerManager.Instance.realServer.proxyCli.CtorNpc(crtMsg);
 }
Exemplo n.º 7
0
        private Polygon Select(ServerNPC caster, EffectConfigData efCfg)
        {
                        #if DEBUG
            Utils.Assert(caster == null, "Can't find target unless caster isn't null.");
            Utils.Assert(efCfg == null, "Can't find target unless EffectConfigData isn't null.");
                        #endif

            UTran trans = caster.transform;
            float Y     = trans.localPosition.y;

            float halfWidth = efCfg.eParam2 * 0.5F;
            float Height    = efCfg.eParam1;

            UVec3[] localVecs = new UVec3[4];
            localVecs[0] = new UVec3(-halfWidth, Y, 0f);
            localVecs[1] = new UVec3(-halfWidth, Y, Height);
            localVecs[2] = new UVec3(halfWidth, Y, Height);
            localVecs[3] = new UVec3(halfWidth, Y, 0f);


            UVec3[] WorldVecs = new UVec3[4];
            WorldVecs[0] = trans.TransformPoint(localVecs[0]);
            WorldVecs[1] = trans.TransformPoint(localVecs[1]);
            WorldVecs[2] = trans.TransformPoint(localVecs[2]);
            WorldVecs[3] = trans.TransformPoint(localVecs[3]);

            PointF[] vecs = new PointF[4];

            vecs[0] = new PointF()
            {
                X = WorldVecs[0].x,
                Y = WorldVecs[0].z,
            };

            vecs[1] = new PointF()
            {
                X = WorldVecs[1].x,
                Y = WorldVecs[1].z,
            };

            vecs[2] = new PointF()
            {
                X = WorldVecs[2].x,
                Y = WorldVecs[2].z,
            };

            vecs[3] = new PointF()
            {
                X = WorldVecs[3].x,
                Y = WorldVecs[3].z,
            };

            Polygon rectangle = new Polygon(vecs);

            return(rectangle);
        }
Exemplo n.º 8
0
        void Awake()
        {
            efcfg = new EffectConfigData()
            {
                eParam1 = 2.0F,
                eParam2 = 3.0F,
            };

            npc = GetComponent <ServerNPC>();
        }
Exemplo n.º 9
0
 public override void OnStart()
 {
     if (self)
     {
         npc = GetComponent <ServerNPC> ();
     }
     else
     {
         npc = hero.Value;
     }
 }
Exemplo n.º 10
0
        private void SelTarget()
        {
            NeHeQiaoNpcMgr npcMgr = WarServerManager.Instance.npcMgr as NeHeQiaoNpcMgr;

            //自家泉水
            if (myHero.Camp == CAMP.Player && npcMgr.SelfSpring != null)
            {
                npcList.Add(npcMgr.SelfSpring);
            }
            else if (myHero.Camp == CAMP.Enemy && npcMgr.EnemySpring != null)
            {
                npcList.Add(npcMgr.EnemySpring);
            }

            //公共泉水
            if (npcMgr.NeutralSpring != null)
            {
                npcList.Add(npcMgr.NeutralSpring);
            }


            //所有道具
            List <ServerNPC> allProp = WarServerManager.Instance.npcMgr.GetNPCByType(LifeNPCType.Prop, CAMP.None);

            if (allProp != null && allProp.Count > 0)
            {
                npcList.AddRange(allProp.ToArray());
            }

            //得到距离自己最近的
            ServerNPC npcTarget = null;

            if (npcList.Count > 0)
            {
                float minDis = Mathf.Infinity;

                for (int i = 0; i < npcList.Count; i++)
                {
                    float distance = AITools.GetSqrDis(this.transform.position, npcList [i].transform.position);
                    if (distance < minDis)
                    {
                        minDis    = distance;
                        npcTarget = npcList [i];
                    }
                }
            }

            target.Value = npcTarget;
            mTrans       = myHero.transform;
            mTargetTrans = target.Value.transform;
        }
Exemplo n.º 11
0
    //得到在范围内距离自己最近的npc
    public static ServerNPC GetNearNPCInRange(Vector3 from, float range, ServerNPC[] npcs)
    {
        float     dis  = Mathf.Infinity;
        ServerNPC near = null;

        for (int i = 0; i < npcs.Length; i++)
        {
            if (IsInRange(from, range, npcs[i].transform))
            {
                float distance = GetSqrDis(from, npcs [i].transform.position);
                if (distance < dis * dis)
                {
                    dis  = distance;
                    near = npcs[i];
                }
            }
        }
        return(near);
    }
Exemplo n.º 12
0
        public override TaskStatus OnUpdate()
        {
            curGroup = freshGroupModel.GetFreshGroup(curPool.freshPool[curGroupIndex.Value]);

            if (curGroup != null)
            {
                npcCnt.count.Value = curGroup.freshGroup.Count;
            }
            else
            {
                //空的一波怪
                curIndex.Value = 0;
                curGroupIndex.Value++;
                curGroupCnt.Value++;

                //循环利用刷新池的数据
                if (curGroupIndex.Value >= curPool.freshPool.Count)
                {
                    curGroupIndex.Value = 0;
                }

                return(TaskStatus.Success);
            }
            if (curIndex.Value < curGroup.freshGroup.Count)
            {
                npcNum = curGroup.freshGroup [curIndex.Value];
            }


            ServerNPC newNpc = WarServerManager.Instance.npcMgr.GetNpcFromCache(npcNum);

            if (newNpc != null)
            {
                WarServerManager.Instance.npcMgr.RemoveNpcFromCache(newNpc);
            }
            else
            {
                newNpc = loader.Load(npcNum, myHero.dataInScene.camp, mWarPoint);
            }

            GameObject go = newNpc.gameObject;

            go.SetActive(true);
            go.transform.localPosition = this.transform.localPosition;
            newNpc.data.rtData.curHp   = newNpc.data.rtData.totalHp;
            newNpc.Camp            = myHero.dataInScene.camp;
            newNpc.data.btData.way = myHero.dataInScene.way;
            newNpc.dataInScene     = myHero.dataInScene;

            //发送消息通知客户端
            SendCreateNpcMsg(newNpc);
            SendHpMsg(newNpc);

            InitAi(newNpc);
            InitBuff(newNpc);

            if (newNpc is ServerLifeNpc)
            {
                ServerLifeNpc life = newNpc as ServerLifeNpc;
                life.SwitchAutoBattle(true);
            }

            //同一拨,当前造兵索引++
            curIndex.Value++;

            //同一拨,如果造了最后一个兵,当前造兵波数++
            if (curIndex.Value >= curGroup.freshGroup.Count)
            {
                curIndex.Value = 0;
                curGroupIndex.Value++;
                curGroupCnt.Value++;

                //循环利用刷新池的数据
                if (curGroupIndex.Value >= curPool.freshPool.Count)
                {
                    curGroupIndex.Value = 0;
                }

                return(TaskStatus.Success);
            }
            return(TaskStatus.Success);
        }
Exemplo n.º 13
0
        //初始化AI
        private void InitAi(ServerNPC npc)
        {
            //			//如果是npc刷新点
            if (npc.data.num == NpcMgr <BNPC> .FRESH_NPC)
            {
                                #if NO_SOLDIER
                                #else
                BehaviorTree tree = npc.gameObject.GetComponent <BehaviorTree> ();
                if (tree == null)
                {
                    tree = npc.gameObject.AddComponent <BehaviorTree>();
                }

                tree.ExternalBehavior    = AiLoader.load(AILoader.NPC_FRESH);
                tree.StartWhenEnabled    = true;
                tree.RestartWhenComplete = false;
                                #endif
            }
            else
            {
                NPCAIType     type = (NPCAIType)npc.dataInScene.AIType;
                ServerLifeNpc life = npc as ServerLifeNpc;
                switch (type)
                {
                case NPCAIType.Pathfind_Atk:
                {
                    BehaviorTree tree = npc.gameObject.GetComponent <BehaviorTree> ();
                    if (tree == null)
                    {
                        tree = npc.gameObject.AddComponent <BehaviorTree>();
                    }

                    tree.ExternalBehavior    = AiLoader.load(AILoader.PATHFIND_ATK);
                    tree.StartWhenEnabled    = true;
                    tree.RestartWhenComplete = true;

                    if (life != null && !life.pathFinding.enabled)
                    {
                        life.pathFinding.enabled = true;
                    }

                    if (!tree.enabled)
                    {
                        tree.enabled = true;
                    }
                    break;
                }

                case NPCAIType.Simple_PfAtk:
                {
                    BehaviorTree tree = npc.gameObject.GetComponent <BehaviorTree> ();
                    if (tree == null)
                    {
                        tree = npc.gameObject.AddComponent <BehaviorTree>();
                    }

                    tree.ExternalBehavior    = AiLoader.load(AILoader.SIMPLE_PFATK);
                    tree.StartWhenEnabled    = true;
                    tree.RestartWhenComplete = true;

                    if (life != null && !life.pathFinding.enabled)
                    {
                        life.pathFinding.enabled = true;
                    }

                    if (!tree.enabled)
                    {
                        tree.enabled = true;
                    }
                    break;
                }

                case NPCAIType.Patrol:
                {
                    BehaviorTree tree = npc.gameObject.GetComponent <BehaviorTree> ();
                    if (tree == null)
                    {
                        tree = npc.gameObject.AddComponent <BehaviorTree>();
                    }

                    tree.ExternalBehavior    = AiLoader.load(AILoader.NORMAL_ATTACK);
                    tree.StartWhenEnabled    = true;
                    tree.RestartWhenComplete = true;

                    if (life != null && !life.pathFinding.enabled)
                    {
                        life.pathFinding.enabled = true;
                    }

                    if (!tree.enabled)
                    {
                        tree.enabled = true;
                    }

                    break;
                }
                }
            }
        }
Exemplo n.º 14
0
        private Polygon Select(ServerNPC caster, EffectConfigData efCfg)
        {
            Transform trans = caster.transform;
            float     Y     = trans.localPosition.y;
            //角度转化为弧度
            float angel  = Mathf.Deg2Rad * efCfg.eParam2 * 0.5f;
            float radius = efCfg.eParam1;
            float X      = Mathf.Sin(angel) * radius;
            float Z      = Mathf.Cos(angel) * radius;

            //本地坐标
            UVec3[] localVecs = new UVec3[4];
            localVecs[0] = new UVec3()
            {
                x = 0F,
                y = Y,
                z = 0F,
            };

            localVecs[1] = new UVec3()
            {
                x = -X,
                y = Y,
                z = Z,
            };

            localVecs[2] = new UVec3()
            {
                x = 0,
                y = Y,
                z = radius,
            };

            localVecs[3] = new UVec3()
            {
                x = X,
                y = Y,
                z = Z,
            };

            //世界坐标
            UVec3[] worldVecs = new UVec3[4];
            worldVecs[0] = trans.TransformPoint(localVecs[0]);
            worldVecs[1] = trans.TransformPoint(localVecs[1]);
            worldVecs[2] = trans.TransformPoint(localVecs[2]);
            worldVecs[3] = trans.TransformPoint(localVecs[3]);


            //转换为2D坐标
            PointF[] Vecs = new PointF[4];
            Vecs[0] = new PointF()
            {
                X = worldVecs[0].x,
                Y = worldVecs[0].z
            };
            Vecs[1] = new PointF()
            {
                X = worldVecs[1].x,
                Y = worldVecs[1].z
            };
            Vecs[2] = new PointF()
            {
                X = worldVecs[2].x,
                Y = worldVecs[2].z
            };
            Vecs[3] = new PointF()
            {
                X = worldVecs[3].x,
                Y = worldVecs[3].z
            };

            Polygon polygon = new Polygon(Vecs);

            return(polygon);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Loads the bullet.
        /// </summary>
        /// <returns>The bullet.</returns>
        /// <param name="num">Number.</param>
        /// <param name="camp">Camp.</param>
        /// <param name="pos">Position.</param>
        /// <param name="rot">Rot.</param>
        public GameObject LoadNpcObj(int num, CAMP camp, Vector3 pos, Quaternion rot)
        {
            if (NpcModel == null)
            {
                NpcModel = Core.Data.getIModelConfig <NPCModel>();
            }

            NPCConfigData configData = NpcModel.get(num);

            #if DEBUG
            Utils.Assert(configData == null, "Virtual Npc load can't find npc configure. NPC id = " + num);
            #endif

            string path = SPath.Combine(ResourceSetting.PACKROOT, NPC);

            if (configData.healthpoint > 0)
            {
                path = SPath.Combine(path, "LifeSummonNpc");
            }
            else
            {
                path = SPath.Combine(path, "NoneLifeSummonNpc");
            }

            UObj obj = URes.Load(path);

            GameObject go = GameObject.Instantiate(obj) as GameObject;
            go.transform.position = pos;
            go.transform.rotation = rot;

            if (configData.moveable == Moveable.Movable)
            {
                Seeker seek = go.AddComponent <Seeker>();
                seek.drawGizmos = false;

                AIPath pathFinding = go.AddComponent <AIPath>();

                pathFinding.speed                = configData.speed;
                pathFinding.slowdownDistance     = 0.0f;
                pathFinding.pickNextWaypointDist = 2;
                pathFinding.forwardLook          = 1f;

                FunnelModifier modifer = go.AddComponent <FunnelModifier>();
                modifer.Priority = 2;

                CharacterController box = go.AddComponent <CharacterController>();

                box.radius = configData.radius;
                box.height = 2;

                if (box.radius >= box.height)
                {
                    box.center = Vector3.up * box.radius;
                }
                else
                {
                    box.center = Vector3.up * box.height / 2;
                }
            }
            else if (configData.radius > 0)
            {
                CapsuleCollider cap = go.AddComponent <CapsuleCollider>();
                cap.radius = configData.radius;
                cap.height = 2;

                if (cap.radius >= cap.height)
                {
                    cap.center = Vector3.up * cap.radius;
                }
                else
                {
                    cap.center = Vector3.up * cap.height / 2;
                }

                NavmeshCut cut = go.AddComponent <NavmeshCut>();
                cut.type         = NavmeshCut.MeshType.Circle;
                cut.circleRadius = configData.radius;
                cut.height       = 10;
                cut.center       = Vector3.up * 5;
            }

            ServerNPC npc = go.GetComponent <ServerNPC>();
            if (npc != null)
            {
                DynamicDataInit(npc, configData, camp);
            }

            return(go);
        }
Exemplo n.º 16
0
        public ServerNPC Load(int num, CAMP camp, GameObject WarPoint)
        {
            if (NpcModel == null)
            {
                NpcModel = Core.Data.getIModelConfig <NPCModel>();
            }

            NPCConfigData configData = NpcModel.get(num);

                        #if DEBUG
            Utils.Assert(configData == null, "Virtual Npc load can't find npc configure. NPC id = " + num);
                        #endif

            if (cached == null)
            {
                string path = SPath.Combine(ResourceSetting.PACKROOT, NPC);
                path   = SPath.Combine(path, VIRTUAL);
                cached = URes.Load(path);
            }

            GameObject go = GameObject.Instantiate(cached) as GameObject;
            UnityUtils.AddChild_Reverse(go, WarPoint);

            if (configData.type == LifeNPCType.Build)
            {
                go.layer = LayerMask.NameToLayer(Consts.LAYER_BUILD);
            }
            else
            {
                go.layer = LayerMask.NameToLayer(Consts.LAYER_NPC);
            }

            ServerNPC npc = null;
            if (configData.healthpoint > 0)
            {
                npc = go.AddComponent <ServerLifeNpc>();
            }
            else
            {
                npc = go.AddComponent <ServerNPC>();
            }

            //如果是可以移动的,添加寻路脚本
            if (configData.moveable == Moveable.Movable)
            {
                Seeker seek = go.AddComponent <Seeker>();
                seek.drawGizmos = false;

                AIPath pathFinding = go.AddComponent <AIPath>();

                pathFinding.speed                = configData.speed;
                pathFinding.slowdownDistance     = 0.0f;
                pathFinding.pickNextWaypointDist = 2;
                pathFinding.forwardLook          = 1f;

                FunnelModifier modifer = go.AddComponent <FunnelModifier>();
                modifer.Priority = 2;

                CharacterController box = go.AddComponent <CharacterController>();

                box.radius = configData.radius;
                box.height = 2;

                if (box.radius >= box.height)
                {
                    box.center = Vector3.up * box.radius;
                }
                else
                {
                    box.center = Vector3.up * box.height / 2;
                }
            }
            else if (configData.radius > 0)
            {
                CapsuleCollider cap = go.AddComponent <CapsuleCollider>();
                cap.radius = configData.radius;
                cap.height = 2;

                if (cap.radius >= cap.height)
                {
                    cap.center = Vector3.up * cap.radius;
                }
                else
                {
                    cap.center = Vector3.up * cap.height / 2;
                }

                NavmeshCut cut = go.AddComponent <NavmeshCut>();
                cut.type         = NavmeshCut.MeshType.Circle;
                cut.circleRadius = configData.radius;
                cut.height       = 10;
                cut.center       = Vector3.up * 5;
            }

            DynamicDataInit(npc, configData, camp);

            go.name = "NPC_" + configData.ID + "_" + npc.UniqueID;

            return(npc);
        }
Exemplo n.º 17
0
 public override void SetValue(object value)
 {
     mValue = (ServerNPC)value;
 }