This commit is contained in:
puxuan 2025-06-23 22:10:39 +08:00
parent e5cff3bde0
commit ecbae1e4e6
4 changed files with 62 additions and 6 deletions

View File

@ -1,5 +1,6 @@
local GConst = {} local GConst = {}
GConst.DEFAULT_FACTOR = 10000
GConst.NOT_VISIBLE_POS = 10000000000 GConst.NOT_VISIBLE_POS = 10000000000
local CONST_PATHS = { local CONST_PATHS = {

View File

@ -1857,11 +1857,13 @@ function GFunc.readOnlyTab(inputTable)
end end
function GFunc.encryptNumber(value) function GFunc.encryptNumber(value)
return value + GConst.NUMBER_ENCRYPTION_CONSTANT -- return value + GConst.NUMBER_ENCRYPTION_CONSTANT
return value
end end
function GFunc.decryptNumber(value) function GFunc.decryptNumber(value)
return value - GConst.NUMBER_ENCRYPTION_CONSTANT -- return value - GConst.NUMBER_ENCRYPTION_CONSTANT
return value
end end
function GFunc.formatPlayerName(name) function GFunc.formatPlayerName(name)
@ -1952,4 +1954,15 @@ function GFunc.getStarImg(starType)
end end
end end
-- 获取计算了加成的最终属性值全部属性固定属性id加成属性id
function GFunc.getFinalAttrValue(allAttrs, fixedId, factorId)
local fixedValue = allAttrs[fixedId] or 0
local factorValue = allAttrs[factorId] or 0
if factorValue > 0 then
return math.floor(fixedValue * (1 + factorValue / GConst.DEFAULT_FACTOR) + 0.0000001)
else
return fixedValue
end
end
return GFunc return GFunc

View File

@ -14,6 +14,9 @@ function HeroData:ctor()
self.heroDanUnlockMap = {} self.heroDanUnlockMap = {}
self.heroDanUnlockMapBi = {} self.heroDanUnlockMapBi = {}
self.allAtkpAttr = {}
self.allAtkpAttrByHero = {}
end end
function HeroData:clear() function HeroData:clear()
@ -383,4 +386,28 @@ function HeroData:isSkinOpen()
return true return true
end end
-- endregion -- endregion
-- region 属性相关
function HeroData:getAttrByMatchType(matchType, attrType)
self.allAtkpAttr[matchType] = self.allAtkpAttr[matchType] or {}
return self.allAtkpAttr[matchType][attrType] or 0
end
function HeroData:setHeroAttr(heroId, attr)
self.allAtkpAttrByHero[heroId] = attr
self:calcAttr()
end
function HeroData:calcAttr()
for heroId, attrs in pairs(self.allAtkpAttrByHero) do
-- self.baseAttrOriginal[ATTR_NAME.ATK_RED] = 0
local matchType = self.heroes[heroId]:getMatchType()
self.allAtkpAttr[matchType] = self.allAtkpAttr[matchType] or {}
for k,v in pairs(attrs) do
self.allAtkpAttr[matchType][k] = (self.allAtkpAttr[matchType][k] or 0) + v
end
end
end
-- endregion
return HeroData return HeroData

View File

@ -61,6 +61,21 @@ function HeroEntity:updateAllAttr()
self:updateStarAttr() self:updateStarAttr()
self:updateSkinAttr() self:updateSkinAttr()
self:updateTotalAttr() self:updateTotalAttr()
if self.allAttr[GConst.MATCH_ALL_ATKP_NAME[self:getMatchType()]] ~= nil then
local attr = {}
attr[GConst.MATCH_ALL_ATKP_NAME[self:getMatchType()]] = self.allAttr[GConst.MATCH_ALL_ATKP_NAME[self:getMatchType()]]
-- self.allAttr[GConst.MATCH_ALL_ATKP_NAME[self:getMatchType()]] = nil
DataManager.HeroData:setHeroAttr(self:getCfgId(), attr)
end
-- 攻击力(百分比)
local atkType = GConst.MATCH_ATTACK_NAME[self:getMatchType()]
local atkpType = GConst.MATCH_ALL_ATKP_NAME[self:getMatchType()]
local factorValue = DataManager.HeroData:getAttrByMatchType(self:getMatchType(), atkpType)
if factorValue > 0 then
self.allAttr[atkType] = math.floor(self.allAttr[atkType] * (1 + factorValue / GConst.DEFAULT_FACTOR) + 0.0000001)
end
end end
-- 更新英雄基础属性 -- 更新英雄基础属性
@ -77,9 +92,9 @@ end
-- 更新皮肤属性 -- 更新皮肤属性
function HeroEntity:updateStarAttr() function HeroEntity:updateStarAttr()
self.starAttr = {} self.starAttr = {}
local attr = self:getStarAttrCfg()[self.data.star] for i = 1, self.data.star do
for index, value in ipairs(attr or {}) do local attr = self:getStarAttrCfg()[i]
self.starAttr[value.type] = value.num self.starAttr[attr.type] = attr.num
end end
end end
@ -149,7 +164,7 @@ end
function HeroEntity:addTotalAttrValue(name, add) function HeroEntity:addTotalAttrValue(name, add)
-- Logger.logHighlight("add "..name..":"..add) -- Logger.logHighlight("add "..name..":"..add)
local before = self:getTotalAttrValue(name) local before = self:getTotalAttrValue(name)
self.allAttr[name] = GFunc.encryptNumber(before + add or 0) self.allAttr[name] = GFunc.encryptNumber(before + (add or 0))
end end
function HeroEntity:getTotalAttrValue(name) function HeroEntity:getTotalAttrValue(name)