%% --------------------------------
%% module  :pp_marble.erl
%% time    :19/11/18
%% author  :hh
%% desc    :附能寻宝协议映射模块 
%%  TODO 后续弹珠要从此模块剥离出去
%% --------------------------------

-module(pp_marble).

-export([handle/3]).

-include("server.hrl").
-include("common.hrl").
-include("def_module.hrl").
-include("marble.hrl").

handle(Cmd, Player, Data) ->
    case lib_module:is_open(Player, ?MOD_MARBLE) of
        true ->
            do_handle(Cmd, Player, Data);
        _ ->
            ok
    end.

%% 充能弹珠界面
do_handle(41400, Player, _) ->
    lib_marble:marble_info(Player);

%% 开始抽奖
do_handle(41401, Player, [Type, CostOpt, StartTime]) ->
    lib_marble:start_marble(Player, Type, CostOpt, StartTime);

%% 抽奖结果
do_handle(41402, Player, [Result, QualId, Tokens]) ->
    lib_marble:marble_result(Player, Result, QualId, Tokens);

%% 领取充能节点奖励
% do_handle(41403, Player, [RewardId]) ->
%     lib_marble:energy_reward(Player, RewardId);

%% 手动充值充能数据
do_handle(41404, Player, _) ->
    lib_marble:reset_marble(Player);

%% 获取商店信息
do_handle(41405, Player, _) ->
    #player_status{sid = Sid, role_lattice_shop = RoleLatticeShop} = Player,
    #role_lattice_shop{shop_count = ShopCount, shop_info = ShopInfo} = RoleLatticeShop,
    Now = utime:unixtime(),
    EndTime = utime:unixtime({tomorrow, Now}),
    lib_server_send:send_to_sid(Sid, pt_414, 41405, [ShopCount, ShopInfo, EndTime]),
    ok;

%% 购买
do_handle(41406, Player, [Index]) ->
    lib_lattice_shop:shopping(Player, Index);

%% 手动刷新
do_handle(41407, Player, _) ->
    lib_lattice_shop:reset_shop(Player);

%% 兑换
do_handle(41408, Player, [ExchangeId, Num]) ->
    lib_marble:marble_exchange(Player, ExchangeId, Num);

%% 
do_handle(41409, Player, _) ->
    lib_lattice:get_role_lattice_info(Player),
    {ok, Player};

%%
do_handle(41410, Player, [Type]) ->
    lib_lattice:lattice_go(Type, Player);

%%
do_handle(41411, Player, _) ->
    lib_lattice:lattice_reset(Player);

do_handle(_Cmd, _Player, _Data) ->
    ?PRINT("~p ~p", [_Cmd, _Data]),
    ok.