Beispiel #1
0
def grant_limit_fellow_award(all_ranks, activity_id, timestamp):
    '''
    @param: timestamp-借用时间戳作为callLater的有效性验证
    '''
    log.warn('limit fellow award. activity_id: {0}, timestamp: {1}, ACTIVITY_AWARD_TIME: {2}.'.format( activity_id, timestamp, ACTIVITY_AWARD_TIME ))
    # 判断是否是正确的callLater
    if ACTIVITY_AWARD_TIME != timestamp:
        defer.returnValue( None )

    _max_rank = max(all_ranks)
    if _max_rank > 0:
        _rank = 1
        _name_scores = yield redis.zrevrange( SET_LIMIT_FELLOW_NAME_SCORE, 0, _max_rank, withscores=True )
        for _nick_name, _score in _name_scores:
            if _score <= 0:
                continue
            _cid = yield redis.hget(DICT_NICKNAME_REGISTERED, str(_nick_name))
            if _cid:
                yield g_AwardCenterMgr.new_award( _cid, AWARD_TYPE_LIMIT_FELLOW_RANK, [int(time()), activity_id, _rank] )
            _rank += 1

    if 0 in all_ranks:
        _names = yield redis.zrangebyscore( SET_LIMIT_FELLOW_NAME_SCORE, 60, '+inf' )
        for _name in _names:
            _cid = yield redis.hget(DICT_NICKNAME_REGISTERED, str(_name))
            if _cid:
                yield g_AwardCenterMgr.new_award( _cid, AWARD_TYPE_LIMIT_FELLOW_SCORE, [int(time()), activity_id, 0] )

    yield redis.delete( HASH_LIMIT_FELLOW_SHRINE, SET_LIMIT_FELLOW_NAME_SCORE )
Beispiel #2
0
def reward_to_center(cid, pay_date, package_id):
    ''' 将未领的豪华签到奖励发放到领奖中心 
    @param: pay_date-查询当天的充值记录
    @param: package_id-豪华签到的礼包ID
    '''
    conf = get_pay_login_package_conf(package_id)
    if not conf:
        defer.returnValue(NOT_FOUND_CONF)

    # had total cost
    _date = pay_date.strftime("%Y-%m-%d")
    _had_cost = yield get_daily_pay_record(cid, _date)

    if conf['NeedCost'] > _had_cost:
        defer.returnValue(REQUEST_LIMIT_ERROR)

    # timestamp-豪华签到奖励的时间点
    timestamp = datetime2time(pay_date)
    yield g_AwardCenterMgr.new_award(cid, AWARD_TYPE_PAY_LOGIN,
                                     [timestamp, package_id])
    # 更新豪华签到记录
    yield redis.hset(HASH_PAY_LOGIN_PACKAGE, cid,
                     dumps([timestamp, package_id, 1]))

    defer.returnValue(NO_ERROR)
Beispiel #3
0
    def update_lucky_ranklist(self):
        '''
        @summary: 每晚22:00-22:15发放奖励时替换新旧幸运排名
        '''
        _lucky_data = yield self.lucky_ranklist()
        _old_data   = []
        _timestamp  = int(time())
        for _l in _lucky_data[1]:
            _detail = yield self.get_rank_detail( _l[0], flag=False )
            if _detail:
                _old_data.append( [_l[0], _detail[2], _l[1], _detail[7]] )
                if _detail[0] > 0:
                    # 给离线玩家钻石
                    yield g_AwardCenterMgr.new_award( _detail[0], AWARD_TYPE_ARENA_LUCKY, [_timestamp, [[ITEM_TYPE_MONEY, ITEM_MONEY_CREDITS, _l[1]]]], False )
                    #_user_lucky = yield gs_offline_login( _detail[0] )
                    #if _user_lucky:
                    #    _user_lucky.get_credits( _l[1], WAY_ARENA_LUCK_RANK )
                    #    reactor.callLater(SESSION_LOGOUT_REAL, gs_offline_logout, _detail[0])
                    #else:
                    #    log.warn('User login fail. lucky_cid: {0}.'.format( _detail[0] ))
        # 再次随机幸运排名
        _new_data   = []
        _lucky_rank = random.sample(range(1, 501), 10)
        for _rank in _lucky_rank[0:3]:
            _new_data.append( [_rank, 50] )
        for _rank in _lucky_rank[3:]:
            _new_data.append( [_rank, 25] )

        # write redis
        _lucky_data = [_old_data, _new_data]
        yield redis.hset( HASH_ARENA_LUCKY_RANKLIST, LUCKY_RANKLIST, dumps( _lucky_data ) )
Beispiel #4
0
def check_grant_items(cid, user):
    ''' 检查是否有全服发放的道具可领, 有时发放到领奖中心
    '''
    _register_ts    = datetime2time( user.base_att.register_time )
    _grant_keys_got = yield redis.smembers( SET_GOT_GRANT_KEYS%cid )

    _all_grants = yield redis.hgetall( HASH_GM_GRANT_ITEMS )
    if not _all_grants:
        defer.returnValue( NO_ERROR )

    for _grant_key, _grant_info in _all_grants.iteritems():
        _grant_key = int(_grant_key)
        # 判断注册时间点是否在发送道具时间点之后
        if _register_ts and _grant_key < _register_ts:
            continue
        if _grant_key in _grant_keys_got:
            continue
        # 检查时间是否过期, 14天
        if check_valid_time(_grant_key, hour=AWARD_VALID_HOURS):
            yield redis.hdel( HASH_GM_GRANT_ITEMS, _grant_key )
            continue
        # _grant_info=[玩家cid列表, 发放的道具, 过期时间戳]
        _grant_info = loads(_grant_info)
        if not _grant_info[0] or cid in _grant_info[0]:
            yield redis.sadd( SET_GOT_GRANT_KEYS%cid, _grant_key )
            yield g_AwardCenterMgr.new_award( cid, AWARD_TYPE_GM, [_grant_key, _grant_info[1]], flag=False )
 
    defer.returnValue( NO_ERROR )
    def finish_climbing(self, start_layer):
        '''
        @summary: 使用钻石购买扫荡到最高塔层的时间, 更新玩家当前所在塔层及最大塔层, 给通关后的奖励
        '''
        if start_layer > self.climbing.max_layer:
            log.error(
                'Could not climbing. cur_layer: {0}, start_layer: {1}, max_layer: {2}.'
                .format(self.climbing.cur_layer, start_layer,
                        self.climbing.max_layer))
            defer.returnValue(IN_CLIMBING_MAX_LAYER)

        award_layer = []  # 可获得奖励的塔层列表
        total_credits = 0  # 需要消耗的钻石
        finish_layer = start_layer  # self.climbing.cur_layer
        while finish_layer <= self.climbing.max_layer:
            conf = get_climbing_conf(finish_layer)
            if not conf:
                log.error('No conf. tower layer: {0}.'.format(finish_layer))
                defer.returnValue(NOT_FOUND_CONF)
            total_credits += conf['NeedTime']
            award_layer.append(finish_layer)
            finish_layer += 1
        if (total_credits % COOLDOWN_TIME_COST):
            total_credits = (total_credits / COOLDOWN_TIME_COST) + 1
        else:
            total_credits = (total_credits / COOLDOWN_TIME_COST)

        if total_credits > self.user.base_att.credits:
            log.error('Credits not enough. need: {0}, cur: {1}.'.format(
                total_credits, self.user.base_att.credits))
            defer.returnValue(CHAR_CREDIT_NOT_ENOUGH)
        # 重置扫荡的开始时间
        self.climbing.start_datetime = 0

        self.climbing.cur_layer = finish_layer
        yield self.user.consume_credits(total_credits, WAY_CLIMBING_DONE)
        if award_layer:
            g_AwardCenterMgr.new_award(self.cid, AWARD_TYPE_CLIMBING,
                                       [int(time()), award_layer])
            # 每日任务计数
            yield self.user.daily_quest_mgr.update_daily_quest(
                DAILY_QUEST_ID_9, len(award_layer))

        defer.returnValue((self.climbing.cur_layer, self.climbing.max_layer,
                           self.user.base_att.credits))
Beispiel #6
0
    def reward_to_char(self, cid, last_attacker_id, rank):
        reward_golds, reward_farm, last_kill_golds, last_kill_fame = 0, 0, 0, 0

        _conf = get_worldboss_reward(rank)
        if _conf:
            #_golds_add, _farm_add = 0, 0
            reward_golds = _conf['Gold']
            reward_farm = _conf['Prestige']

            #_golds_add += reward_golds
            #_farm_add  += reward_farm

            _reward_items = [
                (ITEM_TYPE_MONEY, ITEM_MONEY_GOLDS, reward_golds),
                (ITEM_TYPE_MONEY, ITEM_MONEY_PRESTIGE, reward_farm),
            ]

            _rand = rand_num()
            if _rand <= _conf['Rate']:
                _reward_items.extend(_conf['RandomItem'])

            g_AwardCenterMgr.new_award(cid, AWARD_TYPE_WORLDBOSS_RANK,
                                       [int(time()), _reward_items], True)

            if int(last_attacker_id) == int(cid):
                log.debug('[ reward_to_char ]: last_attacker_id:{0}, cid:{1}.'.
                          format(last_attacker_id, cid))
                _last_kill_conf = get_worldboss_reward(0)

                last_kill_golds = _last_kill_conf['Gold']
                last_kill_fame = _last_kill_conf['Prestige']

                _reward_items = [
                    (ITEM_TYPE_MONEY, ITEM_MONEY_GOLDS, last_kill_golds),
                    (ITEM_TYPE_MONEY, ITEM_MONEY_PRESTIGE, last_kill_fame)
                ]

                _rand = rand_num()
                if _rand <= _last_kill_conf['Rate']:
                    _reward_items.extend(_last_kill_conf['RandomItem'])

                g_AwardCenterMgr.new_award(cid, AWARD_TYPE_WORLDBOSS_LASTKILL,
                                           [int(time()), _reward_items], True)

        return reward_golds, reward_farm, last_kill_golds, last_kill_fame
Beispiel #7
0
    def reward_to_char(self, cid, last_attacker_id, rank):
        reward_golds, reward_farm, last_kill_golds, last_kill_fame = 0, 0, 0, 0

        _conf = get_worldboss_reward(rank)
        if _conf:
            #_golds_add, _farm_add = 0, 0
            reward_golds = _conf['Gold']
            reward_farm  = _conf['Prestige']

            #_golds_add += reward_golds
            #_farm_add  += reward_farm

            _reward_items = [
                    (ITEM_TYPE_MONEY, ITEM_MONEY_GOLDS, reward_golds),
                    (ITEM_TYPE_MONEY, ITEM_MONEY_PRESTIGE, reward_farm),
                ]

            _rand = rand_num()
            if _rand <= _conf['Rate']:
                _reward_items.extend(_conf['RandomItem'])

            g_AwardCenterMgr.new_award(cid, AWARD_TYPE_WORLDBOSS_RANK, [int(time()), _reward_items], True)

            if int(last_attacker_id) == int(cid):
                log.debug('[ reward_to_char ]: last_attacker_id:{0}, cid:{1}.'.format(last_attacker_id, cid))
                _last_kill_conf = get_worldboss_reward(0)

                last_kill_golds = _last_kill_conf['Gold']
                last_kill_fame  = _last_kill_conf['Prestige']

                _reward_items = [
                        (ITEM_TYPE_MONEY, ITEM_MONEY_GOLDS, last_kill_golds),
                        (ITEM_TYPE_MONEY, ITEM_MONEY_PRESTIGE, last_kill_fame)
                    ]

                _rand = rand_num()
                if _rand <= _last_kill_conf['Rate']:
                    _reward_items.extend(_last_kill_conf['RandomItem'])

                g_AwardCenterMgr.new_award(cid, AWARD_TYPE_WORLDBOSS_LASTKILL, [int(time()), _reward_items], True)

        return reward_golds, reward_farm, last_kill_golds, last_kill_fame
Beispiel #8
0
def grant_limit_fellow_award(all_ranks, activity_id, timestamp):
    '''
    @param: timestamp-借用时间戳作为callLater的有效性验证
    '''
    log.warn(
        'limit fellow award. activity_id: {0}, timestamp: {1}, ACTIVITY_AWARD_TIME: {2}.'
        .format(activity_id, timestamp, ACTIVITY_AWARD_TIME))
    # 判断是否是正确的callLater
    if ACTIVITY_AWARD_TIME != timestamp:
        defer.returnValue(None)

    _max_rank = max(all_ranks)
    if _max_rank > 0:
        _rank = 1
        _name_scores = yield redis.zrevrange(SET_LIMIT_FELLOW_NAME_SCORE,
                                             0,
                                             _max_rank,
                                             withscores=True)
        for _nick_name, _score in _name_scores:
            if _score <= 0:
                continue
            _cid = yield redis.hget(DICT_NICKNAME_REGISTERED, str(_nick_name))
            if _cid:
                yield g_AwardCenterMgr.new_award(
                    _cid, AWARD_TYPE_LIMIT_FELLOW_RANK,
                    [int(time()), activity_id, _rank])
            _rank += 1

    if 0 in all_ranks:
        _names = yield redis.zrangebyscore(SET_LIMIT_FELLOW_NAME_SCORE, 60,
                                           '+inf')
        for _name in _names:
            _cid = yield redis.hget(DICT_NICKNAME_REGISTERED, str(_name))
            if _cid:
                yield g_AwardCenterMgr.new_award(
                    _cid, AWARD_TYPE_LIMIT_FELLOW_SCORE,
                    [int(time()), activity_id, 0])

    yield redis.delete(HASH_LIMIT_FELLOW_SHRINE, SET_LIMIT_FELLOW_NAME_SCORE)
Beispiel #9
0
def new_award_to_center(p, req):
    ''' 新增兑换码奖励到领奖中心 '''
    cid, item_id = req
 
    item_conf = get_item_by_itemid( item_id )
    if not item_conf:
        log.error('Can not find conf. cid: {0}, item_id: {1}.'.format( cid, item_id ))
        defer.returnValue( GIFT_CODE_OVERDUE )

    timestamp = int(time())
    yield g_AwardCenterMgr.new_award( cid, AWARD_TYPE_GIFT_CODE, [timestamp, [[item_conf['ItemType'], item_id, 1]]] )

    defer.returnValue( NO_ERROR )
    def finish_climbing(self, start_layer):
        '''
        @summary: 使用钻石购买扫荡到最高塔层的时间, 更新玩家当前所在塔层及最大塔层, 给通关后的奖励
        '''
        if start_layer > self.climbing.max_layer:
            log.error('Could not climbing. cur_layer: {0}, start_layer: {1}, max_layer: {2}.'.format( self.climbing.cur_layer, start_layer, self.climbing.max_layer ))
            defer.returnValue( IN_CLIMBING_MAX_LAYER )
 
        award_layer   = [] # 可获得奖励的塔层列表
        total_credits = 0  # 需要消耗的钻石
        finish_layer  = start_layer # self.climbing.cur_layer
        while finish_layer <= self.climbing.max_layer:
            conf = get_climbing_conf( finish_layer )
            if not conf:
                log.error('No conf. tower layer: {0}.'.format( finish_layer ))
                defer.returnValue( NOT_FOUND_CONF )
            total_credits += conf['NeedTime']
            award_layer.append( finish_layer )
            finish_layer += 1
        if (total_credits % COOLDOWN_TIME_COST):
            total_credits = (total_credits / COOLDOWN_TIME_COST) + 1
        else:
            total_credits = (total_credits / COOLDOWN_TIME_COST)

        if total_credits > self.user.base_att.credits:
            log.error('Credits not enough. need: {0}, cur: {1}.'.format( total_credits, self.user.base_att.credits ))
            defer.returnValue( CHAR_CREDIT_NOT_ENOUGH )
        # 重置扫荡的开始时间
        self.climbing.start_datetime = 0

        self.climbing.cur_layer = finish_layer
        yield self.user.consume_credits( total_credits, WAY_CLIMBING_DONE )
        if award_layer:
            g_AwardCenterMgr.new_award( self.cid, AWARD_TYPE_CLIMBING, [int(time()), award_layer] )
            # 每日任务计数
            yield self.user.daily_quest_mgr.update_daily_quest( DAILY_QUEST_ID_9, len(award_layer) )
 
        defer.returnValue( (self.climbing.cur_layer, self.climbing.max_layer, self.user.base_att.credits) )
def grant_excite_activity_award(activity_id,
                                redis_key,
                                award_center_type,
                                timestamp=0):
    ''' 精彩活动结束时 定时发放未领的奖励到领奖中心 
    @param: activity_id-精彩活动ID
    @param: redis_key-精彩活动对应的redis_key
    @param: award_center_type-领奖中心奖励类型
    @param: timestamp-借用时间戳作为callLater的有效性验证
    '''
    log.warn(
        'excite activity award. activity_id: {0}, timestamp: {1}, ACTIVITY_AWARD_TIME: {2}.'
        .format(activity_id, timestamp,
                (PAY_ACTIVITY_AWARD_TIME, CONSUME_ACTIVITY_AWARD_TIME)))

    _field = None
    _award_conf = None
    # 判断是否是正确的callLater
    if activity_id == EXCITE_PAY_ACTIVITY:
        _field = 'TotalPay'
        _award_conf = get_pay_activity_conf()
        if PAY_ACTIVITY_AWARD_TIME != timestamp:
            defer.returnValue(None)
    elif activity_id == EXCITE_CONSUME_ACTIVITY:
        _field = 'TotalConsume'
        _award_conf = get_consume_activity_conf()
        if CONSUME_ACTIVITY_AWARD_TIME != timestamp:
            defer.returnValue(None)

    if not _award_conf:
        defer.returnValue(None)

    _all_data = yield redis.hgetall(redis_key)
    if not _all_data:
        defer.returnValue(None)
    # 进领奖中心
    for _cid, _data in _all_data.iteritems():
        _data = loads(_data)
        _award_ids = []
        for _award in _award_conf.itervalues():
            if _award['ID'] in _data[0] or _award['ID'] in _award_ids:
                continue
            if _award[_field] <= _data[1]:
                _award_ids.append(_award['ID'])
                yield g_AwardCenterMgr.new_award(
                    _cid, award_center_type,
                    [int(time()), activity_id, _award['ID']])
    # 删除旧的活动数据
    yield redis.delete(redis_key)
    def stop_climbing(self, stop_layer):
        '''
        @summary: 根据结束时间计算可扫荡到的塔层, 奖励进领奖中心。
        '''
        timestamp = int(time())
        total_sceonds = timestamp - self.climbing.start_datetime
        if (not self.climbing.start_datetime) or (total_sceonds <= 0):
            log.error(
                'Unknown error. start climbing time: {0}, cur_layer: {1}, stop_layer: {2}, total_sceonds: {3}.'
                .format(self.climbing.start_datetime, self.climbing.cur_layer,
                        stop_layer, total_sceonds))
            defer.returnValue(IN_CLIMBING_DONE)
        # 重置扫荡的开始时间
        self.climbing.start_datetime = 0

        #log.info('For Test. cur_layer: {0}, stop_layer: {1}, total_sceonds: {2}.'.format( self.climbing.cur_layer, stop_layer, total_sceonds ))
        flag = True
        award_layer = []  # 可获得奖励的塔层列表
        while flag:
            conf = get_climbing_conf(self.climbing.cur_layer)
            if not conf:
                log.error('No conf. tower layer: {0}.'.format(
                    self.climbing.cur_layer))
                defer.returnValue(NOT_FOUND_CONF)

            if total_sceonds < conf['NeedTime']:
                flag = False
            else:
                total_sceonds -= conf['NeedTime']
                # 奖励进领奖中心
                award_layer.append(self.climbing.cur_layer)
                # 判断是否已经到达了conf的最高层
                if self.climbing.cur_layer >= self.MAX_LAYER:
                    flag = False
                    self.climbing.cur_layer = self.MAX_LAYER
                else:
                    if self.climbing.cur_layer >= self.climbing.max_layer:
                        flag = False
                    self.climbing.cur_layer += 1
                # 每日任务计数
                yield self.user.daily_quest_mgr.update_daily_quest(
                    DAILY_QUEST_ID_9, 1)
            #log.info('For Test. cur_layer: {0}, stop_layer: {1}, total_sceonds: {2}, flag: {3}.'.format( self.climbing.cur_layer, stop_layer, total_sceonds, flag ))

        if award_layer:
            yield g_AwardCenterMgr.new_award(self.cid, AWARD_TYPE_CLIMBING,
                                             [timestamp, award_layer])

        defer.returnValue((self.climbing.cur_layer, self.climbing.max_layer))
Beispiel #13
0
def get_resource_reward(p, req):
    ''' 领取第一次下载资源包的奖励 '''
    cid, [version] = req

    # 检查奖励是否已领取
    flag = yield redis.hexists(HASH_RESOURCE_REWARD, cid)
    if flag:
        log.error('Resource reward had got. cid: {0}.'.format( cid ))
        defer.returnValue( NO_ERROR )

    # 奖励发往领奖中心
    yield g_AwardCenterMgr.new_award( cid, AWARD_TYPE_RESOURCE_REWARD, [int(time())] )

    yield redis.hset(HASH_RESOURCE_REWARD, cid, version)

    defer.returnValue( NO_ERROR )
Beispiel #14
0
    def reward_to_center(self):
        ''' 0点时将未领奖励发放到领奖中心 '''
        items_list = []
        for idx, reward in enumerate(self.rewards):
            if reward[3]:
                continue
            if self.score >= Constellation.stars_need( idx ):
                items_list.append( reward[:3] )
                # 更新领奖状态
                reward[3] = 1
                self.rewards[idx] = reward
                self.synced = False

        if items_list:
            timestamp = int(time())
            yield g_AwardCenterMgr.new_award( self.cid, AWARD_TYPE_CONSTELLATION, [timestamp, items_list] )
Beispiel #15
0
    def reward_to_center(self):
        ''' 0点时将未领奖励发放到领奖中心 '''
        items_list = []
        for idx, reward in enumerate(self.rewards):
            if reward[3]:
                continue
            if self.score >= Constellation.stars_need(idx):
                items_list.append(reward[:3])
                # 更新领奖状态
                reward[3] = 1
                self.rewards[idx] = reward
                self.synced = False

        if items_list:
            timestamp = int(time())
            yield g_AwardCenterMgr.new_award(self.cid,
                                             AWARD_TYPE_CONSTELLATION,
                                             [timestamp, items_list])
Beispiel #16
0
    def reward_to_award_center(self, total_rank=4999, interval=99):
        try:
            timestamp = int(time())
            cid_ranks = yield redis.zrange( SET_ARENA_CID_RANK, total_rank-interval, total_rank, withscores=True )
            if cid_ranks:
                log.debug('redis start: {0}, stop: {1}, cid_ranks: {2}.'.format( total_rank-interval, total_rank, cid_ranks ))
            for _cid, _rank in cid_ranks:
                yield g_AwardCenterMgr.new_award( int(_cid), AWARD_TYPE_ARENARANK, [timestamp, int(_rank)], False )
                #rank_award_conf = get_arena_rank_award( int(_rank) )
                #if rank_award_conf:
                #    items_list = split_items( rank_award_conf['ArenaRankList'] )
                #    ms_send('write_mail', (_cid, MAIL_PAGE_SYSTEM, MAIL_SYSTEM_1, [timestamp, int(_rank), items_list]))
        except Exception as e:
            log.error('Exception e: {0}.'.format( e ))

        if total_rank  > interval:
            total_rank -= (interval + 1)
            reactor.callLater( 2, self.reward_to_award_center, total_rank, interval )
def grant_group_buy_award(activity_id,
                          redis_key,
                          award_center_type,
                          timestamp=0):
    log.warn(
        'excite activity award. activity_id: {0}, timestamp: {1}, GROUP_BUY_AWRAD_TIME: {2}.'
        .format(activity_id, timestamp, GROUP_BUY_AWARD_TIME))

    _field = None
    _award_conf = None
    if GROUP_BUY_AWARD_TIME != timestamp:
        defer.returnValue(None)
    if activity_id != EXCITE_GROUP_BUY:
        defer.returnValue(None)
    _all_data = yield redis.hgetall(redis_key)
    if not _all_data:
        defer.returnValue(None)
    _group_buy_info = yield redis.hgetall(DICT_GROUP_BUY_INFO)
    _wlist = list(set(get_group_buy_count()))  #buy_num level
    _gdict = dict()
    #save group_buy activity buy_num
    for k, v in _group_buy_info.iteritems():
        _gdict[k] = loads(v)

    for _cid, _data in _all_data.iteritems():
        _data = loads(_data)
        _args_list = []
        for _index, (_count, _status) in enumerate(_data):
            if _count <= 0:
                break
            _award_ids = []
            for dex, i in enumerate(_status):
                if i == 1 or dex in _award_ids:
                    continue
                if _gdict[_index + 1] >= _wlist[_index] and i == 0:
                    _args_list.append([_index + 1, _wlist[_index + 1]])
                    _award_ids.append(dex)
        if len(_args_list) >= 1:
            yield g_AwardCenterMgr.new_award(
                _cid, award_center_type,
                [int(time()), activity_id, _args_list])

    yield redis.delete(redis_key)
    yield redis.delete(DICT_GROUP_BUY_INFO)
Beispiel #18
0
    def reward_to_award_center(self, total_count, interval):
        try:
            timestamp = int(time())
            start_rank = total_count - interval + 1 if total_count > interval else 0
            all_cids = yield redis.zrange(SET_JOUST_LAST_CID_SCORE, start_rank,
                                          total_count)
            for _idx, _cid in enumerate(all_cids):
                _rank = (_idx + start_rank + 1)
                yield g_AwardCenterMgr.new_award(_cid, AWARD_TYPE_JOUSTRANK,
                                                 [timestamp, _rank])
                # Reset score
                yield redis.zadd(SET_JOUST_CID_SCORE, _cid, -JOUST_BASIC_SCORE)
        except Exception as e:
            log.exception()

        if total_count > interval:
            total_count -= interval
            reactor.callLater(1, self.reward_to_award_center, total_count,
                              interval)
    def stop_climbing(self, stop_layer):
        '''
        @summary: 根据结束时间计算可扫荡到的塔层, 奖励进领奖中心。
        '''
        timestamp     = int(time())
        total_sceonds = timestamp - self.climbing.start_datetime
        if (not self.climbing.start_datetime) or (total_sceonds <= 0):
            log.error('Unknown error. start climbing time: {0}, cur_layer: {1}, stop_layer: {2}, total_sceonds: {3}.'.format( self.climbing.start_datetime, self.climbing.cur_layer, stop_layer, total_sceonds ))
            defer.returnValue( IN_CLIMBING_DONE )
        # 重置扫荡的开始时间
        self.climbing.start_datetime = 0

        #log.info('For Test. cur_layer: {0}, stop_layer: {1}, total_sceonds: {2}.'.format( self.climbing.cur_layer, stop_layer, total_sceonds ))
        flag = True
        award_layer = [] # 可获得奖励的塔层列表
        while flag:
            conf = get_climbing_conf( self.climbing.cur_layer )
            if not conf:
                log.error('No conf. tower layer: {0}.'.format( self.climbing.cur_layer ))
                defer.returnValue( NOT_FOUND_CONF )

            if total_sceonds < conf['NeedTime']:
                flag = False
            else:
                total_sceonds -= conf['NeedTime']
                # 奖励进领奖中心
                award_layer.append( self.climbing.cur_layer )
                # 判断是否已经到达了conf的最高层
                if self.climbing.cur_layer >= self.MAX_LAYER:
                    flag = False
                    self.climbing.cur_layer = self.MAX_LAYER
                else:
                    if self.climbing.cur_layer >= self.climbing.max_layer:
                        flag = False
                    self.climbing.cur_layer += 1
                # 每日任务计数
                yield self.user.daily_quest_mgr.update_daily_quest( DAILY_QUEST_ID_9, 1 )
            #log.info('For Test. cur_layer: {0}, stop_layer: {1}, total_sceonds: {2}, flag: {3}.'.format( self.climbing.cur_layer, stop_layer, total_sceonds, flag ))

        if award_layer:
            yield g_AwardCenterMgr.new_award( self.cid, AWARD_TYPE_CLIMBING, [timestamp, award_layer] )
 
        defer.returnValue( (self.climbing.cur_layer, self.climbing.max_layer) )
Beispiel #20
0
def gs_gm_grant_to_center(p, req):
    ''' GM给在线玩家的奖励发放到领奖中心, '''
    all_cids, grant_key, items_list = req
 
    # 单次发放人数 100
    _loop_num = 100
    _tmp_cids = all_cids[:_loop_num]
    for cid in _tmp_cids:
        user = g_UserMgr.getUser(cid)
        if not user or user.offline_flag:
            continue

        yield redis.sadd( SET_GOT_GRANT_KEYS%cid, grant_key )
        yield g_AwardCenterMgr.new_award( cid, AWARD_TYPE_GM, [grant_key, items_list] )

    all_cids  = all_cids[_loop_num:]
    if all_cids:
        reactor.callLater(1, gs_gm_grant_to_center, all_cids, grant_key, items_list)
    else:
        defer.returnValue( NO_ERROR )
def grant_excite_activity_award(activity_id, redis_key, award_center_type, timestamp=0):
    ''' 精彩活动结束时 定时发放未领的奖励到领奖中心 
    @param: activity_id-精彩活动ID
    @param: redis_key-精彩活动对应的redis_key
    @param: award_center_type-领奖中心奖励类型
    @param: timestamp-借用时间戳作为callLater的有效性验证
    '''
    log.warn('excite activity award. activity_id: {0}, timestamp: {1}, ACTIVITY_AWARD_TIME: {2}.'.format( activity_id, timestamp, (PAY_ACTIVITY_AWARD_TIME,CONSUME_ACTIVITY_AWARD_TIME) ))

    _field = None
    _award_conf = None
    # 判断是否是正确的callLater
    if activity_id == EXCITE_PAY_ACTIVITY:
        _field = 'TotalPay'
        _award_conf = get_pay_activity_conf()
        if PAY_ACTIVITY_AWARD_TIME != timestamp:
            defer.returnValue( None )
    elif activity_id == EXCITE_CONSUME_ACTIVITY:
        _field = 'TotalConsume'
        _award_conf = get_consume_activity_conf()
        if CONSUME_ACTIVITY_AWARD_TIME != timestamp:
            defer.returnValue( None )

    if not _award_conf:
        defer.returnValue( None )

    _all_data = yield redis.hgetall( redis_key )
    if not _all_data:
        defer.returnValue( None )
    # 进领奖中心 
    for _cid, _data in _all_data.iteritems():
        _data = loads(_data)
        _award_ids = []
        for _award in _award_conf.itervalues():
            if _award['ID'] in _data[0] or _award['ID'] in _award_ids:
                continue
            if _award[_field] <= _data[1]:
                _award_ids.append( _award['ID'] )
                yield g_AwardCenterMgr.new_award( _cid, award_center_type, [int(time()), activity_id, _award['ID']] )
    # 删除旧的活动数据
    yield redis.delete( redis_key )
Beispiel #22
0
    def reward_to_center(self, score, had_reward):
        ''' 重置前将未领的奖励发放到领奖中心 
        @param: score-获得的总积分
        @param: had_reward-已领取奖励的档位ID
        '''
        _all_reward_conf = get_all_daily_quest_reward_conf()
        if not _all_reward_conf:
            defer.returnValue( NOT_FOUND_CONF )

        _reward_ids = [] # 可领还未领的档位ID列表
        for _id, _conf in _all_reward_conf.iteritems():
            # 该档位已领取
            if _id in had_reward:
                continue
            # 总积分不足
            if _conf['Score'] > score:
                continue
            _reward_ids.append( _id )

        if _reward_ids:
            timestamp = int(time())
            yield g_AwardCenterMgr.new_award( self.cid, AWARD_TYPE_DAILY_QUEST, [timestamp, _reward_ids] )
def grant_group_buy_award(activity_id, redis_key, award_center_type, timestamp=0):
    log.warn('excite activity award. activity_id: {0}, timestamp: {1}, GROUP_BUY_AWRAD_TIME: {2}.'.format( activity_id, timestamp,
        GROUP_BUY_AWARD_TIME))

    _field = None
    _award_conf = None
    if GROUP_BUY_AWARD_TIME != timestamp:
        defer.returnValue( None )
    if activity_id != EXCITE_GROUP_BUY:
        defer.returnValue( None )
    _all_data = yield redis.hgetall( redis_key )
    if not _all_data:
        defer.returnValue( None )
    _group_buy_info = yield redis.hgetall( DICT_GROUP_BUY_INFO )
    _wlist = list(set(get_group_buy_count())) #buy_num level
    _gdict = dict()
    #save group_buy activity buy_num
    for k, v in _group_buy_info.iteritems():
        _gdict[k] = loads(v)

    for _cid, _data in _all_data.iteritems():
        _data = loads(_data)
        _args_list = []
        for _index, (_count, _status) in enumerate(_data):
            if _count <= 0:
                break
            _award_ids = []
            for dex, i in enumerate(_status):
                if i == 1 or dex in _award_ids:
                    continue
                if _gdict[_index+1] >= _wlist[_index] and i == 0:
                    _args_list.append([_index+1, _wlist[_index+1]])
                    _award_ids.append(dex)
        if len(_args_list) >= 1:
            yield g_AwardCenterMgr.new_award( _cid, award_center_type, [int(time()), activity_id, _args_list] )

    yield redis.delete( redis_key )
    yield redis.delete( DICT_GROUP_BUY_INFO )
Beispiel #24
0
def reward_to_center(cid, pay_date, package_id):
    ''' 将未领的豪华签到奖励发放到领奖中心 
    @param: pay_date-查询当天的充值记录
    @param: package_id-豪华签到的礼包ID
    '''
    conf = get_pay_login_package_conf( package_id )
    if not conf:
        defer.returnValue( NOT_FOUND_CONF )

    # had total cost
    _date = pay_date.strftime("%Y-%m-%d")
    _had_cost = yield get_daily_pay_record(cid, _date)

    if conf['NeedCost'] > _had_cost:
        defer.returnValue( REQUEST_LIMIT_ERROR )

    # timestamp-豪华签到奖励的时间点
    timestamp = datetime2time( pay_date )
    yield g_AwardCenterMgr.new_award( cid, AWARD_TYPE_PAY_LOGIN, [timestamp, package_id] )
    # 更新豪华签到记录
    yield redis.hset(HASH_PAY_LOGIN_PACKAGE, cid, dumps([timestamp, package_id, 1]))

    defer.returnValue( NO_ERROR )
Beispiel #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) )
Beispiel #26
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))