Beispiel #1
0
        /// <summary>
        /// 服务器还需要同步Speed用于表示Entity是否移动的一个状态
        /// </summary>
        /// <returns></returns>
        public override Vector3 GetServerPos()
        {
            if (positions.Count > 0)
            {
                var p1       = positions[positions.Count - 1];
                var passTime = NetworkScene.Instance.GetPredictPassServerTime(p1.FrameID);
                var speed    = NetworkUtil.FloatPos(p1.SpeedX, 0, p1.SpeedY);
                if (passTime > 0)
                {
                    return(MobaUtil.FloatPos(p1) + speed * (passTime + Util.FrameSecTime));
                }
                else
                {
                    return(MobaUtil.FloatPos(p1) + speed * Util.FrameSecTime);
                }
            }
            else
            {
                return(MobaUtil.FloatPos(curInfo));
            }

            /*
             * var passTime = NetworkScene.Instance.GetPredictPassServerTime(curInfo.FrameID);
             * //客户端跑的比服务器快 外插值
             * if (passTime > 0)
             * {
             *  var c = positions.Count;
             *  if (c >= 2)
             *  {
             *      var p1 = positions[c - 1];
             *      var p0 = positions[c - 2];
             *      var deltaFrame = p1.FrameID - p0.FrameID;
             *      //速度没有归0
             *      if (deltaFrame > 0)
             *      {
             *          var tm = MobaUtil.DeltaFrameToTime(deltaFrame);
             *          var sp = MobaUtil.DeltaPos(p1, p0);
             *          var speed = MobaUtil.Speed(sp, tm);
             *
             *          //var speed = new Vector3(curInfo.SpeedX, 0, curInfo.SpeedY);
             *          speed = Util.NetToGameVec(speed);
             *          var extraPos = passTime * speed;
             *          return MobaUtil.FloatPos(curInfo) + extraPos;
             *      }else
             *      {
             *          return MobaUtil.FloatPos(curInfo);
             *      }
             *  }else
             *  {
             *      return MobaUtil.FloatPos(curInfo);
             *  }
             * }else
             * {
             *  return MobaUtil.FloatPos(curInfo);
             * }
             */
        }
Beispiel #2
0
        //迭代加权平滑 弹簧 物理运动平滑手段
        private Vector3 GetInfoPredictPos(AvatarInfo p1)
        {
            var passTime = NetworkScene.Instance.GetPredictPassServerTime(p1.FrameID);
            var speed    = NetworkUtil.FloatPos(p1.SpeedX, 0, p1.SpeedY);

            if (passTime > 0)
            {
                return(MobaUtil.FloatPos(p1) + speed * (passTime + Util.FrameSecTime));
            }
            else
            {
                return(MobaUtil.FloatPos(p1) + speed * Util.FrameSecTime);
            }
        }
Beispiel #3
0
        /// <summary>
        /// 其它玩家复活立即切换状态,重置HP
        /// 设置RebornShader
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        public IEnumerator NetworkRevive(GCPlayerCmd cmd)
        {
            var ainfo = cmd.AvatarInfo;

            Log.Sys("Revive");
            var np = NetworkUtil.FloatPos(ainfo.X, ainfo.Y, ainfo.Z);

            Util.ForceResetPos(this.GetComponent <Rigidbody>(), np);
            var nr = Quaternion.Euler(new Vector3(0, ainfo.Dir, 0));

            this.GetComponent <Rigidbody>().MoveRotation(nr);
            SetHPNet(HP_Max);
            ReviveAI();
            //StartCoroutine(SetRebornShader());
            yield return(null);
        }
Beispiel #4
0
        /// <summary>
        /// 怪物统一使用 Rigidbody 控制
        /// 子弹型刚体
        /// </summary>
        private void SendMoveCmd()
        {
            if (!curInfo.HasX)
            {
                return;
            }
            var dir       = (int)transform.localRotation.eulerAngles.y;
            var meAttr    = gameObject.GetComponent <NpcAttribute>();
            var serverPos = NetworkUtil.FloatPos(curInfo.X, curInfo.Y, curInfo.Z);
            var cmd       = new MoveCMD();

            cmd.targetPos = serverPos;
            cmd.dir       = curInfo.Dir;
            //cmd.speed = Util.NetToGameNum(curInfo.Speed);
            GetComponent <LogicCommand>().PushCommand(cmd);
        }
Beispiel #5
0
        public static void DoNetworkAttack(GameObject gameObject, GCPlayerCmd proto)
        {
            var sk  = proto.SkillAction;
            var cmd = new SkillCMD();

            cmd.skillId     = sk.SkillId;
            cmd.skillLevel  = sk.SkillLevel;
            cmd.staticShoot = sk.IsStaticShoot;
            cmd.targetPos   = NetworkUtil.FloatPos(sk.X, sk.Y, sk.Z);
            cmd.dir         = sk.Dir;
            cmd.skillAction = sk;
            cmd.runFrame    = sk.RunFrame;
            cmd.proto       = proto;

            Log.GUI("Other Player Attack LogicCommand");
            gameObject.GetComponent <LogicCommand>().PushCommand(cmd);
        }
Beispiel #6
0
 private void NetworkMove(EntityInfo info)
 {
     if (aibase == null)
     {
         aibase = gameObject.GetComponent <AIBase>();
     }
     if (aibase != null)
     {
         var aiState = aibase.GetAI().state;
         if (aiState != null && aiState.type == AIStateEnum.IDLE)
         {
             var curPos = transform.position;
             var tarPos = NetworkUtil.FloatPos(info.X, info.Y, info.Z);
             var vdir   = tarPos - curPos;
             if (vdir.sqrMagnitude >= 2)
             {
                 transform.position = tarPos;
             }
         }
     }
 }
Beispiel #7
0
 public static Vector3 FloatPos(AvatarInfo curInfo)
 {
     return(NetworkUtil.FloatPos(curInfo.X, curInfo.Y, curInfo.Z));
 }
Beispiel #8
0
        void MsgHandler(KBEngine.Packet packet)
        {
            var proto = packet.protoBody as GCPlayerCmd;

            Log.Net("Map4Receive: " + proto);
            var cmds = proto.Result.Split(' ');

            if (cmds [0] == "Login")
            {
                myId = Convert.ToInt32(cmds [1]);
                ObjectManager.objectManager.RefreshMyServerId(myId);
            }
            else if (cmds [0] == "Add")
            {
                ObjectManager.objectManager.CreateOtherPlayer(proto.AvatarInfo);
                PlayerDataInterface.DressEquip(proto.AvatarInfo);
                var player = ObjectManager.objectManager.GetPlayer(proto.AvatarInfo.Id);
                if (player != null)
                {
                    var sync = player.GetComponent <PlayerSync>();
                    if (sync != null)
                    {
                        sync.NetworkMove(proto.AvatarInfo);
                    }
                    else
                    {
                        var sync2 = player.GetComponent <MySelfAttributeSync>();
                        sync2.NetworkAttribute(proto.AvatarInfo);
                    }
                }
            }
            else if (cmds [0] == "Remove")
            {
                ObjectManager.objectManager.DestroyPlayer(proto.AvatarInfo.Id);
            }
            else if (cmds [0] == "Update")
            {
                var player = ObjectManager.objectManager.GetPlayer(proto.AvatarInfo.Id);
                if (player != null)
                {
                    var sync = player.GetComponent <PlayerSync>();
                    if (sync != null)
                    {
                        sync.NetworkMove(proto.AvatarInfo);
                    }
                    else
                    {
                        var myselfAttr = player.GetComponent <MySelfAttributeSync>();
                        if (myselfAttr != null)
                        {
                            myselfAttr.NetworkAttribute(proto.AvatarInfo);
                        }
                    }
                }
            }
            else if (cmds [0] == "Damage")
            {
                var dinfo = proto.DamageInfo;
                var enemy = ObjectManager.objectManager.GetPlayer(dinfo.Enemy);
                if (enemy != null)
                {
                    var sync = enemy.GetComponent <PlayerSync>();
                    if (sync != null)
                    {
                        sync.DoNetworkDamage(proto);
                    }
                }
                if (!NetworkUtil.IsMaster() && enemy != null)
                {
                    var sync = enemy.GetComponent <MonsterSync>();
                    if (sync != null)
                    {
                        sync.DoNetworkDamage(proto);
                    }
                }
            }
            else if (cmds [0] == "Skill")
            {
                var sk     = proto.SkillAction;
                var player = ObjectManager.objectManager.GetPlayer(sk.Who);
                if (player != null)
                {
                    var sync = player.GetComponent <PlayerSync>();
                    if (sync != null)
                    {
                        sync.NetworkAttack(sk);
                    }
                }
            }
            else if (cmds [0] == "Buff")
            {
                var target = proto.BuffInfo.Target;
                var sync   = NetDateInterface.GetPlayer(target);
                var player = ObjectManager.objectManager.GetPlayer(target);
                if (sync != null)
                {
                    sync.NetworkBuff(proto);
                }
                if (player != null && !NetworkUtil.IsNetMaster())
                {
                    var monSync = player.GetComponent <MonsterSync>();
                    if (monSync != null)
                    {
                        monSync.NetworkBuff(proto);
                    }
                }
            }
            else if (cmds [0] == "AddEntity")
            {
                var ety = proto.EntityInfo;
                if (ety.EType == EntityType.CHEST)
                {
                    StartCoroutine(WaitZoneInit(ety));
                }
                else if (ety.EType == EntityType.DROP)
                {
                    var itemData = Util.GetItemData((int)ItemData.GoodsType.Props, (int)ety.ItemId);
                    var itemNum  = ety.ItemNum;
                    var pos      = NetworkUtil.FloatPos(ety.X, ety.Y, ety.Z);
                    DropItemStatic.MakeDropItemFromNet(itemData, pos, itemNum, ety);
                }
            }
            else if (cmds [0] == "UpdateEntity")
            {
                var ety = proto.EntityInfo;
                var mon = ObjectManager.objectManager.GetPlayer(ety.Id);
                Log.Net("UpdateEntityHP: " + ety.Id + " hp " + ety.HasHP + " h " + ety.HP);
                if (!NetworkUtil.IsMaster() && mon != null)
                {
                    var sync = mon.GetComponent <MonsterSync>();
                    if (sync != null)
                    {
                        sync.SyncAttribute(proto);
                    }
                }
            }
            else if (cmds [0] == "RemoveEntity")
            {
                var ety = proto.EntityInfo;
                var mon = ObjectManager.objectManager.GetPlayer(ety.Id);
                if (!NetworkUtil.IsMaster() && mon != null)
                {
                    var netView = mon.GetComponent <KBEngine.KBNetworkView>();
                    if (netView != null)
                    {
                        ObjectManager.objectManager.DestroyByLocalId(netView.GetLocalId());
                    }
                }
            }
            else if (cmds [0] == "Pick")
            {
                if (!NetworkUtil.IsMaster())
                {
                    var action = proto.PickAction;
                    var ety    = ObjectManager.objectManager.GetPlayer(action.Id);
                    var who    = ObjectManager.objectManager.GetPlayer(action.Who);
                    if (ety != null)
                    {
                        var item = ety.GetComponent <DropItemStatic>();
                        if (item != null)
                        {
                            item.PickItemFromNetwork(who);
                        }
                    }
                }
            }
            else if (cmds [0] == "Revive")
            {
                var player = ObjectManager.objectManager.GetPlayer(proto.AvatarInfo.Id);
                if (player != null)
                {
                    var sync = player.GetComponent <PlayerSync>();
                    if (sync != null)
                    {
                        sync.Revive();
                    }
                }
            }
            else if (cmds [0] == "Dead")
            {
                var dinfo = proto.DamageInfo;
                ScoreManager.Instance.NetAddScore(dinfo.Attacker, dinfo.Enemy);
            }
            else if (cmds [0] == "SyncTime")
            {
                if (!NetworkUtil.IsNetMaster())
                {
                    ScoreManager.Instance.NetSyncTime(proto.LeftTime);
                }
            }
            else if (cmds [0] == "GameOver")
            {
                if (!NetworkUtil.IsNetMaster())
                {
                    ScoreManager.Instance.NetworkGameOver();
                }
            }
            else if (cmds [0] == "AllReady")
            {
                Util.ShowMsg("所有客户端准备完成");
                //当所有客户端准备好之后 服务器推送Entity给所有客户端
                NetMatchScene.Instance.SetAllReady();

                //更新IsMaster 这样才能生成Entity
                var player     = ObjectManager.objectManager.GetMyPlayer();
                var myselfAttr = player.GetComponent <MySelfAttributeSync>();
                var matchRoom  = NetMatchScene.Instance.GetComponent <MatchRoom>();
                if (myselfAttr != null)
                {
                    myselfAttr.NetworkAttribute(matchRoom.GetMyInfo());
                }
            }
        }
Beispiel #9
0
        /*
         * public void CreateNpc(UnitData unitData, GameObject spawn)
         * {
         *  if (WorldManager.worldManager.station == WorldManager.WorldStation.Enter)
         *  {
         *      var Resource = Resources.Load<GameObject>(unitData.ModelName);
         *      GameObject g = Instantiate(Resource) as GameObject;
         *      if (g.GetComponent<CharacterController>() == null)
         *      {
         *          var c = g.AddComponent<CharacterController>();
         *          c.center = new Vector3(0, 0.7f, 0);
         *          c.height = 1.6f;
         *      }
         *
         *      NpcAttribute npc = NGUITools.AddMissingComponent<NpcAttribute>(g);
         *
         *      var type = Type.GetType("MyLib." + unitData.AITemplate);
         *      var t = typeof(NGUITools);
         *      var m = t.GetMethod("AddMissingComponent");
         *      Log.AI("Monster Create Certain AI  " + unitData.AITemplate + " " + type);
         *      var geMethod = m.MakeGenericMethod(type);
         *      geMethod.Invoke(null, new object[]{ g });// as AIBase;
         *
         *      g.transform.parent = transform;
         *      g.tag = GameTag.Npc; //Player Or Npc
         *      g.layer = (int)GameLayer.IgnoreCollision;
         *
         *      //Register Unique Id To Npc
         *      var netView = g.GetComponent<KBEngine.KBNetworkView>();
         *      netView.SetServerID(Util.NotInitServerID);
         *      netView.IsPlayer = false;
         *
         *      npc.SetObjUnitData(unitData);
         *      AddObject(netView.GetServerID(), netView);
         *
         *      npc.transform.position = spawn.transform.position;
         *      var rotY = spawn.transform.localRotation.eulerAngles.y;
         *      npc.transform.localRotation = Quaternion.Euler(new Vector3(0, rotY, 0));
         *
         *      NpcManager.Instance.RegNpc(unitData.name, g);
         *  } else
         *  {
         *      cacheNpc.Add(new MonsterInit(unitData, spawn));
         *  }
         * }
         */

        /// <summary>
        /// 伤害区域
        /// Moba中的移动小兵
        /// </summary>
        /// <param name="unitData"></param>
        /// <param name="spawn"></param>
        /// <param name="info"></param>
        public void CreateSpawnZoneEntity(UnitData unitData, SpawnZone spawn, EntityInfo info)
        {
            Log.Sys("CreateSpawnZoneEntity: " + unitData + spawn + " info " + info);
            //TODO: 这里可能有BUG
            if (info != null)
            {
                var oldMon = ObjectManager.objectManager.GetPlayer(info.Id);
                if (oldMon != null)
                {
                    var nv = oldMon.GetComponent <KBEngine.KBNetworkView>();
                    if (nv != null)
                    {
                        ObjectManager.objectManager.DestroyByLocalId(nv.GetLocalId());
                    }
                }
            }

            var          Resource = Resources.Load <GameObject>(unitData.ModelName);
            GameObject   g        = Instantiate(Resource) as GameObject;
            NpcAttribute npc      = NGUITools.AddMissingComponent <NpcAttribute>(g);

            //npc.spawnTrigger = spawn.gameObject;

            g.transform.parent = transform;
            g.tag   = GameTag.Enemy;
            g.layer = (int)GameLayer.Npc;
            if (info != null)
            {
                g.name += "_" + info.Id;
            }

            var type = Type.GetType("MyLib." + unitData.AITemplate);
            var t    = typeof(NGUITools);
            var m    = t.GetMethod("AddMissingComponent");

            Log.AI("Monster Create Certain AI  " + unitData.AITemplate + " " + type);
            var geMethod = m.MakeGenericMethod(type);

            geMethod.Invoke(null, new object[] { g });// as AIBase;


            var netView = g.GetComponent <KBEngine.KBNetworkView>();

            //服务器返回的ViewId
            //Owner 客户端怪物 服务器怪物
            //Id ViewId
            if (info != null)
            {
                netView.SetServerID(info.Id);
            }
            else
            {
                netView.SetServerID(Util.NotInitServerID);
            }

            netView.IsPlayer = false;

            npc.SetObjUnitData(unitData);
            AddObject(netView.GetServerID(), netView);

            //不算怪物允许不去打
            if (info != null)
            {
                npc.transform.position = NetworkUtil.FloatPos(info.X, info.Y, info.Z);
            }
            else
            {
                //npc.transform.position = spawn.transform.position;
            }

            //BattleManager.battleManager.AddEnemy(npc.gameObject);
            //npc.SetDeadDelegate = BattleManager.battleManager.EnemyDead;

            var sync = npc.GetComponent <MonsterSync>();

            if (sync != null)
            {
                sync.SyncAttribute(info);
            }
        }
Beispiel #10
0
        public void MsgHandler(KBEngine.Packet packet)
        {
            var proto = packet.protoBody as GCPlayerCmd;

            Log.Net("Map4Receive: " + proto);
            var cmds = proto.Result.Split(' ');
            var cmd0 = cmds[0];

            if (cmds [0] == "Add")
            {
                ObjectManager.objectManager.CreateOtherPlayer(proto.AvatarInfo);
                //PlayerDataInterface.DressEquip(proto.AvatarInfo);
                var player = ObjectManager.objectManager.GetPlayer(proto.AvatarInfo.Id);
                if (player != null)
                {
                    var sync = player.GetComponent <ISyncInterface>();

                    if (!proto.AvatarInfo.HasScore)
                    {
                        proto.AvatarInfo.Score = 0;
                    }
                    if (sync != null)
                    {
                        var ainfo = NetMatchScene.Instance.matchRoom.GetPlayerInfo(proto.AvatarInfo.Id);
                        sync.InitSync(ainfo);
                        sync.NetworkAttribute(proto);
                    }
                }
            }
            else if (cmds [0] == "Remove")
            {
                ObjectManager.objectManager.DestroyPlayer(proto.AvatarInfo.Id);
            }
            else if (cmds [0] == "Update")
            {
                var player = ObjectManager.objectManager.GetPlayer(proto.AvatarInfo.Id);
                if (player != null)
                {
                    var sync = player.GetComponent <ISyncInterface>();
                    if (sync != null)
                    {
                        sync.NetworkAttribute(proto);
                    }
                }
            }
            else if (cmds [0] == "Damage")
            {
                var dinfo = proto.DamageInfo;
                var enemy = ObjectManager.objectManager.GetPlayer(dinfo.Enemy);
                if (enemy != null)
                {
                    var sync = enemy.GetComponent <ISyncInterface>();
                    if (sync != null)
                    {
                        sync.DoNetworkDamage(proto);
                    }
                }
            }
            else if (cmds [0] == "Skill")
            {
                var sk     = proto.SkillAction;
                var player = ObjectManager.objectManager.GetPlayer(sk.Who);
                if (player != null)
                {
                    var sync = player.GetComponent <ISyncInterface>();
                    if (sync != null)
                    {
                        sync.NetworkAttack(proto);
                    }
                }
            }
            else if (cmds [0] == "Buff")
            {
                var target = proto.BuffInfo.Target;
                var player = ObjectManager.objectManager.GetPlayer(target);
                if (player != null)
                {
                    var sync = player.GetComponent <ISyncInterface>();
                    if (sync != null)
                    {
                        sync.NetworkBuff(proto);
                    }
                }

                /*
                 * var target = proto.BuffInfo.Target;
                 * var sync = NetDateInterface.GetPlayer(target);
                 * var player = ObjectManager.objectManager.GetPlayer(target);
                 * if (sync != null)
                 * {
                 *  sync.NetworkBuff(proto);
                 * }
                 * else if(player != null)
                 * {
                 *  var sync2 = player.GetComponent<MySelfAttributeSync>();
                 *  if (sync2 != null)
                 *  {
                 *      sync2.NetworkBuff(proto);
                 *  }
                 * }
                 * if (player != null && !NetworkUtil.IsNetMaster())
                 * {
                 *  var monSync = player.GetComponent<MonsterSync>();
                 *  if (monSync != null)
                 *  {
                 *      monSync.NetworkBuff(proto);
                 *  }
                 * }
                 */
            }
            else if (cmds[0] == "RemoveBuff")
            {
                var target = proto.BuffInfo.Target;
                var player = ObjectManager.objectManager.GetPlayer(target);
                if (player != null)
                {
                    var sync = player.GetComponent <ISyncInterface>();
                    if (sync != null)
                    {
                        sync.NetworkRemoveBuff(proto);
                    }
                }
            }
            else if (cmds [0] == "AddEntity")
            {
                var ety = proto.EntityInfo;
                if (ety.EType == EntityType.CHEST)
                {
                    WaitZoneInit(ety);
                }
                else if (ety.EType == EntityType.DROP)
                {
                    var itemData = Util.GetItemData((int)ItemData.GoodsType.Props, (int)ety.ItemId);
                    var itemNum  = ety.ItemNum;
                    var pos      = NetworkUtil.FloatPos(ety.X, ety.Y, ety.Z);
                    DropItemStatic.MakeDropItemFromNet(itemData, pos, itemNum, ety);
                }
            }
            else if (cmds [0] == "UpdateEntity")
            {
                var ety = proto.EntityInfo;
                var mon = ObjectManager.objectManager.GetPlayer(ety.Id);
                Log.Net("UpdateEntityHP: " + ety.Id + " hp " + ety.HasHP + " h " + ety.HP + ":" + ety + ":" + mon);
                //if (!NetworkUtil.IsMaster() && mon != null)
                if (mon != null)
                {
                    var sync = mon.GetComponent <MonsterSync>();
                    if (sync != null)
                    {
                        sync.NetworkAttribute(proto);
                    }
                }
            }
            else if (cmds [0] == "RemoveEntity")
            {
                var ety = proto.EntityInfo;
                var mon = ObjectManager.objectManager.GetPlayer(ety.Id);
                //if (!NetworkUtil.IsMaster() && mon != null)
                if (mon != null)
                {
                    var netView = mon.GetComponent <KBEngine.KBNetworkView>();
                    if (netView != null)
                    {
                        ObjectManager.objectManager.DestroyByLocalId(netView.GetLocalId());
                    }
                }
            }
            else if (cmds [0] == "Pick")
            {
                //if (!NetworkUtil.IsMaster())
                {
                    var action = proto.PickAction;
                    var ety    = ObjectManager.objectManager.GetPlayer(action.Id);
                    var who    = ObjectManager.objectManager.GetPlayer(action.Who);
                    if (ety != null)
                    {
                        var item = ety.GetComponent <DropItemStatic>();
                        if (item != null)
                        {
                            item.PickItemFromNetwork(who);
                        }
                    }
                }
            }
            else if (cmds [0] == "Revive")
            {
                var player = ObjectManager.objectManager.GetPlayer(proto.AvatarInfo.Id);
                if (player != null)
                {
                    var sync = player.GetComponent <ISyncInterface>();
                    if (sync != null)
                    {
                        sync.Revive(proto);
                    }
                }
            }
            else if (cmd0 == "DeadActor")
            {
                var player = ObjectManager.objectManager.GetPlayer(proto.ActorId);
                if (player != null)
                {
                    var sync = player.GetComponent <ISyncInterface>();
                    if (sync != null)
                    {
                        sync.Dead(proto);
                    }
                }
            }
            else if (cmds [0] == "Dead")
            {
                //ScoreManager.Instance.NetAddScore(dinfo.Attacker, dinfo.Enemy);
                ScoreManager.Instance.Dead(proto);
            }
            else if (cmds [0] == "SyncTime")
            {
                //if (!NetworkUtil.IsNetMaster())
                ScoreManager.Instance.NetSyncTime(proto.LeftTime);
            }
            else if (cmds [0] == "GameOver")
            {
                //if (!NetworkUtil.IsNetMaster())
                {
                    ScoreManager.Instance.NetworkGameOver();
                }
            }
            else if (cmds [0] == "AllReady")
            {
                Util.ShowMsg("所有客户端准备完成");
                //当所有客户端准备好之后 服务器推送Entity给所有客户端
                NetMatchScene.Instance.SetAllReady();
            }
            else if (cmds[0] == "News")
            {
                var con = proto.News;
                Util.ShowMsg(con);
            }
            else if (cmds[0] == "UDPLost")
            {
                Util.ShowMsg("Server Side UDPLost!");
                UDPLost();
            }
            else if (cmd0 == "SyncFrame")
            {
                SyncFrame(proto);
            }
        }
Beispiel #11
0
        public void CreateChestFromNetwork(UnitData unitData, SpawnChest spawn, EntityInfo info = null)
        {
            Log.Sys("Create Chest Unit " + unitData.name);
            var          Resource = Resources.Load <GameObject>(unitData.ModelName);
            GameObject   g        = Instantiate(Resource) as GameObject;
            NpcAttribute npc      = NGUITools.AddMissingComponent <NpcAttribute>(g);

            npc.spawnTrigger = spawn.gameObject;

            g.transform.parent = transform;
            g.tag   = GameTag.Enemy;
            g.layer = (int)GameLayer.Npc;

            var type = Type.GetType("MyLib." + unitData.AITemplate);
            var t    = typeof(NGUITools);
            var m    = t.GetMethod("AddMissingComponent");

            Log.AI("Monster Create Certain AI  " + unitData.AITemplate + " " + type);
            var geMethod = m.MakeGenericMethod(type);

            geMethod.Invoke(null, new object[] { g });// as AIBase;


            var netView = g.GetComponent <KBEngine.KBNetworkView>();

            //服务器返回的ViewId
            //Owner 客户端怪物 服务器怪物
            //Id ViewId
            if (info != null)
            {
                netView.SetID(new KBEngine.KBViewID(info.Id, myPlayer));
            }
            else
            {
                netView.SetID(new KBEngine.KBViewID(-1, myPlayer));
            }

            netView.IsPlayer = false;

            npc.SetObjUnitData(unitData);
            AddObject(netView.GetServerID(), netView);

            //不算怪物允许不去打
            if (info != null)
            {
                npc.transform.position = NetworkUtil.FloatPos(info.X, info.Y, info.Z);
            }
            else
            {
                npc.transform.position = spawn.transform.position;
            }


            BattleManager.battleManager.AddEnemy(npc.gameObject);
            npc.SetDeadDelegate = BattleManager.battleManager.EnemyDead;


            var sync = npc.GetComponent <MonsterSync>();

            if (sync != null)
            {
                sync.SyncAttribute(info);
            }
        }