Example #1
0
        //中途退出战斗
        public void ExitFight(Player player)
        {
            //摧毁坦克
            if (playerList[player.id] != null)
            {
                playerList[player.id].tempData.hp = -1;
            }

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

            protocolRet.AddString("Hit");
            protocolRet.AddString(player.id);
            protocolRet.AddString(player.id);
            protocolRet.AddFloat(999);
            Broadcast(protocolRet);

            //增加失败次数
            if (IsWin() == 0)
            {
                player.data.fail++;
            }
            //胜负判断
            UpdateWin();
        }
Example #2
0
        //发送列表
        public void SendPlayerList(Player player)
        {
            int           count    = playerList.Count;
            ProtocolBytes protocol = new ProtocolBytes();

            protocol.AddString("GetList");
            protocol.AddInt(count);
            for (int i = 0; i < count; i++)
            {
                ScenePlayer p = playerList[i];
                protocol.AddString(p.id);
                protocol.AddFloat(p.x);
                protocol.AddFloat(p.y);
                protocol.AddFloat(p.z);
                protocol.AddInt(p.score);
            }
            player.Send(protocol);
        }
Example #3
0
        public void MsgHit(Player player, ProtocolBase protoBase)
        {
            //解析协议
            int           start     = 0;
            ProtocolBytes protocol  = (ProtocolBytes)protoBase;
            string        protoName = protocol.GetString(start, ref start);
            string        enemyName = protocol.GetString(start, ref start);
            float         damage    = protocol.GetFloat(start, ref start);

            //作弊校验
            //long lastShootTime = (long)player.tempData.lastShootTime;
            //if(Sys.GetTimeStamp()-lastShootTime<1)
            //{
            //    Console.WriteLine("MsgHit开炮作弊 " + player.id);
            //    return;
            //}
            //player.tempData.lastShootTime = Sys.GetTimeStamp();

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

            //扣除生命值
            if (!room.playerList.ContainsKey(enemyName))
            {
                Console.WriteLine("MsgHit not contains enemy" + enemyName);
                return;
            }

            Player enemy = room.playerList[enemyName];

            if (enemy == null)
            {
                return;
            }

            if (enemy.tempData.hp <= 0)
            {
                return;
            }
            enemy.tempData.hp -= damage;
            Console.WriteLine("MsgHit " + enemyName + "   hp" + enemy.tempData.hp);
            //广播
            ProtocolBytes protocolRet = new ProtocolBytes();

            protocolRet.AddString("Hit");
            protocolRet.AddString(player.id);
            protocolRet.AddString(enemy.id);
            protocolRet.AddFloat(damage);
            room.Broadcast(protocolRet);
            //胜负判断
            room.UpdateWin();
        }
Example #4
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);
        }
Example #5
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);
        }
Example #6
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);
        }