297 lines
6.4 KiB
Lua
297 lines
6.4 KiB
Lua
local HeroEntity = class("HeroEntity", BaseData)
|
|
local ATTR_NAME = GConst.BattleConst.ATTR_NAME
|
|
|
|
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.beginLv = self.config.begin_lv -- 初始等级
|
|
|
|
self.baseAttrOriginal = {}
|
|
self.allAttr = {}
|
|
self:initAttr()
|
|
self:updateAttr()
|
|
end
|
|
|
|
function HeroEntity:initAttr()
|
|
self:setAttrValue(ATTR_NAME.HP, 0)
|
|
self:setAttrValue(ATTR_NAME.ATK, 0)
|
|
self:setAttrValue(ATTR_NAME.ATK_RED, 0)
|
|
self:setAttrValue(ATTR_NAME.ATK_YELLOW, 0)
|
|
self:setAttrValue(ATTR_NAME.ATK_GREEN, 0)
|
|
self:setAttrValue(ATTR_NAME.ATK_BLUE, 0)
|
|
self:setAttrValue(ATTR_NAME.ATK_PURPLE, 0)
|
|
end
|
|
|
|
function HeroEntity:setLv(lv)
|
|
if not lv then
|
|
return
|
|
end
|
|
if self.data.lv == lv then
|
|
return
|
|
end
|
|
self.data.lv = lv
|
|
ModuleManager.TaskManager:addTaskProgress(GConst.TaskConst.TASK_TYPE.X_HERO_LV_UP, lv)
|
|
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:getBeginLv()
|
|
return self.beginLv
|
|
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()
|
|
self:updateAllAttr()
|
|
end
|
|
|
|
function HeroEntity:updateBaseAttr()
|
|
self.baseAttrOriginal[ATTR_NAME.HP] = self:getCfgHp()
|
|
self.baseAttrOriginal[ATTR_NAME.ATK_RED] = 0
|
|
self.baseAttrOriginal[ATTR_NAME.ATK_YELLOW] = 0
|
|
self.baseAttrOriginal[ATTR_NAME.ATK_GREEN] = 0
|
|
self.baseAttrOriginal[ATTR_NAME.ATK_BLUE] = 0
|
|
self.baseAttrOriginal[ATTR_NAME.ATK_PURPLE] = 0
|
|
self.baseAttrOriginal[GConst.MATCH_ATTACK_NAME[self.config.position]] = self:getCfgAtk()
|
|
end
|
|
|
|
function HeroEntity:getCfgHp(lv)
|
|
lv = lv or self.data.lv
|
|
if lv > self:getMaxLv() then
|
|
lv = self:getMaxLv()
|
|
end
|
|
if self.config and self.config.hp then
|
|
return self.config.hp[lv] or 0
|
|
end
|
|
|
|
return 0
|
|
end
|
|
|
|
function HeroEntity:getCfgAtk(lv)
|
|
lv = lv or self.data.lv
|
|
if lv > self:getMaxLv() then
|
|
lv = self:getMaxLv()
|
|
end
|
|
if self.config and self.config.atk then
|
|
return self.config.atk[lv] or 0
|
|
end
|
|
|
|
return 0
|
|
end
|
|
|
|
function HeroEntity:getUnlcokChapter()
|
|
return self.config.unlock_chapter
|
|
end
|
|
|
|
function HeroEntity:getIsShowUnlcokChapter()
|
|
return self.config.is_show == 1
|
|
end
|
|
|
|
function HeroEntity:updateAllAttr()
|
|
for k, v in pairs(self.baseAttrOriginal) do
|
|
self:setAttrValue(k, v)
|
|
end
|
|
end
|
|
|
|
function HeroEntity:setAttrValue(name, value)
|
|
self.allAttr[name] = GFunc.encryptNumber(value or 0)
|
|
end
|
|
|
|
function HeroEntity:getAttrValue(name)
|
|
if not self.allAttr[name] then
|
|
return 0
|
|
end
|
|
return GFunc.decryptNumber(self.allAttr[name])
|
|
end
|
|
|
|
function HeroEntity:getAtk()
|
|
local atkAddName = GConst.MATCH_ATTACK_ADD_NAME[self:getMatchType()]
|
|
local atkName = GConst.MATCH_ATTACK_NAME[self:getMatchType()]
|
|
return self:getAttrValue(atkName) + self:getAttrValue(atkAddName)
|
|
end
|
|
|
|
function HeroEntity:getHp()
|
|
local atkAddName = GConst.MATCH_HP_ADD_NAME[self:getMatchType()]
|
|
return self:getAttrValue(GConst.BattleConst.ATTR_NAME.HP) + self:getAttrValue(atkAddName)
|
|
end
|
|
|
|
function HeroEntity:setDirty()
|
|
self.attrDirty = true
|
|
end
|
|
|
|
function HeroEntity:isMaxLv()
|
|
return self.data.lv >= self:getMaxLv()
|
|
end
|
|
|
|
function HeroEntity:getMaxLv()
|
|
if not self.maxLv then
|
|
self.maxLv = ConfigManager:getConfigNum("hero_level")
|
|
end
|
|
return self.maxLv
|
|
end
|
|
|
|
function HeroEntity:canLvUp(showToast)
|
|
if self:isMaxLv() then
|
|
return false, GConst.HeroConst.CHECK_LV_UP_STATE.MAX_LV
|
|
end
|
|
|
|
local cost = self:getLvUpMaterials()
|
|
if not cost then
|
|
return false, GConst.HeroConst.CHECK_LV_UP_STATE.NO_COST
|
|
end
|
|
|
|
local fragmentCost = cost[1] or 0
|
|
if not GFunc.checkCost(self:getFragmentId(), fragmentCost, showToast) then
|
|
return false, GConst.HeroConst.CHECK_LV_UP_STATE.FRAGMENT_NOT_ENOUGH
|
|
end
|
|
local goldCost = cost[2] or 0
|
|
if not GFunc.checkCost(GConst.ItemConst.ITEM_ID_GOLD, goldCost, showToast) then
|
|
return false, GConst.HeroConst.CHECK_LV_UP_STATE.COIN_NOT_ENOUGH
|
|
end
|
|
|
|
return true, GConst.HeroConst.CHECK_LV_UP_STATE.SUCCESS
|
|
end
|
|
|
|
function HeroEntity:isUnlock()
|
|
if self:isActived() then
|
|
return true
|
|
end
|
|
local unlockChapter = self:getUnlcokChapter()
|
|
if unlockChapter and unlockChapter <= DataManager.ChapterData:getMaxChapterId() then
|
|
return true
|
|
end
|
|
return false
|
|
end
|
|
|
|
function HeroEntity:isActived()
|
|
return self.data.lv >= self:getBeginLv()
|
|
end
|
|
|
|
function HeroEntity:getLvUpMaterials()
|
|
local lv = self.data.lv + 1
|
|
if lv < self:getBeginLv() then
|
|
lv = self:getBeginLv()
|
|
end
|
|
local nextLvInfo = ConfigManager:getConfig("hero_level")[lv]
|
|
if not nextLvInfo then
|
|
return
|
|
end
|
|
local fieldName = "cost_" .. self:getQlt()
|
|
return nextLvInfo[fieldName]
|
|
end
|
|
|
|
function HeroEntity:getConfig()
|
|
return self.config
|
|
end
|
|
|
|
function HeroEntity:getModelId()
|
|
return self.config.model_id
|
|
end
|
|
|
|
function HeroEntity:getBaseSkill()
|
|
return self.config.base_skill
|
|
end
|
|
|
|
function HeroEntity:getAssistingSkill()
|
|
return self.config.support_skill
|
|
end
|
|
|
|
function HeroEntity:getHurtSkill()
|
|
return self.config.hurt_skill
|
|
end
|
|
|
|
function HeroEntity:getFragmentId()
|
|
return self.config.item_id
|
|
end
|
|
|
|
function HeroEntity:getIcon()
|
|
return self.config.icon
|
|
end
|
|
|
|
function HeroEntity:getHurtNum()
|
|
return self.config.hurt_num
|
|
end
|
|
|
|
function HeroEntity:getName()
|
|
return ModuleManager.HeroManager:getHeroName(self:getCfgId())
|
|
end
|
|
|
|
function HeroEntity:getDesc()
|
|
return ModuleManager.HeroManager:getHeroDesc(self:getCfgId())
|
|
end
|
|
|
|
|
|
function HeroEntity:getActiveRogueCount()
|
|
local lvInfo = ConfigManager:getConfig("hero_level")[self.data.lv]
|
|
if not lvInfo then
|
|
return 0
|
|
end
|
|
return lvInfo.unlock_skill
|
|
end
|
|
|
|
function HeroEntity:getUnlockRogueId()
|
|
return self.config.rouge_skill
|
|
end
|
|
|
|
function HeroEntity:getRogueSkillList()
|
|
if not self.rogueSkillList then
|
|
self.rogueSkillList = {}
|
|
local count = 1
|
|
while true do
|
|
local id = self.config["rouge_skill_" .. count]
|
|
if id then
|
|
table.insert(self.rogueSkillList, id)
|
|
else
|
|
break
|
|
end
|
|
count = count + 1
|
|
end
|
|
end
|
|
|
|
return self.rogueSkillList
|
|
end
|
|
|
|
function HeroEntity:getActiveRogueSkills()
|
|
local list = {}
|
|
for i = 1, self:getActiveRogueCount() do
|
|
local id = self:getRogueSkillList()[i]
|
|
if id then
|
|
table.insert(list, id)
|
|
else
|
|
break
|
|
end
|
|
end
|
|
|
|
return list
|
|
end
|
|
|
|
return HeroEntity |