%% ------------------------
%% desc  :经验放置
%% author:hh
%% time  :20/01/16
%% ------------------------

%% 快速挂机基础经验
-record(base_fast_onhook_reward, {
    lv = 0,             %% 等级
    base_exp = 0,       %% 基础经验
    time = 0            %% 持续时间
    }).

%% 快速挂机多倍领取次数
-record(base_fast_onhook_multi_reward_count, {
    vip = 0,            %% vip等级
    count = 0           %% 次数
    }).

%% 货币类(经验)效率
-record(base_onhook_exp_effiency, {
    wave = 0,           %% 波数(关卡)
    effiency = 0        %% 效率
    }).

%% 掉落规则配置
-record(base_exp_dun_drop_rule, {
    lv   = 0,           %% 等级
    wave = 0,           %% 波数
    rule = []           %% 规则 [{1(轮次),[{2000(权重),[{1(掉落包id),1(掉落包个数)}]}]}] 万分制概率
    }).

%% 掉落物品配置
-record(base_exp_dun_drop_goods, {
    id = 0,             %% 掉落id
    list_id = 0,        %% 列表id
    goods_type = 0,     %% 物品类型
    goods_id = 0,       %% 物品id
    min = 0,            %% 最小数量
    max = 0,            %% 最大数量
    open_day = [],      %% 开服天数 
    weight = 0          %% 权重
    }).

%% -------------------------------------------------------

%% 公共进程数据
-record(exp_dun_drop_state, {
    calc_maps = #{},      %% 结算组别 #{组id => [role_id,....]} 映射列表
    start_time = 0,       %% 开始时间
    ref = undefined       %% 结算定时器
    }).

%% 个人数据,存储在公共进程字典
-record(drop_role, {
    id = 0,               %% 个人id
    wave_point = [],      %% 波数通关节点 [{wave, reach_time},...]
    off_point = [],       %% 离线时间节点 [{离线开始, 离线结束},...]
    start_time = 0,       %% 结算开启时间(领取完或玩家结算开启),个人活动状态决定开启时间
    calc_time = 0,        %% 最近一次结算时间,公共进程结算个人时更新此时间
    calc_goods = [],      %% 累积物品道具(最多不超过配置规定时限)
    goods_limit = [],     %% 限制的物品 产出数量
    is_rewarding = 0,     %% 是否在领奖,若领奖且正结算,则忽略 0否|1是
    remain = 0,           %% 上次结算结余时间
    extra_data = []       %% 其他数据如宠物生活技能/离线加成剩余时长 等 [{Mod, Data}]
    }).

%% 玩家放置经验&快速挂机数据-个人进程
-record(role_exp_dun_drop, {
    fast_drop_time = 0,
    cache_time_last = 0,
    last_time = 0
    }).

-ifdef (DEV_SERVER).
-define(EXP_DUN_DROP_INTERVAL,  600).    %% 玩家结算的间隔
-define(EXP_DUN_DROP_GROUP,       2).    %% 在玩家结算间隔中分割所有玩家的组数量
-else.
-define(EXP_DUN_DROP_INTERVAL,  3600).   %% 玩家结算的间隔
-define(EXP_DUN_DROP_GROUP,       15).   %% 在玩家结算间隔中分割所有玩家的组数量
-endif.

-define(EXP_DUN_DROP_SEC_PER_MIN, 60).

-define(EXP_DUN_RATIO_MAX, 10000).

%% 公共进程人物字典key
-define(DROP_ROLE_KEY(X), {drop_role, X}).

%%
-define(DB_MAX_LEN, 10).

%% 限制物品
-define(DROP_BLUE_EQUIP,   2). %% 蓝装
-define(DROP_PURPLE_EQUIP, 3). %% 紫装以上

%% 是否正领奖
-define(EXP_DROP_NOT_REWARD,    0).
-define(EXP_DROP_REWARDING,     1).

-define(EXP_DROP_CALCING,       2). %% 系统结算中

%% 开放功能子id
-define(EXP_DROP_1, 2).     %% 放置经验开启
-define(EXP_DROP_2, 15).    %% 快速挂机开启

%% 经验副本前置任务
-define(EXP_DUN_PRE_TASK, 10730).

%% 最小领取间隔
-define(EXP_DROP_REWARD_INTERVAL, 600).

%% 
-define(EXP_DROP_ERROR_LOG_TIME, exp_drop_log_time).

%% 离线挂机加成卡物品子类
-define(EXP_DROP_GOODS_SUB_TYPE, 41).

%% 数据移除最大间隔
-define(EXP_DROP_REMOVE, 259200).

-ifdef(DEV_SERVER).
-define(SVR_RATIO_ADD(ExpDropAddRatio, VipPrivilege, ServerLvExpRatio), 
    1 + ExpDropAddRatio/?RATIO_MAX + VipPrivilege/100 + 0/max(1, ServerLvExpRatio)).
-else.
-define(SVR_RATIO_ADD(ExpDropAddRatio, VipPrivilege, ServerLvExpRatio),
    1 + ExpDropAddRatio/?RATIO_MAX + VipPrivilege/100 + ServerLvExpRatio/100).
-endif.


-define(SELECT_ROLE_DROP_INFO,
    <<"SELECT calc_time, start_time, extra_data FROM role_exp_dun_drop WHERE role_id = ~p">>).
-define(REPLACE_INTO_DROP_INFO, 
    <<"REPLACE INTO role_exp_dun_drop SET role_id = ~p, calc_time = ~p, start_time = ~p, extra_data = ~ts">>).
-define(UPDATE_DROP_INFO_CALC_TIME, 
    <<"UPDATE role_exp_dun_drop SET calc_time = ~p WHERE role_id = ~p">>).
-define(UPDATE_DROP_INFO_START_TIME, 
    <<"UPDATE role_exp_dun_drop SET start_time = ~p WHERE role_id = ~p">>).
-define (UPDATE_DROP_INFO_EXTRA_DATA, 
    <<"UPDATE role_exp_dun_drop SET extra_data = ~ts WHERE role_id = ~p">>).
-define (UPDATE_DROP_INFO, 
    <<"UPDATE role_exp_dun_drop SET start_time = ~p, calc_time = ~p, extra_data = ~ts WHERE role_id = ~p">>).
-define (UPDATE_DROP_INFO_EXCLUDE_EXTRA_DATA, 
    <<"UPDATE role_exp_dun_drop SET start_time = ~p, calc_time = ~p WHERE role_id = ~p">>).

-define(SELECT_ROLE_FAST_EXP, 
    <<"SELECT fast_hook_time FROM role_fast_exp WHERE role_id = ~p">>).
-define(REPLACE_DROP_INFO_FAST_DROP_TIME,
    <<"REPLACE INTO role_fast_exp SET role_id = ~p, fast_hook_time = ~p">>).

-define(SELECT_ROLE_GOODS_DROP,
    <<"SELECT goods_type, goods_id, num FROM role_exp_dun_drop_goods WHERE role_id = ~p">>).
-define(BATCH_UPDATE_ROLE_GOODS, 
    <<"REPLACE INTO `role_exp_dun_drop_goods` (`role_id`, `goods_type`, `goods_id`, `num`)">>).
-define(DELETE_ROLE_ALL_GOODS, 
    <<"DELETE FROM role_exp_dun_drop_goods WHERE role_id = ~p">>).

-define(SELECT_ROLE_EXP_DUN_WAVE, 
    <<"SELECT wave, time FROM role_exp_dun_wave_info WHERE role_id = ~p">>).
-define(REPLACE_INTOEXP_DUN_WAVE, 
    <<"REPLACE INTO role_exp_dun_wave_info SET role_id = ~p, wave = ~p, time = ~p">>).
-define(DELETE_ROLE_EXP_DUN_WAVE, 
    <<"DELETE FROM role_exp_dun_wave_info WHERE role_id = ~p AND wave in ~s">>).

-define(SELECT_ROLE_EXP_DUN_REC,
    <<"SELECT data FROM dungeon_best_record WHERE player_id = ~p AND dun_id = ~p">>).

-define(SELECT_ROLE_OFF_POINT,
    <<"SELECT off_start, off_end FROM role_exp_dun_off_point WHERE role_id = ~p">>).
-define(BATCH_REPLACE_INTO_OFF_POINT,
    <<"REPLACE INTO role_exp_dun_off_point(`role_id`, `off_start`, `off_end`) VALUES ~ts">>).
-define(BATCH_REPLACE_OFF_POINT_VAL, <<"(~p, ~p, ~p)">>).
-define(REPLACE_INTO_EXP_DROP_OFF_POINT,
    <<"REPLACE INTO role_exp_dun_off_point SET `role_id` = ~p, `off_start` = ~p, `off_end` = ~p">>).
-define(DELETE_ROLE_OFF_POINT,
    <<"DELETE FROM role_exp_dun_off_point WHERE role_id = ~p AND off_start in ~s">>).