예제 #1
0
    def exchange_list(self, detail = False):
        '''
        @summary: 获取当前user可以兑换的兑换信息
        '''
        _list = []

        _begin_t, _end_t = self.excite_activity_mgr.open_and_close_time( EXCITE_EXCHANGE_LIMITED )
        if not (_begin_t and _end_t):
            log.error('unknown conf. begin t:{0}, end t:{1}.'.format( _begin_t, _end_t ))
            defer.returnValue( _list )

        if not self.__list:
            _data = yield redis.hget( HASH_EXCHANGE_LIMITED, self.cid )

            _n = int( time() )
            if _data:
                self.__t_lastupdate, _data = loads( _data )

                if self.__t_lastupdate < _begin_t or self.__t_lastupdate > _end_t:
                    _data = []
            else:
                self.__t_lastupdate = _n
                _data               = []

            _all_exchange_conf = get_all_exchange_limited_conf()

            for _conf in _all_exchange_conf.itervalues():
                _id, _title, _type = _conf['ExchangeID'], _conf['Title'], _conf['Type']
                _reset_cnt, _last_reset_t, _exchanged_cnt, _last_exchange_t, _locked_type = 0, _n, 0, _n, 0
                _material_1, _material_2, _material_3, _target = None, None, None, None

                for _haved in _data:
                    if _haved[0] == _id:
                        _reset_cnt, _last_reset_t, _exchanged_cnt, _last_exchange_t, _locked_type, _material_1, _material_2, _material_3, _target = _haved[3:]
                        if not timestamp_is_today( _last_reset_t ):
                            _reset_cnt = 0
                            _last_reset_t = _n
                        if not timestamp_is_today( _last_exchange_t ):
                            _exchanged_cnt = 0
                            _last_exchange_t = _n

                        break
                else:
                    _material_1, _material_2, _material_3, _target = yield self.refresh_materials( _type, False )

                #这个就是__list的数据结构了,找不到,就到这里来找
                _list.append( [ _id, _title, _type, _reset_cnt, _last_reset_t, _exchanged_cnt, _last_exchange_t, _locked_type, _material_1, _material_2, _material_3, _target ] )

            self.__list = _list
            self.sync()

        defer.returnValue( self.value(detail) )
예제 #2
0
    def get_campcard_data(self):
        ''' 获取玩家的阵营抽卡信息 '''
        reset_flag = False
        curr_time  = int(time())
        comm_data  = yield redis.hget(HASH_CAMPRAND_COMMON, 'CAMPRAND')
        if comm_data:
            comm_data = loads(comm_data)
            if curr_time >= comm_data[0]:
                reset_flag = True
                comm_data[0] += CAMP_RAND_TIME
                comm_data[1] = 0 if len(CAMP_GROUP_IDS) <= comm_data[1]+1 else comm_data[1] + 1
                yield redis.hset(HASH_CAMPRAND_COMMON, 'CAMPRAND', dumps(comm_data))
            else:
                camp_data = yield redis.hget(HASH_CAMPRAND_COMMON, self.cid)
                if camp_data:
                    camp_data = loads(camp_data)
                    if 1 == timestamp_is_today(camp_data[0]):
                        curr_camp_data, next_camp_data = camp_data[1], camp_data[2]
                    else:
                        reset_flag = True
                else:
                    reset_flag = True
        else:
            reset_flag = True
            comm_data = [get_reset_timestamp() + CAMP_RAND_TIME, 0]
            yield redis.hset(HASH_CAMPRAND_COMMON, 'CAMPRAND', dumps(comm_data))

        if reset_flag:
            curr_camp_data = [[camp_id, 0] for camp_id in CAMP_GROUP_IDS[comm_data[1]]]
            next_group_id  = 0 if len(CAMP_GROUP_IDS) <= comm_data[1]+1 else comm_data[1] + 1
            next_camp_data = [[camp_id, 0] for camp_id in CAMP_GROUP_IDS[next_group_id]]
            yield redis.hset(HASH_CAMPRAND_COMMON, self.cid, dumps([curr_time, curr_camp_data, next_camp_data]))

        defer.returnValue( (comm_data[0], curr_camp_data, next_camp_data) )
예제 #3
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)
예제 #4
0
    def check_valid_messages(self, cid, flag=False):
        ''' 
        @param: flag-True:需要详细信息的标志位, False:不需要详情
        '''
        _all_messages = yield redis.hget(HASH_ALLIANCE_MESSAGES, self.__id)
        if _all_messages:
            _all_messages = loads(_all_messages)
        else:
            _all_messages = []

        _daily_count    = 0 # 今日已留言的次数
        _valid_messages = []
        _details = []
        for _message in _all_messages:
            _m = g_UserMgr.getUser( _message[1] )
            if not _m:
                continue
            # 检查时间是否过期, 7天
            if check_valid_time(_message[0], hour=MESSAGES_VALID_HOUR):
                continue
            if cid == _m.cid and timestamp_is_today(_message[0]):
                _daily_count += 1
            _valid_messages.append( _message )
            if flag:
                _details.append( (_message[0], _m.cid, _m.lead_id, _m.nick_name, _m.level, _m.position, _message[2]) )

        defer.returnValue( (_daily_count, _valid_messages, _details) )
예제 #5
0
    def received_today(cid):
        _received = False

        _stream = yield redis.hget(DICT_NEWYEAR_PACKAGE, cid)
        if _stream:
            _last_recv_t = int(_stream)
            _received = timestamp_is_today(_last_recv_t)

        defer.returnValue(_received)
예제 #6
0
    def received_today(cid):
        _received = False

        _stream = yield redis.hget(DICT_NEWYEAR_PACKAGE, cid)
        if _stream:
            _last_recv_t = int(_stream)
            _received = timestamp_is_today(_last_recv_t)

        defer.returnValue(_received)
예제 #7
0
    def refresh_exchange_material(self, exchange_id):
        res = EXCHANGE_NOT_FOUND
        #res = [ EXCHANGE_NOT_FOUND, 0, None ]

        if not self.__list:
            yield self.exchange_list()

        for _exchange in self.__list:
            if _exchange[0] == int(exchange_id):
                reset_cnt, _last_reset_t = _exchange[3:5]

                if not timestamp_is_today(_last_reset_t):
                    reset_cnt = 0

                _credits_need = 0

                if reset_cnt:
                    _conf = get_exchange_limited_conf(exchange_id)
                    if not _conf:
                        log.warn('not found exchange config. id:{0}'.format(
                            exchange_id))
                    else:
                        _credits_need = min(
                            _conf['MaxCost'], _conf['ResetCost'] +
                            (reset_cnt - 1) * _conf['AddCost'])
                        res_consume = yield self.user.consume_credits(
                            _credits_need, WAY_LIMIT_EXCHANGE_REFRESH)

                        if res_consume:
                            defer.returnValue(res_consume)

                _materials = yield self.refresh_materials(
                    _exchange[2],
                    add_cnt=True,
                    lock_type=_exchange[7],
                    material_3=_exchange[10],
                    target=_exchange[11])
                _exchange[8], _exchange[9] = _materials[:2]
                _exchange[10] = _materials[2] or _exchange[10]
                _exchange[11] = _materials[3] or _exchange[11]

                _exchange[3] += 1  #更新当日刷新次数
                _exchange[4] = int(time())  #更新最后一次刷新时间戳

                self.sync()

                res = [
                    self.user.credits,
                    [
                        _exchange[0], _exchange[1], _exchange[2], _exchange[3],
                        _exchange[5], _exchange[7], _exchange[8:]
                    ]
                ]
                break

        defer.returnValue(res)
예제 #8
0
    def get_scene_reset_daily(self):
        ''' 获取玩家当天已全扫荡的次数、道具重置的次数、钻石重置的次数 '''
        reset_data = yield redis.hget(HASH_SCENE_RESET_DAILY, self.cid)
        if reset_data:
            reset_data = loads(reset_data)
            # 0-diff date, 1-same today
            if 1 == timestamp_is_today(reset_data[0]):
                defer.returnValue( reset_data )

        defer.returnValue( [int(time()), 0, 0, 0] )
예제 #9
0
    def get_scene_reset_daily(self):
        ''' 获取玩家当天已全扫荡的次数、道具重置的次数、钻石重置的次数 '''
        reset_data = yield redis.hget(HASH_SCENE_RESET_DAILY, self.cid)
        if reset_data:
            reset_data = loads(reset_data)
            # 0-diff date, 1-same today
            if 1 == timestamp_is_today(reset_data[0]):
                defer.returnValue(reset_data)

        defer.returnValue([int(time()), 0, 0, 0])
예제 #10
0
    def exchange_refresh_times(self):
        _cnt = 0

        _list = yield self.exchange_list(True)
        for _exchange in _list:
            reset_cnt, _last_reset_t = _exchange[3:5]

            if not reset_cnt or not timestamp_is_today( _last_reset_t ):
                _cnt += 1

        defer.returnValue( _cnt )
예제 #11
0
    def get_enemy_cids(self, cid):
        ''' '''
        _enemy_data = yield redis.hget(HASH_JOUST_ENEMY_INFO, cid)
        if _enemy_data:
            _enemy_data = loads(_enemy_data)
            if not timestamp_is_today(_enemy_data[0]):
                _enemy_data = [int(time()), []]
        else:
            _enemy_data = [int(time()), []]

        defer.returnValue(_enemy_data)
예제 #12
0
    def exchange_refresh_times(self):
        _cnt = 0

        _list = yield self.exchange_list(True)
        for _exchange in _list:
            reset_cnt, _last_reset_t = _exchange[3:5]

            if not reset_cnt or not timestamp_is_today(_last_reset_t):
                _cnt += 1

        defer.returnValue(_cnt)
예제 #13
0
    def load(character_id):
        _data = yield redis.hget(DICT_CONSTELLATION, character_id)
        _changed = False

        if _data:
            try:
                _stars4hit, _stars4select, _score, _select_cnt, _hitted_cnt, _free_cnt, _rewards, _last_select_time, _last_reward_time = loads(
                    _data)
            except:
                _stars4hit, _stars4select, _score, _select_cnt, _free_cnt, _rewards, _last_select_time, _last_reward_time = loads(
                    _data)
                _hitted_cnt = 0
        else:
            _last_select_time = 0
            _last_reward_time = 0

        if not timestamp_is_today(_last_select_time):
            _stars4hit, _stars4select = Constellation.rand_star_today()
            _score = 0
            _free_cnt = 0
            _select_cnt = 0
            _hitted_cnt = 0
            _last_select_time = int(time())

            _changed = True

        if not timestamp_is_today(_last_reward_time):
            _rewards = Constellation.default_reward_today()
            _last_reward_time = int(time())

            _changed = True

        _self = Constellation(character_id, _score, _select_cnt, _hitted_cnt,
                              _free_cnt, _last_select_time, _stars4hit,
                              _stars4select, _last_reward_time, _rewards)

        if _changed:
            _self.sync()

        defer.returnValue(_self)
예제 #14
0
    def load(character_id):
        _data    = yield redis.hget(DICT_CONSTELLATION, character_id)
        _changed = False

        if _data:
            try:
                _stars4hit, _stars4select, _score, _select_cnt, _hitted_cnt, _free_cnt, _rewards, _last_select_time, _last_reward_time = loads( _data )
            except:
                _stars4hit, _stars4select, _score, _select_cnt, _free_cnt, _rewards, _last_select_time, _last_reward_time = loads( _data )
                _hitted_cnt = 0
        else:
            _last_select_time = 0
            _last_reward_time = 0

        if not timestamp_is_today( _last_select_time):
            _stars4hit, _stars4select = Constellation.rand_star_today()
            _score                    = 0
            _free_cnt                 = 0
            _select_cnt               = 0
            _hitted_cnt               = 0
            _last_select_time         = int(time())

            _changed = True

        if not timestamp_is_today( _last_reward_time ):
            _rewards          = Constellation.default_reward_today()
            _last_reward_time = int(time())

            _changed = True

        _self = Constellation(character_id, _score, _select_cnt, _hitted_cnt, _free_cnt, _last_select_time, _stars4hit, _stars4select, _last_reward_time, _rewards)

        if _changed:
            _self.sync()

        defer.returnValue( _self )
예제 #15
0
    def buyed_count_today(self, cid):
        _buyed_cnt_list = []

        _group = self.current_group()
        if _group and _group.is_open:
            _stream = yield redis.hget(DICT_TIME_LIMITED_SHOP_BUYED, cid)
            if _stream:
                _tuple_all_buyed = loads(_stream)

                for _id, _buyed_cnt, _last_buy_t in _tuple_all_buyed:
                    if timestamp_is_today(_last_buy_t):
                        _buyed_cnt_list.append([_id, _buyed_cnt, _last_buy_t])
        else:
            redis.hdel(DICT_TIME_LIMITED_SHOP_BUYED, cid)

        defer.returnValue(_buyed_cnt_list)
예제 #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))
예제 #17
0
    def do_exchange(self, exchange_id ):
        res = EXCHANGE_NOT_FOUND

        if not self.__list:
            yield self.exchange_list()

        for _exchange in self.__list:
            if _exchange[0] == int( exchange_id ):
                _conf = get_exchange_limited_conf( exchange_id )
                if not _conf:
                    defer.returnValue( res )

                _exchanged_cnt, _last_exchange_t = _exchange[5:7]
                if not timestamp_is_today( _last_exchange_t ):
                    _exchanged_cnt = _exchange[5] = 0

                if _exchanged_cnt >= _conf['ExchangeNum']:
                    defer.returnValue( res )

                _material_1, _material_2, _material_3, _target = _exchange[8:12]
                err, _material_1_remain = yield item_use( self.user, ItemType=_material_1[0], ItemID=_material_1[1], ItemNum=_material_1[2] )
                if err:
                    log.error( 'do_exchange err:{0}, material:{1}.'.format( err, _material_1 ) )

                err, _material_2_remain = yield item_use( self.user, ItemType=_material_2[0], ItemID=_material_2[1], ItemNum=_material_2[2] )
                if err:
                    log.error( 'do_exchange err:{0}, material:{1}.'.format( err, _material_2 ) )

                err, _material_3_remain = yield item_use( self.user, ItemType=_material_3[0], ItemID=_material_3[1], ItemNum=_material_3[2], UseType=WAY_LIMIT_EXCHANGE )
                if err:
                    log.error( 'do_exchange err:{0}, material:{1}.'.format( err, _material_3 ) )

                err, _target_added = yield item_add( self.user, ItemType=_target[0], ItemID=_target[1], ItemNum=_target[2], AddType=WAY_LIMIT_EXCHANGE )

                res = err

                if not err:
                    _exchanged_cnt = _exchange[5] = _exchanged_cnt + 1
                    _exchange[6]   = int( time() )
                    _exchange[7]   = LOCK_TYPE_NONE  # 重置锁定

                    self.sync()
                    res = [ _exchanged_cnt, _material_1_remain, _material_2_remain, _material_3_remain, _target_added ]

                break

        defer.returnValue( res )
예제 #18
0
    def update(self):
        _n = int(time())
        if timestamp_is_today(self.last_opened_t):
            _hours_passed = int(floor((_n - self.last_opened_t) / 3600))
            if _hours_passed >= 1:
                if self.normal_rose + _hours_passed <= 5:
                    self.normal_rose += _hours_passed
                    self.last_opened_t += (_hours_passed * 3600)
                else:
                    self.normal_rose = 5
                    self.last_opened_t = _n
        else:
            self.reset()
            self.normal_rose = 5
            self.extra_blue_rose = 0
            self.last_opened_t = _n

        self.sync()
예제 #19
0
 def update(self):
     _n = int(time())
     if timestamp_is_today(self.last_opened_t):
         _hours_passed = int(floor((_n - self.last_opened_t) / 3600))
         if _hours_passed >= 1:
             if self.normal_rose + _hours_passed <= 5:
                 self.normal_rose += _hours_passed
                 self.last_opened_t += (_hours_passed * 3600)
             else:
                 self.normal_rose = 5
                 self.last_opened_t = _n
     else:
         self.reset()
         self.normal_rose = 5
         self.extra_blue_rose = 0
         self.last_opened_t = _n
     
     self.sync()
예제 #20
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)
예제 #21
0
    def get_campcard_data(self):
        ''' 获取玩家的阵营抽卡信息 '''
        reset_flag = False
        curr_time = int(time())
        comm_data = yield redis.hget(HASH_CAMPRAND_COMMON, 'CAMPRAND')
        if comm_data:
            comm_data = loads(comm_data)
            if curr_time >= comm_data[0]:
                reset_flag = True
                comm_data[0] += CAMP_RAND_TIME
                comm_data[1] = 0 if len(
                    CAMP_GROUP_IDS) <= comm_data[1] + 1 else comm_data[1] + 1
                yield redis.hset(HASH_CAMPRAND_COMMON, 'CAMPRAND',
                                 dumps(comm_data))
            else:
                camp_data = yield redis.hget(HASH_CAMPRAND_COMMON, self.cid)
                if camp_data:
                    camp_data = loads(camp_data)
                    if 1 == timestamp_is_today(camp_data[0]):
                        curr_camp_data, next_camp_data = camp_data[
                            1], camp_data[2]
                    else:
                        reset_flag = True
                else:
                    reset_flag = True
        else:
            reset_flag = True
            comm_data = [get_reset_timestamp() + CAMP_RAND_TIME, 0]
            yield redis.hset(HASH_CAMPRAND_COMMON, 'CAMPRAND',
                             dumps(comm_data))

        if reset_flag:
            curr_camp_data = [[camp_id, 0]
                              for camp_id in CAMP_GROUP_IDS[comm_data[1]]]
            next_group_id = 0 if len(
                CAMP_GROUP_IDS) <= comm_data[1] + 1 else comm_data[1] + 1
            next_camp_data = [[camp_id, 0]
                              for camp_id in CAMP_GROUP_IDS[next_group_id]]
            yield redis.hset(
                HASH_CAMPRAND_COMMON, self.cid,
                dumps([curr_time, curr_camp_data, next_camp_data]))

        defer.returnValue((comm_data[0], curr_camp_data, next_camp_data))
예제 #22
0
    def refresh_exchange_material(self, exchange_id):
        res = EXCHANGE_NOT_FOUND
        #res = [ EXCHANGE_NOT_FOUND, 0, None ]

        if not self.__list:
            yield self.exchange_list()

        for _exchange in self.__list:
            if _exchange[0] == int( exchange_id ):
                reset_cnt, _last_reset_t = _exchange[3:5]

                if not timestamp_is_today( _last_reset_t ):
                    reset_cnt = 0

                _credits_need = 0

                if reset_cnt:
                    _conf = get_exchange_limited_conf( exchange_id )
                    if not _conf:
                        log.warn('not found exchange config. id:{0}'.format( exchange_id ))
                    else:
                        _credits_need = min( _conf['MaxCost'], _conf['ResetCost'] + ( reset_cnt - 1 ) * _conf['AddCost'] )
                        res_consume = yield self.user.consume_credits( _credits_need, WAY_LIMIT_EXCHANGE_REFRESH )

                        if res_consume:
                            defer.returnValue( res_consume )

                _materials = yield self.refresh_materials( _exchange[2], add_cnt = True, lock_type=_exchange[7], material_3=_exchange[10], target=_exchange[11] )
                _exchange[8], _exchange[9] = _materials[:2]
                _exchange[10] = _materials[2] or _exchange[10]
                _exchange[11] = _materials[3] or _exchange[11]

                _exchange[3] += 1                #更新当日刷新次数
                _exchange[4]  = int( time() )    #更新最后一次刷新时间戳

                self.sync()

                res = [ self.user.credits, [ _exchange[0], _exchange[1], _exchange[2], _exchange[3], _exchange[5] , _exchange[7], _exchange[8:] ] ]
                break

        defer.returnValue( res )
예제 #23
0
 def need_refresh(self):
     ''' True-需要刷新 False-不需要刷新 '''
     if timestamp_is_today(self.last_select_time):
         return False
     else:
         return True
예제 #24
0
 def need_refresh(self):
     ''' True-需要刷新 False-不需要刷新 '''
     if timestamp_is_today(self.last_select_time):
         return False
     else:
         return True
예제 #25
0
    def exchange_list(self, detail=False):
        '''
        @summary: 获取当前user可以兑换的兑换信息
        '''
        _list = []

        _begin_t, _end_t = self.excite_activity_mgr.open_and_close_time(
            EXCITE_EXCHANGE_LIMITED)
        if not (_begin_t and _end_t):
            log.error('unknown conf. begin t:{0}, end t:{1}.'.format(
                _begin_t, _end_t))
            defer.returnValue(_list)

        if not self.__list:
            _data = yield redis.hget(HASH_EXCHANGE_LIMITED, self.cid)

            _n = int(time())
            if _data:
                self.__t_lastupdate, _data = loads(_data)

                if self.__t_lastupdate < _begin_t or self.__t_lastupdate > _end_t:
                    _data = []
            else:
                self.__t_lastupdate = _n
                _data = []

            _all_exchange_conf = get_all_exchange_limited_conf()

            for _conf in _all_exchange_conf.itervalues():
                _id, _title, _type = _conf['ExchangeID'], _conf[
                    'Title'], _conf['Type']
                _reset_cnt, _last_reset_t, _exchanged_cnt, _last_exchange_t, _locked_type = 0, _n, 0, _n, 0
                _material_1, _material_2, _material_3, _target = None, None, None, None

                for _haved in _data:
                    if _haved[0] == _id:
                        _reset_cnt, _last_reset_t, _exchanged_cnt, _last_exchange_t, _locked_type, _material_1, _material_2, _material_3, _target = _haved[
                            3:]
                        if not timestamp_is_today(_last_reset_t):
                            _reset_cnt = 0
                            _last_reset_t = _n
                        if not timestamp_is_today(_last_exchange_t):
                            _exchanged_cnt = 0
                            _last_exchange_t = _n

                        break
                else:
                    _material_1, _material_2, _material_3, _target = yield self.refresh_materials(
                        _type, False)

                #这个就是__list的数据结构了,找不到,就到这里来找
                _list.append([
                    _id, _title, _type, _reset_cnt, _last_reset_t,
                    _exchanged_cnt, _last_exchange_t, _locked_type,
                    _material_1, _material_2, _material_3, _target
                ])

            self.__list = _list
            self.sync()

        defer.returnValue(self.value(detail))
예제 #26
0
    def do_exchange(self, exchange_id):
        res = EXCHANGE_NOT_FOUND

        if not self.__list:
            yield self.exchange_list()

        for _exchange in self.__list:
            if _exchange[0] == int(exchange_id):
                _conf = get_exchange_limited_conf(exchange_id)
                if not _conf:
                    defer.returnValue(res)

                _exchanged_cnt, _last_exchange_t = _exchange[5:7]
                if not timestamp_is_today(_last_exchange_t):
                    _exchanged_cnt = _exchange[5] = 0

                if _exchanged_cnt >= _conf['ExchangeNum']:
                    defer.returnValue(res)

                _material_1, _material_2, _material_3, _target = _exchange[
                    8:12]
                err, _material_1_remain = yield item_use(
                    self.user,
                    ItemType=_material_1[0],
                    ItemID=_material_1[1],
                    ItemNum=_material_1[2])
                if err:
                    log.error('do_exchange err:{0}, material:{1}.'.format(
                        err, _material_1))

                err, _material_2_remain = yield item_use(
                    self.user,
                    ItemType=_material_2[0],
                    ItemID=_material_2[1],
                    ItemNum=_material_2[2])
                if err:
                    log.error('do_exchange err:{0}, material:{1}.'.format(
                        err, _material_2))

                err, _material_3_remain = yield item_use(
                    self.user,
                    ItemType=_material_3[0],
                    ItemID=_material_3[1],
                    ItemNum=_material_3[2],
                    UseType=WAY_LIMIT_EXCHANGE)
                if err:
                    log.error('do_exchange err:{0}, material:{1}.'.format(
                        err, _material_3))

                err, _target_added = yield item_add(self.user,
                                                    ItemType=_target[0],
                                                    ItemID=_target[1],
                                                    ItemNum=_target[2],
                                                    AddType=WAY_LIMIT_EXCHANGE)

                res = err

                if not err:
                    _exchanged_cnt = _exchange[5] = _exchanged_cnt + 1
                    _exchange[6] = int(time())
                    _exchange[7] = LOCK_TYPE_NONE  # 重置锁定

                    self.sync()
                    res = [
                        _exchanged_cnt, _material_1_remain, _material_2_remain,
                        _material_3_remain, _target_added
                    ]

                break

        defer.returnValue(res)