%%% -------------------------------------------------------
%%% @author huangyongxing@yeah.net
%%% @doc
%%% @end
%%% -------------------------------------------------------
-module(cli_battle).
-export([
        handle/3
        , do_revive/2
    ]).

-include("cli_simu.hrl").

%% 被杀通知（需要复活）
handle(20013, CliRole = #cli_role{}, _) ->
    %% 改血量为0，不会发起战斗，
    %% 需要复活成功后，重新从12002/12003协议的返回中获取到血量数据
    NewCliRole = CliRole#cli_role{hp = 0},
    ReviveType = 3,
    do_revive(NewCliRole, ReviveType),
    {ok, NewCliRole};

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

do_revive(#cli_role{scene_id = SceneId, x = X, y = Y, socket = Socket}, ReviveType) ->
    cli_simu_proto:pack_send(20004, [ReviveType]),
    %% 除了1原地复活之外，其他复活类型都需要重新加载场景
    case ReviveType =:= 1 of
        true  -> ignore;
        false ->
            %% 非原地复活，重新切换到死亡时的位置
            GmTokens = ["scene", SceneId, X, Y],
            cli_gm:send_gm(Socket, GmTokens),
            %% 加载场景
            cli_scene:async_load_scene()
    end.
