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

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

%% 羁绊基础信息
handle(Cmd = 14900, Player, []) ->
    List = mate_logic:mate_info(Player),
    lib_server_send:send_to_sid(Player#player_status.sid, pt_149, Cmd, [List]),
    ok;
%% 请求羁绊
handle(Cmd = 14901, Player, [TargetRole]) ->
    case mate_logic:ask_mate(Player, TargetRole) of
        {false, Err} ->
            lib_server_send:send_to_sid(Player#player_status.sid, pt_149, Cmd, [Err]);
        true ->
            lib_server_send:send_to_sid(Player#player_status.sid, pt_149, Cmd, [1])
    end,
    ok;
%% 请求羁绊消息
handle(_Cmd = 14902, Player, []) ->
    mate_mgr:get_ask_mate_info(Player#player_status.id),
    ok;
%% 回应请求羁绊
handle(Cmd = 14903, Player, [TargetRole, Type]) ->
    case mate_logic:response_mate_ask(Player, TargetRole, Type) of
        {false, Err} ->
            lib_server_send:send_to_sid(Player#player_status.sid, pt_149, Cmd, [Err, TargetRole, Type]),
            ok;
        {true, Player1} ->
            lib_server_send:send_to_sid(Player#player_status.sid, pt_149, Cmd, [1, TargetRole, Type]),
            {true, Player1}
    end;
%% 解除羁绊
handle(Cmd = 14905, Player, [TargetRole, Type]) ->
    case mate_logic:relieve_mate(Player, TargetRole, Type) of
        {false, Err} ->
            lib_server_send:send_to_sid(Player#player_status.sid, pt_149, Cmd, [Err, TargetRole, Type]),
            ok;
        {true, Player1} ->
            lib_server_send:send_to_sid(Player#player_status.sid, pt_149, Cmd, [1, TargetRole, Type]),
            {true, Player1}
    end;
%% 请求羁绊消息
handle(_Cmd = 14906, Player, []) ->
    mate_mgr:get_relieve_mate_info(Player#player_status.id),
    ok;
%% 回应请求羁绊
handle(Cmd = 14907, Player, [TargetRole, Type]) ->
    case mate_logic:response_mate_relieve(Player, TargetRole, Type) of
        {false, Err} ->
            lib_server_send:send_to_sid(Player#player_status.sid, pt_149, Cmd, [Err, TargetRole, Type]),
            ok;
        {true, Player1} ->
            lib_server_send:send_to_sid(Player#player_status.sid, pt_149, Cmd, [1, TargetRole, Type]),
            {true, Player1}
    end;
%% 解除羁绊预览
handle(Cmd = 14909, Player, [RoleId]) ->
    List = mate_logic:pre_show_intimacy_goods(Player, RoleId),
    FormatList = [{Id, Num} || {_Type, Id, Num} <- List],
    lib_server_send:send_to_sid(Player#player_status.sid, pt_149, Cmd, [RoleId, FormatList]),
    ok;
%% 修改羁绊称号
handle(Cmd = 14910, Player, [TargetRole, Title]) ->
    case mate_logic:modify_mate_title(Player, TargetRole, Title) of
        {false, Err} ->
            lib_server_send:send_to_sid(Player#player_status.sid, pt_149, Cmd, [Err, TargetRole, Title]),
            ok;
        {true, Player1} ->
            lib_server_send:send_to_sid(Player#player_status.sid, pt_149, Cmd, [1, TargetRole, Title]),
            {true, Player1}
    end;
%% 修改羁绊备注
handle(Cmd = 14911, Player, [TargetRole, Remarks]) ->
    case mate_logic:modify_mate_remarks(Player, TargetRole, Remarks) of
        {false, Err} ->
            lib_server_send:send_to_sid(Player#player_status.sid, pt_149, Cmd, [Err, TargetRole, Remarks]),
            ok;
        {true, Player1} ->
            lib_server_send:send_to_sid(Player#player_status.sid, pt_149, Cmd, [1, TargetRole, Remarks]),
            {true, Player1}
    end;
%% 领取纪念日奖励
handle(Cmd = 14912, Player, [TargetRole, Day]) ->
    case mate_logic:get_anniversary(Player, TargetRole, Day) of
        {false, Err} ->
            lib_server_send:send_to_sid(Player#player_status.sid, pt_149, Cmd, [Err, TargetRole, Day]),
            ok;
        {true, Player1} ->
            lib_server_send:send_to_sid(Player#player_status.sid, pt_149, Cmd, [1, TargetRole, Day]),
            {true, Player1}
    end;
%% 打开友谊的小船
handle(Cmd = 14913, Player, []) ->
    #player_status{mate = #role_mate{boat_stage = Stage, boat_star = Star, boat_exp = Exp}} = Player,
    lib_server_send:send_to_sid(Player#player_status.sid, pt_149, Cmd, [Stage, Star, Exp]),
    ok;
%% 强化友谊的小船
handle(Cmd = 14914, Player, []) ->
    case mate_logic:enhance_our_boat(Player) of
        {false, Err} ->
            lib_server_send:send_to_sid(Player#player_status.sid, pt_149, Cmd, [Err]),
            ok;
        {true, Player1} ->
            lib_server_send:send_to_sid(Player#player_status.sid, pt_149, Cmd, [1]),
            handle(14913, Player1, []),
            {true, Player1}
    end;
%% 佩戴羁绊称号
handle(Cmd = 14915, Player, [TargetRole, Type]) ->
    case mate_logic:wear_mate_title(Player, TargetRole, Type) of
        {false, Err} ->
            lib_server_send:send_to_sid(Player#player_status.sid, pt_149, Cmd, [Err, TargetRole, Type]),
            ok;
        {true, Player1} ->
            lib_server_send:send_to_sid(Player#player_status.sid, pt_149, Cmd, [1, TargetRole, Type]),
            {true, Player1}
    end;
%% 查看他人羁绊
handle(_Cmd = 14916, Player, [RoleA, RoleB]) ->
    mate_logic:ask_others_mate_info(Player#player_status.sid, RoleA, RoleB),
    ok;
%% 请求羁绊检查
handle(Cmd = 14917, Player, [TargetRole]) ->
    case mate_logic:check_be_mate(Player, TargetRole) of
        {false, Err} ->
            lib_server_send:send_to_sid(Player#player_status.sid, pt_149, Cmd, [Err]);
        true ->
            lib_server_send:send_to_sid(Player#player_status.sid, pt_149, Cmd, [1])
    end,
    ok;
%% 新手奖励领取状态
handle(Cmd = 14918, Player, []) ->
    #player_status{mate = #role_mate{newbee = Newbee}} = Player,
    lib_server_send:send_to_sid(Player#player_status.sid, pt_149, Cmd, [Newbee]),
    ok;
%% 新手奖励领取
handle(Cmd = 14919, Player, []) ->
    case mate_logic:get_newbee_reward(Player) of
        {true, Player1} ->
            lib_server_send:send_to_sid(Player#player_status.sid, pt_149, Cmd, [1]),
            handle(14918, Player1, []),
            {true, Player1};
        _ ->
            ok
    end;
%% 羁绊-活动 奖励获取情况
handle(Cmd = 14920, Player, []) ->
    [
        {_, ScoreRhythmMaster},
        {_, ScoreCatchBall}
    ] = lib_daily:get_count(
        Player#player_status.id,
        [
            {?MOD_MATE, ?DEFAULT_SUB_MODULE, ?MATE_ACT_RHYTHM_MASTER},
            {?MOD_MATE, ?DEFAULT_SUB_MODULE, ?MATE_ACT_CATCH_BALL}
        ]
    ),
    Info = [
        {?MATE_ACT_RHYTHM_MASTER, mate_mgr:is_mate_act_open(?MATE_ACT_RHYTHM_MASTER), ScoreRhythmMaster},
        {?MATE_ACT_CATCH_BALL, mate_mgr:is_mate_act_open(?MATE_ACT_CATCH_BALL), ScoreCatchBall}
    ],
    lib_server_send:send_to_sid(Player#player_status.sid, pt_149, Cmd, [Info]);
%%  羁绊-活动 邀请开始
handle(Cmd = 14921, Player, [TargetRole, ActId]) ->
    case mate_logic:mate_act_invite(Player, TargetRole, ActId) of
        {false, Err} ->
            lib_server_send:send_to_sid(Player#player_status.sid, pt_149, Cmd, [Err, TargetRole, ActId]);
        true ->
            lib_server_send:send_to_sid(Player#player_status.sid, pt_149, Cmd, [1, TargetRole, ActId])
    end,
    ok;
%%  羁绊-活动 邀请信息
handle(_Cmd = 14922, Player, []) ->
    mate_mgr:get_mate_act_invite_info(Player#player_status.id),
    ok;
%%  羁绊-活动 回应邀请
handle(Cmd = 14923, Player, [ActId, TargetRole, Res]) ->
    case mate_logic:mate_act_response(Player, TargetRole, ActId, Res) of
        {false, Err} ->
            lib_server_send:send_to_sid(Player#player_status.sid, pt_149, Cmd, [Err, ActId, TargetRole, Res]);
        true ->
            ok
    end,
    ok;
%%  羁绊-节奏大师 点击
handle(_Cmd = 14927, Player, [BitId, TargetRole]) ->
    mate_logic:mate_rhythm_tap(Player, BitId, TargetRole),
    ok;
%%  羁绊-活动 取消邀请
handle(_Cmd = 14931, Player, []) ->
    mate_logic:mate_act_cancel_invite(Player),
    ok;
%%  羁绊-请求结束
handle(_Cmd = 14933, Player, [TargetRole]) ->
    mate_mgr:mate_act_quit(Player#player_status.id, TargetRole),
    ok;
%%  羁绊-抛接球 一方点击中央球 游戏开始
handle(_Cmd = 14936, Player, [MateRole]) ->
    mate_logic:mate_catch_ball_begin(Player, MateRole),
    ok;
%%  羁绊-抛接球 击球
handle(_Cmd = 14937, Player, [MateRole]) ->
    mate_logic:mate_catch_ball_catch(Player, MateRole),
    ok;
%%  羁绊-活动 准备状态
handle(_Cmd = 14940, Player, [MateRole]) ->
    mate_logic:mate_act_get_ready_state(Player, MateRole),
    ok;
%%  羁绊-活动 准备
handle(_Cmd = 14941, Player, [MateRole]) ->
    mate_logic:mate_act_get_ready(Player, MateRole),
    ok;
%%  羁绊-交友大厅 查看信息
handle(_Cmd = 14942, Player, []) ->
    mate_mgr:ask_friendship_hall(Player#player_status.id),
    ok;
%%  羁绊-交友大厅 发布交友信息
handle(Cmd = 14943, Player, [Msg, Type]) ->
    case mate_logic:hall_release(Player, Msg, Type) of
        {false, Err} ->
            lib_server_send:send_to_sid(Player#player_status.sid, pt_149, Cmd, [Err]);
        {true, NewPlayer} ->
            lib_server_send:send_to_sid(Player#player_status.sid, pt_149, Cmd, [1]),
            {true, NewPlayer}
    end;
%% 羁绊-拍照 发出邀请
handle(Cmd = 14945, Player, []) ->
    case mate_logic:take_photo_invite(Player) of
        {false, Err} ->
            lib_server_send:send_to_sid(Player#player_status.sid, pt_149, Cmd, [Err]);
        true ->
            ok
    end;
%% 羁绊-拍照 回应邀请
handle(Cmd = 14947, Player, [Owner, PosId, Res]) ->
    case mate_logic:take_photo_response(Player, Owner, PosId, Res) of
        {false, Err} ->
            lib_server_send:send_to_sid(Player#player_status.sid, pt_149, Cmd, [Err]);
        _ ->
            ok
    end;
%% 羁绊-拍照 准备
handle(Cmd = 14949, Player, [Owner, PosType, Status]) ->
    case mate_logic:take_photo_ready(Player, Owner, PosType, Status) of
        {false, Err} ->
            lib_server_send:send_to_sid(Player#player_status.sid, pt_149, Cmd, [Err]);
        _ ->
            ok
    end;
%% 羁绊-拍照 拍照
handle(_Cmd = 14950, Player, []) ->
    mate_mgr:take_photo_do(Player#player_status.id),
    ok;
%% 羁绊-拍照 取消游戏
handle(_Cmd = 14952, Player, [Owner]) ->
    mate_mgr:take_photo_cancel(Player#player_status.id, Owner),
    ok;
%% 羁绊-日常 日常任务
handle(Cmd = 14953, Player, []) ->
    case mate_logic:refresh_mate_daily(Player, {mate_logic, get_task_info, []}) of
        {ok, NewPlayer} ->
            mate_logic:get_task_info(NewPlayer, []);
        {false, ErrCode} ->
            lib_server_send:send_to_sid(Player#player_status.sid, pt_149, Cmd, [ErrCode, [], []]);
        _ ->
            skip
    end;
%% 羁绊-日常 领取任务奖励
handle(Cmd = 14955, Player, [TargetId]) ->
    case mate_logic:refresh_mate_daily(Player, {mate_logic, receive_task_reward, [TargetId]}) of
        {ok, NewPlayer} ->
            case mate_logic:receive_task_reward(NewPlayer, [TargetId]) of
                {false, Err} ->
                    lib_server_send:send_to_sid(NewPlayer#player_status.sid, pt_149, Cmd, [Err, TargetId]);
                {ok, NewPlayer3} ->
                    {ok, NewPlayer3}
            end;
        {false, ErrCode} ->
            lib_server_send:send_to_sid(Player#player_status.sid, pt_149, Cmd, [ErrCode, TargetId]);
        _ ->
            skip
    end;
%% 羁绊-日常 完成私聊、羁绊分享任务
handle(_Cmd = 14956, Player, [TaskType, OtherId]) ->
    if
        TaskType == 1 ->
            mate_logic:update_take_progress(Player, [OtherId, ?TASK_TYPE_2]);
        TaskType == 2 ->
            mate_logic:update_take_progress(Player, [OtherId, ?TASK_TYPE_4]);
        true ->
            ignore
    end;

handle(Cmd, _Player, Arg) ->
    erlang:display({?MODULE, ?LINE, Cmd, Arg}),
    ok.



