%% ---------------------------------------------------------------------------
%% @doc 任务模块对外接口.

%% @author zzm
%% @since  2016-11-23
%% @deprecated  任务模块对外接口
%% ---------------------------------------------------------------------------
-module(lib_task_api).

-compile(export_all).

-include("common.hrl").
-include("task.hrl").
-include("server.hrl").
-include("figure.hrl").
-include("def_event.hrl").
-include("rec_event.hrl").
-include("def_module.hrl").
-include("goods.hrl").
-include("def_daily.hrl").
-include("guild.hrl").
-include("scene.hrl").
-include("shop.hrl").
-include("arena.hrl").
-include("predefine.hrl").
-include("dungeon.hrl").
-include("local_boss.hrl").
-include("role_foster.hrl").

%% 任务参数
ps2task_args(PS) ->
    #player_status{id=Id, figure=Figure, sid=Sid, scene=Scene, npc_info=NpcInfo, guild = #status_guild{lv=GuildBuildLv}, source = Source} = PS,
    Gs = lib_goods_do:get_goods_status(),
    #task_args{id=Id, figure=Figure, sid=Sid, scene=Scene, npc_info=NpcInfo, gs_dict = Gs#goods_status.dict, guild_build_lv = GuildBuildLv, source = Source}.

%% 击杀怪物
kill_mon(#player_status{id = RoleId}=Ps, MonId) ->
    case data_mon:get(MonId) of
        #mon{boss=B} when B>=3->
            kill_boss_id(Ps,MonId);
        _->
            skip
    end,
    event(?TASK_CONTENT_KILL, {num, MonId, 1}, RoleId);

kill_mon(RoleId, MonId) ->
    case data_mon:get(MonId) of
        #mon{boss=B} when B>=3->
            kill_boss_id(RoleId,MonId);
        _->
            skip
    end,
    event(?TASK_CONTENT_KILL, {num, MonId, 1}, RoleId,false).

%% 击杀BOSS(BOSS类型)
kill_boss(#player_status{id = RoleId}, BossType) ->
    event(?TASK_CONTENT_KILL_BOSS, {num, BossType, 1}, RoleId).
%% 击杀次元幻魔因为参与者都有份都会触发 所以击杀这边不做触发
kill_boss(RoleId, Scene, BossType) ->
    case data_scene:get(Scene)  of
        #ets_scene{type=?SCENE_TYPE_REWARD_BOSS}->
            skip;
        _->
            event(?TASK_CONTENT_KILL_BOSS, {num, BossType, 1}, RoleId,false)
    end.

%击杀指定BOSS
kill_boss_id(RoleId, BossId) when is_integer(RoleId)->
    event(?TASK_CONTENT_KILL_BOSS_ID, {num,BossId,1},RoleId,false);
kill_boss_id(#player_status{id = RoleId}, BossId) ->
    event(?TASK_CONTENT_KILL_BOSS_ID, {num,BossId,1}, RoleId).

%% 收集物品(通过杀怪收集)
collect_goods(#player_status{id = RoleId}, GoodsNumList) ->
    event(?TASK_CONTENT_ITEM, {id_num_list, GoodsNumList}, RoleId);
collect_goods(RoleId, GoodsNumList) ->
    event(?TASK_CONTENT_ITEM, {id_num_list, GoodsNumList}, RoleId,false).

%% 收集物品减少(通过触发任务来更新任务的完成状态)
collect_goods_reduce(#player_status{id = RoleId}, GoodsNumList)->
    event(?TASK_CONTENT_ITEM, {reduce_id_num_list, GoodsNumList}, RoleId);
collect_goods_reduce(RoleId, GoodsNumList) ->
    event(?TASK_CONTENT_ITEM, {reduce_id_num_list, GoodsNumList}, RoleId,false).

%% 采集物品(采集怪物)
collect_mon(#player_status{id = RoleId}, MonId) ->
    event(?TASK_CONTENT_COLLECT, {num, MonId, 1}, RoleId);
collect_mon(RoleId, MonId) ->
    event(?TASK_CONTENT_COLLECT, {num, MonId, 1}, RoleId,false).

%%送信
finish_mailer_run(#player_status{id = RoleId},NpcId)->
    event(?TASK_CONTENT_MAILER_RUN, {id, NpcId}, RoleId).

%% 强化装备(去到任务进程统计EqStrenList=[{StrenLv, Num}])
stren_equip(#player_status{id = RoleId},EqStrenList) ->
    event(?TASK_CONTENT_STREN, {id_num_list, EqStrenList}, RoleId).
%% 自动触发下一个装备强化任务
auto_stren_equip(#player_status{id = RoleId}) ->
    EqStrenList = equipment_api:get_equipment_strength_info(),
    event(?TASK_CONTENT_STREN, {id_num_list, EqStrenList}, RoleId).

%% 附能装备(去到任务进程统计EqStrenList=[{StrenLv, Num}])
empower_equip(#player_status{id = RoleId},EqStrenList) ->
    event(?TASK_CONTENT_EMPOWER, {id_num_list, EqStrenList}, RoleId).
%% 自动触发下一个装备强化任务
auto_empower_equip(#player_status{id = RoleId, equipment = RoleEquipment}) ->
    EqStrenList = equipment_api:get_equipment_empower_info(RoleEquipment),
    event(?TASK_CONTENT_EMPOWER, {id_num_list, EqStrenList}, RoleId).

%%装备套装
suit_equip(#player_status{id = RoleId})->
    SCNList = equipment_api:get_equipment_wear_info_withno_jewelry(),
    event(?TASK_CONTENT_EQUIP_SUIT, {id_num_list, SCNList}, RoleId).

rise_equip(#player_status{id = RoleId},StarN)->
     event(?TASK_CONTENT_ERISE, {num, StarN}, RoleId).
%% 自动触发下一个装备进化任务
auto_rise_equip(#player_status{id = RoleId}) ->
    StarN = equipment_api:include_equipment_stars(),
    event(?TASK_CONTENT_ERISE, {num, StarN}, RoleId).

%%完成选项对话
finish_choose_talk(#player_status{id = RoleId},NpcId,TalkId)->
    event(?TASK_CONTENT_CHOOSE_TALK, {num, lib_role_task:exchange_npc(NpcId), TalkId}, RoleId).


%%有些任务进入就算完成
fin_dun_type_enter(#player_status{id = RoleId},DunType)->
    event(?TASK_CONTENT_DUNGEON_TYPE_ENTER, {num, DunType, 1}, RoleId);
fin_dun_type_enter(RoleId,DunType)->
    event(?TASK_CONTENT_DUNGEON_TYPE_ENTER, {num, DunType, 1}, RoleId, false).

%%有些任务进入就算完成
fin_dun_enter(#player_status{id = RoleId},DunID)->
    event(?TASK_CONTENT_DUNGEON_ID_ENTER, {num, DunID, 1}, RoleId);
fin_dun_enter(RoleId,DunID)->
    event(?TASK_CONTENT_DUNGEON_ID_ENTER, {num, DunID, 1}, RoleId, false).

%% 完成特定类型副本事件
fin_dun_type(#player_status{id=RoleId}, DunType) ->
    event(?TASK_CONTENT_DUNGEON_TYPE, {num, DunType, 1}, RoleId).

%% 完成特定副本的经验
fin_dun_exp(#player_status{id = RoleId}, DunType, Exp) ->
    event(?TASK_CONTENT_DUNGEON_EXP, {num, DunType, Exp}, RoleId);
fin_dun_exp(RoleId, DunType, Exp) ->
    event(?TASK_CONTENT_DUNGEON_EXP, {num, DunType, Exp}, RoleId,false).

%% 完成副本事件
fin_dun(RoleId, DunId) ->
    event(?TASK_CONTENT_DUNGEON, {id, DunId}, RoleId,false).

%%完成经验副本进度
fin_dun_wave(RoleId, DunId, DunWave)->
    event(?TASK_CONTENT_DUN_WAVE, {num, DunId, DunWave}, RoleId,false).

%% 完成层级副本事件
fin_level_dun(#player_status{id = RoleId}, DunType, DunId) ->
    event(?TASK_CONTENT_DUNGEON_RUNE, {id, DunType, DunId}, RoleId);
fin_level_dun(RoleId, DunType, DunId) ->
    event(?TASK_CONTENT_DUNGEON_RUNE, {id, DunType, DunId}, RoleId,false).

%% 到达地点
reach_place(RoleId, Scene, X, Y) ->
    event(?TASK_CONTENT_ENTER_SCENE, {Scene, X, Y}, RoleId,false).

%% 添加好友
add_friend(#player_status{id = RoleId}) ->
    event(?TASK_CONTENT_ADD_FRIEND, {num, 1}, RoleId);
add_friend(RoleId) ->
    event(?TASK_CONTENT_ADD_FRIEND, {num, 1}, RoleId,false).

%% 加入公会（包括创建公会）
join_guild(#player_status{id = RoleId}) ->
    event(?TASK_CONTENT_JOIN_GUILD, {num, 1}, RoleId);
join_guild(RoleId) ->
    event(?TASK_CONTENT_JOIN_GUILD, {num, 1}, RoleId,false).

%% 完成公会装备回收
guild_eq_recycle(#player_status{id = RoleId}, EqStage, EqColor)->
    event(?TASK_CONTENT_GUILD_EQ_RECYCLE, {num, EqStage, EqColor}, RoleId).

%% 完成羁绊缔结
be_mate(#player_status{id = RoleId})->
    event(?TASK_CONTENT_MATE, {num, 1}, RoleId);
be_mate(RoleId)->
    event(?TASK_CONTENT_MATE, {num, 1}, RoleId,false).

%% 完成吞噬装备
devour_equip(#player_status{id = RoleId}, DevourList) ->
    %%吞噬量多,不批量执行,每件装备cast一次.防止别的任务call超时
    [ event(?TASK_CONTENT_DEVOUR, {num, EqStage, EqColor}, RoleId) || {EqStage, EqColor} <- DevourList].

%% 完成公会活动任务
guild_activity(RoleId, SubModId)->
    event(?TASK_CONTENT_GUILD_ACTIVITY, {id, SubModId}, RoleId,false).

%% 公会装备捐献
guild_donate(#player_status{id = RoleId})->
    event(?TASK_CONTENT_GUILD_EQ_DONATE, {num, 1}, RoleId);
guild_donate(RoleId) ->
    event(?TASK_CONTENT_GUILD_EQ_DONATE, {num, 1}, RoleId,false).

%% 从市场购买
buy_from_trading(RoleId) ->
    event(?TASK_CONTENT_BUY_FROM_TRADING, {num, 1}, RoleId,false).

%% 市场上架
trading_putaway(RoleId) ->
    event(?TASK_CONTENT_TRADING_PUTAWAY, {num, 1}, RoleId,false).

%%战魂强化
warsoul_strength(#player_status{id = RoleId},NewLv)->
    event(?TASK_CONTENT_WAR_SOUL_LV, {num, NewLv}, RoleId).

%%龙神抽奖
capsule_egg(#player_status{id = RoleId},Num)->
    event(?TASK_CONTENT_CAPSULE, {num, Num}, RoleId).

%% 完成限时任务
finish_time_task(#player_status{id = RoleId}, MainTaskId)->
    event(?TASK_CONTENT_TIME_TASK, {id, MainTaskId}, RoleId).

%% 物品合成任务
finish_goods_compose(#player_status{id = RoleId}, GId, Num)->
    event(?TASK_CONTENT_GOODS_COMPOSE, {num, GId, Num}, RoleId).

%% 每日活跃度达到xx点
finish_day_activity(#player_status{id = RoleId}, ActivityNum)->
    event(?TASK_CONTENT_DAY_ACTIVITY, {num, ActivityNum}, RoleId).

%% 钓鱼
finish_fish(RoleId) when is_integer(RoleId)->
    event(?TASK_CONTENT_FISH, {num, 1}, RoleId,false);
finish_fish(#player_status{id = RoleId}) ->
    event(?TASK_CONTENT_FISH, {num, 1}, RoleId).

%%市场竞拍
bid_for_goods(#player_status{id = RoleID})->
    event(?TASK_CONTENT_BUY_FROM_TRADING, {num, 1}, RoleID).

%%市场上架
put_on_goods(#player_status{id = RoleID})->
    event(?TASK_CONTENT_TRADING_PUTAWAY, {num, 1}, RoleID).


arena_join(#player_status{id = RoleId}) ->
    Num = lib_daily:get_count(RoleId,?MOD_ARENA, ?ARENA_USE_NUM),
    event(?TASK_CONTENT_ARENA_TIMES, {num, Num}, RoleId).

%%交易商场购买
score_buy(#player_status{id = RoleId},GoodsID) ->
    event(?TASK_CONTENT_SCORE_BUY, {num, GoodsID, 1}, RoleId);
score_buy(RoleId,GoodsID) ->
    event(?TASK_CONTENT_SCORE_BUY, {num, GoodsID, 1}, RoleId,false).

%%新手引导触发
finish_newer(#player_status{id = RoleId},Type)->
    event(?TASK_CONTENT_NEWER, {id, Type}, RoleId).

%%好友送礼
friend_gift(#player_status{id = RoleId})->
    event(?TASK_CONTENT_FRIEND_GIFT, {num, 1}, RoleId);
friend_gift(RoleId)->
    event(?TASK_CONTENT_FRIEND_GIFT, {num, 1}, RoleId,false).

%%好友度
friend_exp(RoleId,Exp)->
    event(?TASK_CONTENT_FRIEND_EXP, {num, Exp}, RoleId).

%%宝宝同心值
child_heart(#player_status{id = RoleId},Exp)->
    event(?TASK_CONTENT_CHILD_HEART, {num, Exp}, RoleId).

%%进阶系统升级 行为计次
foster_lv_up(#player_status{id = RoleId},Type)->
    event(?TASK_CONTENT_FOSTER_LV, {num, Type, 1}, RoleId).

%%进阶系统 阶数进阶
foster_grade_up(#player_status{id = RoleId},Type,Grade)->
    event(?TASK_CONTENT_FOSTER_GRADE, {num,Type,Grade}, RoleId).

%%器灵之路
soul_roll(#player_status{id = RoleId})->
    event(?TASK_CONTENT_ROLL, {num, 1}, RoleId).

%%唤神升级
god_lv_up(#player_status{id = RoleId})->
    event(?TASK_CONTENT_GOD_LV, {num, 1}, RoleId).

%%星辰升级
galaxy_lv(#player_status{id = RoleId})->
    event(?TASK_CONTENT_GALAXY_LV, {num, 1}, RoleId).

%%宠物升级
pet_lv(#player_status{id = RoleId})->
    event(?TASK_CONTENT_PET_LV, {num, 1}, RoleId).

%%晒娃
show_baby(#player_status{id = RoleId})->
    event(?TASK_CONTENT_SHOW_BABY, {num, 1}, RoleId).

%%装备灵能
nucleon_equip(#player_status{id = RoleId})->
    event(?TASK_CONTENT_NUCLEON_EQUIP, {num, 1}, RoleId).

%%灵能寻宝
nucleon_shop(#player_status{id = RoleId})->
    event(?TASK_CONTENT_NUCLEON_SHOP, {num, 1}, RoleId).

some_shop_buy_book(#player_status{id = RoleId},Num,Type)->
    event(?TASK_CONTENT_SOME_SHOP_BUY_BOOK, {num, Type, Num}, RoleId).

any_shop_buy_book(#player_status{id = RoleId},Num)->
    event(?TASK_CONTENT_ANY_SHOP_BUY_BOOK, {num, Num}, RoleId).

active_skill_lv(#player_status{id = RoleId})->
    event(?TASK_CONTENT_ACTIVE_SKILL_LV_TIMES, {num, 1}, RoleId).


%% 事件触发
%% 默认玩家进程 true
event(Event, Params, RoleId) ->
    lib_role_task:event(Event, Params, RoleId).
event(Event, Params, RoleId,IsSelf) ->
    lib_role_task:event(Event, Params, RoleId,IsSelf).

%% 直接提交一个任务(玩家进程)
finish(Status, TaskId) ->
    CellNum = lib_goods_api:get_cell_num(Status),
    lib_role_task:finish(TaskId, [[], CellNum], ps2task_args(Status)).

%% ---------------------------------------------------------------------------
%% @doc 刷新任务
-spec refresh_task(Role) -> ok when
    Role        :: #player_status{}.
%% ---------------------------------------------------------------------------
refresh_task(Role) ->
    TaskArgs = ps2task_args(Role),
    lib_task:lv_up(TaskArgs),
    ok.


%% 处理玩家事件
handle_event(PS, #event_callback{type_id = ?EVENT_CENTER_CONNECTED})->
    TaskArgs = ps2task_args(PS),
    AllTask = lib_task:get_task_bag_id_list(),
    KfDay = data_key_value:get(1030001),
    NewAllTask =  case util:get_open_day()>=KfDay of
        true->
            lib_task:fix_task_npc(AllTask,[],TaskArgs);
        _->
            AllTask
    end,
    lib_task:set_task_bag_list(NewAllTask),
    lib_task:lv_up(TaskArgs),
    {ok, PS};
handle_event(PS, #event_callback{type_id = ?EVENT_CENTER_DISCONNECT})->
    TaskArgs = ps2task_args(PS),
    AllTask = lib_task:get_task_bag_id_list(),
    KfDay = data_key_value:get(1030001),
    NewAllTask =  case util:get_open_day()>=KfDay of
        true->
            lib_task:fix_task_npc(AllTask,[],TaskArgs);
        _->
            AllTask
    end,
    lib_task:set_task_bag_list(NewAllTask),
    lib_task:lv_up(TaskArgs),
    {ok, PS};
handle_event(PS, #event_callback{type_id = ?EVENT_ZERO_CLOCK})->
    TaskArgs = ps2task_args(PS),
    AllTask = lib_task:get_task_bag_id_list(),
    KfDay = data_key_value:get(1030001),
    NewAllTask =  case util:get_open_day()>=KfDay of
        true->
            lib_task:fix_task_npc(AllTask,[],TaskArgs);
        _->
            AllTask
    end,
    lib_task:set_task_bag_list(NewAllTask),
    lib_task:lv_up(TaskArgs),
    {ok, PS};
handle_event(Status, #event_callback{type_id=?EVENT_LV_UP}) ->
    TaskArgs = ps2task_args(Status),
    lib_role_task:lv_up(TaskArgs),
    {ok, Status};
handle_event(PS, #event_callback{type_id=?EVENT_GUILD_DONATE}) ->
    guild_donate(PS),
    {ok, PS};
handle_event(PS, #event_callback{type_id = ?EVENT_LOGIN_CAST})->
    TaskArgs = ps2task_args(PS),
    AllTask = lib_task:get_task_bag_id_list(),
    KfDay = data_key_value:get(1030001),
    NewAllTask =  case util:get_open_day()>=KfDay of
        true->
            lib_task:fix_task_npc(AllTask,[],TaskArgs);
        _->
            AllTask
    end,
    lib_task:set_task_bag_list(NewAllTask),
    lib_task:handle_refresh_trigger(TaskArgs),
    lib_role_task:auto_trigger_daily_task(TaskArgs),
    {ok, PS};
handle_event(PS, #event_callback{type_id = ?EVENT_TURN_UP})->
    TaskArgs = ps2task_args(PS),
    lib_role_task:lv_up(TaskArgs),
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{turn = NewTurn} = Figure,
    event(?TASK_CONTENT_TURN, {num, NewTurn, 1}, RoleId),
    {ok, PS};
handle_event(PS, #event_callback{type_id = ?EVENT_COMBAT_POWER})->
    #player_status{id = RoleId, combat_power = Combat} = PS,
    event(?TASK_CONTENT_COMBAT, {num, Combat}, RoleId),
    {ok, PS};
% %%进入分区警戒  跨服任务转本服
% handle_event(PS, #event_callback{type_id = ?EVENT_CZONE_NOTICE_REZONE})->
%     TaskArgs = ps2task_args(PS),
%     AllTask = lib_task:get_task_bag_id_list(),
%     KfDay = data_key_value:get(1030001),
%     NewAllTask =  case util:get_open_day()>=KfDay of
%         true->
%             lib_task:fix_task_npc(AllTask,[],TaskArgs);
%         _->
%             AllTask
%     end,
%     lib_task:set_task_bag_list(NewAllTask),
%     lib_task:lv_up(TaskArgs),
%     {ok, PS};
% handle_event(PS, #event_callback{type_id = ?EVENT_CZONE_REZONE_FINSIH})->
%     TaskArgs = ps2task_args(PS),
%     AllTask = lib_task:get_task_bag_id_list(),
%     KfDay = data_key_value:get(1030001),
%     NewAllTask =  case util:get_open_day()>=KfDay of
%         true->
%             lib_task:fix_task_npc(AllTask,[],TaskArgs);
%         _->
%             AllTask
%     end,
%     lib_task:set_task_bag_list(NewAllTask),
%     lib_task:lv_up(TaskArgs),
%     {ok, PS};
handle_event(PS, _) ->
    {ok, PS}.

opday_change(Status)->
    czone_api:notice_city_state(Status#player_status.sid),
    TaskArgs = ps2task_args(Status),
    AllTask = lib_task:get_task_bag_id_list(),
    NewAllTask = lib_task:fix_task_npc(AllTask,[],TaskArgs),
    lib_task:set_task_bag_list(NewAllTask),
    lib_role_task:get_my_task_list(lib_task_api:ps2task_args(Status)).

%% 出售，交易物品减少，任务状态修改
handle_task_goods_reduce(Ps, ReduceGoodsList) ->
    TaskGoodsIdList = lib_task:can_gain_item(),
    case TaskGoodsIdList of
        [] -> skip;
        _  ->
            %% 找到需要处理的物品
            Fun = fun({GoodTypeId, Num}, [TL, GNL]) ->
                          case lists:member(GoodTypeId, TaskGoodsIdList) of
                              false -> [TL, GNL];
                              true ->  [[{GoodTypeId, Num}|TL], [GoodTypeId|GNL]]
                          end
                  end,
            case lists:foldl(Fun, [[], []], ReduceGoodsList) of
                [[], _] -> skip;
                [ReduceTaskList, L] ->
                    GNumL = lib_goods_api:get_goods_num(Ps, L),
                    Fun1 = fun({GID, GNUM}, GAL) ->
                                   case lists:keyfind(GID, 1, GNumL) of
                                       false -> [{GID, GNUM, 0}|GAL];
                                       {_, AllNum} -> [{GID, GNUM, AllNum}|GAL]
                                   end
                           end,
                    Reduces = lists:foldl(Fun1, [], ReduceTaskList),
                    lib_task_api:collect_goods_reduce(Ps, Reduces)
            end
    end.

%% 玩家进程刷新支线任务
cast_handle_refresh_trigger(PS, []) -> PS;
cast_handle_refresh_trigger(PS, EventList) ->
    {NewPS, ActionList} = make_action_list(PS, EventList, []),
    case ActionList == [] of
        true -> NewPS;
        false ->
            %%批量刷新
            lib_task:action_more(ActionList)
    end,
    NewPS.

make_action_list(PS, [], ActionList) -> {PS, ActionList};
%%好友数量
make_action_list(PS, [{TaskId, ?TASK_CONTENT_ADD_FRIEND, NeedNum, NowNum}| T], ActionList) ->
    #player_status{id = RoleId} = PS,
    FriendNum = length(lib_relationship:get_friend_id_on_dict(RoleId)),
    LeftNum = max(0, FriendNum - NowNum),
    case FriendNum >= NeedNum of
        true-> make_action_list(PS, T, [{TaskId, ?TASK_CONTENT_ADD_FRIEND, {num, FriendNum}, RoleId}| ActionList]);
        false when LeftNum > 0 -> make_action_list(PS, T, [{TaskId, ?TASK_CONTENT_ADD_FRIEND, {num, FriendNum}, RoleId}| ActionList]);
        _ -> make_action_list(PS, T, ActionList)
    end;
make_action_list(PS,[{TaskId, ?TASK_CONTENT_FRIEND_EXP,Num}|T],ActionList)->
    #player_status{id = RoleId} = PS,
    MaxIntimacy = lib_relationship:get_max_intimacy(RoleId),
    case MaxIntimacy>=Num of
        true->
            make_action_list(PS, T, [{TaskId, ?TASK_CONTENT_FRIEND_EXP,{num, MaxIntimacy}, RoleId}| ActionList]);
        _ ->
            make_action_list(PS, T, ActionList)
    end;
%%副本进度
make_action_list(PS, [{TaskId, ?TASK_CONTENT_DUN_WAVE, DunId}| T], ActionList) ->
    NewPS = #player_status{id = RoleId, dungeon_record = DungeonRecord} = lib_dungeon:load_dungeon_record(PS),
    Record = maps:get(DunId, DungeonRecord, []),
    case lists:keyfind(3,1,Record)  of
        {_,Wave}->
            make_action_list(NewPS, T, [{TaskId, ?TASK_CONTENT_DUN_WAVE, {num, DunId, Wave}, RoleId}| ActionList]);
        _ ->
            make_action_list(NewPS, T,ActionList)
    end;
%%某个副本
make_action_list(PS, [{TaskId, ?TASK_CONTENT_DUNGEON, DunId}| T], ActionList) ->
    NewPS = #player_status{id = RoleId, dungeon_record = DungeonRecord} = lib_dungeon:load_dungeon_record(PS),
    Record = maps:get(DunId, DungeonRecord, false),
    DunList = [],
    case Record == false orelse lists:member(DunId, DunList) of
        true ->
            %%判断是否终身次数
            case lib_counter:get_count(RoleId, ?MOD_DUNGEON, ?MOD_DUNGEON_ENTER, DunId) of
                Num when Num > 0 ->
                    make_action_list(NewPS, T, [{TaskId, ?TASK_CONTENT_DUNGEON, {id, DunId}, RoleId}| ActionList]);
                _ -> make_action_list(NewPS, T, ActionList)
            end;
        _ ->
            make_action_list(NewPS, T, [{TaskId, ?TASK_CONTENT_DUNGEON, {id, DunId}, RoleId}| ActionList])
    end;
%%副本类型 个人幻魔
make_action_list(PS, [{TaskId, ?TASK_CONTENT_DUNGEON_TYPE, ?DUNGEON_TYPE_PER_BOSS}| T], ActionList) ->
    #player_status{id = RoleId}=PS,
    Num = lib_counter:get_count(RoleId, ?MOD_DUNGEON,?MOD_DUNGEON_PER_BOSS_ENTER,?DUNGEON_TYPE_PER_BOSS),
    make_action_list(PS, T, [{TaskId, ?TASK_CONTENT_DUNGEON_TYPE, {init, ?DUNGEON_TYPE_PER_BOSS, Num}, RoleId}| ActionList]);
%%副本类型
make_action_list(PS, [{TaskId, ?TASK_CONTENT_DUNGEON_TYPE, DunType}| T], ActionList) ->
    NewPS = #player_status{id = RoleId, dungeon_record = DungeonRecord} = lib_dungeon:load_dungeon_record(PS),
    case lib_dungeon:is_pass_dun_type(DunType, DungeonRecord) of
        false -> make_action_list(NewPS, T, ActionList);
        _ ->
            make_action_list(NewPS, T, [{TaskId, ?TASK_CONTENT_DUNGEON_TYPE, {num, DunType, 1}, RoleId}| ActionList])
    end;
%%装备进化
make_action_list(PS, [{TaskId, ?TASK_CONTENT_ERISE}| T], ActionList) ->
    StarN = equipment_api:include_equipment_stars(),
    case StarN =< 0  of
        true ->
            make_action_list(PS, T, ActionList);
        false ->
            make_action_list(PS, T, [{TaskId, ?TASK_CONTENT_ERISE, {num, StarN}, PS#player_status.id}| ActionList])
    end;
%%装备强化
make_action_list(PS, [{TaskId, ?TASK_CONTENT_STREN}| T], ActionList) ->
    EqStrenList = equipment_api:get_equipment_strength_info(),
    case EqStrenList == [] of
        true -> make_action_list(PS, T, ActionList);
        false ->
            make_action_list(PS, T, [{TaskId, ?TASK_CONTENT_STREN, {id_num_list, EqStrenList}, PS#player_status.id}| ActionList])
    end;
%%装备附能
make_action_list(PS, [{TaskId, ?TASK_CONTENT_EMPOWER}| T], ActionList) ->
    EqStrenList = equipment_api:get_equipment_empower_info(PS),
    case EqStrenList == [] of
        true -> make_action_list(PS, T, ActionList);
        false ->
            make_action_list(PS, T, [{TaskId, ?TASK_CONTENT_EMPOWER, {id_num_list, EqStrenList}, PS#player_status.id}| ActionList])
    end;
%%活跃度
make_action_list(PS, [{TaskId, ?TASK_CONTENT_DAY_ACTIVITY}| T], ActionList) ->
    Live = lib_daily:get_count(PS#player_status.id, ?MOD_ACTIVITY, ?ACTIVITY_LIVE_DAILY),
    make_action_list(PS, T, [{TaskId, ?TASK_CONTENT_DAY_ACTIVITY, {num, Live}, PS#player_status.id}| ActionList]);
%%副本类型特定经验
make_action_list(PS, [{TaskId, ?TASK_CONTENT_DUNGEON_EXP, DunType, NeedNum}| T], ActionList) ->
    NewPS = #player_status{id = RoleId, dungeon_record = DungeonRecord} = lib_dungeon:load_dungeon_record(PS),
    Score = lib_dungeon:get_pass_dun_top_score(DunType, DungeonRecord),
    case is_integer(Score) andalso Score >= NeedNum of
        true ->
            make_action_list(NewPS, T, [{TaskId, ?TASK_CONTENT_DUNGEON_EXP, {num, DunType, Score}, RoleId}| ActionList]);
        false -> make_action_list(NewPS, T, ActionList)
    end;
%%副本类型特定经验
make_action_list(PS, [{TaskId, ?TASK_CONTENT_DUNGEON_RUNE, DunType, DunId}| T], ActionList) ->
    NewPS = #player_status{id = RoleId, dungeon_record = DungeonRecord} = lib_dungeon:load_dungeon_record(PS),
    case maps:get(DunId, DungeonRecord, false) of
        false -> make_action_list(NewPS, T, ActionList);
        _ ->
            make_action_list(NewPS, T, [{TaskId, ?TASK_CONTENT_DUNGEON_RUNE, {id, DunType, DunId}, RoleId}| ActionList])
    end;
make_action_list(PS,[{TaskId, ?TASK_CONTENT_SCORE_BUY,GoodsID,ShopId}|T],ActionList)->
    case data_shop:get_shop_config(ShopId) of
        #shop{counter_module = Mod,counter_id = Count}->
            HasF = lib_counter:get_count(PS#player_status.id, Mod, Count),
            make_action_list(PS, T, [{TaskId, ?TASK_CONTENT_SCORE_BUY,{num, GoodsID, HasF}, PS#player_status.id}| ActionList]);
        _->
            make_action_list(PS, T, ActionList)
    end;
%%玩家转生
make_action_list(PS, [{TaskId, ?TASK_CONTENT_TURN,NeedTurn}| T], ActionList) ->
    #player_status{figure=Figure}=PS,
    #figure{turn=Turn}=Figure,
    case Turn < NeedTurn  of
        true ->
            make_action_list(PS, T, ActionList);
        false ->
            make_action_list(PS, T, [{TaskId, ?TASK_CONTENT_TURN, {num, NeedTurn, 1}, PS#player_status.id}| ActionList])
    end;
%%装备套装
make_action_list(PS, [{TaskId, ?TASK_CONTENT_EQUIP_SUIT}| T], ActionList) ->
    SCNList = equipment_api:get_equipment_wear_info_withno_jewelry(),
    make_action_list(PS, T, [{TaskId, ?TASK_CONTENT_EQUIP_SUIT, {id_num_list, SCNList}, PS#player_status.id}| ActionList]);
%%竞技场
make_action_list(PS, [{TaskId, ?TASK_CONTENT_ARENA_TIMES}| T], ActionList) ->
    Num = lib_daily:get_count(PS#player_status.id,?MOD_ARENA, ?ARENA_USE_NUM),
    make_action_list(PS, T, [{TaskId, ?TASK_CONTENT_ARENA_TIMES, {num, Num}, PS#player_status.id}| ActionList]);
%%指定BOSS
make_action_list(PS, [{TaskId, ?TASK_CONTENT_KILL_BOSS, ?MON_REWARD_BOSS}| T], ActionList) ->
    #player_status{id = RoleId}=PS,
    Num = lib_daily:get_count(RoleId,?MOD_LOCAL_BOSS, ?COUNT_REWARD_BOSS_DAILY_KILL),
    %Num = lib_counter:get_count(RoleId, ?MOD_LOCAL_BOSS,?COUNT_REWARD_ALLBOSS_COUNTER_KILL,?MON_REWARD_BOSS),
    make_action_list(PS, T, [{TaskId, ?TASK_CONTENT_KILL_BOSS, {init, ?MON_REWARD_BOSS, Num}, RoleId}| ActionList]);
%%进阶系统
make_action_list(PS, [{TaskId, ?TASK_CONTENT_FOSTER_GRADE, Type}| T], ActionList) ->
    #player_status{id = RoleId}=PS,
    {_IsOpen,#cell_foster{grade=Num}} = lib_role_foster:get_sub_foster(Type,PS),
    make_action_list(PS, T, [{TaskId, ?TASK_CONTENT_FOSTER_GRADE, {num, Type, Num}, RoleId}| ActionList]);
%%预期任务
make_action_list(PS, [{TaskId, ?TASK_CONTENT_EXPECT_TASK, ExpectTask}| T], ActionList) ->
    #player_status{id = RoleId}=PS,
    case lib_role_task:is_finish_task_id(ExpectTask) of
        true->
            make_action_list(PS, T, [{TaskId, ?TASK_CONTENT_EXPECT_TASK, {id,ExpectTask}, RoleId}| ActionList]);
        _->
            make_action_list(PS, T, ActionList)
    end;
make_action_list(PS,[{TaskId, ?TASK_CONTENT_CHILD_HEART,Num}|T],ActionList)->
    #player_status{id = RoleId} = PS,
    LinkHeart = lib_child:get_player_link_heart(PS),
    case LinkHeart>=Num of
        true->
            make_action_list(PS, T, [{TaskId, ?TASK_CONTENT_CHILD_HEART,{num, LinkHeart}, RoleId}| ActionList]);
        _ ->
            make_action_list(PS, T, ActionList)
    end;
make_action_list(PS,[{TaskId, ?TASK_CONTENT_COMBAT,Num}|T],ActionList)->
    #player_status{id = RoleId,combat_power=Combat} = PS,
    case Combat>=Num of
        true->
            make_action_list(PS, T, [{TaskId, ?TASK_CONTENT_COMBAT,{num, Combat}, RoleId}| ActionList]);
        _ ->
            make_action_list(PS, T, ActionList)
    end;
make_action_list(PS,[{TaskId, ?TASK_CONTENT_ACTIVE_SKILL_LV_TIMES,Num,NeedNum}|T],ActionList)->
    #player_status{id = RoleId} = PS,
    Times = lib_skill:calc_lv_times(NeedNum,PS),
    case Times>=Num of
        true->
            make_action_list(PS, T, [{TaskId, ?TASK_CONTENT_ACTIVE_SKILL_LV_TIMES,{value, Times}, RoleId}| ActionList]);
        _ ->
            make_action_list(PS, T, ActionList)
    end;
make_action_list(PS,[{TaskId, ?TASK_CONTENT_SOME_SHOP_BUY_BOOK,ShopId,Num,NeedNum}|T],ActionList)->
    #player_status{id = RoleId} = PS,
    CurNum = lib_shop:get_buy_times([ShopId],NeedNum,PS),
    case CurNum>=Num of
        true->
            make_action_list(PS, T, [{TaskId, ?TASK_CONTENT_SOME_SHOP_BUY_BOOK,{value,ShopId,CurNum}, RoleId}| ActionList]);
        _ ->
            make_action_list(PS, T, ActionList)
    end;
make_action_list(PS,[{TaskId, ?TASK_CONTENT_ANY_SHOP_BUY_BOOK,Num,NeedNum}|T],ActionList)->
    #player_status{id = RoleId} = PS,
    CurNum = lib_shop:get_buy_times(NeedNum,PS),
    case CurNum>=Num of
        true->
            make_action_list(PS, T, [{TaskId, ?TASK_CONTENT_ANY_SHOP_BUY_BOOK,{value, CurNum}, RoleId}| ActionList]);
        _ ->
            make_action_list(PS, T, ActionList)
    end;
make_action_list(PS, [_Event | T], ActionList) ->
    make_action_list(PS, T, ActionList).