138 lines
2.5 KiB
Lua
138 lines
2.5 KiB
Lua
local HeroEntity = class("HeroEntity", BaseData)
|
|
|
|
function HeroEntity:ctor(cfgId, lv)
|
|
self.id = cfgId
|
|
self.cfgId = cfgId
|
|
self.data.lv = lv
|
|
self.atkKey = nil
|
|
self.hpKey = nil
|
|
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
|
|
if self.data.lv == lv then
|
|
return
|
|
end
|
|
self.data.lv = lv
|
|
self.atkKey = nil
|
|
self.hpKey = nil
|
|
self:setDirty()
|
|
end
|
|
|
|
function HeroEntity:getCfgId()
|
|
return self.cfgId
|
|
end
|
|
|
|
function HeroEntity:getLv()
|
|
return self.data.lv
|
|
end
|
|
|
|
function HeroEntity:getQlt()
|
|
return self.config.qlt
|
|
end
|
|
|
|
function HeroEntity:getMatchType()
|
|
return self.config.position
|
|
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[self:getHpKey()] or 0
|
|
self.baseAttrOriginal[GConst.ATTR_TYPE.atk] = self.config[self:getAtkKey()] or 0
|
|
end
|
|
|
|
function HeroEntity:getHpKey()
|
|
if self.hpKey == nil then
|
|
self.hpKey = "hp_" .. self.data.lv
|
|
end
|
|
return self.hpKey
|
|
end
|
|
|
|
function HeroEntity:getAtkKey()
|
|
if self.atkKey == nil then
|
|
self.atkKey = "atk_" .. self.data.lv
|
|
end
|
|
return self.atkKey
|
|
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
|
|
|
|
function HeroEntity:getModelId()
|
|
return self.config.model_id
|
|
end
|
|
|
|
function HeroEntity:getActiveSkill()
|
|
return self.config.base_skill
|
|
end
|
|
|
|
return HeroEntity |