示例#1
0
        public void MsgShooting(Player player, ProtocolBase protoBase)
        {
            //获取数值
            int           start     = 0;
            ProtocolBytes protocol  = (ProtocolBytes)protoBase;
            string        protoName = protocol.GetString(start, ref start);
            float         posX      = protocol.GetFloat(start, ref start);
            float         posY      = protocol.GetFloat(start, ref start);
            float         posZ      = protocol.GetFloat(start, ref start);
            float         rotX      = protocol.GetFloat(start, ref start);
            float         rotY      = protocol.GetFloat(start, ref start);
            float         rotZ      = protocol.GetFloat(start, ref start);

            //获取房间
            if (player.tempData.status != PlayerTempData.Status.Fight)
            {
                return;
            }
            Room room = player.tempData.room;
            //广播
            ProtocolBytes protocolRet = new ProtocolBytes();

            protocolRet.AddString("Shooting");
            protocolRet.AddString(player.id);
            protocolRet.AddFloat(posX);
            protocolRet.AddFloat(posY);
            protocolRet.AddFloat(posZ);
            protocolRet.AddFloat(rotX);
            protocolRet.AddFloat(rotY);
            protocolRet.AddFloat(rotZ);
            room.Broadcast(protocolRet);
        }
示例#2
0
        //增加分数
        //协议参数:
        public void MsgAddScore(Player player, ProtocolBase protocolBase)
        {
            //获取数值
            int           start     = 0;
            ProtocolBytes protocol  = (ProtocolBytes)protocolBase;
            string        protoName = protocol.GetString(start, ref start);

            //处理
            player.data.score += 1;
            Console.WriteLine("MsgAddScore()-> " + player.id + "  " + player.data.score.ToString());
        }
示例#3
0
        //同步坦克单元
        public void MsgUpdateUnitInfo(Player player, ProtocolBase protoBase)
        {
            //获取数值
            int           start    = 0;
            ProtocolBytes protocol = (ProtocolBytes)protoBase;

            string protoName = protocol.GetString(start, ref start);
            float  posX      = protocol.GetFloat(start, ref start);
            float  posY      = protocol.GetFloat(start, ref start);
            float  posZ      = protocol.GetFloat(start, ref start);

            float rotX = protocol.GetFloat(start, ref start);
            float rotY = protocol.GetFloat(start, ref start);
            float rotZ = protocol.GetFloat(start, ref start);

            float gunRot  = protocol.GetFloat(start, ref start);
            float gunRoll = protocol.GetFloat(start, ref start);

            //获取房间
            if (player.tempData.status != PlayerTempData.Status.Fight)
            {
                return;
            }

            Room room = player.tempData.room;

            //作弊校验 略

            player.tempData.posX = posX;
            player.tempData.posY = posY;
            player.tempData.posZ = posZ;

            player.tempData.lastUpdateTime = Sys.GetTimeStamp();

            //广播
            ProtocolBytes protocolRet = new ProtocolBytes();

            protocolRet.AddString("UpdateUnitInfo");
            protocolRet.AddString(player.id);
            protocolRet.AddFloat(posX);
            protocolRet.AddFloat(posY);
            protocolRet.AddFloat(posZ);
            protocolRet.AddFloat(rotX);
            protocolRet.AddFloat(rotY);
            protocolRet.AddFloat(rotZ);
            protocolRet.AddFloat(gunRot);
            protocolRet.AddFloat(gunRoll);
            room.Broadcast(protocolRet);
        }
示例#4
0
        /// <summary>
        /// 加入房间
        /// </summary>
        /// <param name="player"></param>
        /// <param name="protocolBase"></param>
        public void MsgEnterRoom(Player player, ProtocolBase protocolBase)
        {
            //获取数值
            int           start     = 0;
            ProtocolBytes protocol  = (ProtocolBytes)protocolBase;
            string        protoName = protocol.GetString(start, ref start);
            int           index     = protocol.GetInt(start, ref start);

            Console.WriteLine("[收到 MsgEnterRoom] " + player.id + "  加入房间号: " + index);

            //构建进入房间的返回协议
            protocol = new ProtocolBytes();
            protocol.AddString("EnterRoom");

            //判断房间是否存在
            if (index < 0 || index >= RoomMgr.instance.roomList.Count)
            {
                Console.WriteLine("MsgEnterRoom index error " + player.id);
                protocol.AddInt(-1);
                player.Send(protocol);
                return;
            }


            //判断房间的状态,只有处于“准备中”的房间才允许玩家加入
            Room room = RoomMgr.instance.roomList[index];

            if (room.status != Room.Status.Prepare)
            {
                Console.WriteLine("MsgEnterRoom status error " + player.id);
                protocol.AddInt(-1);
                player.Send(protocol);
                return;
            }

            //把玩家添加到房间,加入成功返回 0,加入失败返回 -1
            if (room.AddPlayer(player))
            {
                room.Broadcast(room.GetRoomInfo());
                protocol.AddInt(0);
                player.Send(protocol);
            }
            else
            {
                Console.WriteLine("MsgEnterRoom maxPlayer error " + player.id);
                protocol.AddInt(-1);
                player.Send(protocol);
            }
        }
示例#5
0
        //更新信息
        public void MsgUpdateInfo(Player player, ProtocolBase protocolBase)
        {
            //获取数值
            int           start     = 0;
            ProtocolBytes protocol  = (ProtocolBytes)protocolBase;
            string        protoName = protocol.GetString(start, ref start);
            float         x         = protocol.GetFloat(start, ref start);
            float         y         = protocol.GetFloat(start, ref start);
            float         z         = protocol.GetFloat(start, ref start);
            int           score     = player.data.score;

            Scene.instance.UpdateInfo(player.id, x, y, z, score);

            //广播
            ProtocolBytes protocolRet = new ProtocolBytes();

            protocolRet.AddString("UpdateInfo");
            protocolRet.AddString(player.id);
            protocolRet.AddFloat(x);
            protocolRet.AddFloat(y);
            protocolRet.AddFloat(z);
            protocolRet.AddInt(score);
            ServNet.instance.Broadcast(protocolRet);
        }