%% ---------------------------------------------------------------------------
%% @doc lib_role.erl

%% @author  hjh
%% @email  hejiahua@163.com
%% @since  2016-12-26
%% @deprecated 角色辅助信息接口
%% ---------------------------------------------------------------------------
-module(lib_role_api).
-export([]).

-compile(export_all).

-include("server.hrl").
-include("def_event.hrl").
-include("figure.hrl").
-include("rec_event.hrl").
-include("common.hrl").
-include("def_module.hrl").
-include("activitycalen.hrl").
-include("team.hrl").


handle_event(Player, #event_callback{type_id = ?EVENT_LV_UP}) when is_record(Player, player_status) ->
    #player_status{id = RoleId, figure = Figure } = Player,
    lib_role:update_role_show(RoleId, [{figure, Figure}]),
    {ok, Player};

handle_event(Player, #event_callback{type_id = ?EVENT_PICTURE_CHANGE}) when is_record(Player, player_status) ->
    #player_status{id = RoleId, figure = Figure } = Player,
    lib_role:update_role_show(RoleId, [{figure, Figure}]),
    {ok, Player};

handle_event(Player, #event_callback{type_id = ?EVENT_VIP}) when is_record(Player, player_status) ->
    #player_status{id = RoleId, figure = Figure } = Player,
    lib_role:update_role_show(RoleId, [{figure, Figure}]),
    {ok, Player};

handle_event(Player, #event_callback{type_id = ?EVENT_RENAME}) when is_record(Player, player_status) ->
    #player_status{id = RoleId, figure = Figure } = Player,
    lib_role:update_role_show(RoleId, [{figure, Figure}]),
    {ok, Player};

handle_event(Player, #event_callback{type_id = ?EVENT_COMBAT_POWER}) when is_record(Player, player_status) ->
    #player_status{id = RoleId, combat_power = Combat, hightest_combat_power = HCombatPower} = Player,
    lib_role:update_role_show(RoleId, [{combat_power, Combat}, {h_combat_power, max(Combat, HCombatPower)}]),
    {ok, Player};

handle_event(Player, #event_callback{type_id = ?EVENT_TURN_UP}) when is_record(Player, player_status) ->
    #player_status{id = RoleId, figure = Figure } = Player,
    lib_role:update_role_show(RoleId, [{figure, Figure}]),
    {ok, Player};

handle_event(Player, #event_callback{type_id = ?EVENT_ONLINE_FLAG, data = OnlineFlag}) when is_record(Player, player_status) ->
    #player_status{id = RoleId, online = OldOnlineFlag} = Player,
    NowTime = utime:unixtime(),
    if
        OnlineFlag == ?ONLINE_ON ->
            lib_role:update_role_show(RoleId, [{last_login_time, NowTime}, {online_flag, ?ONLINE_ON}]);
        OldOnlineFlag == ?ONLINE_ON andalso OnlineFlag == ?ONLINE_OFF ->
            lib_role:update_role_show(RoleId, [{last_logout_time, NowTime}, {online_flag, ?ONLINE_OFF}]);
        true -> skip
    end,
    {ok, Player};

handle_event(Player, _) ->
    {ok, Player}.
