%%%-------------------------------------------------------------------
%%% @author liushl
%%% @doc
%%%
%%% @end
%%%-------------------------------------------------------------------
-module(fix_equipment_collect).
-author("liushl").

-include("predefine.hrl").
-include("server.hrl").
-include("figure.hrl").
-include("equipment.hrl").
-include("goods.hrl").
%% API

-compile(export_all).

fix_equipment_collect() ->
    %% 找出所有充值玩家
    Sql = <<"select role_id from player_recharge_rfmt where last_pay_time>0">>,
    Roles = db:get_all(Sql),
    Pid = spawn(fun() -> ok end),   % 构造一个过时的Pid
    [
        case lib_player:is_online_global(RoleId) of
            true  ->
                lib_player:apply_cast(RoleId, ?APPLY_CAST_STATUS, ?MODULE, fix_equipment_collect_do, []);
            false ->
                fix_equipment_collect_offline(RoleId, Pid)
        end
        || [RoleId] <- Roles
    ].

%% 离线玩家处理，构造一份数据
fix_equipment_collect_offline(RoleId, Pid) ->
    Equipment = equipment_collect:login(RoleId, #equipment{}),
    Figure = lib_role:get_role_figure(RoleId),
    Player = #player_status{id = RoleId, sid = Pid, figure = Figure, equipment = Equipment},
    fix_equipment_collect_do(Player).

%% 调用已有接口，模拟
fix_equipment_collect_do(Player) ->
    Career = Player#player_status.figure#figure.career,
    GoodsId =
        case Career of
            1  -> 24191015;
            2  -> 24191015;
            3  -> 24291015;
            4  -> 24291015
        end,
    GoodsInfo = #goods{
        goods_id = GoodsId,
        subtype = 1,
        color = 4
    },
    equipment_collect:check_collect(Player, GoodsInfo).