local ServerHeroManager = {} function ServerHeroManager:onUpgradeHero(params, callback) local result = { status = 1 } if params == nil then if callback then callback(result) end return end local heroId = params.heroId local heroCfg = ConfigManager:getConfig("hero")[heroId] if heroId and heroCfg then local ServerGameData = ServerDataManager:getServerGameData() local ItemData = ServerGameData.BagData.ItemData local heroInfo = ServerGameData.HeroData:getHeroByCfgId(heroId) or {cfg_id = heroId, lv = 0} local lv = heroInfo.lv + 1 if lv < heroCfg.begin_lv then lv = heroCfg.begin_lv end local nextLvInfo = ConfigManager:getConfig("hero_level")[lv] if not nextLvInfo then return end local fieldName = "cost_" .. heroCfg.qlt nextLvInfo = nextLvInfo[fieldName] local fragmentCost = nextLvInfo[1] or 0 if not ItemData:tryAddItem(heroCfg.item_id, -fragmentCost) then return end local goldCost = nextLvInfo[2] or 0 if not ItemData:tryAddItem(GConst.ItemConst.ITEM_ID_GOLD, -goldCost) then return end local costs = { { type = GConst.REWARD_TYPE.ITEM, id = heroCfg.item_id, num = fragmentCost }, { type = GConst.REWARD_TYPE.ITEM, id = GConst.ItemConst.ITEM_ID_GOLD, num = goldCost } } ServerGameData.HeroData:upgradeHero(heroId) result.heroId = heroId result.lv = lv result.costs = ServerGameData:addCosts(costs) result.status = 0 end if callback then callback(result) end end return ServerHeroManager