예제 #1
0
    public static void MsgSyncTank(ClientState c, MsgBase msgBase)
    {
        MsgSyncTank msg    = msgBase as MsgSyncTank;
        Player      player = c.player;

        if (player == null)
        {
            return;
        }

        Room room = RoomManager.GetRoom(player.roomId);

        if (room == null || room.status != Room.Status.FIGHT)
        {
            return;
        }

        player.x  = msg.x;
        player.y  = msg.y;
        player.z  = msg.z;
        player.ex = msg.ex;
        player.ey = msg.ey;
        player.ez = msg.ez;

        msg.id = player.id;
        room.Broadcast(msg);
    }
예제 #2
0
    //移动同步
    public void SyncPos(MsgSyncTank msg)
    {
        //预测位置
        Vector3 pos = new Vector3(msg.x, msg.y, msg.z);
        Vector3 rot = new Vector3(msg.ex, msg.ey, msg.ez);

        forecastPos = pos + 2 * (pos - lastPos);
        forecastRot = rot + 2 * (rot - lastRot);
        //更新
        lastPos      = pos;
        lastRot      = rot;
        forecastTime = Time.time;
        //炮塔
        Vector3 le = turret.localEulerAngles;

        le.y = msg.turretY;
        turret.localEulerAngles = le;
    }
예제 #3
0
    //收到同步协议
    public static void OnMsgSyncTank(MsgBase msgBase)
    {
        MsgSyncTank msg = (MsgSyncTank)msgBase;

        //不同步自己
        if (msg.id == GameMain.id)
        {
            return;
        }
        //查找坦克
        SyncTank tank = (SyncTank)GetTank(msg.id);

        if (tank == null)
        {
            return;
        }
        //移动同步
        tank.SyncPos(msg);
    }
예제 #4
0
    //移动同步
    public void SyncPos(MsgSyncTank msg)
    {
        //预测位置
        Vector3 pos = new Vector3(msg.x, msg.y, msg.z);
        Vector3 rot = new Vector3(msg.ex, msg.ey, msg.ez);

        //forecastPos = pos + 2*(pos - lastPos);
        //forecastRot = rot + 2*(rot - lastRot);
        forecastPos     = pos;          //跟随不预测
        forecastRot     = rot;
        forecastTurretY = msg.turretY;
        forecastGunX    = msg.gunX;
        //更新
        lastPos      = pos;
        lastRot      = rot;
        lastTurretY  = turret.localEulerAngles.y;
        lastGunX     = turret.localEulerAngles.x;
        forecastTime = Time.time;
    }
예제 #5
0
    private void SyncUpdate()
    {
        if (Time.time - lastSendSyncTime < syncInterval)
        {
            return;
        }

        lastSendSyncTime = Time.time;
        MsgSyncTank msg = new MsgSyncTank();

        msg.x       = transform.position.x;
        msg.y       = transform.position.y;
        msg.z       = transform.position.z;
        msg.ex      = transform.eulerAngles.x;
        msg.ey      = transform.eulerAngles.y;
        msg.ez      = transform.eulerAngles.z;
        msg.turretY = transform.localEulerAngles.y;
        NetManager.Send(msg);
    }
예제 #6
0
    private static void OnMsgSyncTank(MsgBase msgBase)
    {
        MsgSyncTank msg = (MsgSyncTank)msgBase;

        if (msg.id == GameMain.id)
        {
            return;
        }

        // 找坦克
        SyncTank tank = (SyncTank)GetTank(msg.id);

        if (tank == null)
        {
            return;
        }

        // 同步
        tank.SyncPos(msg);
    }
예제 #7
0
파일: SyncMsgHandle.cs 프로젝트: cocos56/CS
    //同步位置协议
    public static void MsgSyncTank(ClientState c, MsgBase msgBase)
    {
        MsgSyncTank msg    = (MsgSyncTank)msgBase;
        Player      player = c.player;

        if (player == null)
        {
            return;
        }
        //room
        Room room = RoomManager.GetRoom(player.roomId);

        if (room == null)
        {
            return;
        }
        //status
        if (room.status != Room.Status.FIGHT)
        {
            return;
        }
        //是否作弊
        if (Math.Abs(player.x - msg.x) > 5 ||
            Math.Abs(player.y - msg.y) > 5 ||
            Math.Abs(player.z - msg.z) > 5)
        {
            Console.WriteLine("疑似作弊 " + player.id);
        }
        //更新信息
        player.x  = msg.x;
        player.y  = msg.y;
        player.z  = msg.z;
        player.ex = msg.ex;
        player.ey = msg.ey;
        player.ez = msg.ez;
        //广播
        msg.id = player.id;
        room.Broadcast(msg);
    }