%%-----------------------------------------------------------------------------
%% module  :       lib_team_match.erl
%% @author  :       J
%% email   :       j-som@foxmail.com
%% Created :       2018-01-09
%% description:    组队匹配
%%-----------------------------------------------------------------------------

-module (lib_team_match).
-include ("team.hrl").
-include ("common.hrl").

-export ([
    get_match_mod/2
    ,try_match_fake_mb/1
]).

%% 诛邪战场的匹配代理
get_match_mod(2, 50) ->
    lib_evil_smashing_match;

get_match_mod(_ActivityId, _SubTypeId) ->
    undefined.

% try_match_fake_mb(#team{cls_type = ?NODE_GAME} = State) ->
%     Ref = util:send_after(State#team.fake_mb_ref, ?FAKE_JOIN_IN_TIME, self(), try_match_fake_mb),
%     {ok, State#team{fake_mb_ref = Ref}};
try_match_fake_mb(#team{is_task=IsTask} = State) when IsTask==true->
    #team{enlist = #team_enlist{activity_id = ActivityId, subtype_id = SubTypeId}} = State,
    TargetsNeedFakeMb = [{2,1}],
    case lists:member({ActivityId, SubTypeId}, TargetsNeedFakeMb) of
        true ->
            Ref = util:send_after(State#team.fake_mb_ref, 1000, self(), try_match_fake_mb),
            {ok, State#team{fake_mb_ref = Ref}};
        _ ->
            skip
    end;
try_match_fake_mb(#team{} = State) ->
    #team{enlist = #team_enlist{activity_id = ActivityId, subtype_id = SubTypeId}} = State,
    case data_team_ui:get(ActivityId, SubTypeId) of
        #team_enlist_cfg{auto_pair = ?MATCH_FAKE_YES} ->
            Ref = util:send_after(State#team.fake_mb_ref, ?FAKE_JOIN_IN_TIME, self(), try_match_fake_mb),
            {ok, State#team{fake_mb_ref = Ref}};
        _ -> skip
    end;

try_match_fake_mb(_) -> skip.