%%%-------------------------------------------------------------------
%%% @author liushl
%%% @doc
%%%
%%% @end
%%%-------------------------------------------------------------------
-module(pp_guild_war).
-author("liushl").

-include("server.hrl").
-include("errcode.hrl").
%% API
-export([handle/3]).

%% 查看状态状态
handle(_Cmd = 40500, Player, _) ->
    guild_war_mgr:ask_guild_war_info(Player#player_status.id),
    ok;

%% 进入战场
handle(Cmd = 40501, Player, []) ->
    case guild_war_api:ask_enter_guild_war(Player, 0) of
        {false, Error} ->
            {ok, Bin} = pt_405:write(Cmd, [Error]),
            lib_server_send:send_to_sid(Player#player_status.sid, Bin);
        {ok, NewPlayer} ->
            {ok, NewPlayer}
    end;
handle(Cmd = 40501, Player, [PoolId]) when PoolId >= 0 ->
    case guild_war_api:ask_enter_guild_war(Player, PoolId) of
        {false, Error} ->
            {ok, Bin} = pt_405:write(Cmd, [Error]),
            lib_server_send:send_to_sid(Player#player_status.sid, Bin);
        {ok, NewPlayer} ->
            {ok, NewPlayer}
    end;

%% 退出战场
handle(_Cmd = 40502, Player, _) ->
    {ok, guild_war_api:leave_scene(Player)};

%% 战场信息-个人积分排名
handle(_Cmd = 40504, Player, _) ->
    guild_war_mgr:ask_role_rank(Player#player_status.sid),
    ok;

%% 战场信息-公会积分排名
handle(_Cmd = 40505, Player, _) ->
    guild_war_mgr:ask_guild_rank(Player#player_status.sid),
    ok;

%% 战场信息-采集提交
handle(Cmd = 40507, Player, [Npc]) ->
    {Error, NewPlayer} = guild_war_api:collect_commit(Player, Npc),
    {ok, Bin} = pt_405:write(Cmd, [Error]),
    lib_server_send:send_to_sid(Player#player_status.sid, Bin),
    {ok, NewPlayer};

%% 战场信息-上期明星社团
handle(_Cmd = 40509, Player, _) ->
    guild_war_api:ask_top_guild(Player#player_status.sid),
    ok;

%% 战场信息-护盾CD
handle(Cmd = 40513, Player, _) ->
    CdTime = guild_war_api:get_cd_time(Player#player_status.id),
    {ok, Bin} = pt_405:write(Cmd, [CdTime]),
    lib_server_send:send_to_sid(Player#player_status.sid, Bin),
    ok;

%% 使用护盾
handle(Cmd = 40514, Player, _) ->
    case guild_war_api:use_skill(Player) of
        [_|_] = Info ->
            {ok, Bin} = pt_405:write(Cmd, Info),
            lib_server_send:send_to_sid(Player#player_status.sid, Bin);
        _ ->
            ok
    end,
    ok;

handle(Cmd, _Player, Data) ->
    erlang:display({"[LIUSHL]", erlang:localtime(), ?MODULE, ?LINE, Cmd, Data}),
    ok.


