local HeroEntityOther = 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 HeroEntityOther: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
		for matchType, v in ipairs(self.allAtkpAttr) do
			for k, vv in pairs(attrs) do
				self.allAtkpAttr[matchType][k] = (self.allAtkpAttr[matchType][k] or 0) + vv
			end
		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