%%%-------------------------------------------------------------------
%%% @author  tyl
%%% @doc
%%%      成就API
%%% @end
%%% Created : 2021-03-15
%%%-------------------------------------------------------------------
-module(lib_achievement_api).

-include("achievement.hrl").
-include("server.hrl").
-include("def_event.hrl").
-include("def_module.hrl").
-include("def_goods.hrl").
-include("predefine.hrl").
-include("common.hrl").
-include("role.hrl").
-include("figure.hrl").
-include("rec_event.hrl").

-compile(export_all).


%% 重置玩家成就
gm_reset(RoleId) ->
    lib_achievement:gm_reset(RoleId).

%% 完成某个成就
gm_set_finish(PS, Type, SubType, Id) ->
    lib_achievement:gm_set_finish(PS, Type, SubType, Id).

%% 完成所有成就
gm_finish_all_type(PS) ->
    AllType = data_achievement:get_all_type(),
    lib_achievement:gm_finish_all(AllType, PS).

%% 增加成就经验
gm_add_achv_exp(PS, Exp) ->
    lib_achievement:gm_add_exp(PS, Exp).

%% 异步触发
async_event(PlayerId, M, F, A) when is_integer(PlayerId) ->
    lib_player:apply_cast(PlayerId, ?APPLY_CAST_SAVE, M, F, [A]);
async_event(_PlayerId, _M, _F, _A) -> skip.

handle_event(PS, #event_callback{type_id = ?EVENT_LV_UP}) when is_record(PS, player_status)  ->
    #player_status{role_achievement = RoleAchievement, figure = Figure} = PS,
    OpenLv = lib_module:get_open_lv(?MOD_ACHIEVEMENT),
    case Figure#figure.lv == OpenLv of
        true ->
            case data_achievement:get_achievement_stage_cfg(0) of
                #achievement_stage_cfg{attr_list = AttrList} ->
                    skip;
                _ ->
                    AttrList = []
            end,
            NewRoleAchievement = RoleAchievement#role_achievement{attr = AttrList},
            NewPlayer = PS#player_status{role_achievement = NewRoleAchievement},
            RefreshPlayer = lib_achievement:refresh_attr(NewPlayer),
            {ok, RefreshPlayer};
        _ ->
            {ok, PS}
    end.

%%--------------------------------------------------
%% @doc
%%  成就分类
%%      成就分为4大类: 养成，活跃，挑战，收集
%% @end
%%--------------------------------------------------
%%--------------------------------------------------
%% @doc 1. 养成成就 @end
%%--------------------------------------------------
%%--------------------------------------------------
%% 玩家升级 (1,1)
%% @param  PS   description
%% @param  Data
%% @return      description
%%--------------------------------------------------
lv_up_event(PS, _Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_1, 1], role_lv, [{role_lv, RoleLv}]),
    {ok, PS}.

%%--------------------------------------------------
%% 激活幻光xx个 (1,2)
%% @param  PS   description
%% @param  Data 参加数量
%% @return      description
%%--------------------------------------------------
visus_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_1, 2], visus, [{visus, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 幻光培养总战力 (1,3)
%% @param  PS   description
%% @param  Data 参加数量
%% @return      description
%%--------------------------------------------------
visus_power_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_1, 3], visus_power, [{visus_power, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 魂力技能：永恒回复激活xx级 (1,4)
%% @param  PS   description
%% @param  Data Lv
%% @return      description
%%--------------------------------------------------
uranium_skill_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_1, 4], uranium_skill, [{uranium_skill, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 职业技能：职业技能激活xx个 (1,5)
%% @param  PS   description
%% @param  Data Num - 激活总数
%% @return      description
%%--------------------------------------------------
career_skill_active_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_1, 5], career_skill, [{career_skill, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 职业技能：职业技能升级次数 (1,6)
%% @param  PS   description
%% @param  Data Num - 通常为1
%% @return      description
%%--------------------------------------------------
career_skill_up_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_1, 6], career_skill_up, [{career_skill_up, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 职业技能：xx个职业技能提升到xx级 (1,7)
%% @param  PS   description
%% @param  Data [{skill_id, lv}...]
%% @return      description
%%--------------------------------------------------
career_skill_lv_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_1, 7], career_skill_lv, [{career_skill_lv, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 特殊技能：激活特殊技能xx个 (1,8)
%% @param  PS   description
%% @param  Data Num - 激活的特殊技能总数量
%% @return      description
%%--------------------------------------------------
active_spec_skill_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_1, 8], spec_skill, [{spec_skill, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 被动技能：被动技能总等级达到xx级 (1,9)
%% @param  PS   description
%% @param  Data SumLv
%% @return      description
%%--------------------------------------------------
passive_skill_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_1, 9], passive_skill_sum_lv, [{passive_skill_sum_lv, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% xx进阶到xx阶xx星 ((1,10),(1,11),(1,12),(1,13),(1,14),(1,15),(1,16),(1,17))
%% @param  PS   :: #player_status{}
%% @param  Data :: [{Type, Stage, Star}...] | [{Type, Lv}]
%% @return      :: {ok, #player_status{}}
%%--------------------------------------------------
foster_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    case Data of
        [{Type, _, _}|_] -> ok;
        _ -> Type = 0
    end,
    TypeList = get_foster_type_list(Type),
    case TypeList =/= false of
        true -> lib_achievement:trigger(RoleId, RoleLv, TypeList, foster, [{foster, Data}]);
        _ -> ignore
    end,
    {ok, PS}.

foster1_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    case Data of
        [{Type, _}|_] -> ok;
        _ -> Type = 0
    end,
    TypeList = get_foster_type_list(Type),
    case TypeList =/= false of
        true -> lib_achievement:trigger(RoleId, RoleLv, TypeList, foster1, [{foster1, Data}]);
        _ -> ignore
    end,
    {ok, PS}.

get_foster_type_list(Type) ->
    case Type of
        1 ->  [?ACHIEVEMENT_TYPE_1, 10];
        2 ->  [?ACHIEVEMENT_TYPE_1, 11];
        3 ->  [?ACHIEVEMENT_TYPE_1, 12];
        4 ->  [?ACHIEVEMENT_TYPE_1, 13];
        5 ->  [?ACHIEVEMENT_TYPE_1, 14];
        6 ->  [?ACHIEVEMENT_TYPE_1, 15];
        7 ->  [?ACHIEVEMENT_TYPE_1, 16];
        8 ->  [?ACHIEVEMENT_TYPE_1, 17];
        _ ->  false
    end.

%%--------------------------------------------------
%% xx进阶装备xx套xx颜色 ((1,18),(1,19))
%% @param  PS   :: #player_status{}
%% @param  Data :: {Type, {Color => Num ...}}
%% @return      :: {ok, #player_status{}}
%%--------------------------------------------------
foster_equip_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    case Data of
        {Type, _} -> ok;
        _ -> Type = 0
    end,
    TypeList = get_foster_equip_type_list(Type),
    case TypeList =/= false of
        true ->
            lib_achievement:trigger(RoleId, RoleLv, TypeList, foster_equip, [{foster_equip, Data}]);
        _ ->
            ignore
    end,
    {ok, PS}.

get_foster_equip_type_list(Type) ->
    case Type of
        1 ->  [?ACHIEVEMENT_TYPE_1, 18];
        5 ->  [?ACHIEVEMENT_TYPE_1, 19];
        _ ->  false
    end.

%%--------------------------------------------------
%% 进阶技能总等级xx级 (1,20)
%% @param  PS   :: #player_status{}
%% @param  Data :: [{SkillId, Lv}...]
%% @return      :: {ok, #player_status{}}
%%--------------------------------------------------
foster_skill_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_1, 20], foster_skill_sum_lv, [{foster_skill_sum_lv, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 穿戴xx件xx套装xx品质装备(1,21)
%% @param  PS   description
%% @param  Data [lv, color, num]
%% @return      description
%%--------------------------------------------------
own_equip_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_1, 21], equip_num, [{equip_num, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 市场拍卖：获得xx件装备(1,22)
%% @param  PS   description
%% @param  Data 获得的装备件数
%% @return      description
%%--------------------------------------------------
shop_buy_equip_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_1, 22], shop_buy_equip, [{shop_buy_equip, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 市场拍卖：出售xx件装备(1,23)
%% @param  PS   description
%% @param  Data 出售的装备件数
%% @return      description
%%--------------------------------------------------
shop_sell_equip_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_1, 23], shop_sell_equip, [{shop_sell_equip, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 强化装备总等级到xx级(1,24)
%% @param  PS   :: #player_status{}
%% @param  Data :: [{强化等级, 数量}|...]
%% @return      :: {ok, #player_status{}}
%%--------------------------------------------------
equip_stren_up_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_1, 24], equip_stren_sum_lv, [{equip_stren_sum_lv, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 进化装备总等级到xx阶(1,25)
%% @param  PS   :: #player_status{}
%% @param  Data :: [{进化等级, 数量}|...]
%% @return      :: {ok, #player_status{}}
%%--------------------------------------------------
equip_upgrade_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_1, 25], equip_up_sum_lv, [{equip_up_sum_lv, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 镶嵌宝石总等级(1,26)
%% @param  PS   description
%% @param  Data 宝石数量
%% @return      description
%%--------------------------------------------------
wear_equip_stone_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_1, 26], equip_stone_sum_lv, [{equip_stone_sum_lv, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 佩戴xx个xx颜色装备((1,27),(1,28))
%% @param  PS   description
%% @param  Data [{Type, [{Color,Num}...]}...]
%% @return      description
%%--------------------------------------------------
equip_wear_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    case Data of
        [{Type, _}|_] -> ok;
        _ -> Type = 0
    end,
    TypeList = get_equip_type_list(Type),
    case TypeList =/= false of
        true ->
            lib_achievement:trigger(RoleId, RoleLv, TypeList, equip_wear, [{equip_wear, Data}]);
        _ ->
            ignore
    end,
    {ok, PS}.

get_equip_type_list(Type) ->
    case Type of
        8 ->  [?ACHIEVEMENT_TYPE_1, 27];
        11 -> [?ACHIEVEMENT_TYPE_1, 28];
        _ ->  false
    end.

%%--------------------------------------------------
%% 上阵xx个xx品质战魂(1,29)
%% @param  PS   description
%% @param  Data Num
%% @return      description
%%--------------------------------------------------
war_soul_on_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_1, 29], war_soul_on, [{war_soul_on, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 上阵战魂总等级提升到xx级(1,30)
%% @param  PS   description
%% @param  Data  SumLv
%% @return      description
%%--------------------------------------------------
war_soul_up_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_1, 30], war_soul_up, [{war_soul_up, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 上阵战魂总星级到xx星(1,31)
%% @param  PS   description
%% @param  Data  SumStar
%% @return      description
%%--------------------------------------------------
war_soul_star_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_1, 31], war_soul_star, [{war_soul_star, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 拥有xx只xx品质宠物(1,32)
%% @param  PS   :: #player_status{}
%% @param  Data :: [{宠物品质, 数量}|...]
%% @return      :: {ok, #player_status{}}
%%--------------------------------------------------
own_pet_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_1, 32], pet_color, [{pet_color, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 升级宠物总等级到xx级(1,33)
%% @param  PS   :: #player_status{}
%% @param  Data :: [{进化等级, 数量}|...]
%% @return      :: {ok, #player_status{}}
%%--------------------------------------------------
pet_lv_up_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_1, 33], pet_sum_lv, [{pet_sum_lv, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 宠物穿戴xx个xx品质技能石 废弃 todo:
%% @param  PS   :: #player_status{}
%% @param  Data :: [{宠物品质, 数量}|...]
%% @return      :: {ok, #player_status{}}
%%--------------------------------------------------
pet_stone_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_1, 34], pet_stone_num, [{pet_stone_num, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 宠物宝石收集xx套xx颜色(需要佩戴一套完整颜色)(1,34)
%% @param  PS   :: #player_status{}
%% @param  Data :: [{color, 数量}|...]
%% @return      :: {ok, #player_status{}}
%%--------------------------------------------------
pet_stone_suit_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_1, 34], pet_stone_suit, [{pet_stone_suit, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 宠物觉醒等级达到xx级(1,35)
%% @param  PS   :: #player_status{}
%% @param  Data :: Num -- 总等级
%% @return      :: {ok, #player_status{}}
%%--------------------------------------------------
pet_awaken_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_1, 35], pet_awaken_sum_lv, [{pet_awaken_sum_lv, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 激活xx件xx阶红装(1,36)
%% @param  PS   :: #player_status{}
%% @param  Data :: [{阶数, 数量}|...]
%% @return      :: {ok, #player_status{}}
%%--------------------------------------------------
wear_red_equip_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_1, 36], red_equip_num, [{red_equip_num, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 圣物全套xx颜色(以上)(1,37)
%% @param  PS   :: #player_status{}
%% @param  Data :: [{color, Num}...]
%% @return      :: {ok, #player_status{}}
%%--------------------------------------------------
nucleon_suit_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_1, 37], nucleon_suit, [{nucleon_suit, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 圣物觉醒总等级xx级(1,38)
%% @param  PS   :: #player_status{}
%% @param  Data ::  SumLv
%% @return      :: {ok, #player_status{}}
%%--------------------------------------------------
nucleon_awaken_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_1, 38], nucleon_awaken_sum_lv, [{nucleon_awaken_sum_lv, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 神座激活xx个(1,39)
%% @param  PS   :: #player_status{}
%% @param  Data ::  Num
%% @return      :: {ok, #player_status{}}
%%--------------------------------------------------
god_active_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_1, 39], god_active, [{god_active, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 上阵神座总星级提升到xx星(1,40)
%% @param  PS   :: #player_status{}
%% @param  Data :: SumStar
%% @return      :: {ok, #player_status{}}
%%--------------------------------------------------
god_up_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_1, 40], god_lv, [{god_lv, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 穿戴xx个xx颜色座印(1,41)
%% @param  PS   :: #player_status{}
%% @param  Data :: [{color, Num}...]
%% @return      :: {ok, #player_status{}}
%%--------------------------------------------------
god_equip_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_1, 41], god_equip, [{god_equip, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 激活xx个座印4件套(1,42)
%% @param  PS   :: #player_status{}
%% @param  Data :: Num
%% @return      :: {ok, #player_status{}}
%%--------------------------------------------------
god_equip_suit_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_1, 42], god_suit, [{god_suit, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 任意座印达到等级xx级(1,43)
%% @param  PS   :: #player_status{}
%% @param  Data :: [{god_equip, lv}...]
%% @return      :: {ok, #player_status{}}
%%--------------------------------------------------
god_equip_up_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_1, 43], god_equip_lv, [{god_equip_lv, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 穿戴xx个xx颜色星辰(1,44)
%% @param  PS   :: #player_status{}
%% @param  Data :: [{color, num}...]
%% @return      :: {ok, #player_status{}}
%%--------------------------------------------------
galaxy_wear_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_1, 44], galaxy_wear, [{galaxy_wear, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 星辰商店刷新xx次(1,45)
%% @param  PS   :: #player_status{}
%% @param  Data :: Num - 通常为1
%% @return      :: {ok, #player_status{}}
%%--------------------------------------------------
galaxy_shop_refresh_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_1, 45], galaxy_shop_refresh, [{galaxy_shop_refresh, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 星辰商店购买xx次(1,46)
%% @param  PS   :: #player_status{}
%% @param  Data :: Num - 通常为1
%% @return      :: {ok, #player_status{}}
%%--------------------------------------------------
galaxy_shop_buy_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_1, 46], galaxy_shop_buy, [{galaxy_shop_buy, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% @doc 2. 活跃成就 @end
%%--------------------------------------------------
%%--------------------------------------------------
%% 不再孤单(拥有好友数量)(2,1)
%% @param  PS   description
%% @param  Data 当前好友数量
%% @return      description
%%--------------------------------------------------
add_friend_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_2, 1], own_friend, [{own_friend, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 聊天互动(世界聊天xx次)(2,2)
%% @param  PS   :: #player_status{}
%% @param  Data :: 聊天次数
%% @return      :: {ok, #player_status{}}
%%--------------------------------------------------
world_chat_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_2, 2], world_chat, [{world_chat, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 聊天互动(私聊xx次)(2,3)
%% @param  PS   :: #player_status{}
%% @param  Data :: 聊天次数
%% @return      :: {ok, #player_status{}}
%%--------------------------------------------------
private_chat_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_2, 3], private_chat, [{private_chat, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 送花xx慷慨(豪气)值(2,4)
%% @param  PS   :: description
%% @param  Data :: Value
%% @return      :: description
%%--------------------------------------------------
flower_send_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_2, 4], flower, [{flower, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 协助战斗xx次(一定需要成功才算,防止刷次数)(2,5)
%% @param  PS   :: description
%% @param  Data :: Num - 通常为1
%% @return      :: description
%%--------------------------------------------------
support_event(PS, Data) ->
    % ?INFO_TTY("support_event is ~w~n",[Data]),
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_2, 5], support, [{support, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 协助感谢xx次 (2,6)
%% @param  PS   :: description
%% @param  Data :: Num - 通常为1
%% @return      :: description
%%--------------------------------------------------
guild_thank_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_2, 6], guild_thank, [{guild_thank, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 激活xx个羁绊(2,7)
%% @param  PS   :: description
%% @param  Data :: Num
%% @return      :: description
%%--------------------------------------------------
mate_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_2, 7], mate, [{mate, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 宝宝点赞xx次(2,8)
%% @param  PS   :: description
%% @param  Data :: Num - 通常为1
%% @return      :: description
%%--------------------------------------------------
child_vote_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_2, 8], child_vote, [{child_vote, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 宝宝晒娃xx次(2,9)
%% @param  PS   :: description
%% @param  Data :: Num - 通常为1
%% @return      :: description
%%--------------------------------------------------
child_show_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_2, 9], child_show, [{child_show, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 组队战斗(参加xx次多人副本)(2,10)
%% @param  PS   :: #player_status{}
%% @param  Data :: 参加数量
%% @return      :: {ok, #player_status{}}
%%--------------------------------------------------
dungeon_crusade_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_2, 10], multi_dun_num, [{multi_dun_num, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 日常修炼(累计获得xx点日活跃度)(2,11)
%% @param  PS   :: #player_status{}
%% @param  Data :: 活跃度
%% @return      :: {ok, #player_status{}}
%%--------------------------------------------------
activity_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_2, 11], activity_point, [{activity_point, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 参与温泉xx次(2,12)
%% @param  PS   description
%% @param  Data 参加数量
%% @return      description
%%--------------------------------------------------
charm_beach_event(RoleId, Data) when is_integer(RoleId) ->
    async_event(RoleId, ?MODULE, charm_beach_event, Data);
charm_beach_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_2, 12], beach, [{beach, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 参与社团幻魔xx次(2,13)
%% @param  PS   :: description
%% @param  Data :: Num - 通常为1
%% @return      :: description
%%--------------------------------------------------
guild_boss_event(PS, Data) ->
    % ?INFO_TTY("guild_boss_event Data is ~w~n",[Data]),
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_2, 13], guild_boss, [{guild_boss, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 社团拍卖获得xx件商品(2,14)
%% @param  PS   :: description
%% @param  Data :: Num - 通常为1
%% @return      :: description
%%--------------------------------------------------
guild_auction_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_2, 14], guild_auction_get, [{guild_auction_get, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 参与护送xx次(2,15)
%% @param  PS   description
%% @param  Data 参加数量
%% @return      description
%%--------------------------------------------------
convoy_event(RoleId, Data) when is_integer(RoleId) ->
    async_event(RoleId, ?MODULE, convoy_event, Data);
convoy_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_2, 15], husong, [{husong, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 成功封印裂隙xx次(2,16)
%% @param  PS   :: description
%% @param  Data :: Num - 通常为1
%% @return      :: description
%%--------------------------------------------------
guild_collect_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_2, 16], guild_collect, [{guild_collect, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 成功协助击杀裂隙boss xx 次(2,17)
%% @param  PS   :: description
%% @param  Data :: Num - 通常为1
%% @return      :: description
%%--------------------------------------------------
guild_collect_support_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_2, 17], guild_collect_support_kill, [{guild_collect_support_kill, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 无尽领域击杀xx个敌人(2,18)
%% @param  PS   description
%% @param  Data 敌人数量
%% @return      description
%%--------------------------------------------------
void_fam_kill_player_event(RoleId, Data) when is_integer(RoleId) ->
    async_event(RoleId, ?MODULE, void_fam_kill_player_event, Data);
void_fam_kill_player_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_2, 18], void_fam_kill_enemy, [{void_fam_kill_enemy, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 无尽领域获得xx积分(2,19)
%% @param  PS   description
%% @param  Data 获得积分
%% @return      description
%%--------------------------------------------------
void_fam_score_event(RoleId, Data) when is_integer(RoleId) ->
    async_event(RoleId, ?MODULE, void_fam_score_event, Data);
void_fam_score_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_2, 19], void_fam_score, [{void_fam_score, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 参加社团晚宴xx次(2,20)
%% @param  PS   :: description
%% @param  Data :: Num - 通常为1
%% @return      :: description
%%--------------------------------------------------
guild_feast_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_2, 20], guild_feast, [{guild_feast, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 参与赛马投注xx次(2,21)
%% @param  PS   :: description
%% @param  Data :: Num - 通常为1
%% @return      :: description
%%--------------------------------------------------
glamour_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_2, 21], glamour, [{glamour, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 累计获得xx赛马投注币(2,22)
%% @param  PS   :: description
%% @param  Data :: Num
%% @return      :: description
%%--------------------------------------------------
glamour_coin_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_2, 22], glamour_coin, [{glamour_coin, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 参加xx次废土战场(饥饿游戏)(2,23)
%% @param  PS   :: description
%% @param  Data :: Num - 通常为1
%% @return      :: description
%%--------------------------------------------------
wasteland_war_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_2, 23], wasteland_war, [{wasteland_war, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 参加xx次百团大战(2,24)
%% @param  PS   :: description
%% @param  Data :: Num - 通常为1
%% @return      :: description
%%--------------------------------------------------
guild_war_event(PS, Data) ->
    % ?INFO_TTY("guild_war_event Data is ~w~n",[Data]),
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_2, 24], guild_war, [{guild_war, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 百团大战累计运输xx积分军需(2,25)
%% @param  PS   :: description
%% @param  Data :: Num
%% @return      :: description
%%--------------------------------------------------
guild_war_military_event(PS, Data) ->
    % ?INFO_TTY("guild_war_military_event Data is ~w~n",[Data]),
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_2, 25], guild_war_military, [{guild_war_military, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 参与跨服团战xx次(2,26)
%% @param  PS   :: description
%% @param  Data :: Num - 通常为1
%% @return      :: description
%%--------------------------------------------------
cross_camp_war_event(PS, Data) ->
    % ?INFO_TTY("cross_camp_war_event Data is ~w~n",[Data]),
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_2, 26], cross_guild_war, [{cross_guild_war, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 跨服团战中采集xx次(2,27)
%% @param  PS   :: description
%% @param  Data :: Num - 通常为1
%% @return      :: description
%%--------------------------------------------------
cross_camp_war_collect_event(RoleId, Data) when is_integer(RoleId) ->
    async_event(RoleId, ?MODULE, cross_camp_war_collect_event, Data);
cross_camp_war_collect_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_2, 27], cross_guild_war_collect, [{cross_guild_war_collect, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 聊天互动(公会聊天xx次)(2,28)
%% @param  PS   :: #player_status{}
%% @param  Data :: 聊天次数
%% @return      :: {ok, #player_status{}}
%%--------------------------------------------------
guild_chat_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_2, 28], guild_chat, [{guild_chat, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% @doc 3. 挑战成就 @end
%%--------------------------------------------------
%%--------------------------------------------------
%% 竞技场(胜利xx次)(3,1)
%% @param  PS   :: #player_status{}
%% @param  Data :: 通关层数
%% @return      :: {ok, #player_status{}}
%%--------------------------------------------------
arena_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_3, 1], win_arena_count, [{win_arena_count, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 赏金猎人(击杀xx只赏金boss)(3,2)
%% @param  PS   :: #player_status{}
%% @param  Data :: 击杀数量
%% @return      :: {ok, #player_status{}}
%%--------------------------------------------------
kill_reward_boss_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_3, 2], kill_reward_boss_num, [{kill_reward_boss, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 世界boss(击杀xx次世界boss)(废弃) todo:
%% @param  PS   :: #player_status{}
%% @param  Data :: 参加数量
%% @return      :: {ok, #player_status{}}
%%--------------------------------------------------
kill_world_boss_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_3, 4], kill_world_boss_count, [{kill_world_boss_count, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 世界boss最后一击(完成xx次世界boss最后一击)(废弃) todo:
%% @param  PS   :: #player_status{}
%% @param  Data :: 数量
%% @return      :: {ok, #player_status{}}
%%--------------------------------------------------
world_boss_last_att_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_3, 4], world_boss_last_att, [{world_boss_last_att, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% Boss杀手(击杀xx只个人boss)(3,3)
%% @param  PS   :: #player_status{}
%% @param  Data :: 击杀数量
%% @return      :: {ok, #player_status{}}
%%--------------------------------------------------
kill_per_boss_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_3, 3], kill_per_boss_num, [{kill_per_boss, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 击杀混乱星域幻魔xx次(3,4)
%% @param  PS   :: description
%% @param  Data :: Num - 通常为1
%% @return      :: description
%%--------------------------------------------------
deserted_boss_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_3, 4], deserted_boss, [{deserted_boss, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 击杀混乱星域精英xx次(3,5)
%% @param  PS   :: description
%% @param  Data :: Num - 通常为1
%% @return      :: description
%%--------------------------------------------------
deserted_elite_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_3, 5], deserted_elite, [{deserted_elite, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 经验副本(通关xx层)(3,6)
%% @param  PS   :: #player_status{}
%% @param  Data :: 通关层数
%% @return      :: {ok, #player_status{}}
%%--------------------------------------------------
dungeon_exp_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_3, 6], dun_exp, [{dun_exp, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 经验挂机使用一键加速xx次(3,7)
%% @param  PS   :: description
%% @param  Data :: Num - 通常为1
%% @return      :: description
%%--------------------------------------------------
dun_exp_quick_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_3, 7], dun_exp_quick, [{dun_exp_quick, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 爬塔副本(通关xx层)(3,8)
%% @param  PS   :: #player_status{}
%% @param  Data :: 通关层数
%% @return      :: {ok, #player_status{}}
%%--------------------------------------------------
dungeon_tower_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_3, 8], dun_tower, [{dun_tower, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 幻光副本(通关xx层)(3,10)
%% @param  PS   :: #player_status{}
%% @param  Data :: 通关层数
%% @return      :: {ok, #player_status{}}
%%--------------------------------------------------
dungeon_visus_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_3, 10], dun_visus, [{dun_visus, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 进阶材料副本通关xx次(3,11)
%% @param  PS   :: description
%% @param  Data :: Num - 通常为1
%% @return      :: description
%%--------------------------------------------------
dungeon_material_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_3, 11], dun_material, [{dun_material, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 宠物副本通关xx次(不能重复刷同一层)(3,12)
%% @param  PS   :: description
%% @param  Data :: Num - 通常为1
%% @return      :: description
%%--------------------------------------------------
dungeon_pet_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_3, 12], dun_pet, [{dun_pet, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 式神副本通关xx次(3,13)
%% @param  PS   :: description
%% @param  Data :: Num - 通常为1
%% @return      :: description
%%--------------------------------------------------
dungeon_god_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_3, 13], dun_god, [{dun_god, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 星辰副本xx章节(3,14)
%% @param  PS   :: description
%% @param  Data :: Num - 通常为1
%% @return      :: description
%%--------------------------------------------------
dungeon_galaxy_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_3, 14], dun_galaxy_pass, [{dun_galaxy_pass, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 星域世界挑战xx次(3,15)
%% @param  PS   :: description
%% @param  Data :: Num - 通常为1
%% @return      :: description
%%--------------------------------------------------
cross_point_fight_event(PS, Data) ->
    % ?INFO_TTY("cross_point_fight_event Data is ~w~n",[Data]),
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_3, 15], cross_point_fight, [{cross_point_fight, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 跨服国战挑战xx次(3,16)
%% @param  PS   :: description
%% @param  Data :: Num - 通常为1
%% @return      :: description
%%--------------------------------------------------
cross_country_war_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_3, 16], cross_country_war, [{cross_country_war, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 竞技排名达到前xx名(3,17)
%% @param  PS   :: #player_status{}
%% @param  Data :: 当前排名
%% @return      :: {ok, #player_status{}}
%%--------------------------------------------------
arena_rank_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_3, 17], arena_rank, [{arena_rank, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% @doc 4. 收集成就 @end
%%--------------------------------------------------
%%--------------------------------------------------
%% 累计获得xx交易券(4,1)
%% @param  PS   description
%% @param  Data 本次获得的交易券数量
%% @return      description
%%--------------------------------------------------
coin_get_event(RoleId, Data) when is_integer(RoleId) ->
    async_event(RoleId, ?MODULE, coin_get_event, Data);
coin_get_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_4, 1], point, [{point, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 累计消费(交易商店,名望商店)(4,2 - point_store)(4,4 - honour_store)
%% @param  PS   :: #player_status{}
%% @param  Data :: 消费金额
%% @return      :: {ok, #player_status{}}
%%--------------------------------------------------
shop_buy_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    case Data of
        [{?TYPE_COIN, 0, MoneyNum}] ->
            lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_4, 2], point_store, [{point_store, MoneyNum}]);
        [{?TYPE_HONOUR, 0, MoneyNum}] ->
            lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_4, 4], honour_store, [{honour_store, MoneyNum}]);
        [{coin, 0, MoneyNum}] ->
            lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_4, 2], point_store, [{point_store, MoneyNum}]);
        _ ->
            skip
    end,
    {ok, PS}.

%%--------------------------------------------------
%% 累计获得xx名望券(4,3)
%% @param  PS   description
%% @param  Data 本次获得的交易券数量
%% @return      description
%%--------------------------------------------------
honour_get_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_4, 3], honour, [{honour, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 累计获得xx社团贡献(4,5)
%% @param  PS   :: description
%% @param  Data :: Num
%% @return      :: description
%%--------------------------------------------------
guild_donate_get_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_4, 5], guild_donate_get, [{guild_donate_get, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 累计消费xx社团贡献(4,6)
%% @param  PS   :: description
%% @param  Data :: Num
%% @return      :: description
%%--------------------------------------------------
guild_donate_use_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_4, 6], guild_donate_use, [{guild_donate_use, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 累计激活xx件时装(4,7)
%% @param  PS   :: description
%% @param  Data :: Num
%% @return      :: description
%%--------------------------------------------------
active_fashion_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_4, 7], active_fashion, [{active_fashion, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 累计激活xx个称号(4,8)
%% @param  PS   :: description
%% @param  Data :: Num
%% @return      :: description
%%--------------------------------------------------
active_designation_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_4, 8], active_designation, [{active_designation, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 累计激活xx个装扮(4,9)
%% @param  PS   :: description
%% @param  Data :: Num
%% @return      :: description
%%--------------------------------------------------
active_dress_up_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_4, 9], active_dress_up, [{active_dress_up, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 衣橱风采值提升到xx(4,10)
%% @param  PS   :: description
%% @param  Data :: SumValue
%% @return      :: description
%%--------------------------------------------------
wardrobe_value_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_4, 10], wardrobe_value, [{wardrobe_value, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 激活xx个珍宝(4,11)
%% @param  PS   :: description
%% @param  Data :: SumNum
%% @return      :: description
%%--------------------------------------------------
active_foster_skin_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_4, 11], foster_skin_active, [{foster_skin_active, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 珍宝总星级提升到xx星(4,12)
%% @param  PS   :: description
%% @param  Data :: SumStar
%% @return      :: description
%%--------------------------------------------------
foster_skin_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_4, 12], foster_skin_sum_star, [{foster_skin_sum_star, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 激活xx个宝宝玩具(4,13)
%% @param  PS   :: description
%% @param  Data :: Num
%% @return      :: description
%%--------------------------------------------------
child_toy_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_4, 13], child_toy_active, [{child_toy_active, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 收集xx套宝宝玩具(4,14)
%% @param  PS   :: description
%% @param  Data :: Num
%% @return      :: description
%%--------------------------------------------------
child_toy_suit_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_4, 14], child_toy_suit, [{child_toy_suit, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 激活xx个宝宝技能(4,15)
%% @param  PS   :: description
%% @param  Data :: Num
%% @return      :: description
%%--------------------------------------------------
child_skill_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_4, 15], child_skill, [{child_skill, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 激活xx个宝宝时装(4,16)
%% @param  PS   :: description
%% @param  Data :: Num
%% @return      :: description
%%--------------------------------------------------
child_fashion_event(PS, Data) ->
    #player_status{id = RoleId, figure = Figure} = PS,
    #figure{lv = RoleLv} = Figure,
    lib_achievement:trigger(RoleId, RoleLv, [?ACHIEVEMENT_TYPE_4, 16], child_fashion, [{child_fashion, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 装备洗练
%% @param  PS   description
%% @param  Data [{Color, Num}]
%% @return      description
%%--------------------------------------------------
equip_wash_event(PS, _Data) ->
%%    #player_status{id = RoleId, figure = Figure} = PS,
%%    #figure{lv = RoleLv} = Figure,
%%    lib_achievement:trigger(RoleId, RoleLv, property_num, [{equip_wash, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 怪物死亡,备注:修改这里的参数要记得同时匹配lib_achievement do_trigger接口内的SaveDBCD
%% @param  PS    description
%% @param  MonLv 怪物的等级,和玩家等级相差100级以内才算
%% @return       description
%%--------------------------------------------------
mon_die_event(PS, _MonLv) ->
%%    #player_status{id = RoleId, figure = Figure} = PS,
%%    #figure{lv = RoleLv} = Figure,
%%    case RoleLv - MonLv < 100 of
%%        true ->
%%            lib_achievement:trigger(RoleId, RoleLv, kill_monster, [{kill_monster, []}]);
%%        false -> skip
%%    end,
    {ok, PS}.

%%--------------------------------------------------
%% 巅峰竞技中达到指定段位
%% @param  PS   description
%% @param  Data 段位
%% @return      description
%%--------------------------------------------------
top_pk_win_event(PS, _Data) ->
%%    #player_status{id = RoleId, figure = Figure} = PS,
%%    #figure{lv = RoleLv} = Figure,
%%    lib_achievement:trigger(RoleId, RoleLv, dan_race, [{dan_race, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 野外场景击杀玩家
%% @param  PS   description
%% @param  Data []
%% @return      description
%%--------------------------------------------------
kill_player_event(PS, _Data) ->
%%    #player_status{id = RoleId, figure = Figure} = PS,
%%    #figure{lv = RoleLv} = Figure,
%%    lib_achievement:trigger(RoleId, RoleLv, kill_player, [{kill_player, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 击杀红名玩家
%% @param  PS   description
%% @param  Data []
%% @return      description
%%--------------------------------------------------
kill_red_name_event(PS, _Data) ->
%%    #player_status{id = RoleId, figure = Figure} = PS,
%%    #figure{lv = RoleLv} = Figure,
%%    lib_achievement:trigger(RoleId, RoleLv, kill_red_player, [{kill_red_name, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 玩家死亡
%% @param  PS   description
%% @param  Data []
%% @return      description
%%--------------------------------------------------
player_die_event(PS, _Data) ->
%%    #player_status{id = RoleId, figure = Figure} = PS,
%%    #figure{lv = RoleLv} = Figure,
%%    lib_achievement:trigger(RoleId, RoleLv, death, [{death, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 玩家魅力值达到多少
%% @param  PS   description
%% @param  Data 玩家当前魅力值
%% @return      description
%%--------------------------------------------------
flower_get_event(PS, _Data) ->
%%    #player_status{id = RoleId, figure = Figure} = PS,
%%    #figure{lv = RoleLv} = Figure,
%%    lib_achievement:trigger(RoleId, RoleLv, flower_get, [{role_charm, Data}]),
    {ok, PS}.

%%--------------------------------------------------
%% 击杀指定怪物  和玩家等级相差100级以内才算
%% @param  PS   description
%% @param  Data [怪物Id, 怪物的等级]
%% @return      description
%%--------------------------------------------------
kill_monster_event(PS, _Data) ->
%%    {MonId, MonLv} = Data,
%%    #player_status{id = RoleId, figure = Figure} = PS,
%%    #figure{lv = RoleLv} = Figure,
%%    case RoleLv - MonLv < 100 of
%%        true ->
%%            lib_achievement:trigger(RoleId, RoleLv, monster_num, [{monster_id, MonId}]);
%%        false -> skip
%%    end,
    {ok, PS}.