%%-----------------------------------------------------------------------------
%% @Module  :       smashed_egg
%% @Author  :       Czc
%% @Email   :       389853407@qq.com
%% @Created :       2018-03-01
%% @Description:    砸蛋
%%-----------------------------------------------------------------------------

-define(RECORD_LEN, 20).            %% 砸蛋记录长度
-define(SHOW_BEST_COUNT, 5).        %% 显示奖励最好物品的数量
-define(EGG_NUM, 8).                %% 金蛋的数量

-define(CFG_ALL_SMASHED_COST, 1).
-define(CFG_MANUAL_REFRESH_COST, 2).
-define(CFG_SMASHED_GOODS_ID, 3).

-define(SMASHED_TYPE_ONE, 1).
-define(SMASHED_TYPE_ALL, 2).

-define(NOT_SMASHED, 0).
-define(HAS_SMASHED, 1).

-record(goods_reward_cfg, {
    id = 0,                     %% id
    min_wlv = 0,                %% 世界等级下限
    max_wlv = 0,                %% 世界等级上限
    weights = 0,                %% 权重
    goods_id = 0,               %% 物品id
    goods_num = 0,              %% 物品数量
    effect = 0,                 %% 是否有特效
    is_tv = 0,                  %% 是否传闻
    is_rare = 0                 %% 是否稀有
    }).

-record(cumulate_reward_cfg, {
    min_wlv = 0,                %% 世界等级下限
    max_wlv = 0,                %% 世界等级上限
    times = 0,                  %% 累计次数
    reward = []                 %% 奖励
    }).

-record(role_info, {
    key = {0, 0},               %% {活动主类型，活动子类型}
    role_id = 0,                %% 玩家id
    online_time = 0,            %% 累计在线时间
    lfree_smashed_time = 0,     %% 最后一次使用免费砸蛋的时间
    refresh_times = 0,          %% 今日刷新次数
    add_refresh_times = 0,      %% 全砸附赠的刷新次数
    free_smashed_times = 0,     %% 今日使用的免费砸蛋次数
    smashed_times = 0,          %% 累计砸蛋次数
    eggs = [],                  %% 金蛋状态
    cumulate_reward = [],       %% 累计奖励的领取情况 已经领取的奖励id
    show_ids = [],              %% 展示的奖励id列表
    utime = 0,                  %% 数据更新时间
    reward_list = []            %% 未领取奖励列表[{type,id,num}]
    }).

-record(egg_info, {
    id = 0,
    status = 0,
    goods_id = 0,
    goods_num = 0,
    effect = 0
    }).

-record(act_state, {
    role_map = #{},             %% #{role_id => [#role_info{}]}
    record_map = #{}            %% 抽奖记录 #{{活动主类型,活动子类型} => [{role_name, goods_id, num, time}]}
    }).

-define(sql_select_smashed_egg,
    <<"select role_id, subtype, online_time, lfree_smashed_time, refresh_times, add_refresh_times, free_smashed_times, smashed_times, eggs, cumulate_reward, show_ids, utime from player_smashed_egg">>).
-define(sql_save_smashed_egg,
    <<"replace into player_smashed_egg(role_id, subtype, online_time, lfree_smashed_time, refresh_times, add_refresh_times, free_smashed_times, smashed_times, eggs, cumulate_reward, show_ids, utime)
    values(~p, ~p, ~p, ~p, ~p, ~p, ~p, ~p, '~s', '~s', '~s', ~p)">>).
-define(sql_delete_smashed_egg,
    <<"delete from player_smashed_egg where subtype = ~p">>).
-define(sql_clear_smashed_egg,
    <<"truncate table player_smashed_egg">>).
-define(sql_reset_smashed_egg,
    <<"update player_smashed_egg set online_time = ~p, lfree_smashed_time = ~p, refresh_times = ~p, add_refresh_times = ~p, free_smashed_times = ~p, eggs = '~s', utime = ~p">>).
-define(sql_save_smashed_egg_reward,
    "replace into player_smashed_egg_reward(role_id, subtype, goods_id, num) values").
    % <<"replace into player_smashed_egg_reward(role_id, subtype, goods_id, num) values(~p, ~p, ~p, ~p)">>).
-define(sql_select_smashed_egg_reward,
    <<"select goods_id, num from player_smashed_egg_reward where role_id = ~p and subtype = ~p">>).
-define(sql_delete_smashed_reward,
    <<"delete from player_smashed_egg_reward where role_id = ~p and subtype = ~p">>).
-define(sql_delete_smashed_reward_by_goods_id,
    <<"delete from player_smashed_egg_reward where role_id = ~p and subtype = ~p and goods_id = ~p">>).
