%%-----------------------------------------------------------------------------
%% @Module  :       lib_module
%% @Author  :       Czc
%% @Email   :       389853407@qq.com
%% @Created :       2017-10-27
%% @Description:
%%-----------------------------------------------------------------------------
-module(lib_module).

-include("def_module.hrl").
-include("def_event.hrl").
-include("rec_event.hrl").
-include("server.hrl").
-include("figure.hrl").
-include("custom_act.hrl").

-compile([export_all]).

%% TODO 由后台配置取代 代码

%% @doc 获得功能开放等级
get_open_lv(ModId) ->
    data_module:get_module_open_lv(ModId).

get_open_lv(ModId, SubId) ->
    data_module:get_module_open_lv(ModId, SubId).

%% @doc 获得功能开放天数
get_open_day(ModId) ->
    data_module:get_open_day(ModId).

%% @doc 功能是否已开放
is_open(Player, ModId) when is_record(Player, player_status) ->
    is_open(Player#player_status.figure#figure.lv, ModId);
is_open(RoleLv, ModId) ->
    OpenLv = get_open_lv(ModId),
    RoleLv >= OpenLv.

is_open(Player, ModId, SubId) when is_record(Player, player_status) ->
    is_open(Player#player_status.figure#figure.lv, ModId, SubId);
is_open(RoleLv, ModId, SubId) ->
    OpenLv = get_open_lv(ModId, SubId),
    RoleLv >= OpenLv.

handle_event(Player, #event_callback{type_id = ?EVENT_LV_UP}) when is_record(Player, player_status) ->
    OpenList = get_open_modlues(Player#player_status.figure#figure.lv),
    NewPlayer = handle_module_open(Player, OpenList),
    {ok, NewPlayer};

handle_event(Player, _) ->
    {ok, Player}.



get_open_modlues(Lv) ->
    List = [
    ],
    [M || {L, M} <- List, L =:= Lv].

handle_module_open(Player, [{Mod, Sub}|T]) ->
    mod_activitycalen:send_act_status(Mod, Sub, Player#player_status.id, Player#player_status.figure#figure.lv), %% 处理日常红点
    handle_module_open(Player, T);

handle_module_open(Player, []) -> Player.
