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

read(46001, _) ->
    {ok, []};
read(46002, _) ->
    {ok, []};
read(46003, Bin0) ->
    <<BossId:32, _Bin1/binary>> = Bin0, 
    {ok, [BossId]};
read(46004, Bin0) ->
    <<BossId:32, _Bin1/binary>> = Bin0, 
    {ok, [BossId]};
read(46006, Bin0) ->
    <<BossId:32, Bin1/binary>> = Bin0, 
    <<No:8, _Bin2/binary>> = Bin1, 
    {ok, [BossId, No]};
read(46010, _) ->
    {ok, []};
read(46011, _) ->
    {ok, []};
read(46012, _) ->
    {ok, []};
read(46013, _) ->
    {ok, []};
read(46014, Bin0) ->
    <<Type:8, _Bin1/binary>> = Bin0, 
    {ok, [Type]};
read(46015, _) ->
    {ok, []};
read(46016, Bin0) ->
    <<BossId:32, _Bin1/binary>> = Bin0, 
    {ok, [BossId]};
read(46019, Bin0) ->
    <<BossId:32, _Bin1/binary>> = Bin0, 
    {ok, [BossId]};
read(46023, _) ->
    {ok, []};
read(46024, Bin0) ->
    <<BossType:8, Bin1/binary>> = Bin0, 
    <<BossId:32, Bin2/binary>> = Bin1, 
    <<Op:8, _Bin3/binary>> = Bin2, 
    {ok, [BossType, BossId, Op]};
read(46026, _) ->
    {ok, []};
read(46027, _) ->
    {ok, []};
read(46028, Bin0) ->
    <<SceneId:32, _Bin1/binary>> = Bin0, 
    {ok, [SceneId]};
read(46029, Bin0) ->
    <<Id:32, _Bin1/binary>> = Bin0, 
    {ok, [Id]};
read(46031, Bin0) ->
    <<Id:32, _Bin1/binary>> = Bin0, 
    {ok, [Id]};
read(46032, Bin0) ->
    <<BossId:32, _Bin1/binary>> = Bin0, 
    {ok, [BossId]};
read(46033, _) ->
    {ok, []};
read(46034, _) ->
    {ok, []};
read(_Cmd, _R) -> {error, no_match}.

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

write (46002,[
    BossInfo,
    NextTime
] = Src_Data) ->
    BinList_BossInfo = [
        item_to_bin_0(BossInfo_Item) || BossInfo_Item <- BossInfo
    ], 

    BossInfo_Len = length(BossInfo), 
    Bin_BossInfo = list_to_binary(BinList_BossInfo),

    Data = <<
        BossInfo_Len:16, Bin_BossInfo/binary,
        NextTime:32
    >>,
    {ok, pt:encode(46002, Data, Src_Data)};

write (46003,[
    BossId,
    Hp,
    HpMax
] = Src_Data) ->
    Data = <<
        BossId:32,
        Hp:64,
        HpMax:64
    >>,
    {ok, pt:encode(46003, Data, Src_Data)};

write (46004,[
    BossId,
    MyScore,
    RankList
] = Src_Data) ->
    BinList_RankList = [
        item_to_bin_1(RankList_Item) || RankList_Item <- RankList
    ], 

    RankList_Len = length(RankList), 
    Bin_RankList = list_to_binary(BinList_RankList),

    Data = <<
        BossId:32,
        MyScore:32,
        RankList_Len:16, Bin_RankList/binary
    >>,
    {ok, pt:encode(46004, Data, Src_Data)};

write (46005,[
    BossId,
    No
] = Src_Data) ->
    Data = <<
        BossId:32,
        No:8
    >>,
    {ok, pt:encode(46005, Data, Src_Data)};

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

write (46007,[
    BossId,
    BossHp,
    RankList
] = Src_Data) ->
    BinList_RankList = [
        item_to_bin_2(RankList_Item) || RankList_Item <- RankList
    ], 

    RankList_Len = length(RankList), 
    Bin_RankList = list_to_binary(BinList_RankList),

    Data = <<
        BossId:32,
        BossHp:64,
        RankList_Len:16, Bin_RankList/binary
    >>,
    {ok, pt:encode(46007, Data, Src_Data)};

write (46008,[
    BossId,
    RoleId,
    Type,
    Name,
    Hurt
] = Src_Data) ->
    Bin_Name = pt:write_string(Name), 

    Data = <<
        BossId:32,
        RoleId:64,
        Type:8,
        Bin_Name/binary,
        Hurt:64
    >>,
    {ok, pt:encode(46008, Data, Src_Data)};

write (46009,[
    BossId,
    Status
] = Src_Data) ->
    Data = <<
        BossId:32,
        Status:8
    >>,
    {ok, pt:encode(46009, Data, Src_Data)};



write (46011,[
    DailyAward,
    GoodsTimes,
    RecoverTime
] = Src_Data) ->
    Data = <<
        DailyAward:8,
        GoodsTimes:8,
        RecoverTime:32
    >>,
    {ok, pt:encode(46011, Data, Src_Data)};

write (46012,[
    BossInfo
] = Src_Data) ->
    BinList_BossInfo = [
        item_to_bin_3(BossInfo_Item) || BossInfo_Item <- BossInfo
    ], 

    BossInfo_Len = length(BossInfo), 
    Bin_BossInfo = list_to_binary(BinList_BossInfo),

    Data = <<
        BossInfo_Len:16, Bin_BossInfo/binary
    >>,
    {ok, pt:encode(46012, Data, Src_Data)};

write (46013,[
    DropLog
] = Src_Data) ->
    BinList_DropLog = [
        item_to_bin_4(DropLog_Item) || DropLog_Item <- DropLog
    ], 

    DropLog_Len = length(DropLog), 
    Bin_DropLog = list_to_binary(BinList_DropLog),

    Data = <<
        DropLog_Len:16, Bin_DropLog/binary
    >>,
    {ok, pt:encode(46013, Data, Src_Data)};

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

write (46015,[
    BossName,
    BaseRewardList,
    ExtraRewardList
] = Src_Data) ->
    Bin_BossName = pt:write_string(BossName), 

    Bin_BaseRewardList = pt:write_object_list(BaseRewardList), 

    Bin_ExtraRewardList = pt:write_object_list(ExtraRewardList), 

    Data = <<
        Bin_BossName/binary,
        Bin_BaseRewardList/binary,
        Bin_ExtraRewardList/binary
    >>,
    {ok, pt:encode(46015, Data, Src_Data)};

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

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

write (46018,[
    BossId,
    NextTime,
    Killer
] = Src_Data) ->
    Bin_Killer = pt:write_string(Killer), 

    Data = <<
        BossId:32,
        NextTime:32,
        Bin_Killer/binary
    >>,
    {ok, pt:encode(46018, Data, Src_Data)};

write (46019,[
    BossId,
    ByGold,
    ByBgold
] = Src_Data) ->
    Data = <<
        BossId:32,
        ByGold:8,
        ByBgold:8
    >>,
    {ok, pt:encode(46019, Data, Src_Data)};

write (46020,[
    BossId,
    No,
    Max
] = Src_Data) ->
    Data = <<
        BossId:32,
        No:8,
        Max:32
    >>,
    {ok, pt:encode(46020, Data, Src_Data)};

write (46021,[
    BossId,
    RoleId,
    Name,
    Hurt
] = Src_Data) ->
    Bin_Name = pt:write_string(Name), 

    Data = <<
        BossId:32,
        RoleId:64,
        Bin_Name/binary,
        Hurt:64
    >>,
    {ok, pt:encode(46021, Data, Src_Data)};

write (46022,[
    List
] = Src_Data) ->
    BinList_List = [
        item_to_bin_5(List_Item) || List_Item <- List
    ], 

    List_Len = length(List), 
    Bin_List = list_to_binary(BinList_List),

    Data = <<
        List_Len:16, Bin_List/binary
    >>,
    {ok, pt:encode(46022, Data, Src_Data)};

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

write (46024,[
    Res,
    BossType,
    BossId,
    Op
] = Src_Data) ->
    Data = <<
        Res:32,
        BossType:8,
        BossId:32,
        Op:8
    >>,
    {ok, pt:encode(46024, Data, Src_Data)};

write (46025,[
    BossId,
    Hurt
] = Src_Data) ->
    Data = <<
        BossId:32,
        Hurt:64
    >>,
    {ok, pt:encode(46025, Data, Src_Data)};

write (46026,[
    List,
    NextTime
] = Src_Data) ->
    BinList_List = [
        item_to_bin_6(List_Item) || List_Item <- List
    ], 

    List_Len = length(List), 
    Bin_List = list_to_binary(BinList_List),

    Data = <<
        List_Len:16, Bin_List/binary,
        NextTime:32
    >>,
    {ok, pt:encode(46026, Data, Src_Data)};

write (46027,[
    List
] = Src_Data) ->
    BinList_List = [
        item_to_bin_7(List_Item) || List_Item <- List
    ], 

    List_Len = length(List), 
    Bin_List = list_to_binary(BinList_List),

    Data = <<
        List_Len:16, Bin_List/binary
    >>,
    {ok, pt:encode(46027, Data, Src_Data)};

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

write (46029,[
    Id,
    BossId,
    BossHp,
    FirstAtt,
    RankList
] = Src_Data) ->
    Bin_FirstAtt = pt:write_string(FirstAtt), 

    BinList_RankList = [
        item_to_bin_8(RankList_Item) || RankList_Item <- RankList
    ], 

    RankList_Len = length(RankList), 
    Bin_RankList = list_to_binary(BinList_RankList),

    Data = <<
        Id:32,
        BossId:32,
        BossHp:64,
        Bin_FirstAtt/binary,
        RankList_Len:16, Bin_RankList/binary
    >>,
    {ok, pt:encode(46029, Data, Src_Data)};

write (46030,[
    Id,
    RoleId,
    Name,
    Hurt
] = Src_Data) ->
    Bin_Name = pt:write_string(Name), 

    Data = <<
        Id:32,
        RoleId:64,
        Bin_Name/binary,
        Hurt:64
    >>,
    {ok, pt:encode(46030, Data, Src_Data)};

write (46031,[
    Res,
    BossId,
    SceneId,
    Pool
] = Src_Data) ->
    Data = <<
        Res:32,
        BossId:32,
        SceneId:32,
        Pool:16
    >>,
    {ok, pt:encode(46031, Data, Src_Data)};

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

write (46033,[
    UseTimes,
    ProtectTime
] = Src_Data) ->
    Data = <<
        UseTimes:8,
        ProtectTime:32
    >>,
    {ok, pt:encode(46033, Data, Src_Data)};

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

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

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


item_to_bin_0 ({
    BossId,
    Status,
    Hp,
    HpMax
}) ->
    Data = <<
        BossId:32,
        Status:32,
        Hp:64,
        HpMax:64
    >>,
    Data.
item_to_bin_1 ({
    RoleId,
    Name,
    Vip,
    Sex,
    Score
}) ->
    Bin_Name = pt:write_string(Name), 

    Data = <<
        RoleId:64,
        Bin_Name/binary,
        Vip:8,
        Sex:8,
        Score:32
    >>,
    Data.
item_to_bin_2 ({
    RoleId,
    Type,
    Name,
    Hurt
}) ->
    Bin_Name = pt:write_string(Name), 

    Data = <<
        RoleId:64,
        Type:8,
        Bin_Name/binary,
        Hurt:64
    >>,
    Data.
item_to_bin_3 ({
    BossId,
    RebornTime,
    Killer,
    IsFocus,
    KillCount
}) ->
    Bin_Killer = pt:write_string(Killer), 

    Data = <<
        BossId:32,
        RebornTime:32,
        Bin_Killer/binary,
        IsFocus:8,
        KillCount:8
    >>,
    Data.
item_to_bin_4 ({
    BossType,
    ServerNum,
    Killer,
    Scene,
    Boss,
    GoodsId,
    Time
}) ->
    Bin_Killer = pt:write_string(Killer), 

    Data = <<
        BossType:8,
        ServerNum:16,
        Bin_Killer/binary,
        Scene:32,
        Boss:32,
        GoodsId:32,
        Time:32
    >>,
    Data.
item_to_bin_5 ({
    GoodsId,
    Num
}) ->
    Data = <<
        GoodsId:32,
        Num:16
    >>,
    Data.
item_to_bin_6 ({
    SceneId,
    PoolId,
    Num
}) ->
    Data = <<
        SceneId:32,
        PoolId:16,
        Num:8
    >>,
    Data.
item_to_bin_7 ({
    SceneId,
    PoolId,
    MonId
}) ->
    Data = <<
        SceneId:32,
        PoolId:16,
        MonId:32
    >>,
    Data.
item_to_bin_8 ({
    RoleId,
    Name,
    Hurt
}) ->
    Bin_Name = pt:write_string(Name), 

    Data = <<
        RoleId:64,
        Bin_Name/binary,
        Hurt:64
    >>,
    Data.
