%%%--------------------------------------
%%% @Author  : zmh
%%% @Created : 2019.11.11
%%% @Description: 进阶系统
%%%--------------------------------------

-define(FHORSE, 1).     %座驾 1
-define(FWING,  2).     %炫翼 2
-define(FPEARL, 3).     %宝具 3
-define(FWEAPON,4).     %武器 4

-define(FJARVIS,5).     %AI娘 5
-define(FGUN,   6).     %磁炮 6
-define(FCLOUD, 7).     %星翼 7
-define(FARMOUR,8).     %幻甲 8

%% 强进阶系统
-define(GRADE_FOSTER, [
	?FHORSE, ?FWING, ?FPEARL, ?FWEAPON
]).

%% 所有进阶系统
-define(ALL_FOSTER, [
	?FHORSE, ?FWING, ?FPEARL, ?FWEAPON
	,?FJARVIS, ?FGUN, ?FCLOUD, ?FARMOUR
]).

%% 弱进阶升级材料种类
-define(PRIMARY_TYPE,  1).     %% 初级
-define(MIDDLE_TYPE,   2).     %% 中级
-define(SENIOR_TYPE,   3).     %% 高级
-define(MATERIAL_ALL_TYPE, [1,2,3]).

-define(CLEAR_TIME,86400).  %%清理时间


-define(FJARVIS_SKILL,205000).
-define(FPEARL_SKILL, 203000).

%% 进阶系统数据结构
-record(role_foster, {
	attr    = [], %%总属性汇总
	fosters = []  %%系统汇总
}).

-record(cell_foster, {
	type  = 0,         %%子类型
	grade = 0,         %%阶(强进阶系统使用)
	star  = 0,         %%星(强进阶系统使用)
	lv    = 0,         %%等级(弱进阶系统使用)
	exp   = 0,         %%祝福值
	clear = 0,         %%是否清零0否
	display  = 0,      %%当前幻化
	state = 0,         %%坐骑专用 骑乘状态
    lowcore  = 0,      %%低级核心
	highcore = 0,      %%高级核心
	core_ext = [],     %% 其他高级核心 [{2,Num},{3,Num1}]
	click  = 0,        %%临时点击
	etime  = 0,        %%有效时间clear为1时有效  重置后根据clear状态再加24H
	skills = [],       %%技能列表{孔位,等级,技能ID}
	base_skill = 0,    %%基础技能
	equips = [],       %%装备[#grade_equip{}]
	combat = 0,        %%战力
	attrs  = [],       %% 属性汇总(进阶/等级+装备+核心+皮肤)
	equip_attr  = [],  %%装备属性汇总
	skill_attr  = []   %%技能属性汇总
	,skin_list  = []   %% 弱进阶皮肤
	,display_skin = {} %% 弱进阶幻化皮肤{skin_id, star}
}).

%% @doc  强进阶珍宝  @end
%% 珍宝汇总
-record(role_foster_skin, {
	attr    = [], %%总属性
	fosters = []  %%皮肤汇总
}).

%% 强进阶单个类型珍宝
-record(cell_foster_skin, {
	type = 0,
	attrs = [],
	combat = 0,
	skills = [],
	skins = [],
	display = {0,0}
}).

%% 强进阶单个珍宝数据
-record(cell_skin, {
	id = 0,
	star = 0,
	display = 0 %%幻化星 0未幻化
}).

%% @doc  强进阶装备  @end
-record(grade_equip,{
    grade  = 0,   %%标识第几阶的
    equips = [],  %%装备数据#foster_equip{}
    assist = 0    %%0未解锁|1已解锁未激活|2已激活

}).

-record(foster_equip, {
    pos = 0,
    uid = 0, %%弃用
    gtype = 0,
    color = 0,
    lv  = 0,
    exp = 0
}).


%% @doc  弱进阶皮肤  @end
%% 弱进阶单个皮肤数据
-record(sub_cell_foster_skin, {
	skin_id = 0,        %% 皮肤Id
	star    = 0,        %% 星级
	display_star = 0    %% 幻化的星级
}).

%% -------------------------------------------------------------------------------------
%% @doc 配置数据结构 @end
%% 进阶配置
-record(base_foster, {
	type = 0,
	grade = 0,
	name = 0,
	next_grade = 0,     %%下一阶
	star = 0,
	next_star = 0,      %%下一星级
	attrs = [],   		%%阶属性
	tem_attrs = [],     %%临时属性
	cost  = [],   		%%操作消耗
	max   = 0,   	 	%%当前阶上限
	min   = 0,    		%%保底值
	clear = 0,    		%%是否清零
	rate  = 0,    		%%跳阶概率(需满足保底值)
	award = [],    		%%进阶获赠
	is_tv = 0,
	resource = 0        %%外观资源
}).

%%技能
-record(base_foster_skill, {
	type = 0,
	pos = 0,
	lv = 0,
	next_lv = 0,
	skillid = 0,
	limit   = 0,
	cost    = []
}).


%%核心
-record(base_foster_core, {
	type = 0,           %%系统
	kind = 0,           %%0初级1高级
	con  = 0,           %%开放条件
	cost = [],          %%消耗
	ext  = 0,           %%增幅
	max  = []           %%操作上限
}).


%%珍宝
-record(base_foster_skin, {
	type = 0,           %%系统
	id   = 0,           %%外观ID
	star  = 0,          %%星级
	name = "",          %名字
	next_star  = 0,           %%下一星
	cost  = [],           %%消耗
	attrs = [],
	active = [], %%激活
	model  = 0,
	skills = [] %%技能汇总
}).


%%装备
-record(equip_conf, {
    id = 0,
    type = 0,
    name = "",
    pos = 0,
    color = 0,
    exp = 0   %%吞噬获得
}).


%%装备升级
-record(equip_lv_conf, {
	type  = 0,
	pos   = 0,
    color = 0,
    lv = 0,
    next = 0,  %%下一个等级
    need = 0,  %%满级消耗
    attrs = [],
    total = 0  %%累积消耗
}).

%% 装备助战要求
-record (base_foster_equip_assist, {
    type = 0,           %% 系统
    grade = 0,          %% 阶位
    color = 0,          %% 品质
    num = 0             %% 数量
    }).



% %%装备
% -record(equip_base, {
% 	type    = 0,
% 	pos     = 0,
% 	des     = "",
% 	limit   = 0,
% 	attrs   = [],
% 	eattrs  = []
% }).

%% 弱进阶系统升级表
-record(base_foster_sub, {
	type       = 0,           %% 系统
	lv         = 0,           %% 等级
	need_exp   = 0,           %% 所需经验
	attr_list  = [],          %% 属性列表
	next_attr  = []           %% 下级属性
}).

%% 弱进阶系统升级材料表
-record(base_foster_sub_material, {
	type             = 0,       %% 系统
	primary_material = [],      %% 低级材料
	middle_material  = [],      %% 终极材料
	senior_material  = []       %% 高级材料
}).

%% 弱进阶系统皮肤表
-record(base_foster_sub_skin, {
	type             = 0,      %% 系统
	skin_id          = 0,      %% 皮肤Id
	star             = 0,      %% 星级
	name             = ""      %% 名称
	,next_star       = 0       %% 下一星级
	,cost_material   = []      %% 消耗道具
	,attr_list       = []      %% 属性
	,sequence        = 0       %% 排序
	,model_id        = 0       %% 模型Id
}).

-define(SQL_PLAYER_FOSTER_GET, <<"SELECT `type`, `grade`,`star`,`lv`,`exp`,`click`,`clear`,`display`,`isride`,`lowcore`,`highcore`,`core_ext`,`etime`,`skills` FROM `player_foster` WHERE rid=~p">>).
-define(SQL_PLAYER_FOSTER_INSERT,<<"REPLACE INTO `player_foster` (`rid`,`type`,`grade`,`star`,`lv`,`exp`,`click`,`clear`,`display`,`isride`,`lowcore`,`highcore`,`core_ext`,`etime`,`skills`) VALUES (~p,~p,~p,~p,~p,~p,~p,~p,~p,~p,~p,~p,'~ts',~p,'~ts')">>).

-define(SQL_PLAYER_FOSTER_EQUIP_GET,<<"SELECT `grade`,`equips`,`assist` FROM `player_foster_equip` WHERE rid = ~p and type=~p">>).
-define(SQL_PLAYER_FOSTER_EQUIP_INT,<<"REPLACE INTO `player_foster_equip` (`rid`,`type`,`grade`,`equips`,`assist`) VALUES (~p,~p,~p,'~ts',~p)">>).
-define(SQL_PLAYER_FOSTER_EQUIP_BATCH,"REPLACE INTO `player_foster_equip` (`rid`,`type`,`grade`,`equips`,`assist`) VALUES ~ts").

-define(SQL_UPDATE_FOSTER_CORE, <<"UPDATE `player_foster` SET `lowcore`= ~p,`highcore`=~p, `core_ext`='~ts' WHERE `rid` = ~p and `type`=~p">>).

-define(SQL_UPDATE_FOSTER_SKILL,<<"UPDATE `player_foster` SET `skills`= '~ts' WHERE `rid` = ~p and `type`=~p">>).

-define(SQL_UPDATE_FOSTER_DISPLAY, <<"UPDATE `player_foster` SET `display`=~p WHERE `rid` = ~p and `type`=~p">>).

-define(SQL_UPDATE_FOSTER_HORSE, <<"UPDATE `player_foster` SET `isride`= ~p WHERE `rid` = ~p and `type`=~p">>).

-define(SQL_PLAYER_FOSTER_SKIN_GET, <<"SELECT `type`, `id`,`star`,`display` FROM `player_foster_skin` WHERE rid=~p">>).
-define(SQL_UPDATE_FOSTER_SKIN, <<"REPLACE INTO `player_foster_skin` (`rid`,`type`,`id`,`star`,`display`) VALUES (~p,~p,~p,~p,~p)">>).

-define(SQL_PLAYER_FOSTER_LV_GET, <<"SELECT `lv` FROM player_foster WHERE rid = ~p and type = ~p">>).
-define (SQL_UPDATE_FOSTER_EQUIP_ASSIST, <<"UPDATE `player_foster_equip` SET `assist` = ~p WHERE `rid` = ~p and `type` = ~p and `grade` = ~p">>).

%% 弱进阶皮肤
-define(SQL_PLAYER_SUB_FOSTER_SKIN_INSERT, <<"REPLACE INTO `player_sub_foster_skin` (`role_id`,`type`,`skin_id`,`star`,`display_star`) VALUES (~p,~p,~p,~p,~p)">>).
-define(SQL_PLAYER_SUB_FOSTER_SKIN_SELECT, <<"SELECT `skin_id`,`star`,`display_star` FROM `player_sub_foster_skin` WHERE role_id=~p and `type` = ~p">>).
-define(SQL_PLAYER_SUB_FOSTER_SKIN_UPDATE, <<"UPDATE player_sub_foster_skin set `display_star` = 0 WHERE `role_id` = ~p and `type` = ~p">>).
