%%%-------------------------------------------------------------------
%%% @author liushl
%%% @doc
%%%     本服BOSS头文件
%%% @end
%%%-------------------------------------------------------------------
-author("liushl").

%% BOSS类型 读怪物头文件的BOSS类型

-define(WORLD_BOSS_SHIELD_AWARD_TIME,  11). %% 护盾奖励有效期

%% 保护时间
%% 1>类型
-define(REWARD_BOSS_PROTECT_TIME,   1).     %% 赏金boss
-define(DESERTED_BOSS_PROTECT_TIME, 2).     %% 星域幻魔
%% 2>计数器类型
-define(REWARD_BOSS_PROTECT_USE_TIMES,     5).   %% 使用次数
-define(REWARD_BOSS_PROTECT_CONTINUE_TIME, 6).   %% 结束时间
-define(DESERTED_BOSS_PROTECT_USE_TIMES,     4).
-define(DESERTED_BOSS_PROTECT_CONTINUE_TIME, 5).

%% 本服BOSS延迟初始化时间
-ifdef(DEV_SERVER).
-define(LOCAL_BOSS_DELAY_TIME, 5000).
-else.
-define(LOCAL_BOSS_DELAY_TIME, 60000).
-endif.

%% 计数器
%% 周计数器
-define(WORLD_BOSS_WEEK_SCORE, 1). %% 世界BOSS周积分计数器
%% 日计数器
-define(COUNT_REWARD_BOSS_DAILY_USE,            1).  %% 赏金BOSS每日使用次数
-define(COUNT_REWARD_BOSS_BUY,                  2).  %% 赏金BOSS每日购买次数
-define(COUNT_REWARD_BOSS_TOTAL_TIMES,          4).  %% 赏金BOSS每日增加次数

-define(COUNT_REWARD_BOSS_DAILY_KILL,           7).  %% 赏金BOSS每日击杀次数，统计用
-define(COUNT_DESERTED_BOSS_DAILY_KILL,         8).  %% 星域BOSS每日击杀次数，统计用

-define(COUNT_HOME_BOSS_KILL,      1).  %% 幻魔之家击杀次数
%% 终生计数器
-define(COUNT_REWARD_BOSS_COUNTER_KILL,         1).  %% 赏金BOSS击杀次数
-define(COUNT_REWARD_ALLBOSS_COUNTER_KILL,      2).  %% 所有赏金BOSS击杀次数
%% 赏金BOSS掉落日志长度
-define(REWARD_BOSS_LOG_LENGTH,  50).
%% 赏金BOSS结算踢人时间
-define(REWARD_BOSS_CLEAN_TIME, 15).

%% BOSS场景人数限制
-define(BOSS_SCENE_ROLE_NUM,  50).
%% 怪物数据参数
-define(LOCAL_BOSS_ARGS_TOP,       1).  %% 伤害第一
-define(LOCAL_BOSS_ARGS_HURT_LIST, 2).  %% 伤害统计
-define(LOCAL_BOSS_LAST_HIT,       3).  %% 上次击杀时间

%% 认为玩家功击频率
-define(ROLE_HIT_FRE,  3).

-record(boss_hit_info, {
    last_time = 0,      %% 上次受击时间
    sum_time = 0,       %% 统计受击时间
    notice_count = 0,   %% 累计受击次数
    die_state = 0,      %% 死亡状态
    time_need = 0,      %% 存活时间
    count_need = ?ROLE_HIT_FRE      %% 血量刷新间隔：受击次数
}).

%% 本服BOSS玩家数据
-record(status_local_boss,{
    reward_boss_tired = 0       %% 赏金BOSS疲劳值
    , boss_focus = []           %% 关注的赏金BOSS们
    , deserted_boss_tired = 0   %% 废都BOSS疲劳值
    , deserted_elite_tired = 0  %% 废都精英怪疲劳值
    , ta_data = #{}             %% TA 数据上报使用
}).

%%%-------------------------------------------------------------------
%%% @doc 世界BOSS
%%%-------------------------------------------------------------------
%% 管理进程
-record(local_world_boss, {
    boss_info = [],     %% boss信息
    week_rank = #{},    %% 周榜数据 #{榜单类型 => {refresh_flag, Ranks}}
    end_time = 0,       %% 活动结束时间
    next_time = 0,      %% 下次活动开始时间：预告时间
    ref                 %% 活动定时器
}).
%% 世界boss信息
-record(world_boss_info, {
    boss_id = 0
    , boss_pid                  %% 怪物进程
    , mon_id                    %% 怪物唯一id
    , dead_time = 0             %% 死亡时间/0存活
    , hp = 0                    %% 血量
    , hp_lim = 0
    , shield_reward_no = 0      %% 护盾活动编号
    , shield_reward = []        %% 护盾奖励情况[{Id, RoleList, Ref}|_]
    , shield_value = 0          %% 护盾上限值
}).
%% 积分榜单 可以从周计数器里拿
-record(boss_score_rank, {
    role_id = 0
    , score = 0
    , time = 0   %% 刷新时间
    , power = 0  %% 玩家战力
}).
%%%-------------------------------------------------------------------
%%% @doc 赏金BOSS
%%%-------------------------------------------------------------------
%% 管理进程
-record(local_reward_boss, {
    boss_info = []
    , drop_log_low_quality = []
    , drop_log_high_quality = []
    , encourage_info = []   %% 赏金BOSS鼓舞[{玩家id,彩钻鼓舞,红钻鼓舞}], 离开场景清除
}).
%% boss信息
-record(reward_boss_info, {
    boss_id = 0
    , boss_pid              %% 怪物进程
    , mon_id = 0            %% 怪物唯一id
    , born_time = 0         %% 出生时间
    , reborn_time = 0       %% 复活时间，存活则为0
    , last_killer = <<>>    %% 赏金BOSS上次击杀玩家
    , ref_reborn            %% 赏金BOSS复活定时器
}).

%% -------------------------------------------------------------------
%% @doc 古战场boss
%% -------------------------------------------------------------------

-define(DESERTED_BOSS_USE_COUNT,    1). %% boss使用次数
-define(DESERTED_ELITE_USE_COUNT,   2). %% 精英怪使用次数

-record(deserted_boss_state, {
    boss_info = [],
    elite_mon_info = [],
    zone_id = 0,
    fac_id = 0,
    map = #{},
    cls_type = 0
    }).

%% 星域幻魔boss信息
-record(deserted_boss_info, {
    boss_id = 0
    , boss_pid              %% 怪物进程
    , mon_id                %% 怪物唯一id
    , born_time = 0         %% 出生时间
    , reborn_time = 0       %% 复活时间，存活则为0
    , last_killer = <<>>    %% 上次击杀玩家
    , srv_num = 0           %% 击杀者服务器编号
    , ref_reborn            %% 复活定时器
    }).

%% -------------------------------------------------------------------
%% @doc 活动boss
%% -------------------------------------------------------------------
-record(local_act_boss, {
    sub_type    = 0      %% 活动子类
    , boss_info = []            %% 所有BOSS
    , boss_num  = 0
    , next_time = 0             %% 下场BOSS时间戳
    , ref_born  = undefined     %% 出生定时器
}).
%% boss信息
-record(act_boss_info, {
    mon_id          = 0             %% 怪物唯一id
    , boss_id       = 0
    , boss_pid      = undefined     %% 怪物进程
    , alive         = 1             %% 是否存活
    , scene_id      = 0             %% 场景
    , pool_id       = 0             %% 分线
    , x             = 0
    , y             = 0
    , share_roles   = []            %% 分享的玩家
}).

%% -------------------------------------------------------------------
%% @doc 幻魔之家
%% -------------------------------------------------------------------
-record(home_boss_state, {
    sub_module = 0,
    boss_infos = [],                  %% [{rank_index, guild, [#home_boss{}]},...]
    guild_boss_pids = #{},            %% #{guild => {rank_index, scene_pool}} 排名 => {社团, 分线}
    map = #{}
    }).

-record(home_boss, {
    mon_id      = 0             %% 怪物唯一id
    , boss_id   = 0
    , boss_pid  = undefined     %% 怪物进程
    , pool_id   = 0             %% 分线
    , pos       = {0, 0}
    , ref       = undefined
    , killer    = <<>>
    , dead_time = 0             %% 死亡时间
    , born_time = 0             %% 出生时间
    , reborn_time = 0             %% 下次出生时间
    , guild = 0
    }).

%% -------------------------------------------------------------------
%% @doc 掉落日志
%% -------------------------------------------------------------------
-record(boss_drop_log, {
    name = <<>>
    , scene = 0
    , svr_num = 0
    , boss = 0
    , boss_type = 0
    , goods_id = 0
    , time = 0
}).

%% 赏金主线副本任务的怪物id
-define (REWARD_BOSS_DUN_MON, 13010000).
%% 赏金主线副本任务的副本id
-define (REWARD_BOSS_TASK_DUN, 3605).
%% 赏金主线任务id
-define (REWARD_BOSS_TASK_ID, 11260).

%% ------------------------------------------------------------------
%% @doc TA自定义记录数据类型
%% ------------------------------------------------------------------
-define(ENTER_TIME,     1).
-define(INSPIRE_GOLD,   2).
-define(INSPIRE_BGOLD,  3).
-define(INSPIRE_TICK,   4).
-define(REVIVE_TIME,    5).

%%%-------------------------------------------------------------------
%%% @doc DB
%%%-------------------------------------------------------------------
%% 获得世界BOSS状态
-define(SQL_GET_WORLD_BOSS_STATUS, <<"select boss_id,born_time,dead_time from local_boss_status where boss_type=~p">>).
%% 获得周榜数据
-define(SQL_GET_WEEK_RANK, <<"select a.role_id,a.count,a.refresh_time,b.last_combat_power from counter_week a left join player_state b on a.role_id=b.id
    where a.module=~p and a.sub_module=~p and a.type=~p and a.refresh_time>~p">>).
%% 保存世界BOSS状态-批量打包数据
-define(SQL_FORMAT_WORLD_BOSS_STATUS, <<"(~p, ~p, ~p, ~p)">>).
%% 保存世界BOSS状态-批量写入数据
-define(SQL_SAVE_WORLD_BOSS_STATUS, <<"replace into local_boss_status (boss_id,boss_type,born_time,dead_time) values ~ts">>).
%% 世界BOSS死亡，保存状态
-define(SQL_SAVE_ONE_WORLD_BOSS, <<"replace into local_boss_status(boss_id, boss_type, born_time, dead_time) values (~p,~p,~p,~p)">>).

%% 赏金BOSS死亡，获取上次击杀者
-define(SQL_GET_REWARD_BOSS_STATUS, <<"select boss_id,killer from local_boss_status where boss_type=~p">>).
%% 赏金BOSS死亡，保存状态
-define(SQL_SAVE_ONE_REWARD_BOSS, <<"replace into local_boss_status(boss_id, boss_type, born_time, dead_time, killer) values (~p,~p,~p,~p,~ts)">>).

%% 废都boss
-define(SQL_GET_LOCAL_DESERTED_BOSS_STATUS, <<"SELECT boss_id, dead_time, killer FROM local_boss_status WHERE boss_type = ~p">>).
-define(SQL_GET_DESERTED_BOSS_STATUS, <<"SELECT boss_id, dead_time, killer, srv_num FROM deserted_boss_status WHERE zone_id = ~p AND fac_id = ~p">>).
-define(SQL_REPLACE_DESERTED_BOSS_STATUS, <<"REPLACE INTO deserted_boss_status(zone_id, fac_id, boss_id, dead_time, killer, srv_num) values (~p, ~p, ~p, ~p, ~ts, ~p)">>).
-define(SQL_DELETE_DESERTED_BOSS_STATUS, <<"DELETE FROM deserted_boss_status WHERE zone_id = ~p AND fac_id = ~p">>).

%% 获得BOSS关注信息
-define(SQL_GET_BOSS_FOCUS, <<"select boss_id, boss_type from local_boss_focus where role_id=~p">>).
%% 保存BOSS关注
-define(SQL_SAVE_BOSS_FOCUS, <<"replace into local_boss_focus(role_id,boss_id,boss_type) values(~p,~p,~p)">>).
%% 删除BOSS关注
-define(SQL_DEL_BOSS_FOCUS, <<"delete from local_boss_focus where role_id=~p and boss_id=~p">>).

%% BOSS免战时间
-define(SQL_GET_BOSS_PROTECT_TIME, <<"select boss_type,protect_time from boss_protect_time where role_id=~p">>).
%% 保存BOSS关注
-define(SQL_SAVE_BOSS_PROTECT_TIME, <<"replace into boss_protect_time (role_id,boss_type,protect_time) values(~p,~p,~p)">>).

%% 幻魔之家
-define (SQL_GET_HOME_BOSS, <<"SELECT rank_index, boss_id, guild, born_time, dead_time, killer FROM home_boss_status WHERE sub_module = ~p">>).
-define (SQL_SAVE_ONE_HOME_BOSS, <<"REPLACE INTO home_boss_status(sub_module, rank_index, boss_id, guild, born_time, dead_time, killer) VALUES (~p, ~p, ~p, ~p, ~p, ~p, ~ts)">>).
-define (SQL_UPDATE_ONE_HOME_BOSS, <<"UPDATE home_boss_status SET guild = ~p WHERE sub_module = ~p AND rank_index = ~p">>).

%%%-------------------------------------------------------------------
%%% @doc 配置
%%%-------------------------------------------------------------------
-record(base_world_boss_info, {
    boss_id,
    boss_lv,
    boss_name,
    boss_scene,
    boss_position,
    relive_position,
    award_30_p,
    award_60_p,
    award_kill,
    award_assists,
    boss_picture,
    shield,
    rank_type,
    award_show_ratio,
    award_show_base,
    score_limit,
    score_limit_day
}).

-record(base_reward_boss_info, {
    boss_id,
    grade,
    boss_name,
    boss_scene,
    boss_position,
    relive_position,
    reborn_cfg,
    award_base,
    award_extra_num,
    award_extra,
    enter_lv,
    award_base_show,
    award_extra_show,
    boss_picture,
    is_peace,
    recommend_lv,
    recommend_attr,
    recommend_power
}).

-record(base_deserted_boss_info, {
    boss_id = 0,
    boss_name = "",
    level = 0,
    grade = 0,
    born_pos = [],
    reborn_time = [],
    base_reward = [],
    extra_reward = [],
    boss_pic = 0,
    recommend_lv = 0,
    recommend_attr = [],
    recommend_power = 0
    }).

-record(base_deserted_level, {
    level = 0,
    scene = 0,
    cls_scene = 0,
    open_lv = 0
    }).

-record(base_elite_mon, {
    index = 0,
    mon_id = 0,
    mon_name = "",
    level = 0,
    born_pos = [],
    reborn_time = []
    }).

-record(base_deserted_kv, {
    key,
    val,
    desc
    }).

%% 幻魔之家层数表
-record(base_home_boss_level, {
    sub_module = 0,     %% 子功能id 1|2
    level = 0,          %% 层数
    scene = 0,          %% 场景
    enter_lv = 0,       %% 进入等级限制
    condition = [],     %% 进入条件
    cost = []           %% 抵扣货币
    }).

%% 幻魔之家boss表
-record(base_home_boss, {
    sub_module = 0,         %% 子功能id 1|2
    boss_id = 0,            %% bossid
    grade = 0,              %% 代数
    name = "",              %% 名称
    level = 0,              %% 层数
    born_pos = [],          %% 坐标
    reborn_time = [],       %% 重生时间
    drop_show = [],         %% 掉落展示
    boss_pic = 0,           %% 头像
    recommend_power = 0,    %% 推荐战力
    recommend_lv = 0,       %% 推荐等级
    drop_lv_limit = 0,      %% 掉落等级差距
    recommend_attr = []     %% 推荐属性
    }).
