%% ---------------------------------------------------------------------------
%% @doc mod_guild_info.erl

%% @author  zengzy
%% @since  2018-06-11
%% @deprecated 帮派消息处理
%% ---------------------------------------------------------------------------
-module(mod_guild_info).
-export([handle_info/2]).

-include("guild.hrl").
-include("common.hrl").
-include("errcode.hrl").
-include("figure.hrl").

%% 初始化玩家figure
handle_info('init_guild_figure', Status) ->
	GuildMaps = lib_guild_data:get_guild_map(),
	Fun = fun(GuildId, _Guild, _Acc)->
		GuildMemberMap = lib_guild_data:get_guild_member_map(GuildId),
		Fun1 = fun
			(_, #guild_member{} = GuildMember) ->
				#guild_member{id = MemberId,combat_power = LastLogoutCombatPower} = GuildMember,
				case lib_role:get_figure_on_db(MemberId) of
				    [] -> Figure = #figure{};
				    Figure -> ok
				end,
				GuildMember#guild_member{figure=Figure#figure{power=LastLogoutCombatPower}};
			(_, GuildMember) ->
				GuildMember
		end,
		NewGuildMemberMap = maps:map(Fun1, GuildMemberMap),
		lib_guild_data:set_guild_member_map(GuildId, NewGuildMemberMap),
		_Acc
	end,
	maps:fold(Fun, 1, GuildMaps),
	{noreply, Status};

% %% 刷新排行
% handle_info('notify_salary_state', Status) ->
% 	spawn(fun()-> lib_guild_mod:notify_salary_state() end),
% 	{noreply,Status};

%% 同步数据到竞榜(活动开启时间晚于开服第一天才使用)
handle_info({sync_guild_msg}, Status) ->
	lib_guild_race_rank:sync_guild_msg(),
	{noreply, Status};

%% 同步社团的创建时间和上次刷新活跃值时间
handle_info({sync_guild_create_time}, Status) ->
	common_rank_logic:sync_guild_create_time(),
	{noreply, Status};

%% 默认匹配
handle_info(_Info, Status) ->
    ?PRINT("not match info:~p~n", [_Info]),
    {noreply, Status}.
