%%%-------------------------------------------------------------------
%%% @author ljy
%%% @doc
%%%       幻魔宝典任务相关
%%% @end
%%% Created : 22. 9月 2020 11:59
%%%-------------------------------------------------------------------
-module(phantom_task_api).
-include("scene.hrl").
-include("phantom.hrl").
-include("def_module.hrl").

%% API
-export([
    kill_reward_boss_trigger/1
    , kill_guild_boss_trigger/2
    , kill_world_boss_trigger/2
    , kill_person_boss_trigger/1
    , kill_deserted_boss_trigger/1
    , is_in_scene/3
]).

%% 击杀赏金幻魔
kill_reward_boss_trigger(Player) ->
    custom_act_phantom:do_trigger_phantom_task(Player, ?BOUNTY_BOSS).

%% 击杀社团幻魔
kill_guild_boss_trigger(CopyId, Klist) ->
    is_in_scene(CopyId, Klist, ?GUILD_BOSS).

%% 击杀世界幻魔
kill_world_boss_trigger(CopyId, Klist) ->
    is_in_scene(CopyId, Klist, ?WORLD_BOSS).

%% 击杀个人幻魔
kill_person_boss_trigger(RoleId) ->
    custom_act_phantom:do_trigger_phantom_task(RoleId, ?PERSON_BOSS).

%% 击杀废都幻魔
kill_deserted_boss_trigger(RoleId) ->
    custom_act_phantom:trigger_phantom_task(RoleId, ?DESERTED_BOSS).

is_in_scene(CopyId, Klist, BossType) ->
    AllUser = lib_scene_agent:get_scene_user(CopyId),
    [begin
         case lists:keyfind(RoleId, #mon_atter.id, Klist) of
             #mon_atter{} ->
                 BossType == ?GUILD_BOSS andalso lib_role_legion:trigger_task(RoleId, ?MOD_GUILD_BOSS, 0),
                 custom_act_phantom:trigger_phantom_task(RoleId, BossType);
             _ -> skip
         end
     end || #ets_scene_user{id = RoleId} <- AllUser].