Ejemplo n.º 1
0
    def get_dig_treasure_info(self):
        flag = 0
        _stream = yield redis.hget(DICT_DIG_TREASURE_INFO, self.cid)
        if _stream:
            try:
                _data = loads(_stream)
                if _data:
                    self.free_dig_count, self.dig_total_count, self.last_dig_time = _data
                    if not timestamp_is_today(self.last_dig_time):
                        self.free_dig_count = get_vip_conf(self.user.vip_level)["FreeDigCount"]
                        self.vipLevel = self.user.vip_level
                        self.last_dig_time = time()
                        _value = (self.free_dig_count, self.dig_total_count, self.last_dig_time)
                        yield redis.hset(DICT_DIG_TREASURE_INFO, self.cid, dumps(_value))
                    else:
                        if self.user.vip_level > self.vipLevel:
                            count = get_vip_conf(self.user.vip_level)["FreeDigCount"] - get_vip_conf(self.vipLevel)["FreeDigCount"]
                            self.free_dig_count += count
                            self.vipLevel = self.user.vip_level
                            _value = (self.free_dig_count, self.dig_total_count, self.last_dig_time)
                            yield redis.hset(DICT_DIG_TREASURE_INFO, self.cid, dumps(_value))

            except:
                log.exception()
        else:
            self.free_dig_count = get_vip_conf(self.user.vip_level)["FreeDigCount"]
            self.dig_total_count = 0
            self.last_dig_time = time()
            self.vipLevel = self.user.vip_level
            _value = (self.free_dig_count, self.dig_total_count, self.last_dig_time)
            yield redis.hset(DICT_DIG_TREASURE_INFO, self.cid, dumps(_value))
        if self.free_dig_count > 0:
            flag = 1
        defer.returnValue(flag)
Ejemplo n.º 2
0
    def buy_count(self):
        '''
        @summary: 购买挑战次数
               每购买1次额外挑战次数,需要花费10钻石
        '''
        if self.user.base_att.credits < 10:
            log.error('Credits not enough. need: 10, cur: {0}.'.format( self.user.base_att.credits ))
            defer.returnValue( CHAR_CREDIT_NOT_ENOUGH )
        # 还剩余有挑战次数
        if (self.elitescene.free_fight + self.elitescene.buyed_fight > 0):
            log.error('User has more than 1 fight count. free_fight: {0}, buyed_fight: {1}.'.format( self.elitescene.free_fight, self.elitescene.buyed_fight ))
            defer.returnValue( HAVE_NUM_TO_USE )
        # 判断VIP等级对应的可购买次数限制
        self.system_daily_reset()

        conf = get_vip_conf( self.user.vip_level )
        left_buy_fight = conf['EliteSceneCount'] if conf else 0
        left_buy_fight = left_buy_fight - self.elitescene.left_buy_fight if left_buy_fight > self.elitescene.left_buy_fight else 0
        if left_buy_fight < 1:
            log.error('No fight count could buy today.')
            defer.returnValue( BUY_MAX_NUM_ERROR )
        left_buy_fight -= 1
 
        yield self.user.consume_credits(10, WAY_ELITESCENE_FIGHT)
        self.elitescene.left_buy_fight += 1
        self.elitescene.buyed_fight += 1

        defer.returnValue( ((self.elitescene.free_fight + self.elitescene.buyed_fight), left_buy_fight, self.user.base_att.credits) )
Ejemplo n.º 3
0
    def new(self):
        now_weekday = datetime.now().isoweekday()

        conf = get_vip_conf(self.user.base_att.vip_level)
        left_buy = conf['ActiveSceneCount'] if conf else 0

        conf = get_activescene_conf(ACTIVE_PANDA_ID)
        panda_free = self.isOpenCycle(conf, now_weekday)

        conf = get_activescene_conf(ACTIVE_TREASURE_ID)
        treasure_free = self.isOpenCycle(conf, now_weekday)

        conf = get_activescene_conf(ACTIVE_TREE_ID)
        tree_free = self.isOpenCycle(conf, now_weekday)

        dt_now = datetime.now()
        init_data = [
            self.cid, panda_free, 0, left_buy, treasure_free, 0, left_buy,
            tree_free, 0, left_buy, dt_now
        ]
        kwargs = dict(zip(GSActiveSceneMgr._fields[1:], init_data))
        create_data = yield gs_create_table_data(self.cid,
                                                 GSActiveSceneMgr._table,
                                                 **kwargs)
        if create_data:
            create_data = dict(zip(GSActiveSceneMgr._fields, create_data))
            self.activescene.updateGSAttribute(False, **create_data)
        else:  # 新增数据失败
            self.load_flag = False

        defer.returnValue(NO_ERROR)
Ejemplo n.º 4
0
    def buy_count(self):
        '''
        @summary: 购买挑战次数
               每购买1次额外挑战次数,需要花费10钻石
        '''
        if self.user.base_att.credits < 10:
            log.error('Credits not enough. need: 10, cur: {0}.'.format(
                self.user.base_att.credits))
            defer.returnValue(CHAR_CREDIT_NOT_ENOUGH)
        # 还剩余有挑战次数
        if (self.elitescene.free_fight + self.elitescene.buyed_fight > 0):
            log.error(
                'User has more than 1 fight count. free_fight: {0}, buyed_fight: {1}.'
                .format(self.elitescene.free_fight,
                        self.elitescene.buyed_fight))
            defer.returnValue(HAVE_NUM_TO_USE)
        # 判断VIP等级对应的可购买次数限制
        self.system_daily_reset()

        conf = get_vip_conf(self.user.vip_level)
        left_buy_fight = conf['EliteSceneCount'] if conf else 0
        left_buy_fight = left_buy_fight - self.elitescene.left_buy_fight if left_buy_fight > self.elitescene.left_buy_fight else 0
        if left_buy_fight < 1:
            log.error('No fight count could buy today.')
            defer.returnValue(BUY_MAX_NUM_ERROR)
        left_buy_fight -= 1

        yield self.user.consume_credits(10, WAY_ELITESCENE_FIGHT)
        self.elitescene.left_buy_fight += 1
        self.elitescene.buyed_fight += 1

        defer.returnValue(
            ((self.elitescene.free_fight + self.elitescene.buyed_fight),
             left_buy_fight, self.user.base_att.credits))
Ejemplo n.º 5
0
    def new(self):
        now_weekday = datetime.now().isoweekday()

        conf = get_vip_conf( self.user.base_att.vip_level )
        left_buy = conf['ActiveSceneCount'] if conf else 0

        conf = get_activescene_conf( ACTIVE_PANDA_ID )
        panda_free = self.isOpenCycle( conf, now_weekday )

        conf = get_activescene_conf( ACTIVE_TREASURE_ID )
        treasure_free = self.isOpenCycle( conf, now_weekday )

        conf = get_activescene_conf( ACTIVE_TREE_ID )
        tree_free = self.isOpenCycle( conf, now_weekday )

        dt_now = datetime.now()
        init_data = [self.cid, panda_free, 0, left_buy, treasure_free, 0, left_buy, tree_free, 0, left_buy, dt_now]
        kwargs = dict(zip(GSActiveSceneMgr._fields[1:], init_data))
        create_data = yield gs_create_table_data(self.cid, GSActiveSceneMgr._table, **kwargs)
        if create_data:
            create_data = dict(zip(GSActiveSceneMgr._fields, create_data))
            self.activescene.updateGSAttribute( False,  **create_data)
        else: # 新增数据失败
            self.load_flag = False

        defer.returnValue( NO_ERROR )
Ejemplo n.º 6
0
    def reset_dungeon_count(self, scene_id, dungeon_id, reset_way):
        dungeon = yield self.get_dungeon(scene_id, dungeon_id)
        if not dungeon:
            log.error('Unknown dungeon id. scene_id: {0}, dungeon_id: {1}.'.format( scene_id, dungeon_id ))
            defer.returnValue( REQUEST_LIMIT_ERROR )

        # 判断是否还有剩余挑战次数
        #if 1 > dungeon.dungeon_today_count:
        #    defer.returnValue( REQUEST_LIMIT_ERROR )

        daily_info = yield self.get_scene_reset_daily()
        had_reset  = daily_info[2] + daily_info[3]
        # 检查当天最大可重置次数
        vip_conf = get_vip_conf( self.user.vip_level )
        if not vip_conf or (had_reset >= vip_conf['DungeonReset']):
            log.error('Dungeon reset count limit. cid:{0}, vip_level:{1}, max_count:{2}, item_reset:{3}, credit_reset:{4}.'.format( \
                    self.cid, self.user.vip_level, vip_conf['DungeonReset'] if vip_conf else 0, daily_info[2], daily_info[3]))
            defer.returnValue( CHAR_VIP_LEVEL_LIMIT )

        items_return = []
        # 检查reset_way
        if reset_way == SCENE_RESET_ITEM:
            daily_info[2] += 1
            # 扣道具 
            total_item, item_attribs = yield self.user.bag_item_mgr.get_items( ITEM_SCENE_RESET_ID )
            if 1 > total_item:
                defer.returnValue( CHAR_ITEM_NOT_ENOUGH )
            res_err, used_attribs = yield self.user.bag_item_mgr.use(ITEM_SCENE_RESET_ID, 1)
            if res_err:
                defer.returnValue( res_err )
            # used_attribs-已使用的道具
            for _a in used_attribs:
                items_return.append( [_a.attrib_id, ITEM_TYPE_ITEM, ITEM_SCENE_RESET_ID, _a.item_num] )
                # add syslog
                syslogger(LOG_ITEM_LOSE, self.cid, self.user.level, self.user.vip_level, \
                        self.user.alliance_id, _a.attrib_id, ITEM_SCENE_RESET_ID, 1, WAY_SCENE_RESET)
        elif reset_way == SCENE_RESET_CREDIT:
            daily_info[3] += 1
            # 扣钻石
            need_credits = get_scene_reset_conf(daily_info[3])
            if 0 == need_credits:
                defer.returnValue( SCENE_RESET_ERROR )
            if need_credits > self.user.credits:
                log.error('credits not enough. cid:{0}, need:{1}, curr:{2}, credit_reset:{3}.'.format( self.cid, need_credits, self.user.credits, daily_info[3] ))
                defer.returnValue( CHAR_CREDIT_NOT_ENOUGH )
            yield self.user.consume_credits( need_credits, WAY_SCENE_RESET )
        else:
            log.error('Unknown args. cid: {0}, reset_way: {1}.'.format( self.cid, reset_way ))
            defer.returnValue( REQUEST_LIMIT_ERROR )

        dungeon.dungeon_today_count = 0

        yield redis.hset(HASH_SCENE_RESET_DAILY, self.cid, dumps(daily_info))

        # 删除redis冷却时间记录
        yield redis.hdel( HASH_SCENE_COOLDOWN_TIME, self.cid )

        defer.returnValue( (self.user.credits, items_return) )
Ejemplo n.º 7
0
 def value(self):
     conf  = get_vip_conf( self.user.vip_level )
     total = conf['ActiveSceneCount'] if conf else 0
     panda_left    = total - self.activescene.panda_left_buy if total > self.activescene.panda_left_buy else 0
     treasure_left = total - self.activescene.treasure_left_buy if total > self.activescene.treasure_left_buy else 0
     tree_left     = total - self.activescene.tree_left_buy if total > self.activescene.tree_left_buy else 0
     return ((ACTIVE_PANDA_ID, self.activescene.panda_free+self.activescene.panda_buyed, panda_left), \
             (ACTIVE_TREASURE_ID, self.activescene.treasure_free+self.activescene.treasure_buyed, treasure_left), \
             (ACTIVE_TREE_ID, self.activescene.tree_free+self.activescene.tree_buyed, tree_left))
Ejemplo n.º 8
0
 def value(self):
     conf = get_vip_conf(self.user.vip_level)
     total = conf['ActiveSceneCount'] if conf else 0
     panda_left = total - self.activescene.panda_left_buy if total > self.activescene.panda_left_buy else 0
     treasure_left = total - self.activescene.treasure_left_buy if total > self.activescene.treasure_left_buy else 0
     tree_left = total - self.activescene.tree_left_buy if total > self.activescene.tree_left_buy else 0
     return ((ACTIVE_PANDA_ID, self.activescene.panda_free+self.activescene.panda_buyed, panda_left), \
             (ACTIVE_TREASURE_ID, self.activescene.treasure_free+self.activescene.treasure_buyed, treasure_left), \
             (ACTIVE_TREE_ID, self.activescene.tree_free+self.activescene.tree_buyed, tree_left))
Ejemplo n.º 9
0
    def get_dig_treasure_info(self):
        flag = 0
        _stream = yield redis.hget(DICT_DIG_TREASURE_INFO, self.cid)
        if _stream:
            try:
                _data = loads(_stream)
                if _data:
                    self.free_dig_count, self.dig_total_count, self.last_dig_time = _data
                    if not timestamp_is_today(self.last_dig_time):
                        self.free_dig_count = get_vip_conf(
                            self.user.vip_level)["FreeDigCount"]
                        self.vipLevel = self.user.vip_level
                        self.last_dig_time = time()
                        _value = (self.free_dig_count, self.dig_total_count,
                                  self.last_dig_time)
                        yield redis.hset(DICT_DIG_TREASURE_INFO, self.cid,
                                         dumps(_value))
                    else:
                        if self.user.vip_level > self.vipLevel:
                            count = get_vip_conf(
                                self.user.vip_level
                            )["FreeDigCount"] - get_vip_conf(
                                self.vipLevel)["FreeDigCount"]
                            self.free_dig_count += count
                            self.vipLevel = self.user.vip_level
                            _value = (self.free_dig_count,
                                      self.dig_total_count, self.last_dig_time)
                            yield redis.hset(DICT_DIG_TREASURE_INFO, self.cid,
                                             dumps(_value))

            except:
                log.exception()
        else:
            self.free_dig_count = get_vip_conf(
                self.user.vip_level)["FreeDigCount"]
            self.dig_total_count = 0
            self.last_dig_time = time()
            self.vipLevel = self.user.vip_level
            _value = (self.free_dig_count, self.dig_total_count,
                      self.last_dig_time)
            yield redis.hset(DICT_DIG_TREASURE_INFO, self.cid, dumps(_value))
        if self.free_dig_count > 0:
            flag = 1
        defer.returnValue(flag)
Ejemplo n.º 10
0
    def get_vip_conf_of_climbing(self):
        conf = get_vip_conf( self.user.vip_level )
        max_free_fight  = conf['TowerFightCount'] if conf else 0
        left_free_fight = max_free_fight - self.climbing.free_fight if max_free_fight > self.climbing.free_fight else 0
        max_free_reset  = conf['TowerResetCount'] if conf else 0
        left_free_reset = max_free_reset - self.climbing.free_reset if max_free_reset > self.climbing.free_reset else 0
        max_buy_reset   = conf['TowerBuyReset'] if conf else 0
        left_buy_reset  = max_buy_reset - self.climbing.left_buy_reset if max_buy_reset > self.climbing.left_buy_reset else 0

        return [left_free_fight, left_free_reset, left_buy_reset, max_free_fight, max_free_reset, max_buy_reset]
Ejemplo n.º 11
0
    def elitescene_data(self):
        '''
        @summary: 获取精英副本的基本信息
        '''
        yield self.load()
        self.system_daily_reset()
        conf = get_vip_conf( self.user.vip_level )
        left_buy_fight = conf['EliteSceneCount'] if conf else 0
        left_buy_fight = left_buy_fight - self.elitescene.left_buy_fight if left_buy_fight > self.elitescene.left_buy_fight else 0

        defer.returnValue( (self.elitescene.free_fight + self.elitescene.buyed_fight, left_buy_fight, self.passed_elitescene_ids) )
Ejemplo n.º 12
0
 def __init__(self, user):
     ''' 精彩活动 '''
     self.user = user
     self.cid  = user.cid
     self.mystical_shop_mgr    = GSMysticalShopMgr( user )
     self.exchange_limited_mgr = GSExchangeLimitedMgr( self, user )
     self.limit_fellow_mgr     = GSLimitFellowMgr( user )
     self.free_dig_count = get_vip_conf(self.user.vip_level)["FreeDigCount"]
     self.dig_total_count = 0
     self.last_dig_time = time()
     self.vipLevel = 0
Ejemplo n.º 13
0
 def __init__(self, user):
     ''' 精彩活动 '''
     self.user = user
     self.cid = user.cid
     self.mystical_shop_mgr = GSMysticalShopMgr(user)
     self.exchange_limited_mgr = GSExchangeLimitedMgr(self, user)
     self.limit_fellow_mgr = GSLimitFellowMgr(user)
     self.free_dig_count = get_vip_conf(self.user.vip_level)["FreeDigCount"]
     self.dig_total_count = 0
     self.last_dig_time = time()
     self.vipLevel = 0
Ejemplo n.º 14
0
    def get_vip_conf_of_climbing(self):
        conf = get_vip_conf(self.user.vip_level)
        max_free_fight = conf['TowerFightCount'] if conf else 0
        left_free_fight = max_free_fight - self.climbing.free_fight if max_free_fight > self.climbing.free_fight else 0
        max_free_reset = conf['TowerResetCount'] if conf else 0
        left_free_reset = max_free_reset - self.climbing.free_reset if max_free_reset > self.climbing.free_reset else 0
        max_buy_reset = conf['TowerBuyReset'] if conf else 0
        left_buy_reset = max_buy_reset - self.climbing.left_buy_reset if max_buy_reset > self.climbing.left_buy_reset else 0

        return [
            left_free_fight, left_free_reset, left_buy_reset, max_free_fight,
            max_free_reset, max_buy_reset
        ]
Ejemplo n.º 15
0
    def elitescene_data(self):
        '''
        @summary: 获取精英副本的基本信息
        '''
        yield self.load()
        self.system_daily_reset()
        conf = get_vip_conf(self.user.vip_level)
        left_buy_fight = conf['EliteSceneCount'] if conf else 0
        left_buy_fight = left_buy_fight - self.elitescene.left_buy_fight if left_buy_fight > self.elitescene.left_buy_fight else 0

        defer.returnValue(
            (self.elitescene.free_fight + self.elitescene.buyed_fight,
             left_buy_fight, self.passed_elitescene_ids))
Ejemplo n.º 16
0
    def buy_battle_count(self, user, buy_count):
        '''
        @param: buy_count-购买的次数
        '''
        _is_open = self.check_time_status()
        if _is_open:
            defer.returnValue(_is_open)

        _joust_data = yield redis.hget(HASH_JOUST_INFO, user.cid)
        if _joust_data:
            _joust_data = loads(_joust_data)
            if not timestamp_is_today(_joust_data[0]):
                _joust_data[2] = 0
        else:
            _joust_data = [int(time()), 0, 0, [], 0]
        # 剩余免费挑战次数大于0, 不能购买, 策划要求
        if JOUST_FREE_COUNT > _joust_data[1]:
            defer.returnValue(JOUST_FREE_COUNT_ERROR)

        _vip_conf = get_vip_conf(user.vip_level)
        if not _vip_conf:
            log.error('No vip conf. cid: {0}, vip_level: {1}.'.format(
                user.cid, user.vip_level))
            defer.returnValue(JOUST_BUY_COUNT_LIMIT_ERROR)
        # 剩余可购买次数
        _left_buy_count = _vip_conf['JoustCount'] - _joust_data[4]
        if _left_buy_count < buy_count:
            log.error('Buy count limit. cid: {0}, can buy: {1}, had buy: {2}.'.
                      format(user.cid, _vip_conf['JoustCount'],
                             _left_buy_count))
            defer.returnValue(JOUST_BUY_COUNT_LIMIT_ERROR)
        #_left_buy_count -= buy_count
        # 所需钻石
        _need_credits = get_joust_buy_count_conf(
            _joust_data[4] + 1, _joust_data[4] + buy_count + 1)
        if user.credits < _need_credits:
            defer.returnValue(CHAR_CREDIT_NOT_ENOUGH)

        # 扣钻石
        user.consume_credits(_need_credits, WAY_JOUST_BATTLE_COUNT)
        # 增加次数
        _joust_data[2] += buy_count
        _joust_data[4] += buy_count
        yield redis.hset(HASH_JOUST_INFO, user.cid, dumps(_joust_data))

        _left_count = JOUST_FREE_COUNT + _joust_data[2] - _joust_data[1]
        defer.returnValue((_left_count, _joust_data[4], user.credits))
Ejemplo n.º 17
0
    def mystical_status(self):
        _conf = get_vip_conf(self.user.base_att.vip_level)
        _max_count = _conf['FreeMaxCount'] if _conf else 2

        _data = yield redis.hget(HASH_MYSTICAL_SHOP, self.cid)
        if _data:
            _last_time, _free_count, _, _ = loads(_data)

            _, _add_count = get_next_refresh_hour(_last_time)
            if _add_count > 0 and _free_count < _max_count:
                _free_count = _max_count if (
                    _free_count + _add_count) >= _max_count else (_free_count +
                                                                  _add_count)
        else:
            _free_count = _max_count

        defer.returnValue([_free_count, _max_count])
Ejemplo n.º 18
0
    def buy_count(self, battle_type):
        '''
        @summary: 购买挑战次数,价格=基础价格*购买次数
        '''
        vip_conf = get_vip_conf(self.user.base_att.vip_level)
        if not vip_conf:
            log.error('No vip conf. vip_level: {0}.'.format(
                self.user.base_att.vip_level))
            defer.returnValue(NOT_FOUND_CONF)
        yield self.system_daily_reset()
        if battle_type == FIGHT_TYPE_PANDA:
            # 还有剩余挑战次数
            if (self.activescene.panda_free + self.activescene.panda_buyed >
                    0):
                log.error(
                    'User has fight count. panda_free: {0}, panda_buyed: {1}.'.
                    format(self.activescene.panda_free,
                           self.activescene.panda_buyed))
                defer.returnValue(HAVE_NUM_TO_USE)
            # 已购买次数达上限
            if self.activescene.panda_left_buy >= vip_conf['ActiveSceneCount']:
                log.error(
                    'No panda fight count could buy today. cid:{0}, vip_level:{1}.'
                    .format(self.cid, self.user.vip_level))
                defer.returnValue(BUY_MAX_NUM_ERROR)
            # 钻石不足
            conf = get_activescene_conf(ACTIVE_PANDA_ID)
            if not conf:
                log.error('Can not find conf. activescene_id: {0}.'.format(
                    ACTIVE_PANDA_ID))
                defer.returnValue(NOT_FOUND_CONF)
            need_credits = (self.activescene.panda_left_buy +
                            1) * conf['Price']
            if self.user.base_att.credits < need_credits:
                log.error('Credits not enough. need: {0}, cur: {1}.'.format(
                    need_credits, self.user.base_att.credits))
                defer.returnValue(CHAR_CREDIT_NOT_ENOUGH)
            yield self.user.consume_credits(need_credits,
                                            WAY_ACTIVESCENE_PANDA_FIGHT)
            self.activescene.panda_left_buy += 1
            self.activescene.panda_buyed += 1

            defer.returnValue(
                ((self.activescene.panda_free + self.activescene.panda_buyed),
                 self.activescene.panda_left_buy, self.user.base_att.credits))
        elif battle_type == FIGHT_TYPE_TREASURE:
            # 还剩余有挑战次数
            if (self.activescene.treasure_free +
                    self.activescene.treasure_buyed > 0):
                log.error(
                    'User has fight count. treasure_free: {0}, treasure_buyed: {1}.'
                    .format(self.activescene.treasure_free,
                            self.activescene.treasure_buyed))
                defer.returnValue(HAVE_NUM_TO_USE)
            # 剩余购买次数不足
            if self.activescene.treasure_left_buy >= vip_conf[
                    'ActiveSceneCount']:
                log.error(
                    'No treasure fight count could buy today. cid:{0}, vip_level:{1}.'
                    .format(self.cid, self.user.vip_level))
                defer.returnValue(BUY_MAX_NUM_ERROR)
            # 钻石不足
            conf = get_activescene_conf(ACTIVE_TREASURE_ID)
            if not conf:
                log.error(
                    'No conf. activescene_id: {0}.'.format(ACTIVE_TREASURE_ID))
                defer.returnValue(NOT_FOUND_CONF)
            need_credits = (self.activescene.treasure_left_buy +
                            1) * conf['Price']
            if self.user.base_att.credits < need_credits:
                log.error('Credits not enough. need: {0}, cur: {1}.'.format(
                    need_credits, self.user.base_att.credits))
                defer.returnValue(CHAR_CREDIT_NOT_ENOUGH)
            yield self.user.consume_credits(need_credits,
                                            WAY_ACTIVESCENE_TREASURE_FIGHT)
            self.activescene.treasure_left_buy += 1
            self.activescene.treasure_buyed += 1

            defer.returnValue(((self.activescene.treasure_free +
                                self.activescene.treasure_buyed),
                               self.activescene.treasure_left_buy,
                               self.user.base_att.credits))
        elif battle_type == FIGHT_TYPE_TREE:
            # 还剩余有挑战次数
            if (self.activescene.tree_free + self.activescene.tree_buyed > 0):
                log.error(
                    'User has fight count. tree_free: {0}, tree_buyed: {1}.'.
                    format(self.activescene.tree_free,
                           self.activescene.tree_buyed))
                defer.returnValue(HAVE_NUM_TO_USE)
            # 剩余购买次数不足
            if self.activescene.tree_left_buy >= vip_conf['ActiveSceneCount']:
                log.error(
                    'No tree fight count could buy today. cid:{0}, vip_level:{1}.'
                    .format(self.cid, self.user.vip_level))
                defer.returnValue(BUY_MAX_NUM_ERROR)
            # 钻石不足
            conf = get_activescene_conf(ACTIVE_TREE_ID)
            if not conf:
                log.error(
                    'No conf. activescene_id: {0}.'.format(ACTIVE_TREE_ID))
                defer.returnValue(NOT_FOUND_CONF)
            need_credits = (self.activescene.tree_left_buy + 1) * conf['Price']
            if self.user.base_att.credits < need_credits:
                log.error('Credits not enough. need: {0}, cur: {1}.'.format(
                    need_credits, self.user.base_att.credits))
                defer.returnValue(CHAR_CREDIT_NOT_ENOUGH)
            yield self.user.consume_credits(need_credits,
                                            WAY_ACTIVESCENE_TREE_FIGHT)
            self.activescene.tree_left_buy += 1
            self.activescene.tree_buyed += 1

            defer.returnValue(
                ((self.activescene.tree_free + self.activescene.tree_buyed),
                 self.activescene.tree_left_buy, self.user.base_att.credits))
        else:
            log.error('Unknown battle_type: {0}.'.format(battle_type))
            defer.returnValue(REQUEST_LIMIT_ERROR)
Ejemplo n.º 19
0
    def buy_count(self, battle_type):
        '''
        @summary: 购买挑战次数,价格=基础价格*购买次数
        '''
        vip_conf = get_vip_conf( self.user.base_att.vip_level )
        if not vip_conf:
            log.error('No vip conf. vip_level: {0}.'.format( self.user.base_att.vip_level ))
            defer.returnValue( NOT_FOUND_CONF )
        yield self.system_daily_reset()
        if battle_type == FIGHT_TYPE_PANDA:
            # 还有剩余挑战次数
            if (self.activescene.panda_free+self.activescene.panda_buyed > 0):
                log.error('User has fight count. panda_free: {0}, panda_buyed: {1}.'.format( self.activescene.panda_free, self.activescene.panda_buyed ))
                defer.returnValue( HAVE_NUM_TO_USE )
            # 已购买次数达上限
            if self.activescene.panda_left_buy >= vip_conf['ActiveSceneCount']:
                log.error('No panda fight count could buy today. cid:{0}, vip_level:{1}.'.format( self.cid, self.user.vip_level ))
                defer.returnValue( BUY_MAX_NUM_ERROR )
            # 钻石不足
            conf = get_activescene_conf( ACTIVE_PANDA_ID )
            if not conf:
                log.error('Can not find conf. activescene_id: {0}.'.format( ACTIVE_PANDA_ID ))
                defer.returnValue( NOT_FOUND_CONF )
            need_credits = (self.activescene.panda_left_buy + 1) * conf['Price']
            if self.user.base_att.credits < need_credits:
                log.error('Credits not enough. need: {0}, cur: {1}.'.format( need_credits, self.user.base_att.credits ))
                defer.returnValue( CHAR_CREDIT_NOT_ENOUGH )
            yield self.user.consume_credits(need_credits, WAY_ACTIVESCENE_PANDA_FIGHT)
            self.activescene.panda_left_buy += 1
            self.activescene.panda_buyed    += 1

            defer.returnValue( ((self.activescene.panda_free + self.activescene.panda_buyed), self.activescene.panda_left_buy, self.user.base_att.credits) )
        elif battle_type == FIGHT_TYPE_TREASURE:
            # 还剩余有挑战次数
            if (self.activescene.treasure_free+self.activescene.treasure_buyed > 0):
                log.error('User has fight count. treasure_free: {0}, treasure_buyed: {1}.'.format( self.activescene.treasure_free, self.activescene.treasure_buyed ))
                defer.returnValue( HAVE_NUM_TO_USE )
            # 剩余购买次数不足
            if self.activescene.treasure_left_buy >= vip_conf['ActiveSceneCount']:
                log.error('No treasure fight count could buy today. cid:{0}, vip_level:{1}.'.format( self.cid, self.user.vip_level ))
                defer.returnValue( BUY_MAX_NUM_ERROR )
            # 钻石不足
            conf = get_activescene_conf( ACTIVE_TREASURE_ID )
            if not conf:
                log.error('No conf. activescene_id: {0}.'.format( ACTIVE_TREASURE_ID ))
                defer.returnValue( NOT_FOUND_CONF )
            need_credits = (self.activescene.treasure_left_buy + 1) * conf['Price']
            if self.user.base_att.credits < need_credits:
                log.error('Credits not enough. need: {0}, cur: {1}.'.format( need_credits, self.user.base_att.credits ))
                defer.returnValue( CHAR_CREDIT_NOT_ENOUGH )
            yield self.user.consume_credits(need_credits, WAY_ACTIVESCENE_TREASURE_FIGHT)
            self.activescene.treasure_left_buy += 1
            self.activescene.treasure_buyed    += 1

            defer.returnValue( ((self.activescene.treasure_free + self.activescene.treasure_buyed), self.activescene.treasure_left_buy, self.user.base_att.credits) )
        elif battle_type == FIGHT_TYPE_TREE:
            # 还剩余有挑战次数
            if (self.activescene.tree_free+self.activescene.tree_buyed > 0):
                log.error('User has fight count. tree_free: {0}, tree_buyed: {1}.'.format( self.activescene.tree_free, self.activescene.tree_buyed ))
                defer.returnValue( HAVE_NUM_TO_USE )
            # 剩余购买次数不足
            if self.activescene.tree_left_buy >= vip_conf['ActiveSceneCount']:
                log.error('No tree fight count could buy today. cid:{0}, vip_level:{1}.'.format( self.cid, self.user.vip_level ))
                defer.returnValue( BUY_MAX_NUM_ERROR )
            # 钻石不足
            conf = get_activescene_conf( ACTIVE_TREE_ID )
            if not conf:
                log.error('No conf. activescene_id: {0}.'.format( ACTIVE_TREE_ID ))
                defer.returnValue( NOT_FOUND_CONF )
            need_credits = (self.activescene.tree_left_buy + 1) * conf['Price']
            if self.user.base_att.credits < need_credits:
                log.error('Credits not enough. need: {0}, cur: {1}.'.format( need_credits, self.user.base_att.credits ))
                defer.returnValue( CHAR_CREDIT_NOT_ENOUGH )
            yield self.user.consume_credits(need_credits, WAY_ACTIVESCENE_TREE_FIGHT)
            self.activescene.tree_left_buy += 1
            self.activescene.tree_buyed    += 1

            defer.returnValue( ((self.activescene.tree_free + self.activescene.tree_buyed), self.activescene.tree_left_buy, self.user.base_att.credits) )
        else:
            log.error('Unknown battle_type: {0}.'.format( battle_type ))
            defer.returnValue( REQUEST_LIMIT_ERROR )
Ejemplo n.º 20
0
    def reset_dungeon_count(self, scene_id, dungeon_id, reset_way):
        dungeon = yield self.get_dungeon(scene_id, dungeon_id)
        if not dungeon:
            log.error(
                'Unknown dungeon id. scene_id: {0}, dungeon_id: {1}.'.format(
                    scene_id, dungeon_id))
            defer.returnValue(REQUEST_LIMIT_ERROR)

        # 判断是否还有剩余挑战次数
        #if 1 > dungeon.dungeon_today_count:
        #    defer.returnValue( REQUEST_LIMIT_ERROR )

        daily_info = yield self.get_scene_reset_daily()
        had_reset = daily_info[2] + daily_info[3]
        # 检查当天最大可重置次数
        vip_conf = get_vip_conf(self.user.vip_level)
        if not vip_conf or (had_reset >= vip_conf['DungeonReset']):
            log.error('Dungeon reset count limit. cid:{0}, vip_level:{1}, max_count:{2}, item_reset:{3}, credit_reset:{4}.'.format( \
                    self.cid, self.user.vip_level, vip_conf['DungeonReset'] if vip_conf else 0, daily_info[2], daily_info[3]))
            defer.returnValue(CHAR_VIP_LEVEL_LIMIT)

        items_return = []
        # 检查reset_way
        if reset_way == SCENE_RESET_ITEM:
            daily_info[2] += 1
            # 扣道具
            total_item, item_attribs = yield self.user.bag_item_mgr.get_items(
                ITEM_SCENE_RESET_ID)
            if 1 > total_item:
                defer.returnValue(CHAR_ITEM_NOT_ENOUGH)
            res_err, used_attribs = yield self.user.bag_item_mgr.use(
                ITEM_SCENE_RESET_ID, 1)
            if res_err:
                defer.returnValue(res_err)
            # used_attribs-已使用的道具
            for _a in used_attribs:
                items_return.append([
                    _a.attrib_id, ITEM_TYPE_ITEM, ITEM_SCENE_RESET_ID,
                    _a.item_num
                ])
                # add syslog
                syslogger(LOG_ITEM_LOSE, self.cid, self.user.level, self.user.vip_level, \
                        self.user.alliance_id, _a.attrib_id, ITEM_SCENE_RESET_ID, 1, WAY_SCENE_RESET)
        elif reset_way == SCENE_RESET_CREDIT:
            daily_info[3] += 1
            # 扣钻石
            need_credits = get_scene_reset_conf(daily_info[3])
            if 0 == need_credits:
                defer.returnValue(SCENE_RESET_ERROR)
            if need_credits > self.user.credits:
                log.error(
                    'credits not enough. cid:{0}, need:{1}, curr:{2}, credit_reset:{3}.'
                    .format(self.cid, need_credits, self.user.credits,
                            daily_info[3]))
                defer.returnValue(CHAR_CREDIT_NOT_ENOUGH)
            yield self.user.consume_credits(need_credits, WAY_SCENE_RESET)
        else:
            log.error('Unknown args. cid: {0}, reset_way: {1}.'.format(
                self.cid, reset_way))
            defer.returnValue(REQUEST_LIMIT_ERROR)

        dungeon.dungeon_today_count = 0

        yield redis.hset(HASH_SCENE_RESET_DAILY, self.cid, dumps(daily_info))

        # 删除redis冷却时间记录
        yield redis.hdel(HASH_SCENE_COOLDOWN_TIME, self.cid)

        defer.returnValue((self.user.credits, items_return))
Ejemplo n.º 21
0
    def scene_all_sweep(self, scene_id, sweep_way=SCENE_SWEEP_CREDIT):
        ''' 对该副本的所有怪物组全扫荡, 掉落放入领奖中心
        '''
        # 检查玩家的VIP等级限制
        vip_conf = get_vip_conf(self.user.base_att.vip_level)
        if not vip_conf or not vip_conf['SceneALLSweep']:
            log.error('Not found vip conf. cid:{0}, vip_level:{1}.'.format(
                self.cid, self.user.vip_level))
            defer.returnValue(CHAR_VIP_LEVEL_LIMIT)

        scene_conf = get_scene_conf(scene_id)
        if not scene_conf:
            defer.returnValue(NOT_FOUND_CONF)
        # 判断是否是满星副本
        had_star, left_dungeon_ids = 0, []
        scene = yield self.get_scene(scene_id)
        if not scene:
            defer.returnValue(NOT_FOUND_CONF)

        for dungeon_id, dungeon in scene.iteritems():
            had_star += dungeon.dungeon_star
            for dungeon_conf in scene_conf['dungeons']:
                if dungeon_conf['DungeonID'] != dungeon_id:
                    continue
                #if dungeon_conf['RushMax'] > dungeon.dungeon_today_count and dungeon_id not in left_dungeon_ids:
                if dungeon_conf['RushMax'] > dungeon.dungeon_today_count:
                    left_dungeon_ids.append(
                        (dungeon_id, dungeon_conf['RushMax'] -
                         dungeon.dungeon_today_count))
        # 不是满星副本
        if had_star < scene_conf['StarNum']:
            defer.returnValue(SCENE_STAR_NOT_ENOUGH)
        # 判断是否还有挑战次数
        if not left_dungeon_ids:
            defer.returnValue(SCENE_CHALLENGE_COUNT_LIMIT)
        # 判断钻石数, 4-全部扫荡花费
        daily_info = yield self.get_scene_reset_daily()
        #all_sweep_cost = get_game_limit_value(4)
        #all_sweep_cost = int(all_sweep_cost) if all_sweep_cost else SCENE_ALL_SWEEP_COST
        items_return = []
        # 判断道具和钻石
        if sweep_way == SCENE_SWEEP_ITEM:
            # 扣道具
            total_item, item_attribs = yield self.user.bag_item_mgr.get_items(
                ITEM_SCENE_SWEEP_ID)
            if 1 > total_item:
                defer.returnValue(CHAR_ITEM_NOT_ENOUGH)
            res_err, used_attribs = yield self.user.bag_item_mgr.use(
                ITEM_SCENE_SWEEP_ID, 1)
            if res_err:
                defer.returnValue(res_err)
            # used_attribs-已使用的道具
            for _a in used_attribs:
                items_return.append([
                    _a.attrib_id, ITEM_TYPE_ITEM, ITEM_SCENE_SWEEP_ID,
                    _a.item_num
                ])
                # add syslog
                syslogger(LOG_ITEM_LOSE, self.cid, self.user.level, self.user.vip_level, \
                        self.user.alliance_id, _a.attrib_id, ITEM_SCENE_SWEEP_ID, 1, WAY_SCENE_ALL_SWEEP)
        else:
            all_sweep_cost = get_scene_sweep_cost_conf(daily_info[1] + 1)
            if self.user.credits < all_sweep_cost:
                defer.returnValue(CHAR_CREDIT_NOT_ENOUGH)
            # 扣钻石
            self.user.consume_credits(all_sweep_cost, WAY_SCENE_ALL_SWEEP)
            # 副本 钻石扫荡次数累积
            daily_info[1] += 1
            yield redis.hset(HASH_SCENE_RESET_DAILY, self.cid,
                             dumps(daily_info))

        # 副本全扫荡 dungeon battle奖励金币、仙魂、经验
        battle_count = 0  # 扫荡副本的次数
        drop_items = []  # [[type, id, num], ...]
        dungeon_info = []  # 副本的怪物组挑战次数信息
        exp_reward, soul_reward, golds_reward = 0, 0, 0
        for d_id, d_count in left_dungeon_ids:
            dungeon = yield self.get_dungeon(scene_id, d_id)
            if not dungeon:
                log.error(
                    'Unknown dungeon id. cid: {0}, scene_id: {1}, dungeon_id: {2}.'
                    .format(self.cid, scene_id, d_id))
                continue
            dungeon.dungeon_today_count += d_count
            dungeon.dungeon_last_time = datetime.now()
            dungeon_info.append((d_id, dungeon.dungeon_today_count))
            # 怪物组conf
            monster_conf = get_monster_conf(d_id, scene_conf['SceneDiff'])
            if not monster_conf:
                log.error(
                    'Can not find monster conf. cid: {0}, dungeon_id: {1}.'.
                    format(self.cid, d_id))
                continue
            # 累计副本战斗次数
            battle_count += d_count
            for _c in range(0, d_count):
                tmp_golds, tmp_soul, tmp_exp, no_energy = 0, 0, 0, False
                if self.user.base_att.energy >= 5:
                    self.user.base_att.energy -= 5
                    tmp_exp = self.user.base_att.level * BATTLE_MONSTER_EXP_RATIO
                else:
                    no_energy = True
                    tmp_exp = self.user.base_att.level
                tmp_soul = monster_conf['Soul']
                tmp_golds = monster_conf['Money']

                # 获取怪物组掉落
                tmp_drop = yield self.dungeon_star_drop(
                    d_id, scene_conf['SceneDiff'], no_energy)
                for _t in tmp_drop:
                    drop_items = add_new_items(_t, drop_items)
                # 发放奖励, 判断是否升级
                yield self.user.update_battle_attr(
                    tmp_soul, tmp_golds, tmp_exp, way_type=WAY_SCENE_ALL_SWEEP)
                exp_reward += tmp_exp
                soul_reward += tmp_soul
                golds_reward += tmp_golds
        # 掉落发放到领奖中心
        if drop_items:
            timestamp = int(time())
            yield g_AwardCenterMgr.new_award(self.cid, AWARD_TYPE_SCENE_SWEEP,
                                             [timestamp, scene_id, drop_items])

        # 每日任务计数
        yield self.user.daily_quest_mgr.update_daily_quest(
            DAILY_QUEST_ID_3, battle_count)
        # add syslog

        defer.returnValue(
            (dungeon_info, (golds_reward, soul_reward,
                            exp_reward), self.user.base_att.credits,
             self.user.base_att.energy, items_return))
Ejemplo n.º 22
0
    def win_streak(self, scene_id, dungeon_id, dungeon_star, battle_count):
        '''
        @summary: 连续战斗
        '''
        # 检查功能开放中连战的限制

        # 检查剩余可连续战斗次数
        vip_conf = get_vip_conf(self.user.base_att.vip_level)
        if not vip_conf:
            log.error('Unknown vip conf. cid:{0}, vip_level: {1}.'.format(
                self.cid, self.user.vip_level))
            defer.returnValue(CHAR_VIP_LEVEL_LIMIT)
        cur_time = int(time())
        old_data = yield redis.hget(HASH_SCENE_COOLDOWN_TIME, self.cid)
        end_cooldown_time = int(old_data or 0)
        if end_cooldown_time > cur_time:
            log.error(
                'In CoolDown time. end time: {0}.'.format(end_cooldown_time))
            defer.returnValue(IN_COOLDOWN_ERROR)
        end_cooldown_time = cur_time + vip_conf['DungeonTime']
        if battle_count > vip_conf['ContinuousBattles']:
            log.error('count limit. req_count: {0}, max_count: {1}.'.format(
                battle_count, vip_conf['ContinuousBattles']))
            defer.returnValue(DUNGEON_CHALLENGE_COUNT_LIMIT)

        dungeon = yield self.get_dungeon(scene_id, dungeon_id)
        if not dungeon:
            log.error('Unknown dungeon id.')
            defer.returnValue(UNKNOWN_ERROR)
        # 当前怪物组的数据
        dungeon_conf = get_scene_dungeon(scene_id, dungeon_id)
        if not dungeon_conf:
            log.error('Unknown dungeon conf.')
            defer.returnValue(NOT_FOUND_CONF)
        # 每天挑战次数限制
        if (dungeon.dungeon_today_count +
                battle_count) > dungeon_conf['RushMax']:
            log.error(
                'count limit. req_count: {0}, today count: {1}, rush max: {2}.'
                .format(battle_count, dungeon.dungeon_today_count,
                        dungeon_conf['RushMax']))
            defer.returnValue(DUNGEON_CHALLENGE_COUNT_LIMIT)
        # 怪物组conf
        monster_conf = get_monster_conf(dungeon_id, dungeon_star)
        if not monster_conf:
            log.error('Can not find monster.')
            defer.returnValue(NOT_FOUND_CONF)

        # 保存end cooldown time
        yield redis.hset(HASH_SCENE_COOLDOWN_TIME, self.cid, end_cooldown_time)
        # 连续n次战斗dungeon battle奖励金币、仙魂、经验
        exp_reward, soul_reward, golds_reward = 0, 0, 0
        dungeon.dungeon_today_count += battle_count
        dungeon.dungeon_last_time = datetime.now()
        dungeon_drop_items = []
        drop_items = []  # [[uid, type, id, num], ...]
        for _c in range(0, battle_count):
            tmp_golds, tmp_soul, tmp_exp, no_energy = 0, 0, 0, False
            if self.user.base_att.energy >= 5:
                self.user.base_att.energy -= 5
                tmp_exp = self.user.base_att.level * BATTLE_MONSTER_EXP_RATIO
            else:
                no_energy = True
                tmp_exp = self.user.base_att.level
            tmp_soul = monster_conf['Soul']
            tmp_golds = monster_conf['Money']

            # 获取怪物组掉落
            tmp_drop = yield self.dungeon_star_drop(dungeon_id, dungeon_star,
                                                    no_energy)
            dungeon_drop_items.append([tmp_drop, tmp_golds, tmp_soul, tmp_exp])
            for _t in tmp_drop:
                drop_items = add_new_items(_t, drop_items)
            # 发放奖励
            yield self.user.update_battle_attr(tmp_soul, tmp_golds, tmp_exp)
            exp_reward += tmp_exp
            soul_reward += tmp_soul
            golds_reward += tmp_golds
        # 玩家背包新增掉落
        way_others = str((FIGHT_TYPE_NORMAL, dungeon_id, dungeon_star))
        add_items = yield self.get_dungeon_drop(drop_items, way_others)

        # 每日任务计数
        yield self.user.daily_quest_mgr.update_daily_quest(
            DAILY_QUEST_ID_3, battle_count)
        # add syslog
        str_drop_items = str(add_items).replace('[', '(')
        str_drop_items = str_drop_items.replace(']', ')')
        syslogger(LOG_SCENE_BATTLE, self.cid, self.user.level,
                  self.user.vip_level, self.user.alliance_id,
                  FIGHT_TYPE_NORMAL, 1, dungeon_id, dungeon_star, exp_reward,
                  soul_reward, golds_reward, str_drop_items)

        defer.returnValue(
            (dungeon_id, dungeon.dungeon_star, dungeon.dungeon_today_count,
             dungeon_drop_items, add_items, self.user.base_att.energy,
             end_cooldown_time))
Ejemplo n.º 23
0
    def mystical_info(self, refresh_type):
        '''
        @summary: 获取神秘商店的刷新时间、道具等信息
        @param  : 0:获取列表,无任何消耗; 1:使用免费次数; 2:使用刷新令道具; 3:使用20钻石
        '''
        _info = []
        _data = yield redis.hget(HASH_MYSTICAL_SHOP, self.cid)
        _conf = get_vip_conf(self.user.base_att.vip_level)
        _max_count = _conf['FreeMaxCount'] if _conf else 2

        if _data:
            _info = loads(_data)
            _info[2] = _max_count
        else:
            _items = yield self.random_items(self.user.base_att.level,
                                             self.user.base_att.vip_level)
            _info = [int(time()), _max_count, _max_count, _items]
            #yield redis.hset( HASH_MYSTICAL_SHOP, self.cid, dumps(_info) )
        # 计算玩家可获得的免费刷新神秘商店的次数
        _next, _add_count = get_next_refresh_hour(_info[0])
        #log.info('For Test. _next: {0}, _add_count: {1}, _info: {2}.'.format( _next, _add_count, _info ))
        if _add_count > 0 and _info[1] < _info[2]:
            _info[1] = _info[2] if (_info[1] + _add_count) >= _info[2] else (
                _info[1] + _add_count)
            _info[0] = int(time())
        # 玩家当前拥有刷新令的个数
        _refresh_count, item_attribs = yield self.user.bag_item_mgr.get_items(
            ITEM_REFRESH_SHOP)
        items_return = []
        # 刷新方式的不同处理
        _freshed = False  # 是否有过刷新的标志位
        if refresh_type == MYSTICAL_REFRESH_FREE:
            if _info[1] <= 0:
                defer.returnValue(REFRESH_MYSTICAL_SHOP_LIMIT)
            else:
                _info[1] -= 1
                _items = yield self.random_items(self.user.base_att.level,
                                                 self.user.base_att.vip_level)
                if _items:
                    _info[3] = _items
                _info[0] = int(time())
                _freshed = True
        elif refresh_type == MYSTICAL_REFRESH_ITEM:
            if _refresh_count <= 0:
                defer.returnValue(CHAR_ITEM_NOT_ENOUGH)
            else:
                _refresh_count -= 1
                res_err, used_attribs = yield self.user.bag_item_mgr.use(
                    ITEM_REFRESH_SHOP, 1)
                if res_err:
                    log.error('Use item error.')
                    defer.returnValue(res_err)
                # used_attribs-已使用的道具
                for _a in used_attribs:
                    items_return.append(
                        [_a.attrib_id, _a.item_type, _a.item_id, _a.item_num])
                _items = yield self.random_items(self.user.base_att.level,
                                                 self.user.base_att.vip_level)
                if _items:
                    _info[3] = _items
                _info[0] = int(time())
                _freshed = True
        elif refresh_type == MYSTICAL_REFRESH_CREDITS:
            if self.user.base_att.credits < MYSTICAL_REFRESH_COST:
                defer.returnValue(CHAR_CREDIT_NOT_ENOUGH)
            else:
                #self.user.base_att.credits -= MYSTICAL_REFRESH_COST
                yield self.user.consume_credits(MYSTICAL_REFRESH_COST,
                                                WAY_MYSTICAL_SHOP)
                _items = yield self.random_items(self.user.base_att.level,
                                                 self.user.base_att.vip_level)
                if _items:
                    _info[3] = _items
                _info[0] = int(time())
                _freshed = True

        yield redis.hset(HASH_MYSTICAL_SHOP, self.cid, dumps(_info))
        # 每日任务计数
        if _freshed:
            yield self.user.daily_quest_mgr.update_daily_quest(
                DAILY_QUEST_ID_1, 1)
            # 开服七天
            yield self.user.open_server_mgr.update_open_server_activity_quest(
                OPEN_SERVER_QUEST_ID_13, 1)
            yield self.user.achievement_mgr.update_achievement_status(
                ACHIEVEMENT_QUEST_ID_13, 1)
        _info[0] = _next
        _info.append(_refresh_count)
        _info.append(self.user.base_att.credits)
        _info.append(items_return)
        defer.returnValue(_info)
Ejemplo n.º 24
0
    def win_streak(self, scene_id, dungeon_id, dungeon_star, battle_count):
        '''
        @summary: 连续战斗
        '''
        # 检查功能开放中连战的限制

        # 检查剩余可连续战斗次数
        vip_conf = get_vip_conf( self.user.base_att.vip_level )
        if not vip_conf:
            log.error('Unknown vip conf. cid:{0}, vip_level: {1}.'.format( self.cid, self.user.vip_level ))
            defer.returnValue( CHAR_VIP_LEVEL_LIMIT )
        cur_time = int(time())
        old_data = yield redis.hget(HASH_SCENE_COOLDOWN_TIME, self.cid)
        end_cooldown_time = int( old_data or 0 )
        if end_cooldown_time > cur_time:
            log.error('In CoolDown time. end time: {0}.'.format( end_cooldown_time ))
            defer.returnValue( IN_COOLDOWN_ERROR )
        end_cooldown_time = cur_time + vip_conf['DungeonTime']
        if battle_count > vip_conf['ContinuousBattles']:
            log.error('count limit. req_count: {0}, max_count: {1}.'.format( battle_count, vip_conf['ContinuousBattles'] ))
            defer.returnValue( DUNGEON_CHALLENGE_COUNT_LIMIT )

        dungeon = yield self.get_dungeon( scene_id, dungeon_id )
        if not dungeon:
            log.error('Unknown dungeon id.')
            defer.returnValue( UNKNOWN_ERROR )
        # 当前怪物组的数据
        dungeon_conf = get_scene_dungeon( scene_id, dungeon_id )
        if not dungeon_conf:
            log.error('Unknown dungeon conf.')
            defer.returnValue( NOT_FOUND_CONF )
        # 每天挑战次数限制
        if (dungeon.dungeon_today_count + battle_count) > dungeon_conf['RushMax']:
            log.error('count limit. req_count: {0}, today count: {1}, rush max: {2}.'.format( battle_count, dungeon.dungeon_today_count, dungeon_conf['RushMax'] ))
            defer.returnValue( DUNGEON_CHALLENGE_COUNT_LIMIT )
        # 怪物组conf
        monster_conf = get_monster_conf( dungeon_id, dungeon_star )
        if not monster_conf:
            log.error('Can not find monster.')
            defer.returnValue( NOT_FOUND_CONF )

        # 保存end cooldown time
        yield redis.hset( HASH_SCENE_COOLDOWN_TIME, self.cid, end_cooldown_time )
        # 连续n次战斗dungeon battle奖励金币、仙魂、经验
        exp_reward, soul_reward, golds_reward = 0, 0, 0
        dungeon.dungeon_today_count += battle_count
        dungeon.dungeon_last_time    = datetime.now()
        dungeon_drop_items = []
        drop_items = [] # [[uid, type, id, num], ...]
        for _c in range(0, battle_count):
            tmp_golds, tmp_soul, tmp_exp, no_energy = 0, 0, 0, False
            if self.user.base_att.energy >= 5:
                self.user.base_att.energy -= 5
                tmp_exp = self.user.base_att.level * BATTLE_MONSTER_EXP_RATIO
            else:
                no_energy = True
                tmp_exp = self.user.base_att.level
            tmp_soul    = monster_conf['Soul']
            tmp_golds   = monster_conf['Money']

            # 获取怪物组掉落
            tmp_drop = yield self.dungeon_star_drop( dungeon_id, dungeon_star, no_energy )
            dungeon_drop_items.append( [tmp_drop, tmp_golds, tmp_soul, tmp_exp] )
            for _t in tmp_drop:
                drop_items = add_new_items(_t, drop_items)
            # 发放奖励
            yield self.user.update_battle_attr( tmp_soul, tmp_golds, tmp_exp )
            exp_reward   += tmp_exp
            soul_reward  += tmp_soul
            golds_reward += tmp_golds
        # 玩家背包新增掉落
        way_others = str((FIGHT_TYPE_NORMAL, dungeon_id, dungeon_star))
        add_items = yield self.get_dungeon_drop( drop_items, way_others )

        # 每日任务计数
        yield self.user.daily_quest_mgr.update_daily_quest( DAILY_QUEST_ID_3, battle_count )
        # add syslog
        str_drop_items = str(add_items).replace('[', '(')
        str_drop_items = str_drop_items.replace(']', ')')
        syslogger(LOG_SCENE_BATTLE, self.cid, self.user.level, self.user.vip_level, self.user.alliance_id, FIGHT_TYPE_NORMAL, 1, dungeon_id, dungeon_star, exp_reward, soul_reward, golds_reward, str_drop_items)

        defer.returnValue( (dungeon_id, dungeon.dungeon_star, dungeon.dungeon_today_count, dungeon_drop_items, add_items, self.user.base_att.energy, end_cooldown_time) )
Ejemplo n.º 25
0
    def scene_all_sweep(self, scene_id, sweep_way=SCENE_SWEEP_CREDIT):
        ''' 对该副本的所有怪物组全扫荡, 掉落放入领奖中心
        '''
        # 检查玩家的VIP等级限制
        vip_conf = get_vip_conf( self.user.base_att.vip_level )
        if not vip_conf or not vip_conf['SceneALLSweep']:
            log.error('Not found vip conf. cid:{0}, vip_level:{1}.'.format( self.cid, self.user.vip_level ))
            defer.returnValue( CHAR_VIP_LEVEL_LIMIT )

        scene_conf = get_scene_conf(scene_id)
        if not scene_conf:
            defer.returnValue( NOT_FOUND_CONF )
        # 判断是否是满星副本
        had_star, left_dungeon_ids = 0, []
        scene    =  yield self.get_scene( scene_id )
        if not scene:
            defer.returnValue( NOT_FOUND_CONF )

        for dungeon_id, dungeon in scene.iteritems():
            had_star += dungeon.dungeon_star
            for dungeon_conf in scene_conf['dungeons']:
                if dungeon_conf['DungeonID'] != dungeon_id:
                    continue
                #if dungeon_conf['RushMax'] > dungeon.dungeon_today_count and dungeon_id not in left_dungeon_ids:
                if dungeon_conf['RushMax'] > dungeon.dungeon_today_count:
                    left_dungeon_ids.append( (dungeon_id, dungeon_conf['RushMax'] - dungeon.dungeon_today_count) )
        # 不是满星副本
        if had_star < scene_conf['StarNum']:
            defer.returnValue( SCENE_STAR_NOT_ENOUGH )
        # 判断是否还有挑战次数
        if not left_dungeon_ids:
            defer.returnValue( SCENE_CHALLENGE_COUNT_LIMIT )
        # 判断钻石数, 4-全部扫荡花费
        daily_info = yield self.get_scene_reset_daily()
        #all_sweep_cost = get_game_limit_value(4)
        #all_sweep_cost = int(all_sweep_cost) if all_sweep_cost else SCENE_ALL_SWEEP_COST
        items_return = []
        # 判断道具和钻石
        if sweep_way == SCENE_SWEEP_ITEM:
            # 扣道具 
            total_item, item_attribs = yield self.user.bag_item_mgr.get_items( ITEM_SCENE_SWEEP_ID )
            if 1 > total_item:
                defer.returnValue( CHAR_ITEM_NOT_ENOUGH )
            res_err, used_attribs = yield self.user.bag_item_mgr.use(ITEM_SCENE_SWEEP_ID, 1)
            if res_err:
                defer.returnValue( res_err )
            # used_attribs-已使用的道具
            for _a in used_attribs:
                items_return.append( [_a.attrib_id, ITEM_TYPE_ITEM, ITEM_SCENE_SWEEP_ID, _a.item_num] )
                # add syslog
                syslogger(LOG_ITEM_LOSE, self.cid, self.user.level, self.user.vip_level, \
                        self.user.alliance_id, _a.attrib_id, ITEM_SCENE_SWEEP_ID, 1, WAY_SCENE_ALL_SWEEP)
        else:
            all_sweep_cost = get_scene_sweep_cost_conf( daily_info[1]+1 )
            if self.user.credits < all_sweep_cost:
                defer.returnValue( CHAR_CREDIT_NOT_ENOUGH )
            # 扣钻石
            self.user.consume_credits(all_sweep_cost, WAY_SCENE_ALL_SWEEP)
            # 副本 钻石扫荡次数累积
            daily_info[1] += 1
            yield redis.hset(HASH_SCENE_RESET_DAILY, self.cid, dumps(daily_info))

        # 副本全扫荡 dungeon battle奖励金币、仙魂、经验
        battle_count = 0  # 扫荡副本的次数
        drop_items   = [] # [[type, id, num], ...]
        dungeon_info = [] # 副本的怪物组挑战次数信息
        exp_reward, soul_reward, golds_reward = 0, 0, 0
        for d_id, d_count in left_dungeon_ids:
            dungeon = yield self.get_dungeon( scene_id, d_id )
            if not dungeon:
                log.error('Unknown dungeon id. cid: {0}, scene_id: {1}, dungeon_id: {2}.'.format( self.cid, scene_id, d_id ))
                continue
            dungeon.dungeon_today_count += d_count
            dungeon.dungeon_last_time    = datetime.now()
            dungeon_info.append( (d_id, dungeon.dungeon_today_count) )
            # 怪物组conf
            monster_conf = get_monster_conf( d_id, scene_conf['SceneDiff'] )
            if not monster_conf:
                log.error('Can not find monster conf. cid: {0}, dungeon_id: {1}.'.format( self.cid, d_id ))
                continue
            # 累计副本战斗次数
            battle_count += d_count
            for _c in range(0, d_count):
                tmp_golds, tmp_soul, tmp_exp, no_energy = 0, 0, 0, False
                if self.user.base_att.energy >= 5:
                    self.user.base_att.energy -= 5
                    tmp_exp = self.user.base_att.level * BATTLE_MONSTER_EXP_RATIO
                else:
                    no_energy = True
                    tmp_exp = self.user.base_att.level
                tmp_soul    = monster_conf['Soul']
                tmp_golds   = monster_conf['Money']

                # 获取怪物组掉落
                tmp_drop = yield self.dungeon_star_drop( d_id, scene_conf['SceneDiff'], no_energy )
                for _t in tmp_drop:
                    drop_items = add_new_items(_t, drop_items)
                # 发放奖励, 判断是否升级
                yield self.user.update_battle_attr( tmp_soul, tmp_golds, tmp_exp, way_type=WAY_SCENE_ALL_SWEEP )
                exp_reward   += tmp_exp
                soul_reward  += tmp_soul
                golds_reward += tmp_golds
        # 掉落发放到领奖中心
        if drop_items:
            timestamp = int(time())
            yield g_AwardCenterMgr.new_award( self.cid, AWARD_TYPE_SCENE_SWEEP, [timestamp, scene_id, drop_items] )

        # 每日任务计数
        yield self.user.daily_quest_mgr.update_daily_quest( DAILY_QUEST_ID_3, battle_count )
        # add syslog
 
        defer.returnValue( (dungeon_info, (golds_reward, soul_reward, exp_reward), self.user.base_att.credits, self.user.base_att.energy, items_return) )
Ejemplo n.º 26
0
def plunder_streak(p, req):
    '''
    @summary: 连续10次抢夺机器人, 非玩家
    '''
    res_err = UNKNOWN_ERROR

    cid, [plunder_cid, shard_id] = req

    user = g_UserMgr.getUser(cid)
    if not user:
        log.error('Can not find user. cid: {0}.'.format( cid ))
        defer.returnValue( res_err )
    # 等级限制 或者 VIP等级开关
    vip_conf = get_vip_conf( user.vip_level )
    res_err  = user.check_function_open(FUNCTION_TEN_PLUNDER)
    if res_err and (not vip_conf.get('TreasureTenPlunder', 0)):
        log.error('cid:{0}, level:{1}, vip_level:{2}.'.format( cid, user.level, user.vip_level ))
        defer.returnValue( CHAR_VIP_LEVEL_LIMIT )

    # 玩家的斗战点不足
    if user.base_att.douzhan < PVP_NEED_DOUZHAN:
        log.error('douzhan of user {0} have been zero!!!'.format( cid ))
        defer.returnValue( CHAR_DOUZHAN_NOT_ENOUGH )
    # 只能连续抢机器人
    if plunder_cid > 0:
        log.error('Can not plunder streak user. plunder_cid: {0}.'.format( plunder_cid ))
        defer.returnValue( REQUEST_LIMIT_ERROR )

    #抢夺,自动去除自己的免战
    yield redis.hdel( HASH_AVOID_WAR_TIME, cid ) 

    battle_count   = 0 # 抢夺的次数
    plunder_result = 0 # 未抢到
    new_shard      = []
    # 翻牌得到的幸运道具
    lottery_items = []
    for _i in range(0, 10):
        # 扣斗战点
        user.base_att.douzhan -= PVP_NEED_DOUZHAN
        # 抢夺次数加1
        battle_count += 1
        # 幸运道具奖励
        new_item = yield random_lottery_items( cid, user.level, user.base_att.vip_level, rand_count=1 )
        if len(new_item) > 0:
            lottery_items.append( new_item[0] )
        else:
            log.error('No lottery items. cid: {0}, level: {1}, vip_level: {2}.'.format( cid, level, vip_level ))
        # 随机碎片
        err, add_items = yield AvoidWarMgr.rand_shard( user, shard_id, plunder_cid )
        if not err and (len(add_items) > 0): #抢到
            plunder_result = 1
            syslogger(LOG_AVOID_WAR, cid, user.level, user.vip_level, user.alliance_id, 1, 1, add_items[0][0], add_items[0][2])
            new_shard = [add_items[0][0], add_items[0][2]]
            break
        # 玩家的斗战点不足
        if user.base_att.douzhan < PVP_NEED_DOUZHAN:
            log.error('douzhan of user {0} have been zero!!!'.format( cid ))
            break
    # 幸运道具进背包
    items_return = []
    for _type, _id, _num, _ in lottery_items:
        model = ITEM_MODELs.get( _type, None )
        if not model:
            log.error('Unknown decomposition item type. item type: {0}.'.format( _type ))
            continue
        res_err, res_value = yield model(user, ItemID=_id, ItemNum=_num, AddType=WAY_LOTTERY_AWARD, CapacityFlag=False)
        if not res_err:
            for _v in res_value:
                items_return = total_new_items(_v, items_return)
    # 每日任务计数
    yield user.daily_quest_mgr.update_daily_quest( DAILY_QUEST_ID_5, battle_count )
    # 开服七天
    yield user.open_server_mgr.update_open_server_activity_quest( OPEN_SERVER_QUEST_ID_8, battle_count)
    yield user.achievement_mgr.update_achievement_status(ACHIEVEMENT_QUEST_ID_8, battle_count)

    defer.returnValue( (plunder_result, user.base_att.douzhan, new_shard, items_return, lottery_items) )
Ejemplo n.º 27
0
def plunder_streak(p, req):
    '''
    @summary: 连续10次抢夺机器人, 非玩家
    '''
    res_err = UNKNOWN_ERROR

    cid, [plunder_cid, shard_id] = req

    user = g_UserMgr.getUser(cid)
    if not user:
        log.error('Can not find user. cid: {0}.'.format(cid))
        defer.returnValue(res_err)
    # 等级限制 或者 VIP等级开关
    vip_conf = get_vip_conf(user.vip_level)
    res_err = user.check_function_open(FUNCTION_TEN_PLUNDER)
    if res_err and (not vip_conf.get('TreasureTenPlunder', 0)):
        log.error('cid:{0}, level:{1}, vip_level:{2}.'.format(
            cid, user.level, user.vip_level))
        defer.returnValue(CHAR_VIP_LEVEL_LIMIT)

    # 玩家的斗战点不足
    if user.base_att.douzhan < PVP_NEED_DOUZHAN:
        log.error('douzhan of user {0} have been zero!!!'.format(cid))
        defer.returnValue(CHAR_DOUZHAN_NOT_ENOUGH)
    # 只能连续抢机器人
    if plunder_cid > 0:
        log.error('Can not plunder streak user. plunder_cid: {0}.'.format(
            plunder_cid))
        defer.returnValue(REQUEST_LIMIT_ERROR)

    #抢夺,自动去除自己的免战
    yield redis.hdel(HASH_AVOID_WAR_TIME, cid)

    battle_count = 0  # 抢夺的次数
    plunder_result = 0  # 未抢到
    new_shard = []
    # 翻牌得到的幸运道具
    lottery_items = []
    for _i in range(0, 10):
        # 扣斗战点
        user.base_att.douzhan -= PVP_NEED_DOUZHAN
        # 抢夺次数加1
        battle_count += 1
        # 幸运道具奖励
        new_item = yield random_lottery_items(cid,
                                              user.level,
                                              user.base_att.vip_level,
                                              rand_count=1)
        if len(new_item) > 0:
            lottery_items.append(new_item[0])
        else:
            log.error(
                'No lottery items. cid: {0}, level: {1}, vip_level: {2}.'.
                format(cid, level, vip_level))
        # 随机碎片
        err, add_items = yield AvoidWarMgr.rand_shard(user, shard_id,
                                                      plunder_cid)
        if not err and (len(add_items) > 0):  #抢到
            plunder_result = 1
            syslogger(LOG_AVOID_WAR, cid, user.level, user.vip_level,
                      user.alliance_id, 1, 1, add_items[0][0], add_items[0][2])
            new_shard = [add_items[0][0], add_items[0][2]]
            break
        # 玩家的斗战点不足
        if user.base_att.douzhan < PVP_NEED_DOUZHAN:
            log.error('douzhan of user {0} have been zero!!!'.format(cid))
            break
    # 幸运道具进背包
    items_return = []
    for _type, _id, _num, _ in lottery_items:
        model = ITEM_MODELs.get(_type, None)
        if not model:
            log.error(
                'Unknown decomposition item type. item type: {0}.'.format(
                    _type))
            continue
        res_err, res_value = yield model(user,
                                         ItemID=_id,
                                         ItemNum=_num,
                                         AddType=WAY_LOTTERY_AWARD,
                                         CapacityFlag=False)
        if not res_err:
            for _v in res_value:
                items_return = total_new_items(_v, items_return)
    # 每日任务计数
    yield user.daily_quest_mgr.update_daily_quest(DAILY_QUEST_ID_5,
                                                  battle_count)
    # 开服七天
    yield user.open_server_mgr.update_open_server_activity_quest(
        OPEN_SERVER_QUEST_ID_8, battle_count)
    yield user.achievement_mgr.update_achievement_status(
        ACHIEVEMENT_QUEST_ID_8, battle_count)

    defer.returnValue((plunder_result, user.base_att.douzhan, new_shard,
                       items_return, lottery_items))