%%%--------------------------------------
%%% @Module  : pp_act_turntable
%%% @Author  : ljy
%%% @Created : 2021.3.10
%%% @Description:  源能转盘
%%%--------------------------------------

-module(pp_act_turntable).

-export([handle/3]).
-include("server.hrl").
-include("common.hrl").
-include("figure.hrl").
-include("custom_act.hrl").
-include("def_module.hrl").

-type(player() :: #player_status{}).
-spec(handle(integer(), player(), list()) -> {ok, player()} | any()).

%% ===============================================================================================
handle(Cmd, Ps, Args) ->
    #player_status{figure = Figure} = Ps,
    #figure{lv = Lv} = Figure,
    ConfigLv = lib_module:get_open_lv(?MOD_AC_CUSTOM, ?CUSTOM_ACT_TYPE_TURNTABLE),
    case Lv >= ConfigLv of
        true ->
            do_handle(Cmd, Ps, Args);
        false ->
            skip
    end.

%% 奖池信息
do_handle(33501, Player, [SubType]) ->
    custom_act_turntable:get_pool_info(Player, SubType),
    ok;

%% 积分兑换信息
do_handle(33502, Player, [SubType]) ->
    custom_act_turntable:score_show_info(Player, SubType),
    ok;

%% 积分兑换
do_handle(33503, Player, [SubType, Id, Num]) when Num > 0 ->
    custom_act_turntable:score_swap(Player, SubType, Id, Num),
    ok;

%% 源能转盘-抽奖
do_handle(33504, Player, [SubType, LotteryType, IsSkip]) ->
    Result =
        case custom_act_turntable:lottery(Player, SubType, LotteryType, IsSkip) of
            {ok, NewPlayer} ->
                {ok, NewPlayer};
            {false, Err} ->
                {false, Err}
        end,
    case Result of
        {ok, NPlayer} ->
            {ok, NPlayer};
        {false, Error} ->
            lib_server_send:send_to_sid(Player#player_status.sid, pt_334, 33408, [Error, SubType, 0, 0, 0, []])
    end;

%% 源能转盘-全服记录
do_handle(33505, Player, [SubType]) ->
    custom_act_turntable:send_lottery_record(Player, SubType),
    ok;


do_handle(_Cmd, _Ps, _Args) ->
    ?ERR("pp_act_turntable cmd unmatch ~p ~p", [_Cmd, _Args]),
    ok.