%%%------------------------------------
%%% @Module  : pp_rush_rank
%%% @Author  :  xiaoxiang
%%% @Created :  2016-11-17
%%% @Description: 通用榜单
%%%------------------------------------

-module(pp_rush_rank).

-compile(export_all).

-include("def_module.hrl").
-include("rush_rank.hrl").
-include("errcode.hrl").
-include("server.hrl").
-include("figure.hrl").
-include("common.hrl").
-include("custom_act.hrl").

%% 榜单信息
handle(22501, Player, [RankType, SubType]) ->
    % ?PRINT(" 22501 RankType:~p ~n", [RankType]),
    case lists:member(RankType, ?RANK_TYPE_LIST) of
        true ->
            {SelValue1,SelValue2,_,_,_} = lib_rush_rank:get_sel_value(Player, RankType),
            mod_rush_rank:send_rank_list(RankType, SubType, Player#player_status.id, SelValue1,SelValue2);
        false ->
            skip
    end,
    {ok,Player};

%% 目标奖励列表
handle(22502, Player, [SubType]) ->
    #player_status{id = RoleId} = Player,
    mod_rush_rank:send_goal_list(SubType, RoleId);

%% 领取目标奖励
handle(22503, Player, [RankType, SubType, GoalId]) ->
    case lists:member(RankType, ?RANK_TYPE_LIST) of
        true ->
            #player_status{id = RoleId, figure = #figure{lv = Lv}} = Player,
            case Lv >= lib_rush_rank:get_open_lv(?CUSTOM_ACT_TYPE_RUSH_RANK, SubType) of
                true ->
                    Reward = lib_rush_rank:get_cfg_goal_reward(RankType, GoalId),
                    %% 检查背包
                    case lib_goods_api:can_give_goods(Player, Reward) of
                        true ->
                            {SelValue,_,_,_,_} = lib_rush_rank:get_sel_value(Player, RankType),
                            mod_rush_rank:get_goal_reward(RoleId, RankType, SubType, GoalId, SelValue);
                        _ ->
                            lib_server_send:send_to_uid(RoleId, pt_225, 22503, [?ERRCODE(err150_no_cell), SubType])
                    end;
                _ -> skip
            end;
        false -> skip
    end;

%% 获取开服冲榜活动配置
handle(22510, Player, []) ->
    lib_rush_rank:send_cfg(Player#player_status.sid);

handle(_Cmd, _Player, _Data) ->
    ?PRINT(" Data:~p ~n", [_Data]),
    {error, "pp_common_rank no match~n"}.