예제 #1
0
    public static List <CustomSyncMsg> extract_msg(List <DS_protocol.p_CustomSyncMsg> p_msg_list)
    {
        List <CustomSyncMsg> msg_list = new List <CustomSyncMsg>();
        CustomSyncMsg        msg;

        if (p_msg_list != null)
        {
            foreach (DS_protocol.p_CustomSyncMsg p_msg in p_msg_list)
            {
                if (p_msg.msg_type == (int)RequestType.INPUT)
                {
                    DS_protocol.p_InputMessage i_msg = p_msg.Input;
                    int   player_id = p_msg.player_id;
                    float moving_x  = i_msg.moving_x;
                    float moving_y  = i_msg.moving_y;
                    float moving_z  = i_msg.moving_z;
                    //Console.WriteLine("get input info: " + player_id +" " + moving_x+" " + moving_y + " " + moving_z);
                    msg = new InputMessage(player_id, new Vector3(moving_x, moving_y, moving_z));
                    msg_list.Add(msg);
                }
                else if (p_msg.msg_type == (int)RequestType.ROTATE)
                {
                    DS_protocol.p_RotateMessage r_msg = p_msg.Rotate;
                    int   player_id  = p_msg.player_id;
                    float rotation_x = r_msg.delta_x;
                    float rotation_y = r_msg.delta_y;
                    //Console.WriteLine("get rotate info: " + player_id + "rotation_x-- " + rotation_x + "rotation_y-- " + rotation_y);
                    msg = new RotateMessage(player_id, new Vector2(rotation_x, rotation_y));
                    msg_list.Add(msg);
                }
                else if (p_msg.msg_type == (int)RequestType.SPAWN)
                {
                    DS_protocol.p_SpawnMessage s_msg = p_msg.Spawn;
                    int   player_id  = p_msg.player_id;
                    float position_x = s_msg.position_x;
                    float position_y = s_msg.position_y;
                    float position_z = s_msg.position_z;
                    //Console.WriteLine("get spawn info: " + player_id + "position_x-- " + position_x + "position_y-- " + position_y + "position_z--" + position_z);
                    msg = new SpawnMessage(player_id, new Vector3(position_x, position_y, position_z));
                    msg_list.Add(msg);
                }
                else if (p_msg.msg_type == (int)RequestType.ENTERAREA)
                {
                    DS_protocol.p_EnterAreaMessage e_msg = p_msg.EnterArea;
                    int   player_id  = p_msg.player_id;
                    int   health     = e_msg.health;
                    float position_x = e_msg.position_x;
                    float position_y = e_msg.position_y;
                    float position_z = e_msg.position_z;

                    float direction_x = e_msg.direction_x;
                    float direction_y = e_msg.direction_y;
                    float direction_z = e_msg.direction_z;

                    float rotation_x = e_msg.rotation_x;
                    float rotation_y = e_msg.rotation_y;
                    //Console.WriteLine("get enterArea info: " + player_id + "position_x-- " + position_x + "position_y-- " + position_y + "position_z--" + position_z);
                    msg = new EnterAreaMessage(player_id, health, new Vector2(rotation_x, rotation_y), new Vector3(direction_x, direction_y, direction_z),
                                               new Vector3(position_x, position_y, position_z));
                    msg_list.Add(msg);
                }
                else if (p_msg.msg_type == (int)RequestType.LEAVEAREA)
                {
                    int player_id = p_msg.player_id;
                    msg = new LeaveAreaMessage(player_id);
                    msg_list.Add(msg);
                }
            }
        }
        return(msg_list);
    }
    public static void Buffer_SyncFrame_msg_list2(List <CustomSyncMsg> msg_list, List <DS_protocol.p_CustomSyncMsg> p_msg_list)
    {
        foreach (CustomSyncMsg msg in msg_list)
        {
            if (msg.msg_type == (int)RequestType.ENTERAREA)
            {
                EnterAreaMessage enterArea           = msg as EnterAreaMessage;
                DS_protocol.p_EnterAreaMessage p_msg = new DS_protocol.p_EnterAreaMessage();
                p_msg.id         = enterArea.id;
                p_msg.health     = enterArea.health;;
                p_msg.position_x = enterArea.position.x;
                p_msg.position_y = enterArea.position.y;
                p_msg.position_z = enterArea.position.z;

                p_msg.direction_x = enterArea.direction.x;
                p_msg.direction_y = enterArea.direction.y;
                p_msg.direction_z = enterArea.direction.z;

                p_msg.rotation_x = enterArea.rotation.x;
                p_msg.rotation_y = enterArea.rotation.y;


                //p_msg.area_id = enterArea.area_id;

                DS_protocol.p_CustomSyncMsg p_basemsg = new DS_protocol.p_CustomSyncMsg();
                p_basemsg.msg_type  = enterArea.msg_type;
                p_basemsg.player_id = enterArea.player_id;
                p_basemsg.EnterArea = p_msg;
                p_msg_list.Add(p_basemsg);
            }
            if (msg.msg_type == (int)RequestType.INPUT)
            {
                InputMessage input = msg as InputMessage;
                DS_protocol.p_InputMessage p_msg = new DS_protocol.p_InputMessage();

                p_msg.moving_x = input.moving.x;
                p_msg.moving_y = input.moving.y;
                p_msg.moving_z = input.moving.z;

                //p_msg.area_id = input.area_id;

                DS_protocol.p_CustomSyncMsg p_basemsg = new DS_protocol.p_CustomSyncMsg();
                p_basemsg.msg_type  = input.msg_type;
                p_basemsg.player_id = input.player_id;
                p_basemsg.Input     = p_msg;
                p_msg_list.Add(p_basemsg);
            }
            if (msg.msg_type == (int)RequestType.LEAVEAREA)
            {
                LeaveAreaMessage leaveArea           = msg as LeaveAreaMessage;
                DS_protocol.p_LeaveAreaMessage p_msg = new DS_protocol.p_LeaveAreaMessage();

                p_msg.id = leaveArea.id;

                //p_msg.area_id = leaveArea.area_id;
                DS_protocol.p_CustomSyncMsg p_basemsg = new DS_protocol.p_CustomSyncMsg();
                p_basemsg.msg_type  = leaveArea.msg_type;
                p_basemsg.player_id = leaveArea.player_id;
                p_basemsg.LeaveArea = p_msg;
                p_msg_list.Add(p_basemsg);
            }
            if (msg.msg_type == (int)RequestType.ROTATE)
            {
                RotateMessage rotate = msg as RotateMessage;
                DS_protocol.p_RotateMessage p_msg = new DS_protocol.p_RotateMessage();


                p_msg.delta_x = rotate.delta.x;
                p_msg.delta_y = rotate.delta.y;

                //p_msg.area_id = rotate.area_id;

                DS_protocol.p_CustomSyncMsg p_basemsg = new DS_protocol.p_CustomSyncMsg();
                p_basemsg.msg_type  = rotate.msg_type;
                p_basemsg.player_id = rotate.player_id;
                p_basemsg.Rotate    = p_msg;
                p_msg_list.Add(p_basemsg);
            }
            if (msg.msg_type == (int)RequestType.POSITION)
            {
                PositionMessage rotate = msg as PositionMessage;
                DS_protocol.p_PositionMessage p_msg = new DS_protocol.p_PositionMessage();

                p_msg.delta_x = rotate.delta.x;
                p_msg.delta_y = rotate.delta.y;

                // p_msg.area_id = rotate.area_id;

                DS_protocol.p_CustomSyncMsg p_basemsg = new DS_protocol.p_CustomSyncMsg();
                p_basemsg.msg_type  = rotate.msg_type;
                p_basemsg.player_id = rotate.player_id;
                p_basemsg.Position  = p_msg;
                p_msg_list.Add(p_basemsg);
            }
            if (msg.msg_type == (int)RequestType.SPAWN)
            {
                SpawnMessage spawn = msg as SpawnMessage;
                DS_protocol.p_SpawnMessage p_msg = new DS_protocol.p_SpawnMessage();

                p_msg.id         = spawn.id;
                p_msg.position_x = spawn.position.x;
                p_msg.position_y = spawn.position.y;
                p_msg.position_z = spawn.position.z;


                //p_msg.area_id = spawn.area_id;

                DS_protocol.p_CustomSyncMsg p_basemsg = new DS_protocol.p_CustomSyncMsg();
                p_basemsg.msg_type  = spawn.msg_type;
                p_basemsg.player_id = spawn.player_id;
                p_basemsg.Spawn     = p_msg;
                p_msg_list.Add(p_basemsg);
            }
        }
    }
예제 #3
0
    public static bool Commpare(DS_protocol.p_CustomSyncMsg T1Ms, DS_protocol.p_CustomSyncMsg T2Ms)
    {
        if (T1Ms.player_id != T2Ms.player_id)
        {
            return(false);
        }

        if (T1Ms.msg_type != T2Ms.msg_type)
        {
            return(false);
        }

        if (T1Ms.msg_type == (int)RequestType.ENTERAREA)
        {
            DS_protocol.p_EnterAreaMessage T1Msg = T1Ms.EnterArea;
            DS_protocol.p_EnterAreaMessage T2Msg = T2Ms.EnterArea;

            if (T1Msg.id != T2Msg.id ||
                T1Msg.health != T2Msg.health ||
                T1Msg.position_x != T2Msg.position_x ||
                T1Msg.position_y != T2Msg.position_y ||
                T1Msg.position_z != T2Msg.position_z ||
                T1Msg.direction_x != T2Msg.direction_x ||
                T1Msg.direction_y != T2Msg.direction_y ||
                T1Msg.direction_z != T2Msg.direction_z ||
                T1Msg.rotation_x != T2Msg.rotation_x ||
                T1Msg.rotation_y != T2Msg.rotation_y)
            {
                return(false);
            }
        }
        else if (T1Ms.msg_type == (int)RequestType.INPUT)
        {
            DS_protocol.p_InputMessage T1Msg = T1Ms.Input;
            DS_protocol.p_InputMessage T2Msg = T2Ms.Input;


            if (T1Msg.moving_x != T2Msg.moving_x ||
                T1Msg.moving_y != T2Msg.moving_y ||
                T1Msg.moving_z != T2Msg.moving_z)
            {
                return(false);
            }
        }
        else if (T1Ms.msg_type == (int)RequestType.LEAVEAREA)
        {
            DS_protocol.p_LeaveAreaMessage T1Msg = T1Ms.LeaveArea;
            DS_protocol.p_LeaveAreaMessage T2Msg = T2Ms.LeaveArea;

            if (T1Msg.id != T2Msg.id)
            {
                return(false);
            }
        }
        else if (T1Ms.msg_type == (int)RequestType.ROTATE)
        {
            DS_protocol.p_RotateMessage T1Msg = T1Ms.Rotate;
            DS_protocol.p_RotateMessage T2Msg = T2Ms.Rotate;

            if (T1Msg.delta_x != T2Msg.delta_x ||
                T1Msg.delta_y != T2Msg.delta_y)
            {
                return(false);
            }
        }
        else if (T1Ms.msg_type == (int)RequestType.POSITION)
        {
            DS_protocol.p_PositionMessage T1Msg = T1Ms.Position;
            DS_protocol.p_PositionMessage T2Msg = T2Ms.Position;

            if (T1Msg.delta_x != T2Msg.delta_x ||
                T1Msg.delta_y != T2Msg.delta_y)
            {
                return(false);
            }
        }
        else if (T1Ms.msg_type == (int)RequestType.SPAWN)
        {
            DS_protocol.p_SpawnMessage T1Msg = T1Ms.Spawn;
            DS_protocol.p_SpawnMessage T2Msg = T2Ms.Spawn;

            if (T1Msg.id != T2Msg.id ||
                T1Msg.position_x != T2Msg.position_x ||
                T1Msg.position_y != T2Msg.position_y ||
                T1Msg.position_z != T2Msg.position_z)
            {
                return(false);
            }
        }


        return(true);
    }