%% -----------------------------------
%% desc     :万物宝典任务相关
%% module   :contract_task_api.erl
%% author   :hh
%% time     :20/08/28
%% -----------------------------------

-module(contract_task_api).

-include("custom_act.hrl").
-include("contract.hrl").
-include("server.hrl").
-include("predefine.hrl").
-include("dungeon.hrl").
-include("common.hrl").
-include("def_event.hrl").
-include("rec_event.hrl").
-include("task.hrl").

-export([
    dun_task_trigger/4
    ,exp_dun_task_trigger/2
    ,show_off_child_trigger/2
    ,vote_child_trigger/2
    ,goods_devour_trigger/2
    ,friend_coupon_trigger/2
    ,world_chat_trigger/2
    ,convoy_trigger/2
    ,kill_reward_boss_trigger/2
    ,place_order_trigger/2
    ,hunt_order_trigger/2
    ,jump_task_trigger/2
    ,enter_world_boss_trigger/2
    ,enter_guild_boss_trigger/2
    ,capsule_egg_trigger/2
    ,request_help_trigger/2
    ,response_help_trigger/2
    ,act_live_trigger/2
    ,beauty_vote_trigger/2
    ,glamour_guess_trigger/2
    ,honour_add_trigger/2
    ]).

-export([
    handle_event/2
    ]).

handle_event(Player, #event_callback{type_id = ?EVENT_FINISH_TASK, data = TaskId}) ->
    #player_status{id = RoleId} = Player,
    case data_task:get(TaskId) of
        #task{type = ?TASK_TYPE_DAILY} ->
            daily_task_trigger(RoleId, 1);
        #task{type = ?TASK_TYPE_GUILD} ->
            guild_task_trigger(RoleId, 1);
        _ ->
            skip
    end,
    {ok, Player}.

%% 副本任务触发
-spec dun_task_trigger(RoleId, DunId, DunType, Count) -> ReturnType when
    RoleId :: integer(),
    DunId  :: integer(),
    DunType :: integer(),
    Count :: integer(),
    ReturnType :: atom().
dun_task_trigger(RoleId, DunId, ?DUNGEON_TYPE_MATERIAL, Count) ->
    material_dun_task_trigger(RoleId, DunId, Count);

% dun_task_trigger(RoleId, _DunId, ?DUNGEON_TYPE_EXP, Count) ->
%     custom_act_contract:trigger_contract_task(RoleId, expdun, [Count]);

dun_task_trigger(RoleId, _DunId, ?DUNGEON_TYPE_CRUSADE, Count) ->
    custom_act_contract:trigger_contract_task(RoleId, teamdun, [Count]);

dun_task_trigger(RoleId, _DunId, ?DUNGEON_TYPE_GUARD, Count) ->
    custom_act_contract:trigger_contract_task(RoleId, guarddun, [Count]);

dun_task_trigger(RoleId, _DunId, ?DUNGEON_TYPE_PET, Count) ->
    custom_act_contract:trigger_contract_task(RoleId, petdun, [Count]);

dun_task_trigger(RoleId, _DunId, ?DUNGEON_TYPE_PER_BOSS, Count) ->
    custom_act_contract:trigger_contract_task(RoleId, personboss, [Count]);

dun_task_trigger(_, _, _, _) ->
    ok.

exp_dun_task_trigger(RoleId, Count) ->
    custom_act_contract:trigger_contract_task(RoleId, expdun, [Count]).

%% 座驾副本|宝具副本|AI娘副本|神翼副本|武器副本
-spec material_dun_task_trigger(RoleId, DunId, Count) -> ReturnType when
    RoleId :: integer(),
    DunId :: 1001|1002|1003|1004|1005,
    Count :: integer(),
    ReturnType :: atom().
material_dun_task_trigger(RoleId, DunId, Count) ->
    TaskType = get_dun_task_type(DunId),
    custom_act_contract:trigger_contract_task(RoleId, TaskType, [Count]).

get_dun_task_type(1001) -> cardun;
get_dun_task_type(1002) -> treasuredun;
get_dun_task_type(1003) -> aigirldun;
get_dun_task_type(1004) -> wingdun;
get_dun_task_type(1005) -> weapondun;
get_dun_task_type(_)    -> undefined.

%% 晒娃触发
show_off_child_trigger(RoleId, Count) ->
    custom_act_contract:trigger_contract_task(RoleId, showbaby, [Count]).

%% 点赞晒娃
vote_child_trigger(RoleId, Count) ->
    custom_act_contract:trigger_contract_task(RoleId, likebaby, [Count]).

%% 吞噬装备
goods_devour_trigger(RoleId, Count) ->
    custom_act_contract:trigger_contract_task(RoleId, devour, [Count]).

%% 好友名望券赠送
friend_coupon_trigger(RoleId, Count) ->
    custom_act_contract:trigger_contract_task(RoleId, givefriend, [Count]).

%% 世界频道发言
world_chat_trigger(RoleId, Count) ->
    custom_act_contract:trigger_contract_task(RoleId, sendmsg, [Count]).

%% 护送
convoy_trigger(RoleId, Count) ->
    custom_act_contract:trigger_contract_task(RoleId, escort, [Count]).

%% 击杀赏金boss
kill_reward_boss_trigger(RoleId, Count) ->
    custom_act_contract:trigger_contract_task(RoleId, bountyboss, [Count]).

%% 完成日常任务
daily_task_trigger(RoleId, Count) ->
    custom_act_contract:trigger_contract_task(RoleId, dailytask, [Count]).

%% 完成周任务
guild_task_trigger(RoleId, Count) ->
    custom_act_contract:trigger_contract_task(RoleId, guildtask, [Count]).

%% 派单触发
place_order_trigger(RoleId, Count) ->
    custom_act_contract:trigger_contract_task(RoleId, ordersend , [Count]).

%% 接单触发
hunt_order_trigger(RoleId, Count) ->
    custom_act_contract:trigger_contract_task(RoleId, ordertake, [Count]).

%% 完成三级跳触发
jump_task_trigger(RoleId, Count) ->
    custom_act_contract:trigger_contract_task(RoleId, jump, [Count]).

%% 世界boss
enter_world_boss_trigger(RoleId, Count) ->
    custom_act_contract:trigger_contract_task(RoleId, worldboss, [Count]).

enter_guild_boss_trigger(RoleId, Count) ->
    custom_act_contract:trigger_contract_task(RoleId, guildboss, [Count]).


%% 龙神宝库
capsule_egg_trigger(RoleId, 1) ->
    custom_act_contract:trigger_contract_task(RoleId, singledraw, [1]);
capsule_egg_trigger(RoleId, 10) ->
    custom_act_contract:trigger_contract_task(RoleId, singledraw, [10]),
    custom_act_contract:trigger_contract_task(RoleId, tendraw, [1]);
capsule_egg_trigger(_RoleId, _) -> skip.

%% 发起协助
request_help_trigger(RoleId, Count) ->
    custom_act_contract:trigger_contract_task(RoleId, assisted, [Count]).

%% 完成协助
response_help_trigger(RoleId, Count) ->
    custom_act_contract:trigger_contract_task(RoleId, assist, [Count]).

%% 活跃度达到X
act_live_trigger(RoleId, AddLive) ->
    custom_act_contract:trigger_contract_task(RoleId, activity, [AddLive]).

%% 明日之星投票胜利次数
beauty_vote_trigger(RoleId, Count) ->
    custom_act_contract:trigger_contract_task(RoleId, beauty, [Count]).

%% 赛马投注
glamour_guess_trigger(RoleId, Count) ->
    custom_act_contract:trigger_contract_task(RoleId, glamour, [Count]).

honour_add_trigger(RoleId, AllHonour) ->
    custom_act_contract:trigger_contract_task(RoleId, fame, [AllHonour]).