diff --git a/lua/app/global/global_const.lua b/lua/app/global/global_const.lua index 7b90b5fb..fb6122d8 100644 --- a/lua/app/global/global_const.lua +++ b/lua/app/global/global_const.lua @@ -1,5 +1,6 @@ local GConst = {} +GConst.DEFAULT_FACTOR = 10000 GConst.NOT_VISIBLE_POS = 10000000000 local CONST_PATHS = { diff --git a/lua/app/global/global_func.lua b/lua/app/global/global_func.lua index 9c0c71c0..81584e7a 100644 --- a/lua/app/global/global_func.lua +++ b/lua/app/global/global_func.lua @@ -1857,11 +1857,13 @@ function GFunc.readOnlyTab(inputTable) end function GFunc.encryptNumber(value) - return value + GConst.NUMBER_ENCRYPTION_CONSTANT + -- return value + GConst.NUMBER_ENCRYPTION_CONSTANT + return value end function GFunc.decryptNumber(value) - return value - GConst.NUMBER_ENCRYPTION_CONSTANT + -- return value - GConst.NUMBER_ENCRYPTION_CONSTANT + return value end function GFunc.formatPlayerName(name) @@ -1952,4 +1954,15 @@ function GFunc.getStarImg(starType) 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 \ No newline at end of file diff --git a/lua/app/userdata/hero/hero_data.lua b/lua/app/userdata/hero/hero_data.lua index e5663b6b..5e5c8fd5 100644 --- a/lua/app/userdata/hero/hero_data.lua +++ b/lua/app/userdata/hero/hero_data.lua @@ -14,6 +14,9 @@ function HeroData:ctor() self.heroDanUnlockMap = {} self.heroDanUnlockMapBi = {} + + self.allAtkpAttr = {} + self.allAtkpAttrByHero = {} end function HeroData:clear() @@ -383,4 +386,28 @@ function HeroData:isSkinOpen() return true end -- 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 \ No newline at end of file diff --git a/lua/app/userdata/hero/hero_entity.lua b/lua/app/userdata/hero/hero_entity.lua index b27e98e8..8b118940 100644 --- a/lua/app/userdata/hero/hero_entity.lua +++ b/lua/app/userdata/hero/hero_entity.lua @@ -61,6 +61,21 @@ function HeroEntity:updateAllAttr() self:updateStarAttr() self:updateSkinAttr() 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 -- 更新英雄基础属性 @@ -77,9 +92,9 @@ end -- 更新皮肤属性 function HeroEntity:updateStarAttr() self.starAttr = {} - local attr = self:getStarAttrCfg()[self.data.star] - for index, value in ipairs(attr or {}) do - self.starAttr[value.type] = value.num + for i = 1, self.data.star do + local attr = self:getStarAttrCfg()[i] + self.starAttr[attr.type] = attr.num end end @@ -149,7 +164,7 @@ end function HeroEntity:addTotalAttrValue(name, add) -- Logger.logHighlight("add "..name..":"..add) local before = self:getTotalAttrValue(name) - self.allAttr[name] = GFunc.encryptNumber(before + add or 0) + self.allAttr[name] = GFunc.encryptNumber(before + (add or 0)) end function HeroEntity:getTotalAttrValue(name)