%%%===================================================================
%%% @author zmh
%%% @doc 擂台赛  元宝擂台(钻石争霸战)
%%% @end
%%% @update by zzy 2017-11-08
%%%===================================================================
-module(pp_drum).
-include("server.hrl").
-include("common.hrl").
-include("drumwar.hrl").
-include("errcode.hrl").

-export([handle/3]).

%%活动状态
handle(13700, Status, [])->
	#player_status{sid = Sid}=Status,
	lib_role_drum:get_clock(Sid),
	{ok, Status};

%%请求展示面板
handle(13701, Status, [])->
	#player_status{id = Uid, sid = Sid, role_drum = RoleDrum}=Status,
	lib_role_drum:get_sign(Uid, RoleDrum, Sid),
	{ok, Status};

%%报名
handle(13702, Status, [])->
	#player_status{sid = Sid}=Status,
	case lib_role_drum:sign_up(Status) of
		{ok, NStatus}->
			{ok, NStatus};
		{false, Err}->?PRINT("error~p~n",[Err]),
			{ok, Bin} = pt_137:write(13702, [Err]),
			lib_server_send:send_to_sid(Sid, Bin),
			{ok, Status}
	end;

%%进入准备场景
handle(13704, Status, [])->
	#player_status{sid = Sid}=Status,
	case lib_role_drum:enter_ready(Status) of
		ok->
			ignore;
		{false,Err}->
			{ok,Bin} = pt_137:write(13704, [Err]),
			lib_server_send:send_to_sid(Sid, Bin)
	end,
	{ok, Status};

%%命数购买
handle(13706, Status, [Num])->
	#player_status{sid = Sid}=Status,
	case lib_role_drum:buy_live(Num, Status) of
		{ok, NStatus}->
			{ok, NStatus};
		{false, Err}->?PRINT("error~p~n",[Err]),
			{ok, Bin} = pt_137:write(13706, [Err, 0]),
			lib_server_send:send_to_sid(Sid, Bin),
			{ok, Status}
	end;

%%退出
handle(13707,Status,[Type]) when Type == 0->
	#player_status{sid = Sid}=Status,
	case lib_role_drum:leave_drum(Type, Status) of
		{ok, NStatus}->
			{ok, Bin} = pt_137:write(13707,[?SUCCESS]),
            lib_server_send:send_to_sid(Sid, Bin),
			{ok, NStatus};
		{false, Err}->
			{ok, Bin} = pt_137:write(13707,[Err]),
			lib_server_send:send_to_sid(Sid, Bin),
			{ok, Status}
	end;

%% 战斗开始
handle(13709, Status, []) ->
	lib_role_drum:active_mon(Status),
	{ok,Status};

%%命数请求
handle(13710,Status,[])->
	lib_role_drum:apply_live_info(Status),
	{ok,Status};

%% 战报
handle(13711,Status,[DrumID])->
	lib_role_drum:war_report(DrumID, Status),
	{ok,Status};

%%竞猜面板
handle(13713,Status,[])->
	lib_role_drum:fetch_guess(Status),
	{ok, Status};

%%竞猜
handle(13714,Status,[Type, Uid])->
	#player_status{sid = Sid}= Status,
	case lib_role_drum:choose_drum(Type, Uid, Status) of
		{ok, NStatus, Act}->
			{ok, Bin} = pt_137:write(13714,[1, Uid, Act]),
			lib_server_send:send_to_sid(Sid, Bin),
			{ok, NStatus};
		{false, Err}->?PRINT("error~p~n",[Err]),
			{ok, Bin} = pt_137:write(13714,[Err, Uid, 0]),
			lib_server_send:send_to_sid(Sid, Bin),
			{ok, Status}
	end;

%% 技能
handle(13715, Status, [SKillID]) ->
	#player_status{sid = Sid}=Status,
	{Res, RemainT, NStatus} = lib_role_drum:use_skill(SKillID,Status),
	{ok,Bin} = pt_137:write(13715,[Res,SKillID,RemainT]),
	lib_server_send:send_to_sid(Sid,Bin),
	{ok,NStatus};

%% 备战场景发弹幕
handle(13718, Status, [Msg, TkTime]) when is_list(Msg) ->
	lib_role_drum:send_ready_scene_msg(Status, Msg, TkTime);

handle(_Cmd, _Player, _Data) ->
	% util:errlog("M:~p, L:~p _Cmd:~p _Data:~p ~n", [?MODULE, ?LINE, _Cmd, {_Data,_Player#player_status.scene_old,_Player#player_status.copy_id_old}]),
	ok.