%%-----------------------------------------------------------------------------
%% @Module  :       lib_custom_act_do_daily_activity
%% @Author  :       Ywf
%% @Email   :       349162727@qq.com
%% @Created :       2019-05-13
%% @Description:	每日活跃
%%-----------------------------------------------------------------------------
-module (lib_custom_act_do_daily_activity).

-compile(export_all).
-include("custom_act.hrl").
-include("common.hrl").
-include("server.hrl").
-include("figure.hrl").
-include("errcode.hrl").
-include("def_fun.hrl").

count_common_progress(Player, #act_info{key = {?CUSTOM_ACT_TYPE_DAILY_ACTIVITY, _SubType}}) ->
    ZeroTime = utime:unixdate(),
    case lib_activitycalen_api:get_live_ness(Player, ZeroTime, ZeroTime + ?ONE_DAY_SECONDS - 1) of
        [{ZeroTime, LiveNess} | _T] -> LiveNess;
        _ -> 0
    end.

check_receive_reward_conditions(Player, #act_info{key = {?CUSTOM_ACT_TYPE_DAILY_ACTIVITY, SubType}}, RwCfg) ->
    #player_status{figure = #figure{lv = RoleLv}} = Player,
    #custom_act_reward_cfg{condition = Condition} = RwCfg,
    OpenLv = lib_custom_act_util:get_act_open_lv(?CUSTOM_ACT_TYPE_DAILY_ACTIVITY, SubType),
    case lib_custom_act_check:check_act_condtion([need_live], Condition) of
        [NeedLive] ->
            ZeroTime = utime:unixdate(),
            Live = case lib_activitycalen_api:get_live_ness(Player, ZeroTime, ZeroTime + ?ONE_DAY_SECONDS -1) of
                [{ZeroTime, LiveNess} | _T] -> LiveNess;
                _ -> 0
            end,
            if
                RoleLv < OpenLv -> {false, ?ERRCODE(err331_act_can_not_get)};
                Live < NeedLive -> {false, ?ERRCODE(err331_act_can_not_get)};
                true -> true
            end;
        _ ->
            {false, ?ERRCODE(err_config)}
    end.

check_reward_receive_times(#player_status{status_custom_act = #status_custom_act{reward_map = RewardMap}},
    #act_info{key = {Type = ?CUSTOM_ACT_TYPE_DAILY_ACTIVITY, SubType}}, #custom_act_reward_cfg{grade = GradeId}) ->
    case maps:get({Type, SubType, GradeId}, RewardMap, []) of
        #reward_status{utime = Utime, receive_times = ReceiveTimes} ->
            case Utime >= utime:unixdate() andalso ReceiveTimes > 0 of
                true -> false;
                false -> {true, 1}
            end;
        _ -> {true, 1}
    end.
