def _update_soldier_succeed(self, data, req, timer): res = hero_pb2.UpdateHeroRes() res.status = 0 response = res.SerializeToString() log = log_formater.output(data, "Upgrade hero soldier succeed", req, res, timer.count_ms()) logger.notice(log) return response
def _upgrade_evolution_level_succeed(self, data, req, timer): res = hero_pb2.UpdateHeroRes() res.status = 0 response = res.SerializeToString() log = log_formater.output(data, "Upgrade evolution level succeed", req, res, timer.count_ms()) logger.notice(log) return response
def _upgrade_evolution_level_failed(self, err, req, timer): logger.fatal("Upgrade evolution level failed[reason=%s]" % err) res = hero_pb2.UpdateHeroRes() res.status = -1 response = res.SerializeToString() logger.notice( "Upgrade evolution level failed[user_id=%d][req=%s][res=%s][consume=%d]" % (timer.id, req, res, timer.count_ms())) return response
def _calc_upgrade_star(self, data, req, timer): """重现客户端升星计算逻辑,和请求进行比较 """ res = hero_pb2.UpdateHeroRes() res.status = 0 hero_id = HeroInfo.generate_id(data.id, req.hero.basic_id) hero = data.hero_list.get(hero_id) item_id = ItemInfo.generate_id(data.id, req.item[0].basic_id) item = data.item_list.get(item_id) if hero is None or item is None: raise Exception("Hero or item not exist") #消耗精魄 soul_num = 0 open_flags = account_business.get_flags() if "HeroUpStarUseSoul" in open_flags: soul_num = data_loader.HeroStarLevelBasicInfo_dict[ req.hero.star_level].soul #使用灵魂石 consume_num = data_loader.HeroStarLevelBasicInfo_dict[ req.hero.star_level].perceptivity ret = hero_business.star_upgrade(data, hero, item, consume_num, soul_num, timer.now) if ret != hero_pb2.HERO_OK: res.ret = ret return self._upgrade_star_succeed(data, req, res, timer) #和请求进行比较 if req.hero.star_level != hero.star: raise Exception("Unexpect hero star[expect star=%d]" % hero.star) #验证 compare.check_hero(data, req.hero, with_star=True) compare.check_item(data, req.item[0]) resource = data.resource.get() resource.update_current_resource(timer.now) res.ret = hero_pb2.HERO_OK pack.pack_resource_info(resource, res.resource) try: if hero.is_need_broadcast_star_level(): self._add_upgrade_star_level_broadcast(data.user.get(), hero) except: logger.warning("Send upgrade star level broadcast failed") defer = DataBase().commit(data) defer.addCallback(self._upgrade_star_succeed, req, res, timer) return defer