%%% -------------------------------------------------------
%%% @author huangyongxing@yeah.net
%%% @doc
%%% 战斗对象挑选处理
%%% 主要包括技能BUFF作用对象、一些AI对象选择等等
%%% @end
%%% -------------------------------------------------------
-module(battle_obj_select).
-include("battle_obj_select.hrl").
-include("battle.hrl").
-include("skill.hrl").

-export([
        get_affected_parties/1
        ,set_affected_parties/1
        ,set_affected_parties_noaction/1
    ]).

%% 获取BUFF作用方与相反的另一方
get_affected_parties(ArgsGetAffects) ->
    #args_get_affects{
        affect = AffectedParties,
        aer = Aer, der = Der, aer_init = OldAer, der_init = OldDer,
        aer_buff = AerBuffList, der_buff = DerBuffList
    } = ArgsGetAffects,
    case AffectedParties of
        ?SKILL_AFFECT_MYSELF ->
            #ret_get_affects{user = Aer, user_buff = AerBuffList, user_init = OldAer,
                oppo_user = Der, oppo_user_buff = DerBuffList, oppo_user_init = OldDer
            };
        _ ->
            #ret_get_affects{user = Der, user_buff = DerBuffList, user_init = OldDer,
                oppo_user = Aer, oppo_user_buff = AerBuffList, oppo_user_init = OldAer
            }
    end.

%% 设置BUFF效果受影响方的信息
%% 当设置了OppoUser时，表明是同时更新双方数据（此时aer、der参数无意义，可不提供）
%% 当未设置时，表明只更新其中一方数据，此时必须提供aer、der、affect_user相关数据
set_affected_parties(ArgsSetAffects) ->
    #args_set_affects{
        affect = AffectedParties,
        aer = Aer, der = Der, aer_buff = AerBuffL, der_buff = DerBuffL,
        affect_user = User, affect_user_buff = UserBuffL,
        oppo_user = OppoUser, oppo_user_buff = OppoUserBuffL
    } = ArgsSetAffects,
    case OppoUser of
        #battle_status{} ->
            case AffectedParties of
                ?SKILL_AFFECT_MYSELF ->
                    #ret_set_affects{aer = User, aer_buff = UserBuffL,
                        der = OppoUser, der_buff = OppoUserBuffL
                    };
                _ ->
                    #ret_set_affects{aer = OppoUser, aer_buff = OppoUserBuffL,
                        der = User, der_buff = UserBuffL
                    }
            end;
        _ ->
            case AffectedParties of
                ?SKILL_AFFECT_MYSELF ->
                    #ret_set_affects{aer = User, aer_buff = UserBuffL,
                        der = Der, der_buff = DerBuffL
                    };
                _ ->
                    #ret_set_affects{aer = Aer, aer_buff = AerBuffL,
                        der = User, der_buff = UserBuffL
                    }
            end
    end.

%% 主要目的在于需要保持用户原样数据时，
%% 方便得到与set_affected_parties同样的返回值，实际上啥也不做
%% 这里要求传递正确的Aer、Der、AerBuffL、DerBuffL
set_affected_parties_noaction(#args_set_affects{
        aer = Aer, der = Der, aer_buff = AerBuffL, der_buff = DerBuffL
    }) ->
    #ret_set_affects{
        aer = Aer, aer_buff = AerBuffL,
        der = Der, der_buff = DerBuffL
    }.

