%% ---------------------------------------------------------
%% Author:  zmh
%% Created: 20201020
%% Description: 魂力
%% --------------------------------------------------------
-module(pp_uranium).
-export([handle/3]).
-include("server.hrl").
-include("goods.hrl").
-include("predefine.hrl").
-include("role_uranium.hrl").
-include("errcode.hrl").
-include("def_module.hrl").
-include("def_goods.hrl").

%%获取信息
handle(14400, Status, []) ->
    #player_status{
        id=RoleID,
        role_uranium = RoleUranium
    } = Status,
    #role_uranium{
        grade = Grade,
        lv = Lv,
        power = Power,
        % init_time  = ITime,
        % start_time = HTime,
        % quick_time = QTime
        have_energy = HaveEnergy
    }=RoleUranium,
    % Total = data_uranium:get_grade_total(Grade),
    % TailTime = Total+ITime-QTime,
    % {ok,Bin} = pt_144:write(14400,[Grade,Lv,Power,HTime,TailTime]),
    {ok, Bin} = pt_144:write(14400, [Grade, Lv, Power, HaveEnergy]),
    lib_server_send:send_to_uid(RoleID,Bin),
    {ok,Status};

%%升级
handle(14401,Status,[AutoNum]) when is_integer(AutoNum) andalso AutoNum > 0->
    #player_status{id=RoleID} = Status,
    case lib_role_uranium:uranium_lv(Status, AutoNum) of
        {ok,NStatus}->
            handle(14400,NStatus,[]),
            Res = ?SUCCESS;
        {false,Res}->
            NStatus = Status
    end,
    {ok,Bin} = pt_144:write(14401,[Res]),
    lib_server_send:send_to_uid(RoleID,Bin),
    {ok,NStatus};

%%进阶
handle(14402,Status,[])->
    #player_status{id=RoleID} = Status,
    case lib_role_uranium:uranium_grade(Status) of
        {ok,NStatus}->
            handle(14400,NStatus,[]),
            Res = ?SUCCESS;
        {false,Res}->
            NStatus = Status
    end,
    {ok,Bin} = pt_144:write(14402,[Res]),
    lib_server_send:send_to_uid(RoleID,Bin),
    {ok,NStatus};

%%充能
% handle(14403,Status,[])->
%     #player_status{id=RoleID} = Status,
%     case lib_role_uranium:uranium_quick(Status) of
%         {ok,NStatus}->
%             handle(14400,NStatus,[]),
%             Res = ?SUCCESS;
%         {false,Res}->
%             NStatus = Status
%     end,
%     {ok,Bin} = pt_144:write(14403,[Res]),
%     lib_server_send:send_to_uid(RoleID,Bin),
%     {ok,NStatus};

handle(_Cmd, _Status, _Data) ->
    {error, "pp_visus no match"}.
