%%%-------------------------------------------------------------------
%%% @author liushl
%%% @doc
%%%     战魂系统协议入口
%%% @end
%%%-------------------------------------------------------------------
-module(pp_warsoul).
-author("liushl").

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

%% 战魂系统-总战力
handle(Cmd = 14300, Player, []) ->
    #player_status{role_war_soul = #role_war_soul{total_power = TotalPower}} = Player,
    lib_server_send:send_to_sid(Player#player_status.sid, pt_143, Cmd, [TotalPower]);
%% 战魂系统-上阵
handle(Cmd = 14301, Player, [GoodsId, Pos]) ->
    case warsoul_logic:warsoul_wear(Player, Pos, GoodsId) of
        {false, Err} ->
            lib_server_send:send_to_sid(Player#player_status.sid, pt_143, Cmd, [Err, GoodsId]),
            ok;
        {ok, NewPlayer} ->
            lib_server_send:send_to_sid(Player#player_status.sid, pt_143, Cmd, [1, GoodsId]),
            {ok, NewPlayer}
    end;
%% 战魂系统-卸下
handle(Cmd = 14302, Player, [GoodsId]) ->
    case warsoul_logic:warsoul_off(Player, GoodsId) of
        {false, Err} ->
            lib_server_send:send_to_sid(Player#player_status.sid, pt_143, Cmd, [Err]),
            ok;
        {ok, NewPlayer} ->
            lib_server_send:send_to_sid(Player#player_status.sid, pt_143, Cmd, [1]),
            {ok, NewPlayer}
    end;
%% 战魂系统-强化
handle(Cmd = 14303, Player, [GoodsId, Location, Count]) ->
    case warsoul_logic:warsoul_strength(Player, GoodsId, Location, Count) of
        {false, Err} ->
            lib_server_send:send_to_sid(Player#player_status.sid, pt_143, Cmd, [Err, 0]),
            ok;
        {ok, NewPlayer, NewLv} ->
            lib_server_send:send_to_sid(Player#player_status.sid, pt_143, Cmd, [1, NewLv]),
            {ok, NewPlayer}
    end;
%% 战魂系统进化升星 pt_15204_[536870920213,1,[],[536870912002],0]
handle(Cmd = 14304, Player, [GoodsId, Location, ExtraGoodsList]) ->
    case warsoul_logic:warsoul_evolution(Player, GoodsId, Location, lists:usort(ExtraGoodsList) -- [GoodsId]) of
        {false, Err} ->
            lib_server_send:send_to_sid(Player#player_status.sid, pt_143, Cmd, [Err, GoodsId]);
        {ok, NewPlayer} ->
            lib_server_send:send_to_sid(Player#player_status.sid, pt_143, Cmd, [1, GoodsId]),
            {ok, NewPlayer}
    end;

%% 战魂系统-图鉴信息
handle(Cmd = 14305, Player, []) ->
    Info = warsoul_logic:get_collect_info(Player),
    lib_server_send:send_to_sid(Player#player_status.sid, pt_143, Cmd, Info);

%% 战魂系统-领取图鉴奖励
handle(Cmd = 14307, Player, []) ->
    case warsoul_logic:get_collect_award(Player) of
        {false, Err} ->
            lib_server_send:send_to_sid(Player#player_status.sid, pt_143, Cmd, [Err, 0]);
        {true, NewPlayer, NextLv} ->
            lib_server_send:send_to_sid(Player#player_status.sid, pt_143, Cmd, [1, NextLv]),
            {ok, NewPlayer}
    end;

%% 战魂系统-回退等级
handle(Cmd = 14308, Player, [GoodsId, Location]) ->
    case warsoul_logic:warsoul_strength_back(Player, GoodsId, Location) of
        {false, Err} ->
            lib_server_send:send_to_sid(Player#player_status.sid, pt_143, Cmd, [Err]);
        {ok, NewPlayer} ->
            lib_server_send:send_to_sid(Player#player_status.sid, pt_143, Cmd, [1]),
            {ok, NewPlayer}
    end;
%% 战魂系统-位置解锁状态
handle(Cmd = 14309, Player, []) ->
    #player_status{role_war_soul = #role_war_soul{pos_list = List}} = Player,
    lib_server_send:send_to_sid(Player#player_status.sid, pt_143, Cmd, [List]);
%% 战魂系统-解锁位置
handle(Cmd = 14310, Player, [Pos]) ->
    case warsoul_logic:unlock_pos(Player, Pos) of
        {false, Err} ->
            lib_server_send:send_to_sid(Player#player_status.sid, pt_143, Cmd, [Err, Pos]);
        {ok, NewPlayer} ->
            lib_server_send:send_to_sid(Player#player_status.sid, pt_143, Cmd, [1, Pos]),
            {ok, NewPlayer}
    end;
handle(Cmd, _Player, Arg) ->
    erlang:display({?MODULE, ?LINE, Cmd, Arg}),
    ok.