%% --------------------------
%% desc     :塔防副本头文件
%% module   :dun_guard.hrl
%% author   :hh
%% time     :20/07/06
%% --------------------------

-ifndef(DUN_GUARD_HRL).
-define(DUN_GUARD_HRL, ok).

-define(DUN_GUARD_TOWER, dun_guard_tower).

-define(SELECT_ROLE_DUN_GUARD_ACHIEVE, 
    <<"SELECT dun_id, wave, state FROM role_dun_guard_achieve WHERE role_id = ~p">>).

-define(REPLACE_INTO_ROLE_DUN_ACHIEVE,
    <<"REPLACE INTO role_dun_guard_achieve SET role_id = ~p, dun_id = ~p, wave = ~p, state = ~p">>).

-record(base_dun_guard_achieve, {
    dun_id = 0,                %% 副本id
    wave   = 0,                %% 波数
    rewards = [],              %% 里程碑奖励
    breaking_rewards = []       %% 全服首通奖励
    }).

-record(base_dun_guard_revive, {
    count = 0,                 %% 复活次数
    cd = 0,                    %% 复活cd
    cost = []                  %% 复活消耗
    }).

-record(base_dun_guard_tower_pos, {
    dun_id = 0,                %% 副本ID
    pos = []                   %% 塔坐标
    }).

-define(TOWER_ALIVE,   0).       %% 初始状态
-define(TOWER_KILLED,  1).       %% 死亡状态

-define(TOWER_EXIST,   2).       %% 仍有塔怪存活
-define(ALL_TOWER_DIE, 3).       %% 所有塔怪死亡

-define(ACHIEVING,        1).    %% 达成可领
-define(HAVE_REWARDED,    2).    %% 已领

-record (guard_assist_state, {
    guard_pass_history = []     %% 历史首通记录 [#guard_pass_log{},...]
    ,map = #{}
    }).

-record (guard_assist_data, {
    assist_rank = []
    ,map = #{}
    }).

-record (guard_pass_log, {
    dun_id = 0,                 %% 副本id
    pass_time = 0,              %% 通关时间
    role_list = []              %% 队伍成员 [#guard_team_role{},...]
    }).

%% 通关记录队伍成员
-record (guard_team_role, {
    role_id = 0,
    figure = undefined,
    server_id = 0,
    server_num = 0
    }).

%% 支援榜个人数据
-record(guard_assist_role, {
    role_id = 0,
    val = 0,
    power = 0,
    rank = 0
    }).


%% 支援榜排名奖励
-record(base_dun_guard_assist_reward, {
    rank_min = 0,               %% 排名上限
    rank_max = 0,               %% 排名下限
    reward = []                 %% 奖励
    }).

-record(base_dun_guard_wave_assist, {
    dun_id = 0,                 %% 副本id
    wave_min = 0,               %% 副本波数上限
    wave_max = 0,               %% 副本波数下限
    val = 0                     %% 支援值
    }).

-define (SQL_SELECT_GUARD_PASS_LOG, 
    <<"SELECT `dun_id`, `pass_time`, `team_mates` FROM `role_guard_pass_log`">>).

-define (SQL_REPLACE_GUARD_PASS_LOG,
    <<"REPLACE INTO `role_guard_pass_log`(`dun_id`, `pass_time`, `team_mates`) VALUES (~p, ~p, ~ts)">>).


-define (SQL_SELECT_GUARD_ASSIST_RANK,
    <<"SELECT `role_id`, `server_id`, `server_num`, `val`, `power` FROM `role_guard_assist_rank`">>).

-define (SQL_BATCH_REPLACE_GUARD_ASSIST_RANK,
    <<"REPLACE INTO `role_guard_assist_rank` (`role_id`, `server_id`, `server_num`, `val`, `power`) VALUES ~ts">>).

-define (SQL_BATCH_GUARD_ASSIST_RANK_VALUES,
    <<"(~p, ~p, ~p, ~p, ~p)">>).

-define (SQL_REPLACE_GUARD_ASSIST_RANK,
    <<"REPLACE INTO `role_guard_assist_rank` SET `role_id` = ~p, `server_id` = ~p, `server_num` = ~p, `val` = ~p, `power` = ~p">>).

-define (SQL_DELETE_GUARD_ASSIST_RANK,
    <<"DELETE FROM `role_guard_assist_rank` WHERE `val` < ~p">>).

-define (SQL_BATCH_DELETE_GUARD_ASSIST_RANK,
    <<"TRUNCATE TABLE `role_guard_assist_rank`">>).

-endif.