%%%-------------------------------------------------------------------
%%% @doc 学位-头文件
%%% Module: degree
%%% Created : 2019-11-25
%%% @Author: tyl
%%%-------------------------------------------------------------------

-define(DegreeOpenLv, 20).  %% 学位系统开放等级
-define(ExpRatio, 20).      %% 经验累积封顶倍数

%% 每日功课完成状态
-define(ClassUnFinish,  1). %% 未完成
-define(ClassUnReceive, 2). %% 未领取奖励
-define(ClassFinish,    3). %% 已完成

%% 每日功课随机数量
-define(RandClassWorkCount, 3).

%% 事件触发类型
-define(FIN_DEGREE_UPGRADE_DUN, 1).
-define(ADD_CLASSWORK_PROGRESS, 2).

%% 每日功课类型
-define(ClassWorkDun,     1).   %% 副本
-define(ClassWorkKillMon, 2).   %% 杀怪
-define(ClassworkMountUp, 3).   %% 坐骑升星

%% 刷新数据
-define(RefreshType1,     1).   %% 学位晋升副本状态刷新
-define(RefreshType2,     2).   %% 日常功课任务状态刷新

%% 学位数据
-record(degree,{
    degree_id = 0,                  %% 学位Id
    degree_exp = 0,                 %% 学位经验
    degree_max_exp = 0,             %% 当前学位等级最大经验
    dun_state = [],                 %% 副本完成状态[{DunId, State}]
    daily_class = [],               %% 日常任务完成情况 #daily_class{}
    attr_list = [],                 %% 属性列表
    power = 0                       %% 战力
}).

%% 日常功课
-record(daily_class, {
    class_status_map = #{},         %% 日常功课完成状态 #{ClassId => State} State:1,未完成 2,未领取 3,已完成
    class_progress_map = #{}        %% 日常功课完成进度 #{ClassId => [Type, Id, Num]} 学位晋升后进度需要清空
}).

%% ==================================== 后台配置 ===========================
%% 学位配置表
-record(degree_cfg, {
    degree_id = 0,          %% 学位Id
    degree_name = "",       %% 学位名称
    icon = 0,               %% 学位icon
    attr_list = [],         %% 属性列表
    need_exp = 0,           %% 升级需要经验
    need_matrial = [],      %% 收集材料列表
    finish_dungeon = 0,     %% 完成副本Id
    description = "",       %% 娱乐描述
    is_tv = 0               %% 是否传闻
}).

%% 日常功课配置表
-record(degree_timetable_cfg, {
    class_id = 0,           %% 功课Id
    class_name = "",        %% 功课名称
    class_desc = "",        %% 功课描述
    target = [],            %% 完成目标，格式：[{Type, Id, Num}] 1.副本，2.击杀怪物，3.坐骑升星
    award_exp = 0,          %% 奖励经验
    need_degree = 0         %% 学位等级限制
}).

%% ==================================== 数据库操作 ===========================
%% 学位相关
-define(SQL_SELECT_PLAYER_DEGREE, <<"SELECT  `degree_id`, `degree_exp`, `dun_state` FROM player_degree WHERE `role_id` = ~p LIMIT 1">>).
-define(SQL_INSERT_PLAYER_DEGREE, <<"REPLACE INTO player_degree (`role_id`, `degree_id`, `degree_exp`, `dun_state`, `time`) VALUES (~p, ~p, ~p, '~ts', ~p)">>).
-define(SQL_UPDATE_PLAYER_DEGREE, <<"UPDATE player_degree SET `degree_id` = ~p, `degree_exp` = ~p, `dun_state` = '~ts', `time` = ~p WHERE `role_id` = ~p">>).
-define(SQL_UPDATE_PLAYER_DEGREE_EXP, <<"UPDATE player_degree SET `degree_exp` = ~p, `time` = ~p WHERE role_id = ~p">>).
-define(SQL_UPDATE_PLAYER_DEGREE_DUN_STATE, <<"UPDATE player_degree SET `dun_state` = '~ts', `time` = ~p WHERE role_id = ~p">>).
%% 日常功课相关
-define(SQL_SELECT_PLAYER_CLASSWORK, <<"SELECT  `class_id`, `content`, `time` FROM player_degree_classwork WHERE `role_id` = ~p">>).
-define(SQL_INSERT_PLAYER_CLASSWORK, <<"REPLACE INTO player_degree_classwork (`role_id`, `class_id`, `content`, `time`) VALUES (~p, ~p, '~ts', ~p)">>).
-define(SQL_UPDATE_PLAYER_CLASSWORK_CONTENT, <<"UPDATE player_degree_classwork SET `content` = '~ts', `time` = ~p WHERE `role_id` = ~p and `class_id` = ~p">>).

%% Degree: dun_state格式 [{DunId, State}]
%% ClassWork: content格式 [ClassType, ClassWorkId, Num, State]

%% 4点清理日常功课
-define(SQL_DELETE_PLAYER_CLASSWORK, <<"TRUNCATE TABLE player_degree_classwork">>).