c1_lua/lua/app/userdata/hero/hero_data_other.lua
2025-09-23 19:55:35 +08:00

60 lines
1.6 KiB
Lua

local HeroEntity = require "app/userdata/hero/hero_entity_other"
local HeroDataOther = class("HeroDataOther", BaseData)
function HeroDataOther:ctor()
self.allAtkpAttr = {}
self.allAtkpAttrByHero = {}
self.allAtkpAttrByTalent = {}
end
function HeroDataOther:clear()
self.allAtkpAttr = {}
self.allAtkpAttrByHero = {}
self.allAtkpAttrByTalent = {}
end
function HeroDataOther:getEntity(heroStruct)
return HeroEntity:create(heroStruct.id, heroStruct.level, heroStruct.skin, heroStruct.star)
end
function HeroDataOther:getMatchType(heroId)
return DataManager.HeroData:getHeroConfig(heroId).position
end
-- region 属性相关
function HeroDataOther:getAttrByMatchType(matchType, attrType)
self.allAtkpAttr[matchType] = self.allAtkpAttr[matchType] or {}
return self.allAtkpAttr[matchType][attrType] or 0
end
function HeroDataOther:setHeroAttr(heroId, attr)
self.allAtkpAttrByHero[heroId] = attr
self:calcAttr()
end
function HeroDataOther:setTalentAttr(attr)
self.allAtkpAttrByTalent = attr
self:calcAttr()
end
function HeroDataOther:calcAttr()
self.allAtkpAttr = {}
for heroId, attrs in pairs(self.allAtkpAttrByHero) do
-- self.baseAttrOriginal[ATTR_NAME.ATK_RED] = 0
local matchType = self:getMatchType(heroId)
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
for k, v in pairs(self.allAtkpAttrByTalent) do
for matchType = 1, 5 do
self.allAtkpAttr[matchType] = self.allAtkpAttr[matchType] or {}
self.allAtkpAttr[matchType][k] = (self.allAtkpAttr[matchType][k] or 0) + v
end
end
end
-- endregion
return HeroDataOther