c1_lua/lua/app/module/hero/hero_manager.lua
2025-09-09 19:24:42 +08:00

200 lines
5.8 KiB
Lua

local HeroManager = class("HeroManager", BaseModule)
function HeroManager:showHeroDetailUI(heroId, onlyLook, heroEntity, formationType)
UIManager:showUI("app/ui/hero/hero_detail_ui", {heroId = heroId, onlyLook = onlyLook, heroEntity = heroEntity, formationType = formationType})
end
function HeroManager:showHeroSkinUI(heroId, onlyLookSkinId)
UIManager:showUI("app/ui/hero/hero_skin_ui", {heroId = heroId, onlyLookSkinId = onlyLookSkinId})
end
function HeroManager:showHeroUnlockUI(heroIdList)
UIManager:showUI("app/ui/hero/hero_unlock_ui", {heroIdList = heroIdList})
end
function HeroManager:showHeroSkillInfoUI(heroEntity, idx, buffId, isUnlock, isPop)
UIManager:showUI("app/ui/hero/hero_skill_info_ui", {heroEntity = heroEntity, idx = idx, buffId = buffId, isUnlock = isUnlock, isPop = isPop})
end
function HeroManager:upgradeHero(heroId, heroEntity, level)
local heroEntity = heroEntity or DataManager.HeroData:getHeroById(heroId)
if not heroEntity then
return
end
local canLvUp, state = heroEntity:canLvUp()
if not canLvUp then
heroEntity:canLvUp(true)
return
end
self:sendMessage(ProtoMsgType.FromMsgEnum.HeroUpgradeReq, {id = heroId, level = level}, {}, self.upgradeHeroFinish, BIReport.ITEM_GET_TYPE.UPGRADE_HERO)
end
function HeroManager:upgradeHeroFinish(result)
if result.err_code == GConst.ERROR_STR.SUCCESS then
DataManager.HeroData:setHeroLv(result.hero.id, result.hero.level)
DataManager.HeroData:setDirty()
DataManager.HeroData:calcPower()
AudioManager:playEffect(AudioManager.EFFECT_ID.HERO_UP)
end
end
function HeroManager:upgradeHeroStar(heroId, heroEntity)
local heroEntity = heroEntity or DataManager.HeroData:getHeroById(heroId)
if not heroEntity then
return
end
local canStarUp, state = heroEntity:canStarUp()
if not canStarUp then
heroEntity:canStarUp(true)
return
end
self:sendMessage(ProtoMsgType.FromMsgEnum.HeroStarReq, {id = heroId}, {}, self.heroStarReqFinish, BIReport.ITEM_GET_TYPE.UPGRADE_HERO)
end
function HeroManager:heroStarReqFinish(result)
if result.err_code == GConst.ERROR_STR.SUCCESS then
DataManager.HeroData:onHeroStarUp(result.hero.id)
DataManager.HeroData:setDirty()
DataManager.HeroData:calcPower()
AudioManager:playEffect(AudioManager.EFFECT_ID.HERO_UP)
end
end
------------------------------------------ 英雄相关的工具方法 ------------------------------
function HeroManager:getHeroName(id, needColor)
local cfg = I18N:getConfig("hero")[id]
if cfg == nil then
return "not find:"..id
end
local name = cfg.name
if name and needColor then
local color = GConst.BattleConst.ELEMENT_COLOR[self:getHeroMatchType(id)]
if color then
name = string.format("<color=%s>%s</color>", color, name)
end
end
return name
end
function HeroManager:getHeroDesc(id)
local cfg = I18N:getConfig("hero")[id]
if cfg == nil then
return "not find:"..id
end
return cfg.desc
end
function HeroManager:getHeroIcon(heroId)
local cfg = ConfigManager:getConfig("hero")[heroId]
return cfg and tostring(cfg.icon)
end
function HeroManager:getHeroSmallFrame(heroId)
local cfg = ConfigManager:getConfig("hero")[heroId]
return cfg and GConst.FRAME_QLT[cfg.qlt]
end
function HeroManager:getHeroMatchType(heroId)
local cfg = ConfigManager:getConfig("hero")[heroId]
return cfg.position
end
function HeroManager:getMatchTypeIcon(matchType)
return GConst.HeroConst.MATCH_ICON_NAME[matchType]
end
function HeroManager:getMatchTypeBg(matchType)
return GConst.ATLAS_PATH.COMMON, "common_quality_" .. matchType
end
function HeroManager:getMatchTypeName(matchType, needColor)
local name = I18N:getGlobalText("ELEMENT_NAME_" .. matchType)
if name and needColor then
local color = GConst.BattleConst.ELEMENT_COLOR[matchType]
if color then
name = string.format("<color=%s>%s</color>", color, name)
end
end
return name
end
function HeroManager:getSkillDesc(skillId)
local cfg = I18N:getConfig("skill")[skillId]
return cfg and cfg.desc
end
function HeroManager:getSkillIcon(skillId)
local cfg = ConfigManager:getConfig("skill")[skillId]
return cfg and tostring(cfg.battle_icon)
end
function HeroManager:getSkillRogueDesc(skillId, value)
local cfg = ConfigManager:getConfig("skill_rogue")[skillId]
if not cfg then
return GConst.EMPTY_STRING
end
local str
if cfg.attr then
str = GFunc.getPerStr(cfg.attr.type, value)
end
return I18N:getText("skill_rogue", skillId, "desc", str)
end
function HeroManager:getSkillRogueDescEntry(skillId, entry)
local cfg = ConfigManager:getConfig("skill_rogue")[skillId]
if not cfg then
return GConst.EMPTY_STRING
end
return I18N:getText("skill_rogue", skillId, "entry_" .. entry)
end
function HeroManager:showValueRogue(skillId)
local cfg = ConfigManager:getConfig("skill_rogue")[skillId]
if cfg and cfg.toast_mark then
return true
end
return false
end
function HeroManager:getSkillRogueIcon(skillId)
local cfg = ConfigManager:getConfig("skill_rogue")[skillId]
return cfg and tostring(cfg.icon)
end
function HeroManager:getSkillRogueBattleBg(skillId)
local cfg = ConfigManager:getConfig("skill_rogue")[skillId]
return cfg and "battle_bg_" .. (cfg.qlt + 5)
end
function HeroManager:getSkillRogueBg(skillId, onlyQlt)
local cfg = ConfigManager:getConfig("skill_rogue")[skillId]
if cfg.skill_position and not onlyQlt then -- 解锁技能类型
return "frame_skill_0"
end
return cfg and "frame_" .. cfg.qlt
end
function HeroManager:getSkillRoguePosition(skillId)
local cfg = ConfigManager:getConfig("skill_rogue")[skillId]
return cfg and cfg.skill_position
end
function HeroManager:getMonsterName(monsterBaseId)
if not I18N:getConfig("monster_base") then
return
end
return I18N:getText("monster_base", monsterBaseId, "name")
end
function HeroManager:getSkillRogueComboHero(skillId)
local cfg = ConfigManager:getConfig("skill_rogue")[skillId]
return cfg and cfg.combo_hero
end
return HeroManager