102 lines
1.8 KiB
Lua
102 lines
1.8 KiB
Lua
local HeroEntity = class("HeroEntity", BaseData)
|
|
|
|
function HeroEntity:ctor(cfgId, lv)
|
|
self.id = cfgId
|
|
self.cfgId = cfgId
|
|
self.data.lv = lv
|
|
self.attrDirty = false
|
|
self.config = ConfigManager:getConfig("hero")[self.cfgId]
|
|
|
|
self.baseAttrOriginal = {}
|
|
self.allAttr = {}
|
|
self:initAttr()
|
|
self:updateAttr()
|
|
end
|
|
|
|
function HeroEntity:initAttr()
|
|
self.allAttr[GConst.ATTR_TYPE.hp] = 0
|
|
self.allAttr[GConst.ATTR_TYPE.atk] = 0
|
|
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:getQlt()
|
|
return self.config.qlt
|
|
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()
|
|
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
|
|
|
|
function HeroEntity:getConfig()
|
|
return self.config
|
|
end
|
|
|
|
return HeroEntity |