%%%------------------------------------
%%% @Module  :  lib_ranking_api
%%% @Author  :  xiaoxiang
%%% @Created :  2016-11-17
%%% @Description: 榜单
%%%------------------------------------

-module(lib_rush_rank_api).

-export([
    handle_event/2,
    login/1,
    refresh_rank_by_foster/2,
    refresh_rank_by_combat/1,
    reload_handle/0
]).

-compile(export_all).

-include("rush_rank.hrl").
-include("server.hrl").
-include("figure.hrl").
-include("def_event.hrl").
-include("rec_event.hrl").
-include("predefine.hrl").
-include("common.hrl").
-include("custom_act.hrl").
-include("role_foster.hrl").

handle_event(Player, #event_callback{type_id = ?EVENT_COMBAT_POWER}) ->
    refresh_rank_by_combat(Player),
    {ok, Player};
handle_event(Player, _Ec) ->
    {ok, Player}.

%% 热更监听
reload_handle() ->
    lib_rush_rank:send_cfg_to_all(),
    ok.


%%1-8培养系统一一对应独占
%%同时需要更新对应进阶单
refresh_rank_by_foster(Type,Player)->
    refresh_rush_rank(Player,Type),
    case lists:member(Type,  ?RANK_TYPE_COMBAT_GRADE_LIST) of
        true ->
            skip;
        _ ->
            refresh_rush_rank(Player,?OFFSET_TYPE+Type)
    end.
refresh_rank_by_combat(Player)->
    refresh_rush_rank(Player, ?RANK_TYPE_RUSH_COMBAT).

%% 登录时刷一遍
login(Player) ->
    refresh_rush_rank_by_all(Player),
    Player.

refresh_rush_rank(Player, RankType) ->
    SubList = lib_custom_act_api:get_open_subtype_ids(?CUSTOM_ACT_TYPE_RUSH_RANK),
    [refresh_rush_rank(Player, RankType, SubType) || SubType <- SubList].

%% 刷新榜单,最好在里面统一处理,修改方便
refresh_rush_rank(Player, RankType, SubType) ->
    case lists:member(RankType, ?RANK_TYPE_LIST) of
        true ->
            case lib_rush_rank:get_refresh_limit(RankType) of
                true ->
                    lib_rush_rank:refresh_rush_rank({RankType, SubType}, Player);
                false -> skip
            end;
        false -> skip
    end.

%% 刷新所有榜单。
refresh_rush_rank_by_all(Player) ->
    [refresh_rush_rank(Player, RankType) || RankType <- data_rush_rank:get_id_list()],
    ok.
