local HeroEntity = class("HeroEntity", BaseData) function HeroEntity:ctor(heroInfo) self.id = heroInfo.id or 1 self.cfgId = heroInfo.cfg_id or self.id self.data.lv = heroInfo.lv or 1 self.attrDirty = false self.data.powerDirty = false self:_loadConfig() self.baseAttrOriginal = {} self:initAttrTab() self:updateAttr() end function HeroEntity:initAttrTab() self.allAttr = {} local cfg = ConfigManager:getConfig("attr") for i = 1, #cfg do self.allAttr[i] = {unit = 0, value = 0} end end function HeroEntity:_loadConfig() self.config = ConfigManager:getConfig("hero")[self.cfgId] end function HeroEntity:setHid(id) self.id = id end function HeroEntity:getHid() return self.id end function HeroEntity:getId() return self.cfgId end function HeroEntity:setId(id) if not id then return end self.cfgId = id self:_loadConfig() self:setDirty() end function HeroEntity:setLv(lv) if not lv then return end self.data.lv = lv self:setDirty() end function HeroEntity:getLv() return self.data.lv end function HeroEntity:setAttrDirty() self.attrDirty = true end function HeroEntity:getAllAttr() if self.attrDirty == true then self.attrDirty = false self:updateAttr() end return self.allAttr end function HeroEntity:updateAttr() self:updateBaseAttr() self:_updateAllAttr() self:calculatePower() end function HeroEntity:updateBaseAttr() self.baseAttrOriginal[GConst.ATTR_TYPE.hp] = self.config.hp or 0 self.baseAttrOriginal[GConst.ATTR_TYPE.atk] = self.config.atk or 0 end function HeroEntity:getAtk() return self.allAttr[GConst.ATTR_TYPE.atk] or 0 end function HeroEntity:getHp() return self.allAttr[GConst.ATTR_TYPE.hp] or 0 end function HeroEntity:setDirty() self.attrDirty = true end function HeroEntity:canLvUp() if self:isMaxLv() then return false end local cost = self:getLvUpMaterials() if not cost then return false end for _, reward in ipairs(cost) do if not GFunc.checkCost(reward.id, reward.num, false) then return false end end return true end function HeroEntity:getLvUpMaterials() local nextLvInfo = ConfigManager:getConfig("hero_up")[self.data.lv + 1] if not nextLvInfo then return end return nextLvInfo.exp end return HeroEntity