%%%--------------------------------------
%%% @Module  : lib_custom_act_do_joy_wish.hrl
%%% @Author  : lhy
%%% @Created : 2019-05-24
%%% @Description:  欢乐许愿
%%%--------------------------------------

-module(lib_custom_act_do_joy_wish).
-include("custom_act.hrl").
-include("common.hrl").
-include("server.hrl").
-include("figure.hrl").
-include("errcode.hrl").
-include("def_fun.hrl").
-include("goods.hrl").
-include("def_module.hrl").
-include("joy_wish.hrl").

-export([
    count_common_progress/2
	   ,check_receive_reward_conditions/3
]).
%% 计算奖励的达成进度
count_common_progress(Player, #act_info{key = {?CUSTOM_ACT_TYPE_JOY_WISH = Type, SubType}}) ->
    #player_status{joy_wish = #joy_wish{wish_times = JoyWishMaps}} = Player,
    WishTimes = maps:get({Type, SubType}, JoyWishMaps, 0),
    WishTimes.

%% 检查判断奖励的状态
check_receive_reward_conditions(Player, #act_info{key = {?CUSTOM_ACT_TYPE_JOY_WISH = Type, SubType}, wlv = Wlv}, RwCfg) ->
    #player_status{joy_wish = #joy_wish{wish_times = JoyWishMaps}} = Player,
    WishTimes = maps:get({Type, SubType}, JoyWishMaps, 0),
    #custom_act_reward_cfg{grade = _GradeId, condition = Condition} = RwCfg,
    case lib_custom_act_check:check_act_condtion([reward_type, wlv], Condition) of
    	[1, [LowerWlv, UpperWlv]] when Wlv >= LowerWlv andalso Wlv =< UpperWlv ->
            case lib_custom_act_check:check_act_condtion([wish_times], Condition) of
                [Times] when WishTimes >=Times ->
                    true;
                _ ->
                    {false, ?ERRCODE(err331_act_can_not_get)}
            end;
        _ ->
    		{false, ?ERRCODE(err331_can_not_pick_up)}
    end.
