コード例 #1
0
        public static void RemoveEntityToNetwork(KBEngine.KBNetworkView view)
        {
            var cg  = CGPlayerCmd.CreateBuilder();
            var ety = EntityInfo.CreateBuilder();

            ety.Id        = view.GetServerID();
            cg.EntityInfo = ety.Build();
            cg.Cmd        = "RemoveEntity";
            NetworkUtil.Broadcast(cg);
        }
コード例 #2
0
ファイル: DropItemStatic.cs プロジェクト: Xnovae/MobaClient
        private void PickByMe()
        {
            var whoAttr = ObjectManager.objectManager.GetMyAttr();
            var cg      = CGPlayerCmd.CreateBuilder();

            cg.Cmd = "Pick";
            var pickAction = PickItemAction.CreateBuilder();

            pickAction.Id      = netView.GetServerID();
            pickAction.ItemId  = itemData.ObjectId;
            pickAction.ItemNum = num;
            pickAction.Who     = whoAttr.GetComponent <KBEngine.KBNetworkView>().GetServerID();
            cg.PickAction      = pickAction.Build();
            NetworkUtil.Broadcast(cg);
        }
コード例 #3
0
 public static void  MakeDropItem(ItemData itemData, Vector3 pos, int num)
 {
     if (NetworkUtil.IsNetMaster())
     {
         var cg = CGPlayerCmd.CreateBuilder();
         cg.Cmd = "AddEntity";
         var etyInfo = EntityInfo.CreateBuilder();
         etyInfo.ItemId  = itemData.ObjectId;
         etyInfo.ItemNum = num;
         var po = NetworkUtil.ConvertPos(pos);
         etyInfo.X     = po [0];
         etyInfo.Y     = po [1];
         etyInfo.Z     = po [2];
         etyInfo.EType = EntityType.DROP;
         cg.EntityInfo = etyInfo.Build();
         NetworkUtil.Broadcast(cg);
     }
 }
コード例 #4
0
        IEnumerator PickItem(GameObject who)
        {
            PickItemFromNetwork(who);

            var cg = CGPlayerCmd.CreateBuilder();

            cg.Cmd = "Pick";
            var pickAction = PickItemAction.CreateBuilder();

            pickAction.Id      = netView.GetServerID();
            pickAction.ItemId  = itemData.ObjectId;
            pickAction.ItemNum = num;
            pickAction.Who     = who.GetComponent <KBEngine.KBNetworkView>().GetServerID();
            cg.PickAction      = pickAction.Build();
            NetworkUtil.Broadcast(cg);
            NetworkUtil.RemoveEntityToNetwork(netView);

            yield break;
        }
コード例 #5
0
        public void SyncToServer()
        {
            var me     = gameObject;
            var pos    = me.transform.position;
            var dir    = (int)me.transform.localRotation.eulerAngles.y;
            var meAttr = me.GetComponent <NpcAttribute>();
            var intPos = NetworkUtil.ConvertPos(pos);
            var ainfo  = EntityInfo.CreateBuilder();

            ainfo.Id = meAttr.GetNetView().GetServerID();
            var change = false;

            if (intPos [0] != lastInfo.X || intPos [1] != lastInfo.Y || intPos [2] != lastInfo.Z)
            {
                change  = true;
                ainfo.X = intPos [0];
                ainfo.Y = intPos [1];
                ainfo.Z = intPos [2];

                lastInfo.X = intPos [0];
                lastInfo.Y = intPos [1];
                lastInfo.Z = intPos [2];
            }
            if (meAttr.HP != lastInfo.HP)
            {
                change      = true;
                ainfo.HP    = meAttr.HP;
                lastInfo.HP = meAttr.HP;
            }
            if (change)
            {
                var etyInfo = ainfo.Build();
                var cg      = CGPlayerCmd.CreateBuilder();
                cg.Cmd        = "UpdateEntityData";
                cg.EntityInfo = etyInfo;
                NetworkUtil.Broadcast(cg);
            }
        }
コード例 #6
0
        public void SyncAttribute()
        {
            var me     = gameObject;
            var pos    = me.transform.position;
            var dir    = (int)me.transform.localRotation.eulerAngles.y;
            var meAttr = me.GetComponent <NpcAttribute>();
            var intPos = NetworkUtil.ConvertPos(pos);

            var ainfo  = AvatarInfo.CreateBuilder();
            var change = false;

            //Pos 和 Dir 同时同步
            if (intPos [0] != lastInfo.X || intPos [1] != lastInfo.Y || intPos [2] != lastInfo.Z || dir != lastInfo.Dir)
            {
                ainfo.X = intPos [0];
                ainfo.Y = intPos [1];
                ainfo.Z = intPos [2];

                curInfo.X = ainfo.X;
                curInfo.Y = ainfo.Y;
                curInfo.Z = ainfo.Z;

                ainfo.Dir   = dir;
                curInfo.Dir = dir;
                change      = true;
            }

            if (meAttr.HP != lastInfo.HP)
            {
                ainfo.HP   = meAttr.HP;
                curInfo.HP = meAttr.HP;
                change     = true;
            }
            var intNetSpeed = (int)(meAttr.NetSpeed * 100);

            if (intNetSpeed != lastInfo.NetSpeed)
            {
                ainfo.NetSpeed   = intNetSpeed;
                curInfo.NetSpeed = intNetSpeed;
                change           = true;
            }
            var intThrowSpeed = (int)(meAttr.ThrowSpeed * 100);

            if (intThrowSpeed != lastInfo.ThrowSpeed)
            {
                ainfo.ThrowSpeed   = intThrowSpeed;
                curInfo.ThrowSpeed = intThrowSpeed;
                change             = true;
            }
            var intJumpSpeed = (int)(meAttr.JumpForwardSpeed * 100);

            if (intJumpSpeed != lastInfo.JumpForwardSpeed)
            {
                ainfo.JumpForwardSpeed   = intJumpSpeed;
                curInfo.JumpForwardSpeed = intJumpSpeed;
                change = true;
            }

            if (meAttr.userName != lastInfo.Name)
            {
                ainfo.Name   = meAttr.userName;
                curInfo.Name = meAttr.userName;
                change       = true;
            }

            if (lastInfo.Job != ServerData.Instance.playerInfo.Roles.Job)
            {
                ainfo.Job   = ServerData.Instance.playerInfo.Roles.Job;
                curInfo.Job = ainfo.Job;
                change      = true;
            }

            if (change)
            {
                lastInfo = AvatarInfo.CreateBuilder(curInfo).Build();

                var cg = CGPlayerCmd.CreateBuilder();
                cg.Cmd        = "UpdateData";
                cg.AvatarInfo = ainfo.Build();
                NetworkUtil.Broadcast(cg);
            }
        }