equip
This commit is contained in:
parent
7d4a361039
commit
7062211624
@ -457,6 +457,31 @@ function GFunc.getAttrShowValue(attrType, attrNum, notPercentSign)
|
|||||||
end
|
end
|
||||||
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)
|
function GFunc.getAttrName(key)
|
||||||
return I18N:getText("attr", key, "name")
|
return I18N:getText("attr", key, "name")
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,28 +1,35 @@
|
|||||||
local EquipData = class("EquipData", BaseData)
|
local EquipData = class("EquipData", BaseData)
|
||||||
local EquipEntity = require "app/userdata/equip/equip_entity"
|
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()
|
function EquipData:ctor()
|
||||||
self.data.isDirty = false
|
self.data.isDirty = false
|
||||||
end
|
end
|
||||||
|
|
||||||
function EquipData:clear()
|
function EquipData:clear()
|
||||||
ModuleManager.EquipManager:updateEquipGiftTimer(true)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function EquipData:init(data)
|
function EquipData:init(data)
|
||||||
data = data or GConst.EMPTY_TABLE
|
data = data or GConst.EMPTY_TABLE
|
||||||
|
if EDITOR_MODE then
|
||||||
Logger.logHighlight("装备数据")
|
Logger.logHighlight("装备数据")
|
||||||
Logger.printTable(data)
|
Logger.printTable(data)
|
||||||
self.equips = {}
|
end
|
||||||
if not data.HeroesEquips then
|
if not data.equips then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
for heroId, equip in pairs(data.HeroesEquips) do
|
self.allEquips = {}
|
||||||
for part, level in pairs(equip.Equips) do
|
if data.equips then
|
||||||
self:addEquip(heroId, part, level)
|
for i, equip in pairs(data.equips) do
|
||||||
|
self:addEquip(equip)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
self.slots = data.slots or {}
|
||||||
end
|
end
|
||||||
|
|
||||||
function EquipData:setDirty()
|
function EquipData:setDirty()
|
||||||
@ -37,108 +44,366 @@ function EquipData:isWeaponOpen(showToast)
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
-- 防具功能是否开启
|
--@region 配置
|
||||||
function EquipData:isArmorOpen(showToast)
|
-- 获取配置
|
||||||
if not ModuleManager:getIsOpen(ModuleManager.MODULE_KEY.EQUIP_ARMOR, not showToast) then
|
function EquipData:getConfig(id)
|
||||||
return false
|
if id then
|
||||||
|
return EquipCfg[id]
|
||||||
|
else
|
||||||
|
return EquipCfg
|
||||||
end
|
end
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function EquipData:addEquip(heroId, part, level)
|
-- 获取强化配置
|
||||||
if not self.equips[heroId] then
|
function EquipData:getLevelConfig(id)
|
||||||
self.equips[heroId] = {}
|
if id then
|
||||||
|
return EquipLevelCfg[id]
|
||||||
|
else
|
||||||
|
return EquipLevelCfg
|
||||||
end
|
end
|
||||||
if self.equips[heroId][part] then
|
end
|
||||||
|
|
||||||
|
-- 获取精炼配置
|
||||||
|
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
|
return
|
||||||
end
|
end
|
||||||
self.equips[heroId][part] = self:createEntity(heroId, part, level)
|
self.allEquips[equip.uid] = self:createEquipEntity(equip)
|
||||||
|
if itemGetType then
|
||||||
|
BIReport:postEquipGet(equip.uid, equip.cfg_id, itemGetType)
|
||||||
|
end
|
||||||
|
self:setDirty()
|
||||||
end
|
end
|
||||||
|
|
||||||
function EquipData:createEntity(heroId, part, level)
|
function EquipData:createEquipEntity(equip)
|
||||||
return EquipEntity:create(heroId, part, level)
|
return EquipEntity:create(equip)
|
||||||
end
|
end
|
||||||
|
|
||||||
function EquipData:getAllEquips()
|
function EquipData:getAllEquips()
|
||||||
return self.equips
|
return self.allEquips
|
||||||
end
|
end
|
||||||
|
|
||||||
function EquipData:getEquip(id, part)
|
function EquipData:getEquipByUid(uid)
|
||||||
if not self.equips[id] then
|
if self.allEquips[uid] then
|
||||||
self.equips[id] = {}
|
return self.allEquips[uid]
|
||||||
end
|
end
|
||||||
if not self.equips[id][part] then
|
|
||||||
self.equips[id][part] = self:createEntity(id, part)
|
|
||||||
end
|
end
|
||||||
return self.equips[id][part]
|
--@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
|
end
|
||||||
|
|
||||||
-- 是否有装备可升级
|
-----获取强化等级
|
||||||
function EquipData:canUpgradeEquip(heroId)
|
function EquipData:getPartLevel(slotId, part)
|
||||||
if self:canUpgradeWeapon(heroId) then
|
local parts = self.slots[slotId].parts
|
||||||
return true
|
if parts then
|
||||||
|
local partInfo = parts[part]
|
||||||
|
if partInfo then
|
||||||
|
return partInfo.level
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return 0
|
||||||
end
|
end
|
||||||
|
|
||||||
if self:canUpgradeArmor(heroId) then
|
--获取精炼等级
|
||||||
return true
|
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
|
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
|
end
|
||||||
|
|
||||||
-- 武器是否可升级
|
function EquipData:getSlotAllAttr(slotId)
|
||||||
function EquipData:canUpgradeWeapon(heroId)
|
local attr = {}
|
||||||
if not self:isWeaponOpen() then
|
for part = 1, 6 do
|
||||||
return false
|
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
|
end
|
||||||
|
|
||||||
local entity = self:getEquip(heroId, GConst.EquipConst.PART_TYPE.WEAPON)
|
function EquipData:getResonateLevelValue(type, value, value2)
|
||||||
if entity:canLevelUp() then
|
local list = self:getResonateList(type)
|
||||||
return true
|
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
|
end
|
||||||
return false
|
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
|
end
|
||||||
|
|
||||||
-- 防具是否可升级
|
function EquipData:getResonateLevel(type, slotId)
|
||||||
function EquipData:canUpgradeArmor(heroId)
|
if type == 1 then
|
||||||
if not self:isArmorOpen() then
|
local minLv = 999
|
||||||
return false
|
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
|
end
|
||||||
|
|
||||||
local entity
|
function EquipData:getLevelCost(refine)
|
||||||
for name, part in pairs(GConst.EquipConst.PART_TYPE) do
|
local cfg = self:getLevelConfig(refine)
|
||||||
entity = self:getEquip(heroId, part)
|
if cfg then
|
||||||
if part ~= GConst.EquipConst.PART_TYPE.WEAPON then
|
return cfg.cost
|
||||||
if entity:canLevelUp() then
|
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
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
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- 获取防具最小阶段
|
function EquipData:getEquipUseForce(uid)
|
||||||
function EquipData:getMinArmorStage(heroId)
|
local equip = self:getEquipByUid(uid)
|
||||||
local minStage = -1
|
local mainTeam = DataManager.ForceData:getTeamList(ModuleManager.BattleManager.BATTLE_TYPE.STAGE)
|
||||||
for name, part in pairs(GConst.EquipConst.PART_TYPE) do
|
local part = equip:getPart()
|
||||||
if part ~= GConst.EquipConst.PART_TYPE.WEAPON then
|
for i,info in ipairs(self.slots) do
|
||||||
local entity = self:getEquip(heroId, part)
|
if info.parts[part] and info.parts[part].equip_uid and info.parts[part].equip_uid == uid then
|
||||||
if minStage == -1 or minStage > entity:getStage() then
|
return mainTeam[i]
|
||||||
minStage = entity:getStage()
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return minStage >= 0 and minStage or 0
|
--@endregion
|
||||||
|
|
||||||
|
--@region 装备分解
|
||||||
|
-- 分解额外返还
|
||||||
|
function EquipData:getResolveReward(id)
|
||||||
|
return self:getConfig(id).decompose
|
||||||
end
|
end
|
||||||
|
|
||||||
-- 装备升级
|
-- 装备分解成功
|
||||||
function EquipData:onUpgradeEquip(heroId, part)
|
function EquipData:onResolveSuccess(uids)
|
||||||
local entity = self:getEquip(heroId, part)
|
if EDITOR_MODE then
|
||||||
if not entity then
|
Logger.logHighlight("装备分解")
|
||||||
return
|
Logger.printTable(uids)
|
||||||
end
|
end
|
||||||
entity:onLevelUp()
|
|
||||||
DataManager.HeroData:getHeroById(heroId):onEquipAttrChange()
|
for i, id in pairs(uids) do
|
||||||
|
self.allEquips[id] = nil
|
||||||
end
|
end
|
||||||
|
self:setDirty()
|
||||||
|
end
|
||||||
|
--@endregion
|
||||||
|
|
||||||
return EquipData
|
return EquipData
|
||||||
@ -1,412 +1,180 @@
|
|||||||
local EquipEntity = class("EquipEntity", BaseData)
|
local EquipEntity = class("EquipEntity", BaseData)
|
||||||
local DEFAULT_FACTOR = GConst.BattleConst.DEFAULT_FACTOR
|
|
||||||
|
|
||||||
function EquipEntity:ctor(heroId, part, level)
|
local AttrNameCfg = ConfigManager:getConfigWithOtherKey("attr", "name")
|
||||||
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
|
|
||||||
|
|
||||||
function EquipEntity:setDirty()
|
function EquipEntity:setDirty()
|
||||||
self.data.isDirty = not self.data.isDirty
|
self.allAttrs = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
-- 获取部位id
|
function EquipEntity:ctor(equip)
|
||||||
function EquipEntity:getId()
|
self:init(equip)
|
||||||
return self.cfgId
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- 获取部位所属英雄
|
function EquipEntity:init(equip)
|
||||||
function EquipEntity:getHeroId()
|
self.uid = equip.uid
|
||||||
return self.cfg.hero
|
self:setId(equip.cfg_id)
|
||||||
|
self:initBaseAttr()
|
||||||
|
self:setExtraAttr(equip.extra_attrs)
|
||||||
|
|
||||||
|
self.lastPower = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
-- 获取部位类型
|
-- 装备唯一id
|
||||||
function EquipEntity:getPart()
|
function EquipEntity:getUid()
|
||||||
return self.cfg.part
|
return self.uid
|
||||||
end
|
end
|
||||||
|
|
||||||
-- 获取部位基础生命值
|
function EquipEntity:setId(id)
|
||||||
function EquipEntity:getBaseHp()
|
self.id = id
|
||||||
if self.cfg.armor_hp and self.cfg.armor_hp[self.level] then
|
|
||||||
return self.cfg.armor_hp[self.level]
|
|
||||||
end
|
|
||||||
return 0
|
|
||||||
end
|
|
||||||
|
|
||||||
-- 获取部位加成后生命值
|
|
||||||
function EquipEntity:getHp()
|
|
||||||
local result = self:getBaseHp()
|
|
||||||
result = result + self:getHeroEntity():getTotalBaseHp() * self:getHpPercent() // DEFAULT_FACTOR
|
|
||||||
return result
|
|
||||||
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
|
|
||||||
end
|
|
||||||
|
|
||||||
-- 获取部位加成后攻击力
|
|
||||||
function EquipEntity:getAttack()
|
|
||||||
local result = self:getBaseAttack()
|
|
||||||
result = result + self:getHeroEntity():getTotalBaseAtk() * self:getAtkPercent() // DEFAULT_FACTOR
|
|
||||||
return result
|
|
||||||
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 = "<color=#EEDFFF>" .. strAttr.. str .. "\n</color>"
|
|
||||||
else
|
|
||||||
strAttr = "<color=#9C94BE>" .. strAttr.. str .. "(" .. I18N:getGlobalText(I18N.GlobalConst.EQUIP_DESC_12) .. ")</color>"
|
|
||||||
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 ""
|
|
||||||
end
|
|
||||||
|
|
||||||
-- 获取部位当前等级
|
|
||||||
function EquipEntity:getLevel()
|
|
||||||
return self.level
|
|
||||||
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()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- 部位是否可升级
|
|
||||||
function EquipEntity:canLevelUp()
|
|
||||||
-- 判断英雄解锁
|
|
||||||
if not self:getHeroEntity():isActived() then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
--判断材料
|
|
||||||
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)
|
|
||||||
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()
|
self:setDirty()
|
||||||
end
|
end
|
||||||
|
|
||||||
function EquipEntity:setHeroEntity(heroEntity)
|
--获取配置id
|
||||||
self.heroEntity = heroEntity
|
function EquipEntity:getId()
|
||||||
|
return self.id
|
||||||
end
|
end
|
||||||
|
|
||||||
function EquipEntity:getHeroEntity()
|
--@region 配置
|
||||||
if self.heroEntity then
|
function EquipEntity:getPart()
|
||||||
return self.heroEntity
|
return DataManager.EquipData:getPart(self:getId())
|
||||||
end
|
end
|
||||||
|
|
||||||
return DataManager.HeroData:getHeroById(self:getHeroId())
|
function EquipEntity:getQlt()
|
||||||
|
return DataManager.EquipData:getQlt(self:getId())
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function EquipEntity:getStar()
|
||||||
|
return DataManager.EquipData:getStar(self:getId())
|
||||||
|
end
|
||||||
|
|
||||||
|
function EquipEntity:getIconRes()
|
||||||
|
return DataManager.EquipData:getIconRes(self:getId())
|
||||||
|
end
|
||||||
|
|
||||||
|
function EquipEntity:getEntityType()
|
||||||
|
return GConst.ENTITY_TYPE.EQUIP_ENTITY
|
||||||
|
end
|
||||||
|
|
||||||
|
function EquipEntity:getName()
|
||||||
|
return DataManager.EquipData:getName(self:getId())
|
||||||
|
end
|
||||||
|
|
||||||
|
function EquipEntity:getNameQltColor()
|
||||||
|
return string.format("<color=%s>%s</color>", GFunc.getQltColor(self:getQlt()), self:getName())
|
||||||
|
end
|
||||||
|
|
||||||
|
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:_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)
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
power = power + math.floor(realValue * cfg.power / GConst.DEFAULT_FACTOR)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return power
|
||||||
|
end
|
||||||
|
--@endregion
|
||||||
|
|
||||||
return EquipEntity
|
return EquipEntity
|
||||||
Loading…
x
Reference in New Issue
Block a user