%%% -------------------------------------------------------
%%% @author huangyongxing@yeah.net
%%% @doc
%%% @end
%%% -------------------------------------------------------
-module(cli_player).
-export([
        handle/3
        , set_pk/2
        , async_get_my_info/0
    ]).

-include("cli_simu.hrl").

%% 获取到角色自身的信息
handle(13001, CliRole = #cli_role{id = _RoleId, socket = Socket}, [
        ServerId, Figure, SceneId, X, Y, Gold, Coin, Hp, HpLim, Speed, Attr
    ]) ->
    #figure{name = _Name, lv = _Level} = Figure,
    NewCliRole = CliRole#cli_role{server_id = ServerId, figure = Figure,
        scene_id = SceneId, x = X, y = Y,
        gold = Gold, coin = Coin, attr = Attr,
        hp = Hp, hp_lim = HpLim, speed = Speed
    },
    case Hp =< 0 of
        true  -> cli_battle:do_revive(Socket, 3);
        false -> ignore
    end,
    ?INFO_TTY("[~w,~ts] lv:~w,Scene:~w,~w,~w", [_RoleId, _Name, _Level, SceneId, X, Y]),
    {ok, NewCliRole};

%% 系统消息
handle(59004, _CliRole, _Code) ->
    throw({error, 59004, _Code}),
    ok;

handle(_, _, _) ->
    ignore.

set_pk(Socket, SetPkState) when SetPkState >= 0 andalso SetPkState =< 2 ->
    % Args = lists:concat(["[", SetPkState, "]"]),
    % GmTokens = ["cmd", 13012, Args],
    % send_gm(Socket, GmTokens);
    cli_simu_proto:pack_send(Socket, 13012, [SetPkState]);
set_pk(_, _SetPkState) ->
    throw({error, {set_pk, _SetPkState}}).

%% 异步获取本人信息
async_get_my_info() ->
    cli_simu_proto:pack_send(13001, []),
    cli_simu_proto:pack_send(21002, []),
    ok.

