예제 #1
0
        public static void FastAddBuff(Affix affix, GameObject attacker, GameObject target, int skillId, int evtId, Vector3 pos)
        {
            var cg    = CGPlayerCmd.CreateBuilder();
            var binfo = BuffInfo.CreateBuilder();

            binfo.BuffType = (int)affix.effectType;
            binfo.Attacker = attacker.GetComponent <KBEngine.KBNetworkView>().GetServerID();
            binfo.Target   = target.GetComponent <KBEngine.KBNetworkView>().GetServerID();
            binfo.SkillId  = skillId;
            binfo.EventId  = evtId;
            //var pos = attacker.transform.position;
            binfo.AddAttackerPos((int)(pos.x * 100));
            binfo.AddAttackerPos((int)(pos.y * 100));
            binfo.AddAttackerPos((int)(pos.z * 100));

            cg.BuffInfo = binfo.Build();
            cg.Cmd      = "Buff";
            var sc = WorldManager.worldManager.GetActive();

            sc.BroadcastMsg(cg);
        }
예제 #2
0
        /// <summary>
        /// 通知服务器选择的英雄
        /// </summary>
        /// <returns></returns>
        private IEnumerator ChooseHeroCor(int hid)
        {
            if (roomState == RoomState.SelectHero)
            {
                roomState = RoomState.TryEnter;
                var cg  = CGPlayerCmd.CreateBuilder();
                var lev = UserInfo.UserLevel;
                cg.Cmd = "ChooseHero";
                var avtar = AvatarInfo.CreateBuilder();
                avtar.PlayerModelInGame = hid;
                cg.AvatarInfo           = avtar.Build();

                Bundle bundle;
                var    data = KBEngine.Bundle.GetPacketFull(cg, out bundle);
                yield return(StartCoroutine(rc.SendWaitResponse(data.data, data.fid, (packet) =>
                {
                    //var cmd = packet.protoBody as GCPlayerCmd;
                    //roomInfo = cmd.RoomInfo;
                    Util.ShowMsg("选择英雄:");
                }, bundle)));
            }
        }
예제 #3
0
        /// <summary>
        ///相同的技能 Skill Configure来触发Buff 但是不要触发 Buff修改非表现属性
        /// </summary>
        /// <param name="affix">Affix.</param>
        /// <param name="attacker">Attacker.</param>
        /// <param name="target">Target.</param>
        public static void FastAddBuff(Affix affix, GameObject attacker, GameObject target, int skillId, int evtId)
        {
            var cg    = CGPlayerCmd.CreateBuilder();
            var binfo = BuffInfo.CreateBuilder();

            binfo.BuffType = (int)affix.effectType;
            binfo.Attacker = attacker.GetComponent <KBEngine.KBNetworkView>().GetServerID();
            binfo.Target   = target.GetComponent <KBEngine.KBNetworkView>().GetServerID();
            binfo.SkillId  = skillId;
            binfo.EventId  = evtId;
            var pos = attacker.transform.position;

            binfo.AddAttackerPos((int)(pos.x * 100));
            binfo.AddAttackerPos((int)(pos.y * 100));
            binfo.AddAttackerPos((int)(pos.z * 100));

            var pos1 = NetworkUtil.ConvertPos(target.transform.position);

            binfo.X   = pos1[0];
            binfo.Y   = pos1[1];
            binfo.Z   = pos1[2];
            binfo.Dir = (int)target.transform.eulerAngles.y;

            var eft  = BuffManager.buffManager.GetBuffInstance(affix.effectType);
            var buff = (IEffect)Activator.CreateInstance(eft);

            buff.attacker = attacker;
            buff.target   = target;
            var param = buff.GetExtraParams();

            binfo.Params = param;

            cg.BuffInfo = binfo.Build();
            cg.Cmd      = "Buff";
            var sc = WorldManager.worldManager.GetActive();

            sc.BroadcastMsg(cg);
        }
예제 #4
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);
            }
        }
예제 #5
0
        IEnumerator InitData()
        {
            Debug.LogError("InitData");
            if (rc == null)
            {
                yield break;
            }
            var cg = CGPlayerCmd.CreateBuilder();

            cg.Cmd = "Login";
            var data = KBEngine.Bundle.GetPacketFull(cg);

            yield return(StartCoroutine(rc.SendWaitResponse(data.data, data.fid, (packet) =>
            {
                var proto = packet.protoBody as GCPlayerCmd;
                var cmds = proto.Result.Split(' ');
                myId = System.Convert.ToInt32(cmds [1]);
                ObjectManager.objectManager.RefreshMyServerId(myId);
            })));

            Log.Net("SendLogin: " + myId);
            SendUserData();
        }
예제 #6
0
 /// <summary>
 /// Master 退出场景所有的Entities都销毁掉简单处理
 /// </summary>
 /// <param name="unitData">Unit data.</param>
 /// <param name="spawn">Spawn.</param>
 public void CreateChest(UnitData unitData, SpawnChest spawn)
 {
     if (NetworkUtil.IsNetMaster())
     {
         var cg = CGPlayerCmd.CreateBuilder();
         cg.Cmd = "AddEntity";
         var entityInfo = EntityInfo.CreateBuilder();
         entityInfo.UnitId = unitData.ID;
         var ip = NetworkUtil.ConvertPos(spawn.transform.position);
         entityInfo.X       = ip [0];
         entityInfo.Y       = ip [1];
         entityInfo.Z       = ip [2];
         entityInfo.SpawnId = spawn.SpawnId;
         entityInfo.HP      = unitData.HP;
         cg.EntityInfo      = entityInfo.Build();
         var scene = WorldManager.worldManager.GetActive();
         scene.BroadcastMsg(cg);
     }
     else
     {
         CreateChestFromNetwork(unitData, spawn);
     }
 }
예제 #7
0
파일: Map3.cs 프로젝트: itcodes/unityRpg
        void SendUserData()
        {
            Debug.Log("SendUserData");
            if (state != WorldState.Connected)
            {
                return;
            }
            if (rc == null)
            {
                return;
            }

            var me  = ObjectManager.objectManager.GetMyPlayer();
            var pos = me.transform.position;

            var cg = CGPlayerCmd.CreateBuilder();

            cg.Cmd = "InitData";
            var ainfo = AvatarInfo.CreateBuilder();

            ainfo.X = (int)(pos.x * 100);
            ainfo.Z = (int)(pos.z * 100);
            ainfo.Y = (int)(pos.y * 100);
            var pinfo = ServerData.Instance.playerInfo;

            foreach (var d in pinfo.DressInfoList)
            {
                ainfo.DressInfoList.Add(d);
            }
            ainfo.Level = ObjectManager.objectManager.GetMyProp(CharAttribute.CharAttributeEnum.LEVEL);
            ainfo.HP    = ObjectManager.objectManager.GetMyProp(CharAttribute.CharAttributeEnum.HP);

            cg.AvatarInfo = ainfo.Build();
            var data = KBEngine.Bundle.GetPacket(cg);

            rc.Send(data);
        }
예제 #8
0
    /// <summary>
    /// 同步客户端位置给服务器
    /// </summary>
    public override void SyncPos()
    {
        Log.Net("SyncPos");
        var me     = gameObject;
        var pos    = me.transform.position;
        var dir    = (int)me.transform.localRotation.eulerAngles.y;
        var intPos = NetworkUtil.ConvertPos(pos);

        var ainfo = AvatarInfo.CreateBuilder();

        ainfo.Id = GetComponent <NpcAttribute>().GetNetView().GetServerID();
        var change = false;
        //第一个报文用于建立UDP连接 在UDP连接没有建立起来一直走TCP

        /*
         * if (frameId == 1)
         * {
         *  change = true;
         * }
         */

        var diffTime = Time.time - lastSyncTime;

        //防止UDP连接断开

        /*
         * if (dir != lastInfo.Dir)
         * {
         *   ainfo.Dir = dir;
         *   lastInfo.Dir = ainfo.Dir;
         *   change = true;
         * }
         */

        if (mv != null)
        {
            //摇杆的操控命令 如何处理命令是服务器的问题
            var vcontroller     = mv.vcontroller;
            var h               = vcontroller.inputVector.x; //CameraRight
            var v               = vcontroller.inputVector.y; //CameraForward
            var camRight        = CameraController.Instance.camRight;
            var camForward      = CameraController.Instance.camForward;
            var targetDirection = h * camRight + v * camForward;
            var mdir            = targetDirection.normalized;
            var speed           = attr.GetSpeed();
            var sp              = mdir * speed;
            var SpeedX          = Util.GameToNetNum(sp.x);
            var SpeedY          = Util.GameToNetNum(sp.z);
            Log.Sys("MoveSpeed:" + SpeedX + ":" + SpeedY + ":" + h + ":" + v + ":" + targetDirection + ":" + camRight + ":" + camForward);
            if (SpeedX != lastInfo.SpeedX || SpeedY != lastInfo.SpeedY)
            {
                ainfo.SpeedX    = SpeedX;
                ainfo.SpeedY    = SpeedY;
                lastInfo.SpeedX = ainfo.SpeedX;
                lastInfo.SpeedY = ainfo.SpeedY;
                change          = true;
            }

            if (diffTime > 1 ||
                (intPos[0] != lastInfo.X || intPos[1] != lastInfo.Y || intPos[2] != lastInfo.Z ||
                 dir != lastInfo.Dir ||
                 SpeedX != lastInfo.SpeedX ||
                 SpeedY != lastInfo.SpeedY)
                )
            {
                lastSyncTime = Time.time;

                ainfo.X      = intPos[0];
                ainfo.Y      = intPos[1];
                ainfo.Z      = intPos[2];
                ainfo.Dir    = dir;
                ainfo.SpeedX = SpeedX;
                ainfo.SpeedY = SpeedY;

                change = true;

                lastInfo.X   = ainfo.X;
                lastInfo.Y   = ainfo.Y;
                lastInfo.Z   = ainfo.Z;
                lastInfo.Dir = ainfo.Dir;

                lastInfo.SpeedX = ainfo.SpeedX;
                lastInfo.SpeedY = ainfo.SpeedY;
            }
        }

        if (change)
        {
            var cg = CGPlayerCmd.CreateBuilder();
            cg.Cmd = "UpdateData";

            /*
             * var nf = frameId++;
             * var find = false;
             * if (low && nf > 127)
             * {
             *  find = true;
             *  low = false;
             * }
             * else if (nf == 0)
             * {
             *  find = true;
             *  low = true;
             * }
             * //ainfo.FrameID = nf;
             */

            cg.AvatarInfo = ainfo.Build();
            //cg.FrameId = NetworkScene.Instance.GetPredictServerTimeForNet();
            NetworkUtil.Broadcast(cg);

            /*
             * //报文区间变化 TCP稳定通知
             * if (find)
             * {
             * }
             * else
             * {
             *  NetworkUtil.BroadcastUDP(cg);
             * }
             */
        }
    }
예제 #9
0
    public override void SyncAttribute()
    {
        Log.Net("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;

        var intNetSpeed = (int)(meAttr.NetSpeed * 100);

        if (intNetSpeed != lastInfo.NetSpeed)
        {
            ainfo.NetSpeed = intNetSpeed;
            change         = true;

            lastInfo.NetSpeed = ainfo.NetSpeed;
        }
        var intThrowSpeed = (int)(meAttr.ThrowSpeed * 100);

        if (intThrowSpeed != lastInfo.ThrowSpeed)
        {
            ainfo.ThrowSpeed = intThrowSpeed;
            change           = true;

            lastInfo.ThrowSpeed = ainfo.ThrowSpeed;
        }
        var intJumpSpeed = (int)(meAttr.JumpForwardSpeed * 100);

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

            lastInfo.JumpForwardSpeed = ainfo.JumpForwardSpeed;
        }

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

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

        if (change)
        {
            var cg = CGPlayerCmd.CreateBuilder();
            cg.Cmd        = "UpdateData";
            cg.AvatarInfo = ainfo.Build();
            NetworkUtil.Broadcast(cg);
        }
    }
예제 #10
0
    private IEnumerator CheckNet()
    {
        yield return(new WaitForSeconds(1));

        while (WorldManager.worldManager.station != WorldManager.WorldStation.Enter)
        {
            yield return(null);
        }
        yield return(new WaitForSeconds(5));

        //Debug.LogError("InitTimeLabel");
        var uiRoot    = WindowMng.windowMng.GetMainUI();
        var timeLabel = WindowMng.windowMng.AddChild(uiRoot, Resources.Load <GameObject>("UI/timeLabel"));
        var label     = timeLabel.GetComponent <IUserInterface>().GetLabel("Label");

        label.text = "";
        StartCoroutine(CheckFPS(timeLabel));

        while (true)
        {
            var ns = this.gameObject.GetComponent <NetworkScene>();

            RemoteClient rc = null;
            if (ns != null)
            {
                rc = ns.rc;
            }
            else
            {
                var nm = GetComponent <NetMatchScene>();
                if (nm != null)
                {
                    rc = nm.rc;
                }
            }


            if (rc != null)
            {
                var ht = CGPlayerCmd.CreateBuilder();
                ht.Cmd = "HeartBeat";
                Bundle bundle;
                var    data      = KBEngine.Bundle.GetPacketFull(ht, out bundle);
                var    startTime = Util.GetTimeNow();
                yield return(StartCoroutine(rc.SendWaitResponse(data.data, data.fid, (packet) =>
                {
                }, bundle)));

                var endTime = Util.GetTimeNow();
                var dt      = endTime - startTime;
                sample.Add(dt);
                var t = ShowTime();
                Log.Sys("HeartBeat: " + dt);
                //if (SaveGame.saveGame.IsTest)
                {
                    label.text = (int)(t * 1000) + "ms";
                }
                yield return(new WaitForSeconds(2));
            }
            else
            {
                yield return(new WaitForSeconds(2));
            }
        }
    }
예제 #11
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);
            }
        }