%%%-------------------------------------------------------------------
%%% @author liushl
%%% @doc
%%%     装备物品cell = 100*套+装备位置
%%%
%%%
%%% @end
%%%-------------------------------------------------------------------
-author("liushl").

-define(EQUIPMENT_STAR_RISE_RATIO, 9500).

%% 装备物品cell
-define(EQUIPMENT_CELL(Series, EquipmentPos), (Series * 100 + EquipmentPos)).
%% 根据装备cell获得装备套数series
-define(EQUIPMENT_SERIES(Cell), (Cell div 100)).

%% 装备类型
-define(EQUIPMENT_WEAPON,    1). % 武器
-define(EQUIPMENT_HEAD,      2). % 头盔
-define(EQUIPMENT_BODY,      3). % 身甲
-define(EQUIPMENT_CLOAK,     4). % 披风
-define(EQUIPMENT_HANDS,     5). % 手甲***
-define(EQUIPMENT_PANTS,     6). % 护胫
-define(EQUIPMENT_FEET,      7). % 靴子
-define(EQUIPMENT_NECKLACE,  8). % 项链
-define(EQUIPMENT_RINGS,     9). % 戒指
-define(EQUIPMENT_EARRINGS, 10). % 耳环
-define(EQUIPMENT_GUARD,    11). % 守护

%% 普通装备:7件
-define(EQUIPMENT_NORMAL, [?EQUIPMENT_WEAPON, ?EQUIPMENT_HEAD, ?EQUIPMENT_BODY,
    ?EQUIPMENT_CLOAK, ?EQUIPMENT_HANDS, ?EQUIPMENT_PANTS, ?EQUIPMENT_FEET]).
%% 项链/戒指/耳环组成首饰
-define(EQUIPMENT_JEWELRY,  [?EQUIPMENT_NECKLACE, ?EQUIPMENT_EARRINGS, ?EQUIPMENT_RINGS]).
%% 首饰和守护组成特殊装备
-define(EQUIPMENT_SPECIAL,  [?EQUIPMENT_GUARD|?EQUIPMENT_JEWELRY]).

-define(EQUIPMENT_KIND_NORMAL,   1).    %% 装备类型：武器和防具
-define(EQUIPMENT_KIND_JEWELRY,  2).    %% 装备类型：首饰
-define(EQUIPMENT_KIND_GUARD,    3).    %% 装备类型：守护
%% -----------------------------------------------------------------
%% @doc 计算属性加成时，装备分类
%% 防具构成
-define(EQUIPMENT_ATTR_PROTECTION, [?EQUIPMENT_HEAD, ?EQUIPMENT_BODY, ?EQUIPMENT_CLOAK, ?EQUIPMENT_PANTS, ?EQUIPMENT_FEET]).
%% 饰品构成
-define(EQUIPMENT_ATTR_JEWELRY, [?EQUIPMENT_HANDS, ?EQUIPMENT_NECKLACE, ?EQUIPMENT_EARRINGS, ?EQUIPMENT_RINGS]).
%% 武器构成不变
%% -----------------------------------------------------------------
-define(GEM_TYPE_ATT,  1).  % 攻击宝石
-define(GEM_TYPE_DEF,  2).  % 防御宝石
-define(GEM_TYPE_HP,   3).  % 血量宝石
%% 装备宝石操作
-define(EQUIPMENT_GEM_OP_INLAY,    1).  %% 镶嵌
-define(EQUIPMENT_GEM_OP_UNLOAD,   2).  %% 卸下
-define(EQUIPMENT_GEM_OP_UPGRADE,  3).  %% 升级
-define(EQUIPMENT_GEM_OP_AUTO,     4).  %% 一键操作
%% 击杀BOSS
-define(EQUIPMENT_KILL_DESERTED_BOSS,  1).  %% 星域幻魔
-define(EQUIPMENT_KILL_PERSONAL_BOSS,  2).  %% 个人BOSS
-define(EQUIPMENT_KILL_REWARD_BOSS,    3).  %% 赏金BOSS
-define(EQUIPMENT_KILL_HOME_BOSS,      4).  %% 幻魔之家

%% 计数器
-define(EQUIPMENT_HELP_SP_ATTR,  1).    %% 每日协助增加sp属性经验次数
-define(EQUIPMENT_HOME_BOSS_KILL, 2).   %% 每日击杀幻魔之家增加经验次数
%% 玩家装备数据
-record(equipment, {
    equipment_series = #{}      %% 不跟随装备#{套数 => #{位置 => #equipment_series{}}}
    , gems_suit = []            %% 宝石套装信息：[{series, lv}]
    , stars = 0                 %% 当前激活的星级数
    , stars_info = []           %% 星级套装激活节点选择[{节点，选择}]
    , unlock_series = 1         %% 当前解锁的套数
    , total_power = 0           %% 总战力
    , attr = []                 %% 总属性
    , skills = []               %% 技能
    , extra_power = 0           %% 装备系统战力
    
    , equipment_collect = []        %% 装备收集情况
    , equipment_collect_attr = []   %% 收集系统属性
    , empower_attr = []             %% 器灵总属性
    
    , follow_guard = 0     %% 跟随的守护
}).

%% 装备套数位置信息
-record(equipment_series, {
    series = 0      %% 套数
    , pos = 0       %% 装备位置
    , gems = []     %% 镶嵌的宝石##[{类型，宝石id}]
    , empower = 0   %% 器灵等级
    , sp_lv = 1     %% 可成长属性等级
    , sp_exp = 0    %% 可成长属性经验
}).

%% 装备收集
-record(equipment_collect, {
    key         = {0, 0},  %% key {series, color}
    series      = 0,    %% 代数
    color       = 0,    %% 品质
    active      = 0,    %% 激活进度
    collect     = []    %% 收集情况 [部位]
}).
%%---------------------------------------------------------------------
%% 数据库
%%---------------------------------------------------------------------
%% 查询装备基础通用信息
-define(SQL_GET_EQUIPMENT_INFO, <<"SELECT stars,stars_info,series,follow_guard,gems_suit FROM equipment WHERE role_id=~p">>).
%% 查询装备套数位置信息
-define(SQL_GET_EQUIPMENT_SERIES, <<"SELECT series,pos,gems,empower_lv,sp_lv,sp_exp FROM equipment_series WHERE role_id=~p">>).
%% 更新装备基础通用信息
-define(SQL_UPDATE_EQUIPMENT, <<"REPLACE INTO equipment(role_id,stars,stars_info,series,follow_guard,gems_suit) VALUES(~p,~p,~ts,~p,~p,~ts)">>).
%% 更新装备套数位置信息
-define(SQL_UPDATE_EQUIPMENT_SERIES, <<"REPLACE INTO equipment_series(role_id,series,pos,gems,empower_lv,sp_lv,sp_exp) VALUES(~p,~p,~p,~ts,~p,~p,~p)">>).
%% 批量更新装备套数位置信息
-define(SQL_UPDATE_EQUIPMENT_SERIES_BATCH, <<"REPLACE INTO equipment_series(role_id,series,pos,gems,empower_lv,sp_lv,sp_exp) VALUES ~ts">>).
%%---------------------------------------------------------------------
%% 配置
%%---------------------------------------------------------------------
-record(base_equipment, {
    goods_id = 0,
    name = <<>>,
    series = 0,             %% 套数
    color = 0,              %% 品质
    career = [],            %% 职业限制
    equip_type = 0,         %% 装备类型
    lv = 0,                 %% 穿戴等级
    suit = [],              %% 套装类型,一个装备可能参与多个套装
    base_attr = [],         %% 基础属性
    great_attr_list = [],   %% 高级属性
    great_num = 0,          %% 卓越属性数量
    great_attr_star = [],   %% 星级卓越属性
    great_attr_normal = [], %% 普通卓越属性
    devour_exp = 0          %% 吞噬经验
}).

-record(base_equipment_strength, {
    series = 0,
    equip_type = 0,
    lv = 0,
    cost = [],
    attr = [],
    ratio = 0,
    fail_add_ratio = 0
}).

-record(base_equipment_great, {
    series = 0,
    equip_type = 0,
    up_num = 0,
    cost = [],
    attr = [],
    great_attr = [],
    rare = 0,
    great_attr_list = [],
    ratio = 0
}).

-record(base_equipment_carve, {
    goods_id = 0,
    name = <<>>,
    color = 0,
    equip_type = 0,
    skill_battle = [],
    skill_normal = [],
    attr = [],
    weight = 0,
    desc = <<>>
}).

-record(base_equipment_gems, {
    goods_id = 0,
    name = <<>>,
    type = 0,
    lv = 0,
    attr = []
}).

-record(base_equipment_empower, {
    series = 0,             %% 代数
    pos = 0,                %% 装备位置
    lv = 0,                 %% 等级
    cost = [],              %% 消耗
    attr = [],              %% 属性
    condition = []          %% 升级条件 {equip_color,4} 装备品质
                            %% {all_series_lv,3,1} 前3代装备全部达到1级
}).
