%% ----------------------------------------
%% desc:唤神副本头文件
%% 
%% ----------------------------------------

%% 波数奖励
-record(base_god_dun_wave_reward, {
    wave = 0,
    rewards = [],
    score = 0,          %% 兑换积分
    rank_score = 0      %% 排行积分
    }).


%% 排名奖励
-record(base_god_dun_rank_reward, {
    rank_type = 0,      %% 1排名值|2百分比
    rank_min = 0,
    rank_max = 0,
    limit = 0,
    rewards = []
    }).

%% 商品项配置
-record(base_god_dun_shop_goods, {
    index = 0,          %% 商品序号
    goods_id = 0,       %% 商品ID
    is_bind = 0,        %% 是否绑定
    goods_num = 0,      %% 单次购买物品数量
    price = 0,          %% 价格
    rank_weight = 0     %% 排序权重
    }).

%% 商品规则配置
-record(base_god_dun_shop_rule, {
    lv_min = 0,             %% 等级上限
    lv_max = 0,             %% 等级下限
    fix_goods = [],         %% 每日固定商品列表
    rand_goods = [],        %% 每日随机商品列表
    rand_num = 0,           %% 每日随机商品数
    week_fix_goods = [],    %% 每周固定商品列表
    week_rand_goods = [],   %% 每周随机商品列表
    week_rand_num = 0       %% 每周随机商品数
    }).

%% 唤神副本-怪物配置
-record(base_god_dun_mon_cfg, {
    mon_id = 0,             %% 怪物ID
    type = 0,               %% 抽取类型
    rank = 0,               %% 排名值
    attrs = [],             %% 属性转换列表
    info_from_rank = 0,     %% 信息抽取排名
    figure = 0              %% 0怪物|1玩家
    }).

%% 百分比排名对照配置
-record(base_god_percent_rank_cfg, {
    rank_min = 0,
    rank_max = 0,
    percent = 0
    }).

%% -----------------------------------------------------
%% 人物唤神副本相关数据
-record(role_god_dun, {
    day_shop_list = [],
    day_time = 0,
    week_shop_list = [],
    week_time = 0,
    role_attrs = [],
    cross_day = 0
    }).


%% 唤神排行数据
-record(god_dun_rank_state, {
    score_rank = [],        %% {zone_id, 积分排行}
    dun_wave_rank = [],     %% 副本轮次排名 {{zone_id, wave}, 波数积分排行}
    power_rank = [],        %% {zone_id, 战力排行}
    today_roles = [],       %% zone_id => [{role_id, time}]今日参与玩家列表(进副本打过的)
    extra_map = #{},
    srvzones = #{},
    zonesrvs = []
    }).

%% 唤神排行本地数据-只读
-record(god_dun_rank_local_state, {
    score_rank = [],        %% [#god_dun_score_role{}]
    dun_wave_rank = [],     %% [{wave, [#god_dun_wave_score_role{}]}]
    power_rank = [],
    today_roles = 0         %% 本区活跃人数
    }).

% 积分排行 小分区范围 周清 定时刷新 
% 波数排行 小分区范围 周清 定时刷新
% 战力排行 小分区范围 每日刷新
% 活跃人数 小分区范围 周清 定时刷新

%% 唤神积分排行人物数据(周清)
-record(god_dun_score_role, {
    role_id = 0,
    rank = 0,
    server_id = 0,
    server_num = 0,
    score = 0,
    display = 0,
    show = undefined,        %% #role_key_figure{}
    pass = 0
    }).

%% 副本截止轮次积分排行信息(周清)
-record(god_dun_wave_score_role, {
    dun_id = 0,
    wave = 0,
    role_id = 0,
    server_id = 0,
    server_num = 0,
    score = 0,
    rank = 0,
    show = undefined         %% #wave_key_figure{}
    }).

%% 战力排行信息(日更)
-record(god_dun_power_role, {
    role_id = 0,
    role_name = "",
    server_id = 0,
    server_num = 0,
    lv = 0,
    power = 0,
    rank = 0,
    attrs = []              %% 部分基础属性列表
    }).

%% 人物简要信息
-record(role_key_figure, {
        id = 0,
        name = "",
        sex = 0,
        career = 0,
        turn = 0,
        vip_type = 0,
        vip = 0,
        sup_vip = 0,
        lv = 0,
        power = 0,
        picture = "",
        picture_ver = 0,
        profile_photo_id = 0,
        dress_list = []    
    }).

%% 人物简要信息 波数积分用
-record(wave_key_figure, {
    name = "",
    profile_photo_id = 0
    }).

%% 唤神副本其他服的人物信息
-record(god_dun_cls_role, {
    role_id = 0,                        %% 人物id
    node = undefined,                   %% 游戏节点
    svr_num = 0,                        %% 区服编号
    figure = undefined,                 %% 人物形象
    time = 0                            %% 过期时间
    }).

-define(INIT_REF,              1).      %% 初始化定时
-define(NOTICE_REF,            2).      %% 广播定时
-define(ZONE_CALC_SIGN,        3).      %% 分区完成标志
-define(RANK_INIT_SIGN,        4).      %% 排行初始化完成标志
-define(ZONE_INIT_REF,         5).      %% 排行分区数据初始化定时
-define(RANK_ZONE_UPDATE_REF,  6).      %% 排行分区更新定时
-define(NOTICE_POWER_RANK_REF, 7).      %% 通知战力排行上传定时
-define(RESET_POWER_RANK_REF,  8).      %% 刷新战力排行定时

-define(GOD_DUN_USE_ATTR, 
    [1, 2, 4, 5, 6, 7, 8]).

-define(RANK_LIMIT_WAVE, 5).

-define(MOD_GOD_DUN_SCORE,     2).      %% 子类型 - 唤神副本每周最高积分

-define(ETS_GOD_DUN_CLS_ROLE,  ets_god_dun_cls_role).

-define(SQL_ROLE_GOD_DUN_SELECT, 
    <<"SELECT day_shop_list, day_time, week_shop_list, week_time, role_attrs FROM role_god_dun WHERE role_id = ~p">>).

-define(SQL_ROLE_GOD_DUN_REPLACE, 
    <<"REPLACE INTO role_god_dun SET role_id = ~p, day_shop_list = ~ts, day_time = ~p, week_shop_list = ~ts, week_time = ~p, role_attrs = ~ts">>).

-define(SQL_ROLE_ATTRE_SELECT, 
    <<"SELECT role_attrs FROM role_god_dun WHERE role_id = ~p">>).



-define(SQL_GOD_DUN_WAVE_SCORE_SELECT, 
    <<"SELECT dun_id, wave, role_id, server_id, server_num, score, role_show FROM god_dun_wave_score">>).

-define(SQL_BATCH_GOD_DUN_RANK_WAVE_SCORE_REPLACE, 
    <<"REPLACE INTO god_dun_wave_score (dun_id, wave, role_id, server_id, server_num, score, role_show) VALUES ~ts">>).

-define(SQL_BATCH_GOD_DUN_RANK_WAVE_SCORE_VAL, 
    <<"(~p, ~p, ~p, ~p, ~p, ~p, '~ts')">>).

-define(SQL_GOD_DUN_WAVE_SCORE_REPLACE, 
    <<"REPLACE INTO god_dun_wave_score SET dun_id = ~p, wave = ~p, role_id = ~p, server_id = ~p, server_num = ~p, score = ~p, role_show = ~ts">>).

-define(SQL_GOD_DUN_WAVE_SCORE_DELETE, 
    <<"DELETE FROM god_dun_wave_score WHERE dun_id = ~p and wave = ~p and role_id = ~p">>).

-define(SQL_DELETE_DUN_RANK_WAVE_SCORE, 
    <<"TRUNCATE TABLE god_dun_wave_score">>).



-define(SQL_GOD_DUN_SELECT,
    <<"SELECT role_id, server_id, server_num, score, role_show, pass FROM god_dun_score">>).

-define(SQL_BATCH_REPLACE_GOD_DUN_RANK, 
    <<"REPLACE INTO god_dun_score (role_id, server_id, server_num, score, role_show, pass) VALUES ~ts">>).

-define(SQL_BATCH_GOD_DUN_RANK_VAL,
    <<"(~p, ~p, ~p, ~p, '~ts', ~p)">>).

-define(SQL_ROLE_SCORE_REPLACE, 
    <<"REPLACE INTO god_dun_score SET role_id = ~p, server_id = ~p, server_num = ~p, score = ~p, role_show = ~ts, pass = ~p">>).

-define(SQL_DELETE_DUN_RANK_SCORE, 
    <<"TRUNCATE TABLE god_dun_score">>).


-define(SQL_GOD_LIVE_ROLE_SELECT, 
    <<"SELECT role_id, server_id, time FROM role_god_dun_live">>).

-define(SQL_GOD_LIVE_ROLE_REPLACE, 
    <<"REPLACE INTO role_god_dun_live SET role_id = ~p, server_id = ~p, time = ~p">>).

-define(SQL_DELETE_LIVE_ROLE, 
    <<"TRUNCATE TABLE role_god_dun_live">>).