Exemple #1
0
    def _pack_refine_cannt_upgrade(self, data, req, hero, timer):
        res = hero_pb2.RefineHeroRes()
        res.status = 0
        res.return_ret = res.Refine_CANNT_UPGRADE

        pack.pack_hero_info(hero, res.hero, timer.now)
        return self._refine_upgrade_succeed(data, req, res, timer)
Exemple #2
0
 def _refine_upgrade_failed(self, err, req, timer):
     logger.fatal("Refine hero upgrade failed[reason=%s]" % err)
     res = hero_pb2.RefineHeroRes()
     res.status = -1
     response = res.SerializeToString()
     logger.notice("Refine hero upgrade failed"
                   "[user_id=%d][req=%s][res=%s][consume=%d]" %
                   (timer.id, req, res, timer.count_ms()))
     return response
Exemple #3
0
    def _pack_refine_upgrade_succeed(self, data, req, hero, timer):
        res = hero_pb2.RefineHeroRes()
        res.status = 0
        res.return_ret = res.Refine_SUCCESS

        pack.pack_hero_info(hero, res.hero, timer.now)

        defer = DataBase().commit(data)
        defer.addCallback(self._refine_upgrade_succeed, req, res, timer)
        return defer
Exemple #4
0
    def _pack_refine_need_item(self, data, req, hero, timer):
        res = hero_pb2.RefineHeroRes()
        res.status = 0
        res.return_ret = res.Refine_NEED_ITEM

        (item_id, item_num) = hero.refine_item()
        item = item_business.get_item_by_id(data, item_id)
        pack.pack_item_info(item, res.items.add())

        return self._refine_succeed(data, req, res, timer)
Exemple #5
0
    def _pack_refine_succeed(self, data, req, hero, timer):
        res = hero_pb2.RefineHeroRes()
        res.status = 0
        res.return_ret = res.Refine_SUCCESS

        pack.pack_hero_info(hero, res.hero, timer.now)
        (item_id, item_num) = hero.refine_item()
        item = item_business.get_item_by_id(data, item_id)
        pack.pack_item_info(item, res.items.add())

        defer = DataBase().commit(data)
        defer.addCallback(self._refine_succeed, req, res, timer)
        return defer
Exemple #6
0
    def _calc_refine_upgrade(self, data, req, timer):
        res = hero_pb2.RefineHeroRes()
        res.status = 0

        hero = hero_business.get_hero_by_id(data, req.hero.basic_id)
        if hero is None:
            raise Exception(
                "Hero not non-existent[user_id=%d][req_basic_id=%d]" %
                (data.id, req.hero.basic_id))

        ret = hero_business.hero_refine_upgrade(data, hero, timer.now)
        if ret == res.Refine_CANNT_UPGRADE:
            return self._pack_refine_cannt_upgrade(data, req, hero, timer)

        return self._pack_refine_upgrade_succeed(data, req, hero, timer)
Exemple #7
0
    def _calc_refine(self, data, req, timer):
        res = hero_pb2.RefineHeroRes()
        res.status = 0

        hero = hero_business.get_hero_by_id(data, req.hero.basic_id)
        if hero is None:
            raise Exception(
                "Hero not non-existent[user_id=%d][req_basic_id=%d]" %
                (data.id, req.hero.basic_id))

        ret = hero_business.hero_refine(data, hero)
        if ret == res.Refine_NEED_ITEM:
            return self._pack_refine_need_item(data, req, hero, timer)

        return self._pack_refine_succeed(data, req, hero, timer)