%%%-------------------------------------------------------------------
%%% @doc     公会竞速
%%% Module  : lib_guild_race_rank.erl
%%% Created : 2020-07-16
%%% @Author : tyl
%%%-------------------------------------------------------------------
-module(pp_guild_race_rank).

-include("server.hrl").
-include("guild_race_rank.hrl").
-include("guild.hrl").
-include("def_module.hrl").
-include("def_vip.hrl").
-include("figure.hrl").
-include("errcode.hrl").
-include("common.hrl").

-export([handle/3]).


handle(Cmd, Player, Data) ->
	#player_status{figure = Figure} = Player,
	OpenLv = lib_module:get_open_lv(?MOD_AC_CUSTOM, 66),
	case Figure#figure.lv >= OpenLv of
		true ->
			do_handle(Cmd, Player, Data);
		false -> skip
	end.

%% 查询社团榜信息
do_handle(40700, Player, []) ->
	#player_status{guild = StatusGuild} = Player,
	mod_guild_race_rank:get_guild_rank(Player#player_status.id, StatusGuild#status_guild.id),
	{ok, Player};

%% 查询个人榜信息
do_handle(40701, Player, []) ->
	#player_status{id = RoleId, guild = StatusGuild} = Player,
	mod_guild_race_rank:get_member_rank(StatusGuild#status_guild.id, RoleId),
	{ok, Player};

%% 上线查询个人排行和称号
do_handle(40702, Player, []) ->
	#player_status{id = RoleId, guild = StatusGuild, login_time_before_last = LastLoginTime} = Player,
	%% 1小时之内登录多次，只推送一次
	case LastLoginTime + 3600 =< utime:unixtime() of
		true ->
			mod_guild_race_rank:get_member_rank_dsg(StatusGuild#status_guild.id, RoleId);
		_ ->
			ignore
	end,
	{ok, Player};

%% 查询活跃榜排行
do_handle(40703, Player, []) ->
	#player_status{id = RoleId, guild = StatusGuild} = Player,
	mod_guild_race_rank:get_guild_live_rank(RoleId, StatusGuild#status_guild.id),
	{ok, Player};

%% 查询奖励领取状态
do_handle(40704, Player, [RewardType]) ->
	#player_status{id = RoleId, guild = StatusGuild} = Player,
	mod_guild_race_rank:reward_receive_status(RoleId, StatusGuild#status_guild.id, RewardType),
	{ok, Player};

%% 领取奖励
do_handle(40705, Player, [RewardType]) ->
	#player_status{id = RoleId, guild = StatusGuild} = Player,
	case RewardType of
		1 -> mod_guild_race_rank:receive_power_reward(RoleId, StatusGuild#status_guild.id);
		2 -> mod_guild_race_rank:receive_live_reward(RoleId, StatusGuild#status_guild.id);
		3 -> mod_guild_race_rank:receive_captain_power_reward(RoleId, StatusGuild#status_guild.id);
		4 -> mod_guild_race_rank:receive_captain_live_reward(RoleId, StatusGuild#status_guild.id);
		_ -> ignore
	end,
	{ok, Player};

%% 查询团长任务信息
do_handle(40706, Player, []) ->
	lib_guild_race_rank_task:get_task_info(Player),
	{ok, Player};

%% 查询团长任务信息
do_handle(40707, Player, [TaskId]) ->
	lib_guild_race_rank_task:receive_task_reward(Player, TaskId),
	{ok, Player};

do_handle(_Cmd, _Player, _Data) ->
	{error, "pp_guild_race_rank no match~n"}.