diff --git a/lua/app/global/global_func.lua b/lua/app/global/global_func.lua
index 792c7a1b..d700e10f 100644
--- a/lua/app/global/global_func.lua
+++ b/lua/app/global/global_func.lua
@@ -457,6 +457,31 @@ function GFunc.getAttrShowValue(attrType, attrNum, notPercentSign)
end
end
+-- 属性id转属性名
+function GFunc.getAttrNameById(id)
+ local cfg = ConfigManager:getConfig("attr")[id]
+ if cfg then
+ return cfg.name
+ end
+ if EDITOR_MODE then
+ Logger.logError("没有找到属性id:" .. tostring(id))
+ end
+ return nil
+end
+
+-- 属性名转属性id
+function GFunc.getAttrIdByName(type)
+ for id, info in pairs(ConfigManager:getConfig("attr")) do
+ if info.name == type then
+ return id
+ end
+ end
+ if EDITOR_MODE then
+ Logger.logError("没有找到属性名:" .. tostring(type))
+ end
+ return nil
+end
+
function GFunc.getAttrName(key)
return I18N:getText("attr", key, "name")
end
diff --git a/lua/app/userdata/equip/equip_data.lua b/lua/app/userdata/equip/equip_data.lua
index cc21b579..eb48a04f 100644
--- a/lua/app/userdata/equip/equip_data.lua
+++ b/lua/app/userdata/equip/equip_data.lua
@@ -1,144 +1,409 @@
local EquipData = class("EquipData", BaseData)
local EquipEntity = require "app/userdata/equip/equip_entity"
+local EquipCfg = ConfigManager:getConfig("equip")
+local EquipLevelCfg = ConfigManager:getConfig("equip_level")
+local EquipRefineCfg = ConfigManager:getConfig("equip_refine")
+local EquipResonateCfg = ConfigManager:getConfig("equip_resonate")
+
function EquipData:ctor()
- self.data.isDirty = false
+ self.data.isDirty = false
end
function EquipData:clear()
- ModuleManager.EquipManager:updateEquipGiftTimer(true)
end
function EquipData:init(data)
- data = data or GConst.EMPTY_TABLE
- Logger.logHighlight("装备数据")
- Logger.printTable(data)
- self.equips = {}
- if not data.HeroesEquips then
- return
- end
+ data = data or GConst.EMPTY_TABLE
+ if EDITOR_MODE then
+ Logger.logHighlight("装备数据")
+ Logger.printTable(data)
+ end
+ if not data.equips then
+ return
+ end
- for heroId, equip in pairs(data.HeroesEquips) do
- for part, level in pairs(equip.Equips) do
- self:addEquip(heroId, part, level)
- end
- end
+ self.allEquips = {}
+ if data.equips then
+ for i, equip in pairs(data.equips) do
+ self:addEquip(equip)
+ end
+ end
+ self.slots = data.slots or {}
end
function EquipData:setDirty()
- self.data.isDirty = not self.data.isDirty
+ self.data.isDirty = not self.data.isDirty
end
-- 武器功能是否开启
function EquipData:isWeaponOpen(showToast)
- if not ModuleManager:getIsOpen(ModuleManager.MODULE_KEY.EQUIP_WEAPON, not showToast) then
- return false
- end
- return true
+ if not ModuleManager:getIsOpen(ModuleManager.MODULE_KEY.EQUIP_WEAPON, not showToast) then
+ return false
+ end
+ return true
end
--- 防具功能是否开启
-function EquipData:isArmorOpen(showToast)
- if not ModuleManager:getIsOpen(ModuleManager.MODULE_KEY.EQUIP_ARMOR, not showToast) then
- return false
- end
- return true
+--@region 配置
+-- 获取配置
+function EquipData:getConfig(id)
+ if id then
+ return EquipCfg[id]
+ else
+ return EquipCfg
+ end
end
-function EquipData:addEquip(heroId, part, level)
- if not self.equips[heroId] then
- self.equips[heroId] = {}
- end
- if self.equips[heroId][part] then
- return
- end
- self.equips[heroId][part] = self:createEntity(heroId, part, level)
+-- 获取强化配置
+function EquipData:getLevelConfig(id)
+ if id then
+ return EquipLevelCfg[id]
+ else
+ return EquipLevelCfg
+ end
end
-function EquipData:createEntity(heroId, part, level)
- return EquipEntity:create(heroId, part, level)
+-- 获取精炼配置
+function EquipData:getRefineConfig(id)
+ if id then
+ return EquipRefineCfg[id]
+ else
+ return EquipRefineCfg
+ end
+end
+
+-- 获取共鸣配置
+function EquipData:getResonateConfig(id)
+ if id then
+ return EquipResonateCfg[id]
+ else
+ return EquipResonateCfg
+ end
+end
+
+-- 部位 1-6分别对应头盔,护腕,衣服,裤子,鞋子,手套
+function EquipData:getPart(id)
+ return self:getConfig(id).type
+end
+
+-- 装备图标
+function EquipData:getIconRes(id)
+ return tostring(self:getConfig(id).icon)
+end
+
+-- 品质(颜色)
+function EquipData:getQlt(id)
+ return self:getConfig(id).qlt
+end
+
+-- 星级
+function EquipData:getStar(id)
+ return self:getConfig(id).star
+end
+
+-- 基础属性
+function EquipData:getBaseAttr(id)
+ return self:getConfig(id).base_attr
+end
+--@endregion
+
+--@region 装备基础
+function EquipData:addEquip(equip, itemGetType)
+ if equip == nil then
+ return
+ end
+ self.allEquips[equip.uid] = self:createEquipEntity(equip)
+ if itemGetType then
+ BIReport:postEquipGet(equip.uid, equip.cfg_id, itemGetType)
+ end
+ self:setDirty()
+end
+
+function EquipData:createEquipEntity(equip)
+ return EquipEntity:create(equip)
end
function EquipData:getAllEquips()
- return self.equips
+ return self.allEquips
end
-function EquipData:getEquip(id, part)
- if not self.equips[id] then
- self.equips[id] = {}
+function EquipData:getEquipByUid(uid)
+ if self.allEquips[uid] then
+ return self.allEquips[uid]
end
- if not self.equips[id][part] then
- self.equips[id][part] = self:createEntity(id, part)
- end
- return self.equips[id][part]
+end
+--@endregion
+
+--@region 六个部位装备的强化与精炼
+--获取对应位置的装备Id
+function EquipData:getPartEquipUid(slotId, part)
+ local parts = self.slots[slotId].parts
+ if parts then
+ if part == nil then
+ return parts
+ else
+ local partInfo = parts[part]
+ if partInfo then
+ return partInfo.equip_uid
+ end
+ end
+ end
+ return 0
end
--- 是否有装备可升级
-function EquipData:canUpgradeEquip(heroId)
- if self:canUpgradeWeapon(heroId) then
- return true
- end
-
- if self:canUpgradeArmor(heroId) then
- return true
- end
-
- return false
+-----获取强化等级
+function EquipData:getPartLevel(slotId, part)
+ local parts = self.slots[slotId].parts
+ if parts then
+ local partInfo = parts[part]
+ if partInfo then
+ return partInfo.level
+ end
+ end
+ return 0
end
--- 武器是否可升级
-function EquipData:canUpgradeWeapon(heroId)
- if not self:isWeaponOpen() then
- return false
- end
-
- local entity = self:getEquip(heroId, GConst.EquipConst.PART_TYPE.WEAPON)
- if entity:canLevelUp() then
- return true
- end
- return false
+--获取精炼等级
+function EquipData:getPartRefine(slotId, part)
+ local parts = self.slots[slotId].parts
+ if parts then
+ local partInfo = parts[part]
+ if partInfo then
+ return partInfo.refine
+ end
+ end
+ return 0
end
--- 防具是否可升级
-function EquipData:canUpgradeArmor(heroId)
- if not self:isArmorOpen() then
- return false
- end
-
- local entity
- for name, part in pairs(GConst.EquipConst.PART_TYPE) do
- entity = self:getEquip(heroId, part)
- if part ~= GConst.EquipConst.PART_TYPE.WEAPON then
- if entity:canLevelUp() then
- return true
- end
- end
- end
- return false
+-- 精炼成功概率
+function EquipData:getPartRefineFailPro(slotId, part)
+ local parts = self.slots[slotId].parts
+ if parts then
+ local partInfo = parts[part]
+ if partInfo then
+ local cfgRefine = self:getRefineConfig(partInfo.refine + 1)
+ if cfgRefine then
+ return (cfgRefine.base_chance + partInfo.refine_fail * cfgRefine.chance_fail) / GConst.DEFAULT_FACTOR
+ end
+ end
+ end
+ return 0
end
--- 获取防具最小阶段
-function EquipData:getMinArmorStage(heroId)
- local minStage = -1
- for name, part in pairs(GConst.EquipConst.PART_TYPE) do
- if part ~= GConst.EquipConst.PART_TYPE.WEAPON then
- local entity = self:getEquip(heroId, part)
- if minStage == -1 or minStage > entity:getStage() then
- minStage = entity:getStage()
- end
- end
- end
- return minStage >= 0 and minStage or 0
+function EquipData:getSlotAllAttr(slotId)
+ local attr = {}
+ for part = 1, 6 do
+ local level = self:getPartLevel(slotId, part)
+ local refine = self:getPartRefine(slotId, part)
+ for i = 1, level do
+ local cfg = self:getLevelConfig(i)
+ if attr[cfg.base_attr_add.type] then
+ attr[cfg.base_attr_add.type] = attr[cfg.base_attr_add.type] + cfg.base_attr_add.num
+ else
+ attr[cfg.base_attr_add.type] = cfg.base_attr_add.num
+ end
+ end
+ local uid = self:getPartEquipUid(slotId, part)
+ if uid ~= 0 then
+ local equipEntity = self:getEquipByUid(uid)
+ local equipAttrs = equipEntity:getExtraMap()
+ local baseAttrs = equipEntity:getBaseAttr()
+ if attr[baseAttrs.type] then
+ attr[baseAttrs.type] = attr[baseAttrs.type] + baseAttrs.num
+ else
+ attr[baseAttrs.type] = baseAttrs.num
+ end
+ for i,extraAttr in pairs(equipAttrs) do
+ local name = GFunc.getAttrNameById(extraAttr.id)
+ if attr[name] then
+ attr[name] = attr[name] + extraAttr.value
+ else
+ attr[name] = extraAttr.value
+ end
+ local nowAttr = self:getRefineAttrAdd(refine, extraAttr.id)
+ if nowAttr then
+ if attr[nowAttr.type] then
+ attr[nowAttr.type] = attr[nowAttr.type] + nowAttr.num
+ else
+ attr[nowAttr.type] = nowAttr.num
+ end
+ end
+ end
+ end
+ end
+ local resonateLevel = self:getResonateLevel(1, slotId)
+ local list = self:getResonateList(1)
+ for i,v in ipairs(list) do
+ if i <= resonateLevel then
+ if attr[v.attr.type] then
+ attr[v.attr.type] = attr[v.attr.type] + v.attr.num
+ else
+ attr[v.attr.type] = v.attr.num
+ end
+ else
+ break
+ end
+ end
+ local resonateQlt = self:getResonateLevel(2, slotId)
+ list = self:getResonateList(2)
+ for i,v in ipairs(list) do
+ if i <= resonateQlt then
+ if attr[v.attr.type] then
+ attr[v.attr.type] = attr[v.attr.type] + v.attr.num
+ else
+ attr[v.attr.type] = v.attr.num
+ end
+ else
+ break
+ end
+ end
+ local resonateRefine = self:getResonateLevel(3, slotId)
+ list = self:getResonateList(3)
+ for i,v in ipairs(list) do
+ if i <= resonateRefine then
+ if attr[v.attr.type] then
+ attr[v.attr.type] = attr[v.type] + v.attr.num
+ else
+ attr[v.attr.type] = v.attr.num
+ end
+ else
+ break
+ end
+ end
+ return attr
end
--- 装备升级
-function EquipData:onUpgradeEquip(heroId, part)
- local entity = self:getEquip(heroId, part)
- if not entity then
- return
- end
- entity:onLevelUp()
- DataManager.HeroData:getHeroById(heroId):onEquipAttrChange()
+function EquipData:getResonateLevelValue(type, value, value2)
+ local list = self:getResonateList(type)
+ local lv = 0
+ local nextLv = 0
+ local attrNum = 0
+ local attrNextNum = 0
+ for i,v in ipairs(list) do
+ if type == 1 or type == 3 then
+ if v.parameter[1] <= value then
+ lv = i
+ attrNum = attrNum + v.attr.num
+ else
+ nextLv = v.parameter
+ attrNextNum = attrNum + v.attr.num
+ break
+ end
+ elseif type == 2 then
+ local isTrue = false
+ if v.parameter[1] < value then
+ isTrue = true
+ elseif v.parameter[1] == value and v.parameter[2] <= value2 then
+ isTrue = true
+ end
+ if isTrue then
+ lv = i
+ attrNum = attrNum + v.attr.num
+ else
+ nextLv = v.parameter
+ attrNextNum = attrNum + v.attr.num
+ break
+ end
+ end
+ end
+ return lv, nextLv, attrNum / GConst.DEFAULT_FACTOR, attrNextNum / GConst.DEFAULT_FACTOR, table.nums(list)
end
+function EquipData:getResonateLevel(type, slotId)
+ if type == 1 then
+ local minLv = 999
+ for i = 1, 6 do
+ local level = self:getPartLevel(slotId, i)
+ if level < minLv then
+ minLv = level
+ end
+ end
+ return self:getResonateLevelValue(type, minLv)
+ elseif type == 2 then
+ local qlt = 99
+ local star = 99
+ for i = 1, 6 do
+ local uid = self:getPartEquipUid(slotId, i)
+ local equip = self:getEquipByUid(uid)
+ if equip == nil then
+ qlt = 0
+ star = 0
+ break
+ end
+ local q = equip:getQlt()
+ local s = equip:getStar()
+ if qlt > q then
+ qlt = q
+ star = s
+ elseif qlt == q then
+ if star > s then
+ qlt = q
+ star = s
+ end
+ end
+ end
+ return self:getResonateLevelValue(type, qlt, star)
+ elseif type == 3 then
+ local minRefine = 999
+ for i = 1, 6 do
+ local refine = self:getPartRefine(slotId, i)
+ if refine < minRefine then
+ minRefine = refine
+ end
+ end
+ return self:getResonateLevelValue(type, minRefine)
+ end
+end
+
+function EquipData:getLevelCost(refine)
+ local cfg = self:getLevelConfig(refine)
+ if cfg then
+ return cfg.cost
+ end
+end
+function EquipData:getRefineCost(refine)
+ local cfg = self:getRefineConfig(refine)
+ if cfg then
+ return cfg.cost
+ end
+end
+function EquipData:getRefineNeedLevel(refine)
+ local cfg = self:getRefineConfig(refine)
+ if cfg then
+ return cfg.equip_level
+ end
+end
+
+function EquipData:getEquipUseForce(uid)
+ local equip = self:getEquipByUid(uid)
+ local mainTeam = DataManager.ForceData:getTeamList(ModuleManager.BattleManager.BATTLE_TYPE.STAGE)
+ local part = equip:getPart()
+ for i,info in ipairs(self.slots) do
+ if info.parts[part] and info.parts[part].equip_uid and info.parts[part].equip_uid == uid then
+ return mainTeam[i]
+ end
+ end
+end
+--@endregion
+
+--@region 装备分解
+-- 分解额外返还
+function EquipData:getResolveReward(id)
+ return self:getConfig(id).decompose
+end
+
+-- 装备分解成功
+function EquipData:onResolveSuccess(uids)
+ if EDITOR_MODE then
+ Logger.logHighlight("装备分解")
+ Logger.printTable(uids)
+ end
+
+ for i, id in pairs(uids) do
+ self.allEquips[id] = nil
+ end
+ self:setDirty()
+end
+--@endregion
+
return EquipData
\ No newline at end of file
diff --git a/lua/app/userdata/equip/equip_entity.lua b/lua/app/userdata/equip/equip_entity.lua
index 24a798b2..7c2bb648 100644
--- a/lua/app/userdata/equip/equip_entity.lua
+++ b/lua/app/userdata/equip/equip_entity.lua
@@ -1,412 +1,180 @@
local EquipEntity = class("EquipEntity", BaseData)
-local DEFAULT_FACTOR = GConst.BattleConst.DEFAULT_FACTOR
-function EquipEntity:ctor(heroId, part, level)
- self.level = level or 0
-
- self.heroEntity = nil
- self.cfg, self.cfgId = table.find(ConfigManager:getConfig("equip"), function(value)
- return value.hero == heroId and value.part == part
- end)
-end
+local AttrNameCfg = ConfigManager:getConfigWithOtherKey("attr", "name")
function EquipEntity:setDirty()
- self.data.isDirty = not self.data.isDirty
+ self.allAttrs = nil
end
--- 获取部位id
+function EquipEntity:ctor(equip)
+ self:init(equip)
+end
+
+function EquipEntity:init(equip)
+ self.uid = equip.uid
+ self:setId(equip.cfg_id)
+ self:initBaseAttr()
+ self:setExtraAttr(equip.extra_attrs)
+
+ self.lastPower = nil
+end
+
+-- 装备唯一id
+function EquipEntity:getUid()
+ return self.uid
+end
+
+function EquipEntity:setId(id)
+ self.id = id
+ self:setDirty()
+end
+
+--获取配置id
function EquipEntity:getId()
- return self.cfgId
+ return self.id
end
--- 获取部位所属英雄
-function EquipEntity:getHeroId()
- return self.cfg.hero
-end
-
--- 获取部位类型
+--@region 配置
function EquipEntity:getPart()
- return self.cfg.part
+ return DataManager.EquipData:getPart(self:getId())
end
--- 获取部位基础生命值
-function EquipEntity:getBaseHp()
- if self.cfg.armor_hp and self.cfg.armor_hp[self.level] then
- return self.cfg.armor_hp[self.level]
- end
- return 0
+function EquipEntity:getQlt()
+ return DataManager.EquipData:getQlt(self:getId())
end
--- 获取部位加成后生命值
-function EquipEntity:getHp()
- local result = self:getBaseHp()
- result = result + self:getHeroEntity():getTotalBaseHp() * self:getHpPercent() // DEFAULT_FACTOR
- return result
+function EquipEntity:getStar()
+ return DataManager.EquipData:getStar(self:getId())
end
--- 获取部位基础攻击力
-function EquipEntity:getBaseAttack()
- if self.cfg.armor_atk and self.cfg.armor_atk[self.level] then
- return self.cfg.armor_atk[self.level]
- end
- return 0
+function EquipEntity:getIconRes()
+ return DataManager.EquipData:getIconRes(self:getId())
end
--- 获取部位加成后攻击力
-function EquipEntity:getAttack()
- local result = self:getBaseAttack()
- result = result + self:getHeroEntity():getTotalBaseAtk() * self:getAtkPercent() // DEFAULT_FACTOR
- return result
+function EquipEntity:getEntityType()
+ return GConst.ENTITY_TYPE.EQUIP_ENTITY
end
--- 获取部位普攻伤害
-function EquipEntity:getNormalHurt()
- if self.cfg.normal_hurt_add and self.cfg.normal_hurt_add[self.level] then
- return self.cfg.normal_hurt_add[self.level]
- end
- return 0
-end
-
--- 获取部位技能伤害
-function EquipEntity:getSkillHurt()
- if self.cfg.skill_hurt_add and self.cfg.skill_hurt_add[self.level] then
- return self.cfg.skill_hurt_add[self.level]
- end
- return 0
-end
-
--- 获取攻击加成百分比
-function EquipEntity:getAtkPercent()
- local attrs = self:getStageAttr()
- if not attrs or #attrs == 0 then
- return 0
- end
-
- local num = 0
- for index, attr in ipairs(attrs) do
- if table.containValue(GConst.MATCH_ATTACK_ADD_NAME, attr.type) then
- num = num + attr.num
- end
- end
- return num
-end
-
--- 获取生命值加成百分比
-function EquipEntity:getHpPercent()
- local attrs = self:getStageAttr()
- if not attrs or #attrs == 0 then
- return 0
- end
-
- local num = 0
- for index, attr in ipairs(attrs) do
- if table.containValue(GConst.MATCH_HP_ADD_NAME, attr.type) then
- num = num + attr.num
- end
- end
- return num
-end
-
--- 获取暴击率百分比
-function EquipEntity:getCritPercent()
- local attrs = self:getStageAttr()
- if not attrs or #attrs == 0 then
- return 0
- end
-
- local num = 0
- for index, attr in ipairs(attrs) do
- if table.containValue(GConst.MATCH_CRIT_NAME, attr.type) then
- num = num + attr.num
- end
- end
- return num
-end
-
---获取暴击伤害百分比
-function EquipEntity:getCritHurtPercent()
- local attrs = self:getStageAttr()
- if not attrs or #attrs == 0 then
- return 0
- end
-
- local num = 0
- for index, attr in ipairs(attrs) do
- if table.containValue(GConst.MATCH_CRIT_TIME_NAME, attr.type) then
- num = num + attr.num
- end
- end
- return num
-end
-
--- 获取治疗百分比
-function EquipEntity:getHealPercent()
- local attrs = self:getStageAttr()
- if not attrs or #attrs == 0 then
- return 0
- end
-
- local num = 0
- for index, attr in ipairs(attrs) do
- if table.containValue(GConst.MATCH_CURED_NAME, attr.type) then
- num = num + attr.num
- end
- end
- return num
-end
-
--- 获取普攻增伤百分比
-function EquipEntity:getNormalHurtPercent()
- local attrs = self:getStageAttr()
- if not attrs or #attrs == 0 then
- return 0
- end
-
- local num = 0
- for index, attr in ipairs(attrs) do
- if table.containValue(GConst.MATCH_NORMAL_HURTP_NAME, attr.type) then
- num = num + attr.num
- end
- end
- return num
-end
-
--- 获取技能增伤百分比
-function EquipEntity:getSkillHurtPercent()
- local attrs = self:getStageAttr()
- if not attrs or #attrs == 0 then
- return 0
- end
-
- local num = 0
- for index, attr in ipairs(attrs) do
- if table.containValue(GConst.MATCH_SKILL_HURTP_NAME, attr.type) then
- num = num + attr.num
- end
- end
- return num
-end
-
--- 获取部位阶段等级,未达到最低阶段等级时,阶段为0
-function EquipEntity:getStage()
- local stage = 0
- for idx, level in pairs(self.cfg.features_level) do
- if self.level < level then
- break
- end
- stage = idx
- end
- return stage
-end
-
--- 获取属性描述
-function EquipEntity:getAttrDesc()
- local stage = self:getStage()
- if self:getPart() ~= GConst.EquipConst.PART_TYPE.WEAPON then
- stage = DataManager.EquipData:getMinArmorStage(self:getHeroId())
- end
-
- local strAttr = ""
- for i = 1, stage + 1 do
- if i > #self.cfg.features_level or i > #self.cfg.features_attr then
- break
- end
-
- local level = self.cfg.features_level[i]
- local attr = self.cfg.features_attr[i]
- local str = I18N:getGlobalText(I18N.GlobalConst.EQUIP_DESC_3) .. level .. ":".. GFunc.getAttrDesc(attr.type, attr.num)
- if self:getPart() ~= GConst.EquipConst.PART_TYPE.WEAPON then
- str = I18N:getGlobalText(I18N.GlobalConst.EQUIP_DESC_26, level) .. GFunc.getAttrDesc(attr.type, attr.num)
- end
- if i < stage + 1 then
- strAttr = "" .. strAttr.. str .. "\n"
- else
- strAttr = "" .. strAttr.. str .. "(" .. I18N:getGlobalText(I18N.GlobalConst.EQUIP_DESC_12) .. ")"
- end
- end
-
- return strAttr
-end
-
--- 获取部位已获得属性
-function EquipEntity:getStageAttr()
- local stage = self:getStage()
- if self:getPart() ~= GConst.EquipConst.PART_TYPE.WEAPON then
- stage = DataManager.EquipData:getMinArmorStage(self:getHeroId())
- end
-
- if self.curAttr == nil or #self.curAttr ~= stage then
- self.curAttr = {}
- for i = 1, stage do
- table.insert(self.curAttr, self.cfg.features_attr[i])
- end
- end
-
- return self.curAttr
-end
-
--- 获取部位图标id
-function EquipEntity:getIconId()
- local stage = self:getStage()
- if stage then
- return self.cfg.weapon_icon[stage + 1]
- end
- return nil
-end
-
--- 获取部位名称
function EquipEntity:getName()
- local names = I18N:getText("equip", self:getId(), "name")
- names = string.split(names, ",")
- return names[self:getStage() + 1] or ""
+ return DataManager.EquipData:getName(self:getId())
end
--- 获取部位当前等级
-function EquipEntity:getLevel()
- return self.level
+function EquipEntity:getNameQltColor()
+ return string.format("%s", GFunc.getQltColor(self:getQlt()), self:getName())
end
--- 获取部位等级上限
-function EquipEntity:getMaxLevel()
- if self:getPart() == GConst.EquipConst.PART_TYPE.WEAPON then
- -- 武器等级上限是玩家等级*2
- return DataManager.PlayerData:getLv() * 2
- else
- -- 防具等级上限是当前英雄武器等级
- return DataManager.EquipData:getEquip(self:getHeroId(), GConst.EquipConst.PART_TYPE.WEAPON):getLevel()
+function EquipEntity:getPartName()
+ return I18N:getGlobalText(GConst.EquipConst.EQUIP_PART_NAME[self:getPart()])
+end
+--@endregion
+
+--@region 属性
+function EquipEntity:initBaseAttr()
+ self.baseAttr = DataManager.EquipData:getBaseAttr(self:getId())
+end
+
+function EquipEntity:setExtraAttr(attr)
+ self.extraAttrs = {}
+ self.extraMap = attr
+ if attr and #attr > 0 then
+ for i, data in pairs(attr) do
+ if self.extraAttrs[GFunc.getAttrNameById(data.id)] then
+ self.extraAttrs[GFunc.getAttrNameById(data.id)] = self.extraAttrs[GFunc.getAttrNameById(data.id)] + data.value
+ else
+ self.extraAttrs[GFunc.getAttrNameById(data.id)] = data.value
+ end
+ end
+ end
+ self.allAttrs = nil
+end
+
+function EquipEntity:getBaseAttrs()
+ return self.baseAttrs
+end
+
+function EquipEntity:getExtraMap()
+ return self.extraMap
+end
+
+function EquipEntity:getExtraAttrs()
+ return self.extraAttrs
+end
+
+function EquipEntity:getAllAttr()
+ if self.allAttrs == nil then
+ self.allAttrs = {}
+ -- 基础
+ for attrName, attrNum in pairs(self:getBaseAttrs()) do
+ self.allAttrs[attrName] = (self.allAttrs[attrName] or 0) + attrNum
+ end
+ -- 额外属性
+ for attrName, attrNum in pairs(self:getExtraAttrs()) do
+ self.allAttrs[attrName] = (self.allAttrs[attrName] or 0) + attrNum
+ end
+
+ self:calcPower()
+ end
+
+ return self.allAttrs
+end
+--@endregion
+
+--@region 战力
+function EquipEntity:setPowerDirty()
+ self.data.isPowerDirty = not self.data.isPowerDirty
+end
+
+function EquipEntity:getPower()
+ return self.curPower
+end
+
+-- 计算战斗力
+function EquipEntity:calcPower()
+ if self.lastPower then
+ self.lastPower = self.curPower
+ end
+ self.curPower = math.floor(self:_getAttrPower())
+ if not self.lastPower then
+ self.lastPower = self.curPower
+ end
+
+ if self.lastPower ~= self.curPower then
+ self:setPowerDirty()
end
end
--- 部位是否可升级
-function EquipEntity:canLevelUp()
- -- 判断英雄解锁
- if not self:getHeroEntity():isActived() then
- return false
- end
+function EquipEntity:_getAttrPower()
+ -- local atk = self.baseAttr.num + (self.extraAttrs[GConst.BattleConst.ATTR_NAME.ATTR_ATK_PRIVATE] or 0)
+ -- local atkPower = AttrNameCfg[GConst.BattleConst.ATTR_NAME.ATTR_ATK_PRIVATE].power or 0
+ -- local crit = self.extraAttrs[GConst.BattleConst.ATTR_NAME.CRIT_PRIVATE] or 0 --暴击
+ -- local critPower = AttrNameCfg[GConst.BattleConst.ATTR_NAME.CRIT_PRIVATE].power or 0
+ -- local critTime = self.extraAttrs[GConst.BattleConst.ATTR_NAME.CRIT_TIME_PRIVATE] or 0 --暴伤
+ -- local critTimePower = AttrNameCfg[GConst.BattleConst.ATTR_NAME.CRIT_TIME_PRIVATE].power or 0
+ -- local def = self.extraAttrs[GConst.BattleConst.ATTR_NAME.DEF_DEC_PRIVATE] or 0 --破防
+ -- local defPower = AttrNameCfg[GConst.BattleConst.ATTR_NAME.DEF_DEC_PRIVATE].power or 0
+ -- def = def / GConst.DEFAULT_FACTOR / (10 * GFunc.getBattleConstIntValue("def_dec_constant_k") + def/ GConst.DEFAULT_FACTOR)
+ -- local score = atk/GConst.DEFAULT_FACTOR
+ -- *(1+crit/GConst.DEFAULT_FACTOR*(critPower / GConst.DEFAULT_FACTOR )
+ -- *critTime/GConst.DEFAULT_FACTOR*(critTimePower/ GConst.DEFAULT_FACTOR))
+ -- *(1+def*defPower/GConst.DEFAULT_FACTOR)
+ -- return math.floor(score)
- --判断材料
- if not self:isEnoughMaterial() then
- return false
- end
-
- -- 判断金币
- if not self:isEnoughGold() then
- return false
- end
-
- -- 判断等级
- if self:isMaxLevel() then
- return false
- end
-
- return true
-end
-
--- 升级材料是否满足
-function EquipEntity:isEnoughMaterial()
- for index, cost in ipairs(self:getUpgradeMaterials()) do
- if cost.num > DataManager.BagData.ItemData:getItemNumById(cost.id) then
- return false
- end
- end
- return true
-end
-
--- 升级金币是否满足
-function EquipEntity:isEnoughGold()
- return DataManager.BagData.ItemData:getItemNumById(GConst.ItemConst.ITEM_ID_GOLD) >= self:getUpgradeGoldNum()
-end
-
--- 部位是否是最大等级
-function EquipEntity:isMaxLevel()
- return self:getLevel() >= self:getMaxLevel()
-end
-
--- 获取部位上一等级实例
-function EquipEntity:getLastLevelEntity()
- if self:getLevel() == 0 then
- return nil
- end
- return DataManager.EquipData:createEntity(self:getHeroId(), self:getPart(), self:getLevel() - 1)
-end
-
--- 获取部位下一等级实例
-function EquipEntity:getNextLevelEntity()
- return DataManager.EquipData:createEntity(self:getHeroId(), self:getPart(), self:getLevel() + 1)
-end
-
--- 获取部位升级所需材料和金币
-function EquipEntity:getUpgradeCost()
- local nextCost = ConfigManager:getConfig("equip_level")[self:getLevel() + 1]
- if not nextCost then
- return
- end
-
- local part = self:getPart()
- if part == GConst.EquipConst.PART_TYPE.WEAPON then
- return nextCost.weapon_cost
- elseif part == GConst.EquipConst.PART_TYPE.HAT then
- return nextCost.hat_cost
- elseif part == GConst.EquipConst.PART_TYPE.CLOTHES then
- return nextCost.clothes_cost
- elseif part == GConst.EquipConst.PART_TYPE.BELT then
- return nextCost.belt_cost
- elseif part == GConst.EquipConst.PART_TYPE.HANDGUARD then
- return nextCost.handguard_cost
- end
-end
-
--- 获取部位升级所需金币数
-function EquipEntity:getUpgradeGoldNum()
- local cost = self:getUpgradeCost()
- if cost then
- for key, value in pairs(cost) do
- if GFunc.getRewardId(value) == GConst.ItemConst.ITEM_ID_GOLD then
- return GFunc.getRewardNum(value)
+ local power = 0
+ for attrName, attrNum in pairs(self:getAllAttr()) do
+ local cfg = AttrNameCfg[attrName]
+ if cfg then
+ local realValue = attrNum
+ -- 特殊处理,玩家基础暴击伤害不算
+ if attrName == GConst.BattleConst.ATTR_NAME.CRIT_TIME then
+ realValue = attrNum - 15000
end
- end
- end
- return 0
-end
-
--- 获取部位升级所需材料
-function EquipEntity:getUpgradeMaterials()
- local cost = self:getUpgradeCost()
- local materials = {}
- if cost then
- for key, value in pairs(cost) do
- if GFunc.getRewardId(value) ~= GConst.ItemConst.ITEM_ID_GOLD then
- table.insert(materials, value)
- end
- end
- end
- return materials
-end
-
--- 升级
-function EquipEntity:onLevelUp()
- self.level = self.level + 1
-
- -- 检查是否升段
- local lastEntity = DataManager.EquipData:getEquip(self:getHeroId(), self:getPart(), self.level - 1)
- if lastEntity:getStage() < self:getStage() then
- EventManager:dispatchEvent(EventManager.CUSTOM_EVENT.EQUIP_UPSECTION_SUCCESS, self:getPart())
- else
- EventManager:dispatchEvent(EventManager.CUSTOM_EVENT.EQUIP_UPGRADE_SUCCESS, self:getPart())
- end
- self:setDirty()
-end
-
-function EquipEntity:setHeroEntity(heroEntity)
- self.heroEntity = heroEntity
-end
-
-function EquipEntity:getHeroEntity()
- if self.heroEntity then
- return self.heroEntity
- end
-
- return DataManager.HeroData:getHeroById(self:getHeroId())
+
+ power = power + math.floor(realValue * cfg.power / GConst.DEFAULT_FACTOR)
+ end
+ end
+
+ return power
end
+--@endregion
return EquipEntity
\ No newline at end of file