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

read(15000, Bin0) ->
    <<RoleId:64, Bin1/binary>> = Bin0, 
    <<GoodsId:64, Bin2/binary>> = Bin1, 
    <<TypeId:32, _Bin3/binary>> = Bin2, 
    {ok, [RoleId, GoodsId, TypeId]};
read(15002, Bin0) ->
    <<Pos:16, Bin1/binary>> = Bin0, 
    <<CellNum:16, _Bin2/binary>> = Bin1, 
    {ok, [Pos, CellNum]};
read(15003, Bin0) ->
    <<GoodId:64, Bin1/binary>> = Bin0, 
    <<FromPos:16, Bin2/binary>> = Bin1, 
    <<ToPos:16, _Bin3/binary>> = Bin2, 
    {ok, [GoodId, FromPos, ToPos]};
read(15004, Bin0) ->
    <<Pos:16, _Bin1/binary>> = Bin0, 
    {ok, [Pos]};
read(15005, Bin0) ->
    <<GoodId:64, Bin1/binary>> = Bin0, 
    <<TypeId:32, Bin2/binary>> = Bin1, 
    <<Num:32, _Bin3/binary>> = Bin2, 
    {ok, [GoodId, TypeId, Num]};
read(15008, Bin0) ->
    <<CurrencyId:32, _Bin1/binary>> = Bin0, 
    {ok, [CurrencyId]};
read(15009, _) ->
    {ok, []};
read(15010, Bin0) ->
    <<Pos:16, _Bin1/binary>> = Bin0, 
    {ok, [Pos]};
read(15011, Bin0) ->
    <<ModuleId:16, Bin1/binary>> = Bin0, 
    <<PlayerId:64, _Bin2/binary>> = Bin1, 
    {ok, [ModuleId, PlayerId]};
read(15019, Bin0) ->
    FunArray0 = fun(<<RestBin0/binary>>) -> 
        <<GoodsId:64, _Args1/binary>> = RestBin0, 
        <<TypeId:32, _Args2/binary>> = _Args1, 
        <<GoodsNum:32, _Args3/binary>> = _Args2, 
        {{GoodsId, TypeId, GoodsNum},_Args3}
        end,
    {GoodsList, _Bin1} = pt:read_array(FunArray0, Bin0),

    {ok, [GoodsList]};
read(15021, Bin0) ->
    FunArray0 = fun(<<RestBin0/binary>>) -> 
        <<GoodsId:64, _Args1/binary>> = RestBin0, 
        <<TypeId:32, _Args2/binary>> = _Args1, 
        <<Num:32, _Args3/binary>> = _Args2, 
        {{GoodsId, TypeId, Num},_Args3}
        end,
    {GoodsList, _Bin1} = pt:read_array(FunArray0, Bin0),

    {ok, [GoodsList]};
read(15022, Bin0) ->
    <<GoldExchange:16, Bin1/binary>> = Bin0, 
    <<GoodsExchange:16, _Bin2/binary>> = Bin1, 
    {ok, [GoldExchange, GoodsExchange]};
read(15023, _) ->
    {ok, []};
read(15024, Bin0) ->
    FunArray0 = fun(<<RestBin0/binary>>) -> 
        <<GoodsId:64, _Args1/binary>> = RestBin0, 
        {GoodsId,_Args1}
        end,
    {GoodsList, _Bin1} = pt:read_array(FunArray0, Bin0),

    {ok, [GoodsList]};
read(15025, Bin0) ->
    <<IsAutoSwallow:8, _Bin1/binary>> = Bin0, 
    {ok, [IsAutoSwallow]};
read(15026, _) ->
    {ok, []};
read(15027, _) ->
    {ok, []};
read(15050, Bin0) ->
    <<GoodsId:64, Bin1/binary>> = Bin0, 
    <<TypeId:32, Bin2/binary>> = Bin1, 
    <<Num:32, _Bin3/binary>> = Bin2, 
    {ok, [GoodsId, TypeId, Num]};
read(15051, Bin0) ->
    <<DestroyType:8, Bin1/binary>> = Bin0, 
    FunArray0 = fun(<<RestBin0/binary>>) -> 
        <<GoodsId:64, _Args1/binary>> = RestBin0, 
        <<TypeId:32, _Args2/binary>> = _Args1, 
        <<Num:32, _Args3/binary>> = _Args2, 
        {{GoodsId, TypeId, Num},_Args3}
        end,
    {DestroyList, _Bin2} = pt:read_array(FunArray0, Bin1),

    {ok, [DestroyType, DestroyList]};
read(15053, Bin0) ->
    <<DropId:32, _Bin1/binary>> = Bin0, 
    {ok, [DropId]};
read(15054, _) ->
    {ok, []};
read(15055, _) ->
    {ok, []};
read(15085, Bin0) ->
    <<GoodsId:32, _Bin1/binary>> = Bin0, 
    {ok, [GoodsId]};
read(15086, Bin0) ->
    <<GiftId:64, Bin1/binary>> = Bin0, 
    <<GoodsId:32, Bin2/binary>> = Bin1, 
    <<Num:32, Bin3/binary>> = Bin2, 
    FunArray0 = fun(<<RestBin0/binary>>) -> 
        <<Seqno:8, _Args1/binary>> = RestBin0, 
        <<Seqnum:16, _Args2/binary>> = _Args1, 
        {{Seqno, Seqnum},_Args2}
        end,
    {SeqList, _Bin4} = pt:read_array(FunArray0, Bin3),

    {ok, [GiftId, GoodsId, Num, SeqList]};
read(15087, Bin0) ->
    <<TypeId:64, _Bin1/binary>> = Bin0, 
    {ok, [TypeId]};
read(15088, _) ->
    {ok, []};
read(_Cmd, _R) -> {error, no_match}.

write (15000,[
    Power,
    GoodsId,
    TypeId,
    Cell,
    GoodsNum,
    Bind,
    ExpireTime,
    ConvertTime,
    OtherData
] = Src_Data) ->
    BinList_OtherData = [
        item_to_bin_0(OtherData_Item) || OtherData_Item <- OtherData
    ], 

    OtherData_Len = length(OtherData), 
    Bin_OtherData = list_to_binary(BinList_OtherData),

    Data = <<
        Power:64,
        GoodsId:64,
        TypeId:32,
        Cell:32,
        GoodsNum:32,
        Bind:8,
        ExpireTime:32,
        ConvertTime:32,
        OtherData_Len:16, Bin_OtherData/binary
    >>,
    {ok, pt:encode(15000, Data, Src_Data)};

write (15002,[
    Code,
    Pos,
    CellNum
] = Src_Data) ->
    Data = <<
        Code:32,
        Pos:16,
        CellNum:16
    >>,
    {ok, pt:encode(15002, Data, Src_Data)};

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

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

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

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

write (15009,[
    CurrencyList
] = Src_Data) ->
    BinList_CurrencyList = [
        item_to_bin_1(CurrencyList_Item) || CurrencyList_Item <- CurrencyList
    ], 

    CurrencyList_Len = length(CurrencyList), 
    Bin_CurrencyList = list_to_binary(BinList_CurrencyList),

    Data = <<
        CurrencyList_Len:16, Bin_CurrencyList/binary
    >>,
    {ok, pt:encode(15009, Data, Src_Data)};

write (15010,[
    Pos,
    CellNum,
    MaxCell,
    DefCell,
    GoodsList
] = Src_Data) ->
    BinList_GoodsList = [
        item_to_bin_2(GoodsList_Item) || GoodsList_Item <- GoodsList
    ], 

    GoodsList_Len = length(GoodsList), 
    Bin_GoodsList = list_to_binary(BinList_GoodsList),

    Data = <<
        Pos:16,
        CellNum:16,
        MaxCell:16,
        DefCell:16,
        GoodsList_Len:16, Bin_GoodsList/binary
    >>,
    {ok, pt:encode(15010, Data, Src_Data)};

write (15011,[
    ModuleId,
    PlayerId,
    EquipList,
    MateStage,
    MateStar,
    Power
] = Src_Data) ->
    BinList_EquipList = [
        item_to_bin_4(EquipList_Item) || EquipList_Item <- EquipList
    ], 

    EquipList_Len = length(EquipList), 
    Bin_EquipList = list_to_binary(BinList_EquipList),

    Data = <<
        ModuleId:16,
        PlayerId:64,
        EquipList_Len:16, Bin_EquipList/binary,
        MateStage:8,
        MateStar:8,
        Power:64
    >>,
    {ok, pt:encode(15011, Data, Src_Data)};

write (15017,[
    Pos,
    ProduceType,
    GoodsList
] = Src_Data) ->
    BinList_GoodsList = [
        item_to_bin_6(GoodsList_Item) || GoodsList_Item <- GoodsList
    ], 

    GoodsList_Len = length(GoodsList), 
    Bin_GoodsList = list_to_binary(BinList_GoodsList),

    Data = <<
        Pos:16,
        ProduceType:16,
        GoodsList_Len:16, Bin_GoodsList/binary
    >>,
    {ok, pt:encode(15017, Data, Src_Data)};

write (15018,[
    Pos,
    GoodsList
] = Src_Data) ->
    BinList_GoodsList = [
        item_to_bin_8(GoodsList_Item) || GoodsList_Item <- GoodsList
    ], 

    GoodsList_Len = length(GoodsList), 
    Bin_GoodsList = list_to_binary(BinList_GoodsList),

    Data = <<
        Pos:16,
        GoodsList_Len:16, Bin_GoodsList/binary
    >>,
    {ok, pt:encode(15018, Data, Src_Data)};

write (15019,[
    Code,
    GoodsList
] = Src_Data) ->
    BinList_GoodsList = [
        item_to_bin_9(GoodsList_Item) || GoodsList_Item <- GoodsList
    ], 

    GoodsList_Len = length(GoodsList), 
    Bin_GoodsList = list_to_binary(BinList_GoodsList),

    Data = <<
        Code:32,
        GoodsList_Len:16, Bin_GoodsList/binary
    >>,
    {ok, pt:encode(15019, Data, Src_Data)};

write (15021,[
    Res,
    TypeIdList
] = Src_Data) ->
    BinList_TypeIdList = [
        item_to_bin_10(TypeIdList_Item) || TypeIdList_Item <- TypeIdList
    ], 

    TypeIdList_Len = length(TypeIdList), 
    Bin_TypeIdList = list_to_binary(BinList_TypeIdList),

    Data = <<
        Res:32,
        TypeIdList_Len:16, Bin_TypeIdList/binary
    >>,
    {ok, pt:encode(15021, Data, Src_Data)};

write (15022,[
    Errcode,
    IsCrit
] = Src_Data) ->
    Data = <<
        Errcode:32,
        IsCrit:8
    >>,
    {ok, pt:encode(15022, Data, Src_Data)};

write (15023,[
    Lv,
    Exp,
    IsAutoSwallow,
    Active
] = Src_Data) ->
    Data = <<
        Lv:16,
        Exp:32,
        IsAutoSwallow:8,
        Active:16
    >>,
    {ok, pt:encode(15023, Data, Src_Data)};

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

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

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

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

write (15050,[
    Res,
    GoodsId,
    GoodsTypeId,
    GoodsNum,
    Hp,
    Num,
    ShowGoods
] = Src_Data) ->
    BinList_ShowGoods = [
        item_to_bin_11(ShowGoods_Item) || ShowGoods_Item <- ShowGoods
    ], 

    ShowGoods_Len = length(ShowGoods), 
    Bin_ShowGoods = list_to_binary(BinList_ShowGoods),

    Data = <<
        Res:32,
        GoodsId:64,
        GoodsTypeId:32,
        GoodsNum:32,
        Hp:32,
        Num:32,
        ShowGoods_Len:16, Bin_ShowGoods/binary
    >>,
    {ok, pt:encode(15050, Data, Src_Data)};

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

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

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

write (15055,[
    PlayerId,
    BuffList
] = Src_Data) ->
    BinList_BuffList = [
        item_to_bin_12(BuffList_Item) || BuffList_Item <- BuffList
    ], 

    BuffList_Len = length(BuffList), 
    Bin_BuffList = list_to_binary(BinList_BuffList),

    Data = <<
        PlayerId:64,
        BuffList_Len:16, Bin_BuffList/binary
    >>,
    {ok, pt:encode(15055, Data, Src_Data)};

write (15085,[
    GoodsId,
    Count
] = Src_Data) ->
    Data = <<
        GoodsId:32,
        Count:8
    >>,
    {ok, pt:encode(15085, Data, Src_Data)};

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

write (15087,[
    TypeId,
    GiftbagType,
    RandomTime,
    RandomRewardList,
    FixRewardList
] = Src_Data) ->
    BinList_RandomRewardList = [
        item_to_bin_13(RandomRewardList_Item) || RandomRewardList_Item <- RandomRewardList
    ], 

    RandomRewardList_Len = length(RandomRewardList), 
    Bin_RandomRewardList = list_to_binary(BinList_RandomRewardList),

    Bin_FixRewardList = pt:write_object_list(FixRewardList), 

    Data = <<
        TypeId:64,
        GiftbagType:8,
        RandomTime:8,
        RandomRewardList_Len:16, Bin_RandomRewardList/binary,
        Bin_FixRewardList/binary
    >>,
    {ok, pt:encode(15087, Data, Src_Data)};

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

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


item_to_bin_0 ({
    Type,
    Info
}) ->
    Bin_Info = pt:write_string(Info), 

    Data = <<
        Type:8,
        Bin_Info/binary
    >>,
    Data.
item_to_bin_1 ({
    CurrencyId,
    Num
}) ->
    Data = <<
        CurrencyId:32,
        Num:32
    >>,
    Data.
item_to_bin_2 ({
    GoodsId,
    TypeId,
    Cell,
    GoodsNum,
    Bind,
    ExpireTime,
    ConvertTime,
    OtherData
}) ->
    BinList_OtherData = [
        item_to_bin_3(OtherData_Item) || OtherData_Item <- OtherData
    ], 

    OtherData_Len = length(OtherData), 
    Bin_OtherData = list_to_binary(BinList_OtherData),

    Data = <<
        GoodsId:64,
        TypeId:32,
        Cell:32,
        GoodsNum:32,
        Bind:8,
        ExpireTime:32,
        ConvertTime:32,
        OtherData_Len:16, Bin_OtherData/binary
    >>,
    Data.
item_to_bin_3 ({
    Type,
    Info
}) ->
    Bin_Info = pt:write_string(Info), 

    Data = <<
        Type:8,
        Bin_Info/binary
    >>,
    Data.
item_to_bin_4 ({
    GoodsId,
    TypeId,
    Cell,
    OtherData
}) ->
    BinList_OtherData = [
        item_to_bin_5(OtherData_Item) || OtherData_Item <- OtherData
    ], 

    OtherData_Len = length(OtherData), 
    Bin_OtherData = list_to_binary(BinList_OtherData),

    Data = <<
        GoodsId:64,
        TypeId:32,
        Cell:32,
        OtherData_Len:16, Bin_OtherData/binary
    >>,
    Data.
item_to_bin_5 ({
    Type,
    Info
}) ->
    Bin_Info = pt:write_string(Info), 

    Data = <<
        Type:8,
        Bin_Info/binary
    >>,
    Data.
item_to_bin_6 ({
    GoodsId,
    TypeId,
    Cell,
    GoodsNum,
    Bind,
    ExpireTime,
    ConvertTime,
    OtherData
}) ->
    BinList_OtherData = [
        item_to_bin_7(OtherData_Item) || OtherData_Item <- OtherData
    ], 

    OtherData_Len = length(OtherData), 
    Bin_OtherData = list_to_binary(BinList_OtherData),

    Data = <<
        GoodsId:64,
        TypeId:32,
        Cell:32,
        GoodsNum:32,
        Bind:8,
        ExpireTime:32,
        ConvertTime:32,
        OtherData_Len:16, Bin_OtherData/binary
    >>,
    Data.
item_to_bin_7 ({
    Type,
    Info
}) ->
    Bin_Info = pt:write_string(Info), 

    Data = <<
        Type:8,
        Bin_Info/binary
    >>,
    Data.
item_to_bin_8 ({
    GoodsId,
    GoodsNum,
    TypeId
}) ->
    Data = <<
        GoodsId:64,
        GoodsNum:32,
        TypeId:32
    >>,
    Data.
item_to_bin_9 ({
    GoodsId,
    TypeId,
    GoodsNum
}) ->
    Data = <<
        GoodsId:64,
        TypeId:32,
        GoodsNum:32
    >>,
    Data.
item_to_bin_10 ({
    TypeId,
    Num
}) ->
    Data = <<
        TypeId:32,
        Num:32
    >>,
    Data.
item_to_bin_11 ({
    Type,
    Goodid,
    Gnum
}) ->
    Data = <<
        Type:8,
        Goodid:32,
        Gnum:32
    >>,
    Data.
item_to_bin_12 ({
    GoodsId,
    BuffType,
    EffectList,
    Time,
    SingleTime
}) ->
    Bin_EffectList = pt:write_string(EffectList), 

    Data = <<
        GoodsId:32,
        BuffType:8,
        Bin_EffectList/binary,
        Time:32,
        SingleTime:32
    >>,
    Data.
item_to_bin_13 ({
    GoodsType,
    GoodsId,
    GoodsNum
}) ->
    Data = <<
        GoodsType:8,
        GoodsId:32,
        GoodsNum:16
    >>,
    Data.
