-module(pt_240).
-include("common.hrl").
-export([
        read/2,
        write/2
    ]).

read(24000, Bin0) ->
    <<ActivityId:8, Bin1/binary>> = Bin0, 
    <<Subtype:8, Bin2/binary>> = Bin1, 
    <<SceneId:32, Bin3/binary>> = Bin2, 
    <<MinLv:16, Bin4/binary>> = Bin3, 
    <<MaxLv:16, Bin5/binary>> = Bin4, 
    <<IsNeedApprove:8, Bin6/binary>> = Bin5, 
    {NeedPassword, _Bin7} = pt:read_string(Bin6), 
    {ok, [ActivityId, Subtype, SceneId, MinLv, MaxLv, IsNeedApprove, NeedPassword]};
read(24001, Bin0) ->
    <<ActivityId:8, Bin1/binary>> = Bin0, 
    <<Subtype:8, Bin2/binary>> = Bin1, 
    <<SceneId:32, _Bin3/binary>> = Bin2, 
    {ok, [ActivityId, Subtype, SceneId]};
read(24002, Bin0) ->
    <<TeamId:64, Bin1/binary>> = Bin0, 
    {NeedPassword, _Bin2} = pt:read_string(Bin1), 
    {ok, [TeamId, NeedPassword]};
read(24003, _) ->
    {ok, []};
read(24004, Bin0) ->
    FunArray0 = fun(<<RestBin0/binary>>) -> 
        <<IsAgree:8, _Args1/binary>> = RestBin0, 
        <<ServerId:16, _Args2/binary>> = _Args1, 
        <<PlayerId:64, _Args3/binary>> = _Args2, 
        {{IsAgree, ServerId, PlayerId},_Args3}
        end,
    {ResRequest, _Bin1} = pt:read_array(FunArray0, Bin0),

    {ok, [ResRequest]};
read(24005, _) ->
    {ok, []};
read(24006, Bin0) ->
    <<ActivityId:8, Bin1/binary>> = Bin0, 
    <<Subtype:8, Bin2/binary>> = Bin1, 
    <<SceneId:32, Bin3/binary>> = Bin2, 
    <<MinLv:16, Bin4/binary>> = Bin3, 
    <<MaxLv:16, Bin5/binary>> = Bin4, 
    <<InviteType:8, Bin6/binary>> = Bin5, 
    FunArray0 = fun(<<RestBin0/binary>>) -> 
        <<PlayerId:64, _Args1/binary>> = RestBin0, 
        {PlayerId,_Args1}
        end,
    {InviteList, _Bin7} = pt:read_array(FunArray0, Bin6),

    {ok, [ActivityId, Subtype, SceneId, MinLv, MaxLv, InviteType, InviteList]};
read(24007, _) ->
    {ok, []};
read(24008, Bin0) ->
    FunArray0 = fun(<<RestBin0/binary>>) -> 
        <<TeamId:64, _Args1/binary>> = RestBin0, 
        <<Res:8, _Args2/binary>> = _Args1, 
        {{TeamId, Res},_Args2}
        end,
    {ResponseList, _Bin1} = pt:read_array(FunArray0, Bin0),

    {ok, [ResponseList]};
read(24009, Bin0) ->
    <<KickId:64, _Bin1/binary>> = Bin0, 
    {ok, [KickId]};
read(24010, _) ->
    {ok, []};
read(24011, Bin0) ->
    <<NewLeaderid:64, _Bin1/binary>> = Bin0, 
    {ok, [NewLeaderid]};
read(24012, Bin0) ->
    <<ActivityId:8, Bin1/binary>> = Bin0, 
    <<Subtype:8, Bin2/binary>> = Bin1, 
    <<SceneId:32, _Bin3/binary>> = Bin2, 
    {ok, [ActivityId, Subtype, SceneId]};
read(24016, Bin0) ->
    <<PlayerId:64, _Bin1/binary>> = Bin0, 
    {ok, [PlayerId]};
read(24017, Bin0) ->
    <<ActivityId:8, Bin1/binary>> = Bin0, 
    <<Subtype:8, Bin2/binary>> = Bin1, 
    <<SceneId:32, Bin3/binary>> = Bin2, 
    <<MinLv:16, Bin4/binary>> = Bin3, 
    <<MaxLv:16, Bin5/binary>> = Bin4, 
    <<IsNeedApprove:8, Bin6/binary>> = Bin5, 
    {NeedPassword, _Bin7} = pt:read_string(Bin6), 
    {ok, [ActivityId, Subtype, SceneId, MinLv, MaxLv, IsNeedApprove, NeedPassword]};
read(24020, Bin0) ->
    <<ActivityId:32, Bin1/binary>> = Bin0, 
    <<Subtype:8, _Bin2/binary>> = Bin1, 
    {ok, [ActivityId, Subtype]};
read(24021, Bin0) ->
    <<ArbitrateId:16, Bin1/binary>> = Bin0, 
    <<Res:8, _Bin2/binary>> = Bin1, 
    {ok, [ArbitrateId, Res]};
read(24023, Bin0) ->
    <<ActivityId:8, Bin1/binary>> = Bin0, 
    <<Subtype:8, _Bin2/binary>> = Bin1, 
    {ok, [ActivityId, Subtype]};
read(24032, Bin0) ->
    FunArray0 = fun(<<RestBin0/binary>>) -> 
        <<TeamId:64, _Args1/binary>> = RestBin0, 
        {TeamId,_Args1}
        end,
    {TeamIds, _Bin1} = pt:read_array(FunArray0, Bin0),

    {ok, [TeamIds]};
read(24045, _) ->
    {ok, []};
read(24047, _) ->
    {ok, []};
read(24048, Bin0) ->
    <<RoleId:64, Bin1/binary>> = Bin0, 
    <<SceneId:32, _Bin2/binary>> = Bin1, 
    {ok, [RoleId, SceneId]};
read(24053, Bin0) ->
    <<ActivityId:8, Bin1/binary>> = Bin0, 
    <<Subtype:8, Bin2/binary>> = Bin1, 
    <<Position:32, Bin3/binary>> = Bin2, 
    <<ListType:8, _Bin4/binary>> = Bin3, 
    {ok, [ActivityId, Subtype, Position, ListType]};
read(24055, Bin0) ->
    <<IsNeedApprove:8, _Bin1/binary>> = Bin0, 
    {ok, [IsNeedApprove]};
read(_Cmd, _R) -> {error, no_match}.

write (24000,[
    Res,
    ErrorCodeArgs
] = Src_Data) ->
    Bin_ErrorCodeArgs = pt:write_string(ErrorCodeArgs), 

    Data = <<
        Res:32,
        Bin_ErrorCodeArgs/binary
    >>,
    {ok, pt:encode(24000, Data, Src_Data)};

write (24001,[
    Res,
    ErrorCodeArgs
] = Src_Data) ->
    Bin_ErrorCodeArgs = pt:write_string(ErrorCodeArgs), 

    Data = <<
        Res:32,
        Bin_ErrorCodeArgs/binary
    >>,
    {ok, pt:encode(24001, Data, Src_Data)};

write (24002,[
    Res,
    ErrorCodeArgs,
    TeamId
] = Src_Data) ->
    Bin_ErrorCodeArgs = pt:write_string(ErrorCodeArgs), 

    Data = <<
        Res:32,
        Bin_ErrorCodeArgs/binary,
        TeamId:64
    >>,
    {ok, pt:encode(24002, Data, Src_Data)};

write (24003,[
    ServerId,
    PlayerId,
    Figure
] = Src_Data) ->
    Bin_Figure = pt:write_figure(Figure), 

    Data = <<
        ServerId:16,
        PlayerId:64,
        Bin_Figure/binary
    >>,
    {ok, pt:encode(24003, Data, Src_Data)};

write (24004,[
    Res
] = Src_Data) ->
    Data = <<
        Res:32
    >>,
    {ok, pt:encode(24004, Data, Src_Data)};

write (24005,[
    Res
] = Src_Data) ->
    Data = <<
        Res:32
    >>,
    {ok, pt:encode(24005, Data, Src_Data)};

write (24006,[
    Res
] = Src_Data) ->
    Data = <<
        Res:32
    >>,
    {ok, pt:encode(24006, Data, Src_Data)};

write (24007,[
    TeamId,
    Num,
    ActivityId,
    Subtype,
    SceneId,
    InviterId,
    InviterFigure,
    InviteSceneId,
    InviteType
] = Src_Data) ->
    Bin_InviterFigure = pt:write_figure(InviterFigure), 

    Data = <<
        TeamId:64,
        Num:8,
        ActivityId:32,
        Subtype:8,
        SceneId:32,
        InviterId:64,
        Bin_InviterFigure/binary,
        InviteSceneId:32,
        InviteType:8
    >>,
    {ok, pt:encode(24007, Data, Src_Data)};

write (24008,[
    Res,
    ErrorCodeArgs
] = Src_Data) ->
    Bin_ErrorCodeArgs = pt:write_string(ErrorCodeArgs), 

    Data = <<
        Res:32,
        Bin_ErrorCodeArgs/binary
    >>,
    {ok, pt:encode(24008, Data, Src_Data)};

write (24009,[
    Res
] = Src_Data) ->
    Data = <<
        Res:32
    >>,
    {ok, pt:encode(24009, Data, Src_Data)};

write (24010,[
    TeamId,
    ActivityId,
    Subtype,
    SceneId,
    PreNumFull,
    AutoMatching,
    MinLv,
    MaxLv,
    NeedPassword,
    PowerLimit,
    IsNeedApprove,
    TeamMemberList
] = Src_Data) ->
    Bin_NeedPassword = pt:write_string(NeedPassword), 

    BinList_TeamMemberList = [
        item_to_bin_0(TeamMemberList_Item) || TeamMemberList_Item <- TeamMemberList
    ], 

    TeamMemberList_Len = length(TeamMemberList), 
    Bin_TeamMemberList = list_to_binary(BinList_TeamMemberList),

    Data = <<
        TeamId:64,
        ActivityId:8,
        Subtype:8,
        SceneId:32,
        PreNumFull:8,
        AutoMatching:8,
        MinLv:16,
        MaxLv:16,
        Bin_NeedPassword/binary,
        PowerLimit:64,
        IsNeedApprove:8,
        TeamMemberList_Len:16, Bin_TeamMemberList/binary
    >>,
    {ok, pt:encode(24010, Data, Src_Data)};

write (24011,[
    Res
] = Src_Data) ->
    Data = <<
        Res:32
    >>,
    {ok, pt:encode(24011, Data, Src_Data)};

write (24012,[
    TeamEnlist
] = Src_Data) ->
    BinList_TeamEnlist = [
        item_to_bin_1(TeamEnlist_Item) || TeamEnlist_Item <- TeamEnlist
    ], 

    TeamEnlist_Len = length(TeamEnlist), 
    Bin_TeamEnlist = list_to_binary(BinList_TeamEnlist),

    Data = <<
        TeamEnlist_Len:16, Bin_TeamEnlist/binary
    >>,
    {ok, pt:encode(24012, Data, Src_Data)};

write (24013,[
    Id,
    TeamId,
    Position
] = Src_Data) ->
    Data = <<
        Id:64,
        TeamId:64,
        Position:8
    >>,
    {ok, pt:encode(24013, Data, Src_Data)};

write (24014,[
    Id
] = Src_Data) ->
    Data = <<
        Id:64
    >>,
    {ok, pt:encode(24014, Data, Src_Data)};

write (24015,[
    Id
] = Src_Data) ->
    Data = <<
        Id:64
    >>,
    {ok, pt:encode(24015, Data, Src_Data)};

write (24016,[
    NeedPassword,
    Res
] = Src_Data) ->
    Data = <<
        NeedPassword:8,
        Res:32
    >>,
    {ok, pt:encode(24016, Data, Src_Data)};

write (24017,[
    Res,
    ActivityId,
    Subtype,
    SceneId,
    MinLv,
    MaxLv,
    IsNeedApprove,
    NeedPassword
] = Src_Data) ->
    Bin_NeedPassword = pt:write_string(NeedPassword), 

    Data = <<
        Res:32,
        ActivityId:8,
        Subtype:8,
        SceneId:32,
        MinLv:16,
        MaxLv:16,
        IsNeedApprove:8,
        Bin_NeedPassword/binary
    >>,
    {ok, pt:encode(24017, Data, Src_Data)};

write (24020,[
    ErrorCode,
    ErrorCodeArgs,
    ActivityId,
    Subtype,
    SceneId,
    ArbitrateId
] = Src_Data) ->
    Bin_ErrorCodeArgs = pt:write_string(ErrorCodeArgs), 

    Data = <<
        ErrorCode:32,
        Bin_ErrorCodeArgs/binary,
        ActivityId:32,
        Subtype:8,
        SceneId:32,
        ArbitrateId:16
    >>,
    {ok, pt:encode(24020, Data, Src_Data)};

write (24021,[
    ErrorCode,
    ErrorCodeArgs,
    Res
] = Src_Data) ->
    Bin_ErrorCodeArgs = pt:write_string(ErrorCodeArgs), 

    Data = <<
        ErrorCode:32,
        Bin_ErrorCodeArgs/binary,
        Res:8
    >>,
    {ok, pt:encode(24021, Data, Src_Data)};

write (24023,[
    Res,
    ActivityId,
    Subtype
] = Src_Data) ->
    Data = <<
        Res:32,
        ActivityId:8,
        Subtype:8
    >>,
    {ok, pt:encode(24023, Data, Src_Data)};

write (24030,[
    Res
] = Src_Data) ->
    Data = <<
        Res:32
    >>,
    {ok, pt:encode(24030, Data, Src_Data)};

write (24032,[
    TeamNums
] = Src_Data) ->
    BinList_TeamNums = [
        item_to_bin_3(TeamNums_Item) || TeamNums_Item <- TeamNums
    ], 

    TeamNums_Len = length(TeamNums), 
    Bin_TeamNums = list_to_binary(BinList_TeamNums),

    Data = <<
        TeamNums_Len:16, Bin_TeamNums/binary
    >>,
    {ok, pt:encode(24032, Data, Src_Data)};

write (24038,[
    ErrorCode,
    ErrorCodeArgs
] = Src_Data) ->
    Bin_ErrorCodeArgs = pt:write_string(ErrorCodeArgs), 

    Data = <<
        ErrorCode:32,
        Bin_ErrorCodeArgs/binary
    >>,
    {ok, pt:encode(24038, Data, Src_Data)};

write (24045,[
    Res
] = Src_Data) ->
    Data = <<
        Res:32
    >>,
    {ok, pt:encode(24045, Data, Src_Data)};

write (24046,[
    RoleId,
    EndTime,
    LeaderName,
    SceneId,
    PosX,
    PosY
] = Src_Data) ->
    Bin_LeaderName = pt:write_string(LeaderName), 

    Data = <<
        RoleId:64,
        EndTime:32,
        Bin_LeaderName/binary,
        SceneId:32,
        PosX:32,
        PosY:32
    >>,
    {ok, pt:encode(24046, Data, Src_Data)};

write (24047,[
    Reqlist
] = Src_Data) ->
    BinList_Reqlist = [
        item_to_bin_4(Reqlist_Item) || Reqlist_Item <- Reqlist
    ], 

    Reqlist_Len = length(Reqlist), 
    Bin_Reqlist = list_to_binary(BinList_Reqlist),

    Data = <<
        Reqlist_Len:16, Bin_Reqlist/binary
    >>,
    {ok, pt:encode(24047, Data, Src_Data)};

write (24048,[
    Res,
    X,
    Y
] = Src_Data) ->
    Data = <<
        Res:32,
        X:16,
        Y:16
    >>,
    {ok, pt:encode(24048, Data, Src_Data)};

write (24050,[
    ExpScale
] = Src_Data) ->
    Data = <<
        ExpScale:16
    >>,
    {ok, pt:encode(24050, Data, Src_Data)};

write (24051,[
    RoleId,
    SceneId
] = Src_Data) ->
    Data = <<
        RoleId:64,
        SceneId:32
    >>,
    {ok, pt:encode(24051, Data, Src_Data)};

write (24052,[
    RoleId,
    Online
] = Src_Data) ->
    Data = <<
        RoleId:64,
        Online:8
    >>,
    {ok, pt:encode(24052, Data, Src_Data)};

write (24053,[
    Users,
    ActivityId,
    Subtype,
    Position,
    ListType
] = Src_Data) ->
    BinList_Users = [
        item_to_bin_5(Users_Item) || Users_Item <- Users
    ], 

    Users_Len = length(Users), 
    Bin_Users = list_to_binary(BinList_Users),

    Data = <<
        Users_Len:16, Bin_Users/binary,
        ActivityId:8,
        Subtype:8,
        Position:32,
        ListType:8
    >>,
    {ok, pt:encode(24053, Data, Src_Data)};

write (24055,[
    IsNeedApprove
] = Src_Data) ->
    Data = <<
        IsNeedApprove:8
    >>,
    {ok, pt:encode(24055, Data, Src_Data)};

write (24056,[
    RoleId,
    RoleName,
    Res
] = Src_Data) ->
    Bin_RoleName = pt:write_string(RoleName), 

    Data = <<
        RoleId:64,
        Bin_RoleName/binary,
        Res:8
    >>,
    {ok, pt:encode(24056, Data, Src_Data)};

write(_Cmd, _R) -> ?DEBUG("no_match:~p,~p~n", [_Cmd, _R]), {ok, pt:pack(0, <<>>)}.


item_to_bin_0 ({
    Id,
    TeamPosition,
    Member,
    HelpType,
    SceneId,
    JoinTime,
    Power,
    Online,
    ServerId
}) ->
    Bin_Member = pt:write_figure(Member), 

    Data = <<
        Id:64,
        TeamPosition:8,
        Bin_Member/binary,
        HelpType:8,
        SceneId:32,
        JoinTime:32,
        Power:64,
        Online:8,
        ServerId:16
    >>,
    Data.
item_to_bin_1 ({
    TeamId,
    Leader,
    Num,
    IsNeedApprove,
    MinLv,
    MaxLv,
    Partner,
    LeaderOnline,
    DungeonTimes,
    HelpType,
    HelpTimes,
    LeaderServer,
    NeedPassword,
    PowerLimit,
    ActivityId,
    Subtype,
    SceneId,
    LeaderSceneId,
    LeaderPosX,
    LeaderPosY
}) ->
    Bin_Leader = pt:write_figure(Leader), 

    BinList_Partner = [
        item_to_bin_2(Partner_Item) || Partner_Item <- Partner
    ], 

    Partner_Len = length(Partner), 
    Bin_Partner = list_to_binary(BinList_Partner),

    Bin_NeedPassword = pt:write_string(NeedPassword), 

    Data = <<
        TeamId:64,
        Bin_Leader/binary,
        Num:8,
        IsNeedApprove:8,
        MinLv:16,
        MaxLv:16,
        Partner_Len:16, Bin_Partner/binary,
        LeaderOnline:8,
        DungeonTimes:8,
        HelpType:8,
        HelpTimes:8,
        LeaderServer:16,
        Bin_NeedPassword/binary,
        PowerLimit:64,
        ActivityId:8,
        Subtype:8,
        SceneId:32,
        LeaderSceneId:32,
        LeaderPosX:32,
        LeaderPosY:32
    >>,
    Data.
item_to_bin_2 ({
    RoleId,
    Gender,
    Carrer,
    Picture,
    PictureVer,
    TurnLevel
}) ->
    Bin_Picture = pt:write_string(Picture), 

    Data = <<
        RoleId:64,
        Gender:8,
        Carrer:8,
        Bin_Picture/binary,
        PictureVer:32,
        TurnLevel:32
    >>,
    Data.
item_to_bin_3 ({
    Leader,
    TeamId,
    TeamNum,
    ActivityId,
    Subtype
}) ->
    Bin_Leader = pt:write_figure(Leader), 

    Data = <<
        Bin_Leader/binary,
        TeamId:64,
        TeamNum:8,
        ActivityId:32,
        Subtype:8
    >>,
    Data.
item_to_bin_4 ({
    ServerId,
    PlayerId,
    Figure
}) ->
    Bin_Figure = pt:write_figure(Figure), 

    Data = <<
        ServerId:16,
        PlayerId:64,
        Bin_Figure/binary
    >>,
    Data.
item_to_bin_5 ({
    Leader,
    HasCount,
    MaxCount
}) ->
    Bin_Leader = pt:write_figure(Leader), 

    Data = <<
        Bin_Leader/binary,
        HasCount:8,
        MaxCount:8
    >>,
    Data.
