c1_lua/lua/app/module/hero/hero_manager.lua
2023-04-21 22:41:32 +08:00

119 lines
3.5 KiB
Lua

local HeroManager = class("HeroManager", BaseModule)
function HeroManager:showHeroDetailUI(heroId)
UIManager:showUI("app/ui/hero/hero_detail_ui", {heroId = heroId})
end
function HeroManager:upgradeHero(heroId, heroEntity)
local heroEntity = heroEntity or DataManager.HeroData:getHeroById(heroId)
if not heroEntity then
return
end
local materials = heroEntity:getLvUpMaterials()
if not materials or not materials[2] then
return
end
local fragmentCost = materials[1] or 0
if not GFunc.checkCost(heroEntity:getFramentId(), fragmentCost, true) then
return
end
if not heroEntity:canLvUp() then
return
end
ServerDataManager:dataOperate(GConst.ServerDataConst.DATA_OP_BEHAVIOR.UPGRADE_HERO, {heroId = heroId}, function(result)
if result.status == 0 then
GFunc.addCosts(result.costs, BIReport.ITEM_GET_TYPE.UPGRADE_HERO)
DataManager.HeroData:setHeroLv(result.heroId, result.lv)
DataManager.HeroData:setDirty()
end
end)
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.HERO_SMALL_FRAME_QLT[cfg.qlt]
end
function HeroManager:getMatchTypeIcon(matchType)
return GConst.HeroConst.MATCH_ICON_NAME[matchType]
end
function HeroManager:getMatchTypeName(matchType)
return I18N:getGlobalText("ELEMENT_NAME_" .. matchType)
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:showValueRogue(skillId)
if (skillId >= 1 and skillId <= 18) or (skillId >= 21 and skillId <= 23) 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_board_" .. cfg.qlt
end
function HeroManager:getSkillRogueBg(skillId)
local cfg = ConfigManager:getConfig("skill_rogue")[skillId]
if cfg.type == GConst.BattleConst.UNLOCK_SKILL_ROGUE_TYPE then -- 解锁技能类型
return "frame_skill_" .. cfg.skill_position
end
return cfg and "frame_" .. cfg.qlt
end
function HeroManager:getActiveRogueLvs()
if not self.activeRogueLvs then
self.activeRogueLvs = {}
local lvMap = {}
for lv, info in ipairs(ConfigManager:getConfig("hero_level")) do
if not lvMap[info.unlock_skill] then
table.insert(self.activeRogueLvs, lv)
lvMap[info.unlock_skill] = true
end
end
end
return self.activeRogueLvs
end
return HeroManager