Esempio n. 1
0
def fellowsoul_combine(p, req):
    res_err = UNKNOWN_ERROR

    cid, [user_fellow_id] = req

    user = g_UserMgr.getUser(cid)
    if not user:
        log.error('Can not find user. cid: {0}.'.format( cid ))
        defer.returnValue( res_err )

    res_err, fellow_id = yield user.bag_fellowsoul_mgr.combine( user_fellow_id )
    if not res_err:
        try:
            # args: fellow_id, is_major, camp_id, on_troop
            res_err, attrib = yield user.fellow_mgr.create_table_data( fellow_id, 0, 0, 0 )
        except Exception as e:
            log.warn('Create fellow fail! e:', e)
            defer.returnValue(res_err)
        #errorno, value = yield user.fellow_mgr.addNewFellow( fellow_id )
        if not res_err:
            _conf = get_fellow_by_fid(fellow_id)
            if _conf:
                q = _conf.get('Quality', 0)
                if q>= 2:
                    user.achievement_mgr.update_achievement_status(29, 1)
                if q>= 3:
                    user.achievement_mgr.update_achievement_status(30, 1)
                if q>= 4:
                    user.achievement_mgr.update_achievement_status(31, 1)
            defer.returnValue( [attrib.attrib_id, attrib.fellow_id] )

    defer.returnValue( res_err )
Esempio n. 2
0
    def camp_randcard(self, camp_id):
        ''' 阵营抽卡 '''
        _, curr_camp_data, next_camp_data = yield self.get_campcard_data()
        # 检查阵营, 累计次数
        rand_time = 0
        for _idx, _data in enumerate(curr_camp_data):
            if _data[0] == camp_id:
                if _data[1] >= CAMP_RAND_MAX:
                    defer.returnValue( CAMP_RANDCARD_MAX_LIMIT )
                _data[1] += 1
                rand_time = _data[1]
                curr_camp_data[_idx] = _data
                break
        else:
            defer.returnValue( CAMP_RANDCARD_ID_ERROR )
        # 随机伙伴
        need_credits = get_campcard_cost_conf(rand_time)
        if not need_credits or need_credits > self.user.credits:
            log.error('Credits not enough. cid:{0}, need:{1}, curr: {2}.'.format( self.cid, need_credits, self.user.credits ))
            defer.returnValue( CHAR_CREDIT_NOT_ENOUGH )

        pool_conf = get_campcard_pool_conf(camp_id, rand_time)
        res_err, card = self.randcard_frompool( pool_conf )
        if res_err:
            log.error('No camp randcard pool. cid:{0}, camp_id:{1}, rand_time:{2}.'.format( self.cid, camp_id, rand_time ))
            defer.returnValue( res_err )
        # 扣钻石
        yield self.user.consume_credits( need_credits, WAY_CAMP_RANDCARD )
        # 更新抽卡次数
        yield redis.hset(HASH_CAMPRAND_COMMON, self.cid, dumps([int(time()), curr_camp_data, next_camp_data]))
        # 新增伙伴
        try:
            new_fellows = []
            # args: fellow_id, is_major, camp_id, on_troop
            res_err, attrib = yield self.user.fellow_mgr.create_table_data( card['ItemID'], 0, 0, 0 )
            if not res_err:
                new_fellows.append( [attrib.attrib_id, card['ItemID']] )
                conf = get_fellow_by_fid( card['ItemID'] )
                if conf:
                    syslogger(LOG_FELLOW_GET, self.cid, self.user.level, self.user.vip_level, self.user.alliance_id, attrib.attrib_id, card['ItemID'], conf['QualityLevel'], conf['Star'], WAY_CAMP_RANDCARD, '')
        except Exception as e:
            log.warn('Create fellow fail! e:', e)
            defer.returnValue(res_err)
        # 阵营抽卡抽到紫卡, 全服广播
        if card['Notice']:
            message = [RORATE_MESSAGE_ACHIEVE, [ACHIEVE_TYPE_RANDCARD, [self.user.nick_name, RANDCARD_TYPE_CAMP, [card['ItemID']]]]]
            gw_broadcast('sync_broadcast', [message])

        yield self.user.daily_quest_mgr.update_daily_quest( DAILY_QUEST_ID_16, 1)
        
        defer.returnValue( (self.user.credits, rand_time, new_fellows) )
Esempio n. 3
0
    def ids_green(self):
        yield self._load()

        ids = []
        for attrib in self.__gsattribs.itervalues():
            if attrib.is_major or attrib.on_troop or attrib.camp_id or attrib.advanced_level:
                continue

            _conf = get_fellow_by_fid(attrib.fellow_id)

            if _conf['Quality'] <= QUALITY_GREEN:
                ids.append(attrib.attrib_id)

        defer.returnValue(ids)
Esempio n. 4
0
    def ids_green(self):
        yield self._load()

        ids = []
        for attrib in self.__gsattribs.itervalues():
            if attrib.is_major or attrib.on_troop or attrib.camp_id or attrib.advanced_level:
                continue

            _conf = get_fellow_by_fid(attrib.fellow_id)

            if _conf['Quality'] <= QUALITY_GREEN:
                ids.append(attrib.attrib_id)

        defer.returnValue(ids)
Esempio n. 5
0
    def create_table_data(self,
                          fellow_id,
                          is_major,
                          camp_id,
                          on_troop,
                          way_type=WAY_UNKNOWN,
                          way_others=''):
        yield self._load()

        time_now = int(time())  #datetime2string()
        gsattrib = GSAttribute(self.cid, GSFellowMgr._table)
        res_err = yield gsattrib.new(cid=self.cid,
                                     fellow_id=fellow_id,
                                     level=1,
                                     exp=0,
                                     advanced_level=0,
                                     on_troop=on_troop,
                                     is_major=is_major,
                                     camp_id=camp_id,
                                     deleted=0,
                                     create_time=time_now,
                                     update_time=time_now,
                                     del_time=0)
        if res_err:
            log.error(
                'GSBagEquipMgr create table data error. res_err: {0}.'.format(
                    res_err))
            defer.returnValue((UNKNOWN_ERROR, None))

        self.__gsattribs[gsattrib.attrib_id] = gsattrib
        # 创建玩家角色时初始化阵容等信息
        if is_major:
            self.initialize(gsattrib)

        conf = get_fellow_by_fid(fellow_id)
        if conf:
            # 判断图鉴
            yield self.user.atlaslist_mgr.new_atlaslist(
                CATEGORY_TYPE_FELLOW, conf['Camp'], conf['Quality'], fellow_id)
            if conf['Quality'] >= QUALITY_PURPLE:
                yield self.user.goodwill_mgr.create_table_data(fellow_id)
            # add syslog
            syslogger(LOG_FELLOW_GET, self.cid, self.user.level,
                      self.user.vip_level, self.user.alliance_id,
                      gsattrib.attrib_id, fellow_id, conf['QualityLevel'],
                      conf['Star'], way_type, way_others)
        defer.returnValue((NO_ERROR, gsattrib))
Esempio n. 6
0
def gs_gm_check_grant_items(p, req):
    ''' 检查道具类型和道具ID是否匹配 '''
    items_list, = req
    error_items = []
    for _type, _id, _num in items_list:
        if _type == ITEM_TYPE_FELLOW:
            item_conf = get_fellow_by_fid( _id )
            if not item_conf:
                error_items.append( {'item_type':_type, 'item_id':_id} )
                continue
        else:
            item_conf = get_item_by_itemid( _id )
            if not item_conf or item_conf['ItemType'] != _type:
                error_items.append( {'item_type':_type, 'item_id':_id} )
                continue

    if error_items:
        return (UNKNOWN_ITEM_ERROR, error_items)
    else:
        return (NO_ERROR, error_items)
Esempio n. 7
0
    def gm_get_camp_fellow(self, ufid):
        _fellow = {}
        attrib = self.get_fellow(ufid)
        if not attrib:
            return _fellow

        _fellow['fellow_name'] = ''
        _fellow['user_fellow_id'] = ufid
        _fellow['advanced_level'] = attrib.advanced_level
        if attrib.is_major > 0:
            _fellow['user_fellow_id'] = self.user.cid
            _fellow['fellow_id'] = self.user.lead_id
            _fellow['level'] = self.user.level
            _fellow['exp'] = self.user.base_att.exp
            _fellow['fellow_name'] = self.user.nick_name
        else:
            conf = get_fellow_by_fid(attrib.fellow_id)
            if conf:
                _fellow['fellow_name'] = conf['Name']
            _fellow['fellow_id'] = attrib.fellow_id
            _fellow['level'] = attrib.level
            _fellow['exp'] = attrib.exp

        return _fellow
Esempio n. 8
0
    def gm_get_camp_fellow(self, ufid):
        _fellow = {}
        attrib = self.get_fellow( ufid )
        if not attrib:
            return _fellow

        _fellow['fellow_name'] = ''
        _fellow['user_fellow_id'] = ufid
        _fellow['advanced_level'] = attrib.advanced_level 
        if attrib.is_major > 0:
            _fellow['user_fellow_id'] = self.user.cid
            _fellow['fellow_id']      = self.user.lead_id
            _fellow['level']          = self.user.level
            _fellow['exp']            = self.user.base_att.exp
            _fellow['fellow_name']    = self.user.nick_name
        else:
            conf = get_fellow_by_fid( attrib.fellow_id )
            if conf:
                _fellow['fellow_name'] = conf['Name']
            _fellow['fellow_id'] = attrib.fellow_id
            _fellow['level']     = attrib.level
            _fellow['exp']       = attrib.exp

        return _fellow
Esempio n. 9
0
    def create_table_data(self, fellow_id, is_major, camp_id, on_troop, way_type=WAY_UNKNOWN, way_others=''):
        yield self._load()

        time_now = int(time()) #datetime2string()
        gsattrib = GSAttribute( self.cid, GSFellowMgr._table )
        res_err  = yield gsattrib.new( cid=self.cid, fellow_id=fellow_id, level=1, exp=0, advanced_level=0, on_troop=on_troop, is_major=is_major, camp_id=camp_id, deleted=0, create_time=time_now, update_time=time_now, del_time=0)
        if res_err:
            log.error('GSBagEquipMgr create table data error. res_err: {0}.'.format( res_err ))
            defer.returnValue( (UNKNOWN_ERROR, None) )

        self.__gsattribs[gsattrib.attrib_id] = gsattrib
        # 创建玩家角色时初始化阵容等信息
        if is_major:
            self.initialize( gsattrib )

        conf = get_fellow_by_fid( fellow_id )
        if conf:
            # 判断图鉴
            yield self.user.atlaslist_mgr.new_atlaslist(CATEGORY_TYPE_FELLOW, conf['Camp'], conf['Quality'], fellow_id)
            if conf['Quality'] >= QUALITY_PURPLE:
                yield self.user.goodwill_mgr.create_table_data( fellow_id )
            # add syslog
            syslogger(LOG_FELLOW_GET, self.cid, self.user.level, self.user.vip_level, self.user.alliance_id, gsattrib.attrib_id, fellow_id, conf['QualityLevel'], conf['Star'], way_type, way_others)
        defer.returnValue( (NO_ERROR, gsattrib) )
Esempio n. 10
0
    def randcard(self, card_type, rand_times):
        '''
        @return : err, credits, res_fellow_list
        '''
        res_err = REQUEST_LIMIT_ERROR

        shrine_data = yield redis.hget(HASH_SHRINE_TYPE % card_type, self.cid)
        if shrine_data:
            shrine_data = loads( shrine_data )
            if len(shrine_data) == 4:
                shrine_level, rand_count, last_free_time, last_purple_time = shrine_data
                first_blue, first_purple = 0, 0
            else:
                shrine_level, rand_count, last_free_time, last_purple_time, first_blue, first_purple = shrine_data
        else:
            shrine_level, rand_count, last_free_time, last_purple_time, first_blue, first_purple = 0, 0, 0, 0, 1, 1
        # 抽卡消耗的配置
        _consume = get_randcard_consume_conf( card_type )
        if not _consume:
            log.error('Can not find conf.')
            defer.returnValue( NOT_FOUND_CONF )

        # 距离下一场免费抽奖所需时间
        need_time = self.left_free_timestamp( last_free_time, _consume['FreeTime'] )
        # 检查道具或钻石是否充足
        user_credits = self.user.base_att.credits
        if (_consume['ItemType'] == ITEM_TYPE_MONEY):
            _rand_cost = _consume['ItemNum']*rand_times
            if rand_times > 1:
                # 无免费抽奖时所需钻石
                if (need_time > 0):
                    _rand_cost = int((_consume['ItemNum'] * 10 * RANDCARD_TEN_RATIO + 99) / 100)
                else:
                    _rand_cost = int((_consume['ItemNum'] * 9 * RANDCARD_TEN_RATIO + 99) / 100)

            # 无免费抽奖时钻石不足
            if (need_time > 0) and (_rand_cost > user_credits):
                log.error('Not enough credits. need: {0}, cur: {1}.'.format( _rand_cost, user_credits ))
                defer.returnValue( CHAR_CREDIT_NOT_ENOUGH )
            # 有免费抽奖且是十连抽时钻石不足
            elif 0 >= need_time and rand_times > 1 and (_rand_cost > user_credits):
                log.error('Not enough credits. need: {0}, cur: {1}.'.format( _rand_cost, user_credits ))
                defer.returnValue( CHAR_CREDIT_NOT_ENOUGH )
        elif (_consume['ItemType'] == ITEM_TYPE_ITEM): 
            total_num, item_attribs = yield self.user.bag_item_mgr.get_items( _consume['ItemID'] )
            # 情缘令不足
            if (_consume['ItemNum']*rand_times) > total_num:
                log.error('cur num: {0}.'.format( total_num ))
                defer.returnValue( CHAR_ITEM_NOT_ENOUGH )
        else:
            log.error('Unknown item type: {0}.'.format( _consume['ItemType'] ))
            defer.returnValue( RANDCARD_TYPE_ERROR )
        # 获取抽卡池
        first_flag = 0
        if card_type  == CARD_SHRINE_BLUE:
            first_flag = first_blue
        elif card_type == CARD_SHRINE_PURPLE:
            first_flag = first_purple
        pool = self.get_randcard_pool( card_type, shrine_level, rand_count, need_time, last_purple_time, first_flag )
        if not pool:
            defer.returnValue( NOT_FOUND_CONF )
        # 无免费抽卡时更新状态位
        if need_time > 0 or (0 >= need_time and rand_times > 1):
            if card_type  == CARD_SHRINE_BLUE:
                if first_blue:
                    first_flag, first_blue = 0, 0
            elif card_type == CARD_SHRINE_PURPLE:
                if first_purple:
                    first_flag, first_purple = 0, 0
        # 抽卡并扣道具或者钻石
        items_return      = []
        card_fellow_ids   = [] # 抽卡抽到的fellow
        msg_fellow_ids    = [] # 走马灯公告的fellow
        cost_credits      = 0  # 主要是处理十连抽
        max_shrine_level  = get_randcard_max_level( card_type )
        for i in range(0, rand_times):
            res_err, card = self.randcard_frompool( pool )
            if res_err:
                defer.returnValue( res_err )
            # 消耗道具或者钻石
            if (_consume['ItemType'] == ITEM_TYPE_MONEY):
                if need_time > 0:
                    cost_credits += _consume['ItemNum']
            elif (_consume['ItemType'] == ITEM_TYPE_ITEM): 
                res_err, used_attribs = yield self.user.bag_item_mgr.use( _consume['ItemID'], 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] )
            card_fellow_ids.append( card['ItemId'] )
            # 更新抽得紫卡的时间
            conf = get_fellow_by_fid( card['ItemId'] )
            if conf and conf['Quality'] == QUALITY_PURPLE:
                msg_fellow_ids.append( card['ItemId'] )
                last_purple_time = int(time())
            # 更新玩家的shrine数据, 含rand_count, shrine_level, 及shrine升级后更新pool
            shrine_level, rand_count, last_free_time = self.update_shrine( card_type, max_shrine_level, shrine_level, rand_count, last_free_time, _consume['FreeTime'] )
            need_time = self.left_free_timestamp( last_free_time, _consume['FreeTime'] )
            # 获取抽卡池
            pool = self.get_randcard_pool( card_type, shrine_level, rand_count, need_time, last_purple_time, first_flag )
        # 保存redis data
        yield redis.hset(HASH_SHRINE_TYPE % card_type, self.cid, dumps((shrine_level, rand_count, last_free_time, last_purple_time, first_blue, first_purple)))
        #log.info('For Test. rand fellow_ids: {0}.'.format( card_fellow_ids ))
        # 抽卡类型 用于广播、syslogger
        if card_type    == CARD_SHRINE_GREEN:
            _type_name  = RANDCARD_TYPE_GREEN
            _way_name   = WAY_RANDCARD_ITEM
        elif card_type  == CARD_SHRINE_BLUE:
            _type_name  = RANDCARD_TYPE_BLUE
            _way_name   = WAY_RANDCARD_BLUE
        elif rand_times == 10:
            _type_name  = RANDCARD_TYPE_TEN
            _way_name   = WAY_RANDCARD_TEN
        else:
            _type_name  = RANDCARD_TYPE_PURPLE
            _way_name   = WAY_RANDCARD_PURPLE

        if cost_credits:
            # 十连抽时打折
            if rand_times > 1:
                cost_credits = int((cost_credits * RANDCARD_TEN_RATIO + 99) / 100)
                msg = [12, [self.user.nick_name, self.user.lead_id]]
                gw_broadcast('sync_broadcast',[[3, msg]] )
            yield self.user.consume_credits( cost_credits, _way_name )
        # 新增fellow
        new_fellows = []
        for _id in card_fellow_ids:
            try:
                # args: fellow_id, is_major, camp_id, on_troop
                res_err, attrib = yield self.user.fellow_mgr.create_table_data( _id, 0, 0, 0 )
                if not res_err:
                    new_fellows.append( [attrib.attrib_id, _id] )
                    conf = get_fellow_by_fid( _id )
                    if conf:
                        syslogger(LOG_FELLOW_GET, self.cid, self.user.level, self.user.vip_level, self.user.alliance_id, attrib.attrib_id, _id, conf['QualityLevel'], conf['Star'], _way_name, '')
            except Exception as e:
                log.warn('Create fellow fail! e:', e)
                defer.returnValue(res_err)
        # 情缘抽到紫卡, 全服广播
        if msg_fellow_ids:
            message = [RORATE_MESSAGE_ACHIEVE, [ACHIEVE_TYPE_RANDCARD, [self.user.base_att.nick_name, _type_name, msg_fellow_ids]]]
            gw_broadcast('sync_broadcast', [message])

        for _item in items_return:
            syslogger(LOG_ITEM_LOSE, self.cid, self.user.level, self.user.vip_level, self.user.alliance_id, _item[0], _item[2], 1, WAY_RANDCARD_ITEM)

        status = yield self.status()
        yield self.user.daily_quest_mgr.update_daily_quest( DAILY_QUEST_ID_16, 1)
        defer.returnValue( (self.user.base_att.credits, new_fellows, status[0], status[1], status[2], status[3], items_return) )
Esempio n. 11
0
    def advanced(self, user_fellow_id):
        ''' 伙伴进阶 '''
        attrib = self.__gsattribs.get( user_fellow_id, None )
        if not attrib:
            log.error('Unknown user fellow id. ufid: {0}.'.format( user_fellow_id ))
            defer.returnValue( UNKNOWN_FELLOW_ERROR )

        # 主角进阶时取sysconfig['character']的config
        if attrib.is_major > 0:
            conf      = get_character_by_leadid( self.user.base_att.lead_id )
            fellow_id = self.user.base_att.lead_id
            attrib.level = self.user.base_att.level
        else:
            conf      = get_fellow_by_fid( attrib.fellow_id )
            fellow_id = attrib.fellow_id

        if not conf:
            log.error('Can not find the conf. ufid: {0}.'.format( user_fellow_id ))
            defer.returnValue( NOT_FOUND_CONF )

        # 可进阶次数限制
        if attrib.advanced_level >= conf['AdvancedCount']:
            log.error('Fellow advanced count limit. max count: {0}.'.format( conf['AdvancedCount'] ))
            defer.returnValue( ADVANCED_MAX_COUNT )

        advanced_conf = get_fellow_advanced( fellow_id, attrib.advanced_level+1 )
        if not advanced_conf:
            log.error('Can not find advanced conf. user_fellow_id: {0}.'.format( user_fellow_id ))
            defer.returnValue( NOT_FOUND_CONF )
        # 进阶时的伙伴等级限制
        if advanced_conf['FellowLevelLimit'] > attrib.level:
            log.error('fellow level limit. user_fellow_id: {0}, need >= {1}, cur: {2}.'.format( user_fellow_id, advanced_conf['FellowLevelLimit'], attrib.level ))
            defer.returnValue( REQUEST_LIMIT_ERROR )
        # 金币不足
        if advanced_conf['Gold'] > self.user.base_att.golds:
            log.error('Advanced need golds: {0}, cur golds: {1}.'.format( advanced_conf['Gold'], self.user.base_att.golds ))
            defer.returnValue( CHAR_GOLD_NOT_ENOUGH )
        # 进阶消耗的道具不足, 含消耗伙伴
        items_list = split_items( advanced_conf['ItemList'] )
        for _type, _id, _num in items_list:
            if _type == ITEM_TYPE_ITEM:
                total_num, item_attribs = yield self.user.bag_item_mgr.get_items( _id )
                if _num > total_num:
                    log.error('item id: {0}, need num: {1}, cur num: {2}.'.format( _id, _num, total_num ))
                    defer.returnValue( CHAR_ITEM_NOT_ENOUGH )
            elif _type == ITEM_TYPE_FELLOW:
                total_num, _ = self.get_fellows_by_fid( _id, user_fellow_id )
                if _num > total_num:
                    log.error('Item id: {0}, need num: {1}, cur_num: {2}.'.format( _id, _num, total_num ))
                    defer.returnValue( FELLOW_NOT_ENOUGH )
            else:
                log.error('Unknown advanced item. item: {0}.'.format( (_type, _id, _num) ))
                defer.returnValue( UNKNOWN_ITEM_ERROR )

        # 扣金币、扣道具
        #self.user.base_att.golds -= advanced_conf['Gold']
        self.user.consume_golds( advanced_conf['Gold'], WAY_FELLOW_REFINE )
        items_return = []
        for _type, _id, _num in items_list:
            if _type == ITEM_TYPE_ITEM:
                res_err, used_attribs = yield self.user.bag_item_mgr.use( _id, _num )
                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, _type, _id, _a.item_num] )
            elif _type == ITEM_TYPE_FELLOW:
                total_num, used_attribs = self.get_fellows_by_fid( _id, user_fellow_id )
                for _a in used_attribs[:_num]:
                    self.delete_table_data( _a.attrib_id )
                    items_return.append( [_a.attrib_id, _type, _id, 0] )
        # add syslog
        syslogger(LOG_FELLOW_REFINE, self.cid, self.user.level, self.user.vip_level, self.user.alliance_id, user_fellow_id, \
                attrib.fellow_id, attrib.advanced_level, attrib.advanced_level+1, '')

        # 进阶后的属性提高
        attrib.advanced_level += 1

        # 已上阵的伙伴或主角强化 同步camp到redis
        #if attrib.on_troop > 0 or attrib.is_major > 0:
        #    yield self.user.sync_camp_to_redis(update=True)

        # 走马灯的成就广播之神将进阶到+5以上, 神将不含主角
        if (attrib.advanced_level > 4):
            message = [RORATE_MESSAGE_ACHIEVE, [ACHIEVE_TYPE_ADVANCED, [self.user.base_att.nick_name, attrib.fellow_id, attrib.advanced_level]]]
            gw_broadcast('sync_broadcast', [message])
 
        defer.returnValue( (user_fellow_id, attrib.advanced_level, self.user.base_att.golds, items_return) )
Esempio n. 12
0
    def strengthen_by_soul(self, user_fellow_id, upgrade_info):
        ''' 
        @summary: 仙魂强化 1仙魂=1经验,扣1金币
        @param  : upgrade_soul_type-1:仙魂普通强化; 2:仙魂自动强化
        '''
        yield self._load()
        [ upgrade_soul_type ] = upgrade_info

        attrib = self.__gsattribs.get( user_fellow_id, None )
        if not attrib:
            log.error('Unknown user fellow id. ufid: {0}.'.format( user_fellow_id ))
            defer.returnValue( UNKNOWN_FELLOW_ERROR )

        conf = get_fellow_by_fid( attrib.fellow_id )
        if not conf:
            log.error('Can not find the conf. fellow_id: {0}.'.format( attrib.fellow_id ))
            defer.returnValue( NOT_FOUND_CONF )

        last_level, last_exp = attrib.level, attrib.exp
        user_soul, user_golds, user_level = self.user.base_att.soul, self.user.base_att.golds, self.user.base_att.level

        _count = 1
        _flag  = True
        while _flag:
            _roleexp_conf = get_roleexp_by_level( last_level )
            _need_exp     = _roleexp_conf.get( FELLOW_QUALITY[conf['Quality']], 0 )
            if not _need_exp:
                log.error("Can not find the roleexp's conf. cur_level: {0}.".format( attrib.level ))
                defer.returnValue( NOT_FOUND_CONF )

            _need_soul    = (_need_exp - last_exp) if (last_exp < _need_exp) else 0
            if _count == 1: # 第一次条件不满足时, 返回错误
                if (user_soul < _need_soul):
                    defer.returnValue( CHAR_SOUL_NOT_ENOUGH )
                if (user_golds < _need_soul):
                    defer.returnValue( CHAR_GOLD_NOT_ENOUGH )
                if (user_level <= last_level):
                    defer.returnValue( CHAR_LEVEL_LIMIT )
            # 仙魂不足, 金币不足, 等级已到上限
            if (user_soul < _need_soul) or (user_golds < _need_soul) or (user_level <= last_level):
                break
            _count     += 1
            last_level += 1
            last_exp    = 0 if (last_exp < _need_exp) else (last_exp - _need_exp)

            user_soul   -= _need_soul
            user_golds  -= _need_soul
            if 1 == upgrade_soul_type: # 普通强化
                _flag = False

        syslogger(LOG_FELLOW_STRENGTHEN, self.cid, self.user.level, self.user.vip_level, self.user.alliance_id, user_fellow_id, \
                attrib.fellow_id, attrib.level, last_level, WAY_FELLOW_SOUL_STRENGTHEN, str((self.user.base_att.soul - user_soul)))
        # 升级等级
        attrib.level, attrib.exp = last_level, last_exp
        # 已上阵的伙伴或主角强化 同步camp到redis
        #if attrib.on_troop > 0 or attrib.is_major > 0:
        #    yield self.user.sync_camp_to_redis(update=True)

        # 扣仙魂、金币
        self.user.base_att.soul  = user_soul
        #self.user.base_att.golds = user_golds
        if user_golds != self.user.base_att.golds:
            self.user.consume_golds( self.user.base_att.golds-user_golds, WAY_FELLOW_SOUL_STRENGTHEN )
 
        defer.returnValue( [user_fellow_id, attrib.fellow_id, attrib.level, attrib.exp, self.user.base_att.golds, self.user.base_att.soul] )
Esempio n. 13
0
    def strengthen_by_card(self, user_fellow_id, upgrade_info):
        '''
        @summary: fellow强化 紫品、已上阵的不能用于强化升级,经验可累积
        '''
        yield self._load()
        if len(upgrade_info) < 1 or len(upgrade_info) > 5:
            log.error('Strengthened fellow count error.')
            defer.returnValue( CLIENT_DATA_ERROR )

        attrib = self.__gsattribs.get( user_fellow_id, None )
        if not attrib:
            log.error('Unknown user fellow id. ufid: {0}.'.format( user_fellow_id ))
            defer.returnValue( UNKNOWN_FELLOW_ERROR )
        conf = get_fellow_by_fid( attrib.fellow_id )
        if not conf:
            log.error('Can not find the conf. fellow_id: {0}.'.format( attrib.fellow_id ))
            defer.returnValue( NOT_FOUND_CONF )
        if 1 == attrib.is_major or attrib.level >= self.user.base_att.level:
            log.error('Can not strengthen major fellow or max level limit.')
            defer.returnValue( LEVEL_UPGRADE_TARGET_INVALID )

        total_add_exp = 0
        used_ufids    = [] # 实际用于强化的user_fellow_id列表
        for _ufid in upgrade_info:
            used_attrib = self.__gsattribs.get( _ufid, None )
            if not used_attrib:
                log.error('Unknown user fellow id. ufid: {0}.'.format( _ufid ))
                defer.returnValue( UNKNOWN_FELLOW_ERROR )
            # 已上阵或主角不可作为强化的材料
            if used_attrib.on_troop > 0 or used_attrib.is_major > 0:
                log.error('Can not use the fellow to strengthen. _ufid: {0}.'.format( _ufid ))
                defer.returnValue( REQUEST_LIMIT_ERROR )
            used_conf = get_fellow_by_fid( used_attrib.fellow_id )
            if not used_conf:
                log.error('Can not find the conf. fellow_id: {0}.'.format( used_attrib.fellow_id ))
                defer.returnValue( NOT_FOUND_CONF )
            # 紫品不可作为强化的材料
            if QUALITY_PURPLE == used_conf['Quality']:
                log.error('Can not use purple fellow to strengthen. _ufid: {0}.'.format( _ufid ))
                defer.returnValue( REQUEST_LIMIT_ERROR )
            #log.info('For Test. total_add_exp: {0}.'.format( total_add_exp ))
            total_add_exp += (used_conf['Exp'] + used_attrib.exp)
            for _level in range(used_conf['Level'], used_attrib.level):
                _roleexp_conf = get_roleexp_by_level( _level )
                _level_exp = _roleexp_conf.get( FELLOW_QUALITY[used_conf['Quality']], 0 )
                #log.info('For Test. total_add_exp: {0}, _level_exp: {1}, _level: {2}, _quality: {3}.'.format( total_add_exp, _level_exp, _level, used_conf['Quality'] ))
                if _level_exp:
                    total_add_exp += _level_exp
            used_ufids.append( _ufid )
 
        consume_golds  = total_add_exp # 1 exp = 1 golds
        if consume_golds > self.user.base_att.golds:
            log.error('Strengthened need golds: {0}, cur golds: {1}.'.format( consume_golds, self.user.base_att.golds ))
            defer.returnValue( CHAR_GOLD_NOT_ENOUGH )
 
        # 扣金币
        #self.user.base_att.golds -= consume_golds
        self.user.consume_golds( consume_golds, WAY_FELLOW_STRENGTHEN )
        # 删除作为材料的fellow
        for _ufid in used_ufids:
            self.delete_table_data( _ufid )
            #used_attrib.delete()

        # 计算升级后的等级和经验
        total_add_exp += attrib.exp
        final_level, final_exp = self.cal_level_upgrade(self.user.base_att.level, conf['Quality'], total_add_exp, attrib.level)
        if final_level != attrib.level:
            syslogger(LOG_FELLOW_STRENGTHEN, self.cid, self.user.level, self.user.vip_level, self.user.alliance_id, user_fellow_id, \
                    attrib.fellow_id, attrib.level, final_level, WAY_FELLOW_STRENGTHEN, str(tuple(used_ufids)))
            attrib.level = final_level
            # 已上阵的伙伴或主角强化 同步camp到redis
            #if attrib.on_troop > 0 or attrib.is_major > 0:
            #    yield self.user.sync_camp_to_redis(update=True)

        if final_exp != attrib.exp:
            attrib.exp   = final_exp
        #成就
        yield self.user.achievement_mgr.update_achievement_status(ACHIEVEMENT_QUEST_ID_28, attrib.level)

        defer.returnValue( [user_fellow_id, attrib.fellow_id, attrib.level, attrib.exp, self.user.base_att.golds, self.user.base_att.soul] )
Esempio n. 14
0
    def randcard(self, card_type, rand_times):
        '''
        @return : err, credits, res_fellow_list
        '''
        res_err = REQUEST_LIMIT_ERROR

        shrine_data = yield redis.hget(HASH_SHRINE_TYPE % card_type, self.cid)
        if shrine_data:
            shrine_data = loads(shrine_data)
            if len(shrine_data) == 4:
                shrine_level, rand_count, last_free_time, last_purple_time = shrine_data
                first_blue, first_purple = 0, 0
            else:
                shrine_level, rand_count, last_free_time, last_purple_time, first_blue, first_purple = shrine_data
        else:
            shrine_level, rand_count, last_free_time, last_purple_time, first_blue, first_purple = 0, 0, 0, 0, 1, 1
        # 抽卡消耗的配置
        _consume = get_randcard_consume_conf(card_type)
        if not _consume:
            log.error('Can not find conf.')
            defer.returnValue(NOT_FOUND_CONF)

        # 距离下一场免费抽奖所需时间
        need_time = self.left_free_timestamp(last_free_time,
                                             _consume['FreeTime'])
        # 检查道具或钻石是否充足
        user_credits = self.user.base_att.credits
        if (_consume['ItemType'] == ITEM_TYPE_MONEY):
            _rand_cost = _consume['ItemNum'] * rand_times
            if rand_times > 1:
                # 无免费抽奖时所需钻石
                if (need_time > 0):
                    _rand_cost = int(
                        (_consume['ItemNum'] * 10 * RANDCARD_TEN_RATIO + 99) /
                        100)
                else:
                    _rand_cost = int(
                        (_consume['ItemNum'] * 9 * RANDCARD_TEN_RATIO + 99) /
                        100)

            # 无免费抽奖时钻石不足
            if (need_time > 0) and (_rand_cost > user_credits):
                log.error('Not enough credits. need: {0}, cur: {1}.'.format(
                    _rand_cost, user_credits))
                defer.returnValue(CHAR_CREDIT_NOT_ENOUGH)
            # 有免费抽奖且是十连抽时钻石不足
            elif 0 >= need_time and rand_times > 1 and (_rand_cost >
                                                        user_credits):
                log.error('Not enough credits. need: {0}, cur: {1}.'.format(
                    _rand_cost, user_credits))
                defer.returnValue(CHAR_CREDIT_NOT_ENOUGH)
        elif (_consume['ItemType'] == ITEM_TYPE_ITEM):
            total_num, item_attribs = yield self.user.bag_item_mgr.get_items(
                _consume['ItemID'])
            # 情缘令不足
            if (_consume['ItemNum'] * rand_times) > total_num:
                log.error('cur num: {0}.'.format(total_num))
                defer.returnValue(CHAR_ITEM_NOT_ENOUGH)
        else:
            log.error('Unknown item type: {0}.'.format(_consume['ItemType']))
            defer.returnValue(RANDCARD_TYPE_ERROR)
        # 获取抽卡池
        first_flag = 0
        if card_type == CARD_SHRINE_BLUE:
            first_flag = first_blue
        elif card_type == CARD_SHRINE_PURPLE:
            first_flag = first_purple
        pool = self.get_randcard_pool(card_type, shrine_level, rand_count,
                                      need_time, last_purple_time, first_flag)
        if not pool:
            defer.returnValue(NOT_FOUND_CONF)
        # 无免费抽卡时更新状态位
        if need_time > 0 or (0 >= need_time and rand_times > 1):
            if card_type == CARD_SHRINE_BLUE:
                if first_blue:
                    first_flag, first_blue = 0, 0
            elif card_type == CARD_SHRINE_PURPLE:
                if first_purple:
                    first_flag, first_purple = 0, 0
        # 抽卡并扣道具或者钻石
        items_return = []
        card_fellow_ids = []  # 抽卡抽到的fellow
        msg_fellow_ids = []  # 走马灯公告的fellow
        cost_credits = 0  # 主要是处理十连抽
        max_shrine_level = get_randcard_max_level(card_type)
        for i in range(0, rand_times):
            res_err, card = self.randcard_frompool(pool)
            if res_err:
                defer.returnValue(res_err)
            # 消耗道具或者钻石
            if (_consume['ItemType'] == ITEM_TYPE_MONEY):
                if need_time > 0:
                    cost_credits += _consume['ItemNum']
            elif (_consume['ItemType'] == ITEM_TYPE_ITEM):
                res_err, used_attribs = yield self.user.bag_item_mgr.use(
                    _consume['ItemID'], 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])
            card_fellow_ids.append(card['ItemId'])
            # 更新抽得紫卡的时间
            conf = get_fellow_by_fid(card['ItemId'])
            if conf and conf['Quality'] == QUALITY_PURPLE:
                msg_fellow_ids.append(card['ItemId'])
                last_purple_time = int(time())
            # 更新玩家的shrine数据, 含rand_count, shrine_level, 及shrine升级后更新pool
            shrine_level, rand_count, last_free_time = self.update_shrine(
                card_type, max_shrine_level, shrine_level, rand_count,
                last_free_time, _consume['FreeTime'])
            need_time = self.left_free_timestamp(last_free_time,
                                                 _consume['FreeTime'])
            # 获取抽卡池
            pool = self.get_randcard_pool(card_type, shrine_level, rand_count,
                                          need_time, last_purple_time,
                                          first_flag)
        # 保存redis data
        yield redis.hset(
            HASH_SHRINE_TYPE % card_type, self.cid,
            dumps((shrine_level, rand_count, last_free_time, last_purple_time,
                   first_blue, first_purple)))
        #log.info('For Test. rand fellow_ids: {0}.'.format( card_fellow_ids ))
        # 抽卡类型 用于广播、syslogger
        if card_type == CARD_SHRINE_GREEN:
            _type_name = RANDCARD_TYPE_GREEN
            _way_name = WAY_RANDCARD_ITEM
        elif card_type == CARD_SHRINE_BLUE:
            _type_name = RANDCARD_TYPE_BLUE
            _way_name = WAY_RANDCARD_BLUE
        elif rand_times == 10:
            _type_name = RANDCARD_TYPE_TEN
            _way_name = WAY_RANDCARD_TEN
        else:
            _type_name = RANDCARD_TYPE_PURPLE
            _way_name = WAY_RANDCARD_PURPLE

        if cost_credits:
            # 十连抽时打折
            if rand_times > 1:
                cost_credits = int(
                    (cost_credits * RANDCARD_TEN_RATIO + 99) / 100)
                msg = [12, [self.user.nick_name, self.user.lead_id]]
                gw_broadcast('sync_broadcast', [[3, msg]])
            yield self.user.consume_credits(cost_credits, _way_name)
        # 新增fellow
        new_fellows = []
        for _id in card_fellow_ids:
            try:
                # args: fellow_id, is_major, camp_id, on_troop
                res_err, attrib = yield self.user.fellow_mgr.create_table_data(
                    _id, 0, 0, 0)
                if not res_err:
                    new_fellows.append([attrib.attrib_id, _id])
                    conf = get_fellow_by_fid(_id)
                    if conf:
                        syslogger(LOG_FELLOW_GET, self.cid, self.user.level,
                                  self.user.vip_level, self.user.alliance_id,
                                  attrib.attrib_id, _id, conf['QualityLevel'],
                                  conf['Star'], _way_name, '')
            except Exception as e:
                log.warn('Create fellow fail! e:', e)
                defer.returnValue(res_err)
        # 情缘抽到紫卡, 全服广播
        if msg_fellow_ids:
            message = [
                RORATE_MESSAGE_ACHIEVE,
                [
                    ACHIEVE_TYPE_RANDCARD,
                    [self.user.base_att.nick_name, _type_name, msg_fellow_ids]
                ]
            ]
            gw_broadcast('sync_broadcast', [message])

        for _item in items_return:
            syslogger(LOG_ITEM_LOSE, self.cid, self.user.level,
                      self.user.vip_level, self.user.alliance_id, _item[0],
                      _item[2], 1, WAY_RANDCARD_ITEM)

        status = yield self.status()
        yield self.user.daily_quest_mgr.update_daily_quest(
            DAILY_QUEST_ID_16, 1)
        defer.returnValue((self.user.base_att.credits, new_fellows, status[0],
                           status[1], status[2], status[3], items_return))
Esempio n. 15
0
    def strengthen_by_card(self, user_fellow_id, upgrade_info):
        '''
        @summary: fellow强化 紫品、已上阵的不能用于强化升级,经验可累积
        '''
        yield self._load()
        if len(upgrade_info) < 1 or len(upgrade_info) > 5:
            log.error('Strengthened fellow count error.')
            defer.returnValue(CLIENT_DATA_ERROR)

        attrib = self.__gsattribs.get(user_fellow_id, None)
        if not attrib:
            log.error(
                'Unknown user fellow id. ufid: {0}.'.format(user_fellow_id))
            defer.returnValue(UNKNOWN_FELLOW_ERROR)
        conf = get_fellow_by_fid(attrib.fellow_id)
        if not conf:
            log.error('Can not find the conf. fellow_id: {0}.'.format(
                attrib.fellow_id))
            defer.returnValue(NOT_FOUND_CONF)
        if 1 == attrib.is_major or attrib.level >= self.user.base_att.level:
            log.error('Can not strengthen major fellow or max level limit.')
            defer.returnValue(LEVEL_UPGRADE_TARGET_INVALID)

        total_add_exp = 0
        used_ufids = []  # 实际用于强化的user_fellow_id列表
        for _ufid in upgrade_info:
            used_attrib = self.__gsattribs.get(_ufid, None)
            if not used_attrib:
                log.error('Unknown user fellow id. ufid: {0}.'.format(_ufid))
                defer.returnValue(UNKNOWN_FELLOW_ERROR)
            # 已上阵或主角不可作为强化的材料
            if used_attrib.on_troop > 0 or used_attrib.is_major > 0:
                log.error(
                    'Can not use the fellow to strengthen. _ufid: {0}.'.format(
                        _ufid))
                defer.returnValue(REQUEST_LIMIT_ERROR)
            used_conf = get_fellow_by_fid(used_attrib.fellow_id)
            if not used_conf:
                log.error('Can not find the conf. fellow_id: {0}.'.format(
                    used_attrib.fellow_id))
                defer.returnValue(NOT_FOUND_CONF)
            # 紫品不可作为强化的材料
            if QUALITY_PURPLE == used_conf['Quality']:
                log.error(
                    'Can not use purple fellow to strengthen. _ufid: {0}.'.
                    format(_ufid))
                defer.returnValue(REQUEST_LIMIT_ERROR)
            #log.info('For Test. total_add_exp: {0}.'.format( total_add_exp ))
            total_add_exp += (used_conf['Exp'] + used_attrib.exp)
            for _level in range(used_conf['Level'], used_attrib.level):
                _roleexp_conf = get_roleexp_by_level(_level)
                _level_exp = _roleexp_conf.get(
                    FELLOW_QUALITY[used_conf['Quality']], 0)
                #log.info('For Test. total_add_exp: {0}, _level_exp: {1}, _level: {2}, _quality: {3}.'.format( total_add_exp, _level_exp, _level, used_conf['Quality'] ))
                if _level_exp:
                    total_add_exp += _level_exp
            used_ufids.append(_ufid)

        consume_golds = total_add_exp  # 1 exp = 1 golds
        if consume_golds > self.user.base_att.golds:
            log.error('Strengthened need golds: {0}, cur golds: {1}.'.format(
                consume_golds, self.user.base_att.golds))
            defer.returnValue(CHAR_GOLD_NOT_ENOUGH)

        # 扣金币
        #self.user.base_att.golds -= consume_golds
        self.user.consume_golds(consume_golds, WAY_FELLOW_STRENGTHEN)
        # 删除作为材料的fellow
        for _ufid in used_ufids:
            self.delete_table_data(_ufid)
            #used_attrib.delete()

        # 计算升级后的等级和经验
        total_add_exp += attrib.exp
        final_level, final_exp = self.cal_level_upgrade(
            self.user.base_att.level, conf['Quality'], total_add_exp,
            attrib.level)
        if final_level != attrib.level:
            syslogger(LOG_FELLOW_STRENGTHEN, self.cid, self.user.level, self.user.vip_level, self.user.alliance_id, user_fellow_id, \
                    attrib.fellow_id, attrib.level, final_level, WAY_FELLOW_STRENGTHEN, str(tuple(used_ufids)))
            attrib.level = final_level
            # 已上阵的伙伴或主角强化 同步camp到redis
            #if attrib.on_troop > 0 or attrib.is_major > 0:
            #    yield self.user.sync_camp_to_redis(update=True)

        if final_exp != attrib.exp:
            attrib.exp = final_exp
        #成就
        yield self.user.achievement_mgr.update_achievement_status(
            ACHIEVEMENT_QUEST_ID_28, attrib.level)

        defer.returnValue([
            user_fellow_id, attrib.fellow_id, attrib.level, attrib.exp,
            self.user.base_att.golds, self.user.base_att.soul
        ])
Esempio n. 16
0
    def randcard(self, rand_type):
        ''' 免费抽卡、钻石抽卡 '''
        _status, _data = yield self.status()
        if _status < 0:
            defer.returnValue( LIMIT_FELLOW_NO_ERROR )
        _need_time = self.left_free_timestamp( _data[3], LIMIT_FELLOW_FREE_TIME )
        _last_time = _data[3]
        # 检查抽卡条件是否满足
        _score = yield redis.zscore( SET_LIMIT_FELLOW_NAME_SCORE, self.user.nick_name )
        _score = int(_score) if _score else 0
        _cost_flag = True # 扣钻石的标识位
        if rand_type == RANDCARD_TYPE_FREE:
            if _need_time > 0:
                defer.returnValue( LIMIT_FELLOW_FREE_ERROR )
            else:
                _last_time = int(time())
                _cost_flag = False
                _need_time = LIMIT_FELLOW_FREE_TIME
        else:
            # 某积分的整数倍时免费钻石抽卡
            if not _score or _score%RAND_COST_FREE_SCORE != 0:
                if self.user.credits < LIMIT_FELLOW_RAND_COST:
                    defer.returnValue( CHAR_CREDIT_NOT_ENOUGH )
            else:
                _cost_flag = False
        # 卡池升级
        res_err, shrine_data = self.update_shrine(_data[1], _data[2])
        if res_err:
            defer.returnValue( res_err )
        #log.info('For Test. shrine_data: {0}, redis_data: {1}.'.format( shrine_data, _data ))
        # 获取抽卡池并抽卡
        card_conf = self.get_randcard_frompool(_data[1], shrine_data[3]-_data[2])
        if not card_conf:
            defer.returnValue( NOT_FOUND_CONF )

        # 更新免费时间或扣钻石
        yield redis.hset( HASH_LIMIT_FELLOW_SHRINE, self.cid, dumps([_data[0], shrine_data[0], shrine_data[1], _last_time]) )
        if _cost_flag:
            yield self.user.consume_credits( LIMIT_FELLOW_RAND_COST, WAY_LIMIT_FELLOW_RANDCARD )
        _score += RANDCARD_ONCE_SCORE
        yield redis.zadd( SET_LIMIT_FELLOW_NAME_SCORE, self.user.nick_name, _score )
        # 新增fellow
        try:
            # args: fellow_id, is_major, camp_id, on_troop
            new_fellow = []
            fellow_id  = card_conf['ItemId']
            res_err, attrib = yield self.user.fellow_mgr.create_table_data( fellow_id, 0, 0, 0 )
            if not res_err:
                new_fellow = [attrib.attrib_id, fellow_id]
                conf = get_fellow_by_fid( fellow_id )
                if conf and conf['Quality'] == QUALITY_PURPLE:
                    syslogger(LOG_FELLOW_GET, self.cid, self.user.level, self.user.vip_level, self.user.alliance_id, \
                            attrib.attrib_id, fellow_id, conf['QualityLevel'], conf['Star'], RANDCARD_TYPE_CREDITS, '')
                    message = [RORATE_MESSAGE_ACHIEVE, [ACHIEVE_TYPE_LIMIT_FELLOW, [self.user.nick_name, fellow_id]]]
                    gw_broadcast('sync_broadcast', [message])
        except Exception as e:
            log.warn('Create fellow fail! e:', e)
            defer.returnValue(res_err)

        _rank  = yield redis.zrevrank( SET_LIMIT_FELLOW_NAME_SCORE, self.user.nick_name )
        _rank  = int(_rank) + 1 if _rank >= 0 else 0
        _ranklist = yield self.ranklist()
        defer.returnValue( [self.user.credits, _rank, _score, _need_time, shrine_data[2], _ranklist, new_fellow] )
Esempio n. 17
0
    def camp_randcard(self, camp_id):
        ''' 阵营抽卡 '''
        _, curr_camp_data, next_camp_data = yield self.get_campcard_data()
        # 检查阵营, 累计次数
        rand_time = 0
        for _idx, _data in enumerate(curr_camp_data):
            if _data[0] == camp_id:
                if _data[1] >= CAMP_RAND_MAX:
                    defer.returnValue(CAMP_RANDCARD_MAX_LIMIT)
                _data[1] += 1
                rand_time = _data[1]
                curr_camp_data[_idx] = _data
                break
        else:
            defer.returnValue(CAMP_RANDCARD_ID_ERROR)
        # 随机伙伴
        need_credits = get_campcard_cost_conf(rand_time)
        if not need_credits or need_credits > self.user.credits:
            log.error(
                'Credits not enough. cid:{0}, need:{1}, curr: {2}.'.format(
                    self.cid, need_credits, self.user.credits))
            defer.returnValue(CHAR_CREDIT_NOT_ENOUGH)

        pool_conf = get_campcard_pool_conf(camp_id, rand_time)
        res_err, card = self.randcard_frompool(pool_conf)
        if res_err:
            log.error(
                'No camp randcard pool. cid:{0}, camp_id:{1}, rand_time:{2}.'.
                format(self.cid, camp_id, rand_time))
            defer.returnValue(res_err)
        # 扣钻石
        yield self.user.consume_credits(need_credits, WAY_CAMP_RANDCARD)
        # 更新抽卡次数
        yield redis.hset(HASH_CAMPRAND_COMMON, self.cid,
                         dumps([int(time()), curr_camp_data, next_camp_data]))
        # 新增伙伴
        try:
            new_fellows = []
            # args: fellow_id, is_major, camp_id, on_troop
            res_err, attrib = yield self.user.fellow_mgr.create_table_data(
                card['ItemID'], 0, 0, 0)
            if not res_err:
                new_fellows.append([attrib.attrib_id, card['ItemID']])
                conf = get_fellow_by_fid(card['ItemID'])
                if conf:
                    syslogger(LOG_FELLOW_GET, self.cid, self.user.level,
                              self.user.vip_level, self.user.alliance_id,
                              attrib.attrib_id, card['ItemID'],
                              conf['QualityLevel'], conf['Star'],
                              WAY_CAMP_RANDCARD, '')
        except Exception as e:
            log.warn('Create fellow fail! e:', e)
            defer.returnValue(res_err)
        # 阵营抽卡抽到紫卡, 全服广播
        if card['Notice']:
            message = [
                RORATE_MESSAGE_ACHIEVE,
                [
                    ACHIEVE_TYPE_RANDCARD,
                    [
                        self.user.nick_name, RANDCARD_TYPE_CAMP,
                        [card['ItemID']]
                    ]
                ]
            ]
            gw_broadcast('sync_broadcast', [message])

        yield self.user.daily_quest_mgr.update_daily_quest(
            DAILY_QUEST_ID_16, 1)

        defer.returnValue((self.user.credits, rand_time, new_fellows))
Esempio n. 18
0
    def fellow_reborn(self, user_fellow_id):
        ''' 
        @summary: 伙伴重生 
            (1) 已上阵 或 未进阶的伙伴 不能重生
            (2) 重生后,进阶等级和强化等级清零, 全额返还该伙伴进阶消耗的道具总数和强化消耗的仙魂、金币, 
            (3) 进阶消耗的金币不返还
        '''
        attrib = self.user.fellow_mgr.get_fellow( user_fellow_id )
        if not attrib:
            log.error('Can not find user fellow. user_fellow_id: {0}.'.format( user_fellow_id ))
            defer.returnValue( UNKNOWN_FELLOW_ERROR )

        fellow_conf = get_fellow_by_fid( attrib.fellow_id )
        if not fellow_conf:
            log.error('Can not find fellow conf. fellow id: {0}.'.format( attrib.fellow_id ))
            defer.returnValue( NOT_FOUND_CONF )

        # 已上阵 或 未进阶的伙伴 不可重生
        if attrib.camp_id > 0 or attrib.advanced_level == 0:
            log.error('Fellow advanced level or camp id error. ufid: {0}, ad_lvl: {1}, camp id: {2}.'.format( user_fellow_id, attrib.advanced_level, attrib.camp_id ))
            defer.returnValue( FELLOW_REBORN_ERROR )

        # 判断钻石消耗
        reborn_conf = get_fellow_reborn_conf( fellow_conf['QualityLevel'], attrib.advanced_level )
        if not reborn_conf:
            log.error('Unknown reborn conf. qLevel: {0}, ad_level: {1}.'.format( fellow_conf['QualityLevel'], attrib.advanced_level ))
            defer.returnValue( NOT_FOUND_CONF )
        # 玩家钻石不足
        if self.user.base_att.credits < reborn_conf['Cost']:
            log.error('Need credits: {0}, cur credits: {1}.'.format( reborn_conf['Cost'], self.user.base_att.credits ))
            defer.returnValue( CHAR_CREDIT_NOT_ENOUGH )
        # 扣钻石
        #self.user.base_att.credits -= reborn_conf['Cost']
        if reborn_conf['Cost']:
            yield self.user.consume_credits( reborn_conf['Cost'], WAY_FELLOW_REBORN )
        # 返还仙魂、金币
        extra_exp   = fellow_conf['Exp'] + attrib.exp
        quality     = fellow_conf['Quality']
        # 返还伙伴强化消耗的经验
        for _level in range(fellow_conf['Level'], attrib.level):
            _conf = get_roleexp_by_level( _level )
            _exp  = _conf.get( FELLOW_QUALITY[quality], 0 )
            if not _exp:
                continue
            extra_exp += _exp
        # 增加1点经验, 需要消耗1个金币,  每1点仙魂, 可以增加1点经验
        #self.user.base_att.golds += extra_exp
        self.user.get_golds( extra_exp, WAY_FELLOW_REBORN )
        self.user.base_att.soul  += extra_exp

        # 返还伙伴进阶消耗的道具
        items_list = []
        for _a_level in range(1, attrib.advanced_level+1):
            advanced_conf = get_fellow_advanced( attrib.fellow_id, _a_level )
            if not advanced_conf:
                log.error('Can not find fellow advanced conf. fellow id: {0}, advanced_level: {1}.'.format( attrib.fellow_id, _a_level ))
                continue
            _list = split_items( advanced_conf['ItemList'] )
            for _l in _list:
                items_list = add_new_items( _l, items_list )
        #log.info('For Test. refine_level: {0}, items_list: {1}.'.format( attrib.advanced_level, items_list ))

        items_return = []
        for _type, _id, _num in items_list:
            # 货币类型特殊处理
            if _type == ITEM_TYPE_MONEY:
                continue
            model = ITEM_MODELs.get( _type, None )
            if not model:
                log.error('Unknown reborn item type. item type: {0}.'.format( _type ))
                continue
            res_err, res_value = yield model(self.user, ItemID=_id, ItemNum=_num, AddType=WAY_FELLOW_REBORN, CapacityFlag=False)
            if not res_err:
                for _v in res_value:
                    items_return = total_new_items(_v, items_return)
        # 进阶等级和强化等级、经验清零
        attrib.level = fellow_conf['Level']
        attrib.exp, attrib.advanced_level = 0, 0
        if extra_exp > 0:
            items_return.append( [0, ITEM_TYPE_MONEY, ITEM_MONEY_GOLDS, extra_exp] )
            items_return.append( [0, ITEM_TYPE_MONEY, ITEM_MONEY_SOUL, extra_exp] )

        defer.returnValue( (self.user.base_att.credits, items_return) )
Esempio n. 19
0
    def fellow_decomposition(self, user_fellow_ids):
        ''' 
        @summary: 伙伴炼化 
            (1) 已上阵 或 进阶等级大于0的不可炼化, 需要先重生
            (2) 炼化产出道具, 读sysconfig['fellow_decomposition'], 返还金币, 仙魂, 魂玉
            (3) 读sysconfig['roleexp'], 返还强化消耗的经验
            (4) 1点经验=1个金币,  1点经验=1点仙魂, 返还金币、仙魂
            (4) 删除用于炼化的材料, 即伙伴
        '''
        for _ufid in user_fellow_ids:
            attrib = self.user.fellow_mgr.get_fellow( _ufid )
            if not attrib:
                log.error('Can not find user fellow. user_fellow_id: {0}.'.format( _ufid ))
                return UNKNOWN_FELLOW_ERROR
                #defer.returnValue( UNKNOWN_FELLOW_ERROR )
            # 已上阵 或 进阶等级大于0的不可炼化, 需要先重生
            if attrib.camp_id > 0 or attrib.advanced_level > 0:
                log.error('Fellow advanced level error. ufid: {0}, camp_id: {1}, ad_lvl: {2}.'.format( _ufid, attrib.camp_id, attrib.advanced_level ))
                return FELLOW_DECOMPOSITION_ERROR
            fellow_conf = get_fellow_by_fid( attrib.fellow_id )
            if not fellow_conf:
                log.error('Can not find fellow conf. fellow id: {0}.'.format( attrib.fellow_id ))
                return NOT_FOUND_CONF
                #defer.returnValue( NOT_FOUND_CONF )

        total_golds, total_soul, total_hunyu = 0, 0, 0
        for _ufid in user_fellow_ids:
            attrib = self.user.fellow_mgr.get_fellow( _ufid )
            if not attrib:
                log.error('Unknown fellow. _ufid: {0}.'.format( _ufid ))
                continue
            fellow_conf = get_fellow_by_fid( attrib.fellow_id )
            # 炼化产出道具
            decomposition_conf = get_fellow_decomposition( fellow_conf['QualityLevel'] )
            if decomposition_conf:
                items_list = split_items( decomposition_conf['ItemList'] )
                for _type, _id, _num in items_list:
                    if _type != ITEM_TYPE_MONEY:
                        log.error('Unknown decomposition item type. item type: {0}.'.format( _type ))
                        continue
                    if _id == ITEM_MONEY_GOLDS:
                        total_golds += _num
                    elif _id == ITEM_MONEY_SOUL:
                        total_soul  += _num
                    elif _id == ITEM_MONEY_HUNYU:
                        total_hunyu += _num

            # 删除用于炼化的fellow
            self.user.fellow_mgr.delete_table_data( _ufid )
            # add syslog
            syslogger(LOG_FELLOW_DECOMPOSITION, self.cid, self.user.level, self.user.vip_level, self.user.alliance_id, _ufid, attrib.fellow_id, fellow_conf['QualityLevel'], fellow_conf['Star'])

            # 返还仙魂、金币
            extra_exp   = fellow_conf['Exp'] + attrib.exp
            quality     = fellow_conf['Quality']
            # 返还伙伴强化消耗的经验
            for _level in range(fellow_conf['Level'], attrib.level):
                _conf = get_roleexp_by_level( _level )
                _exp  = _conf.get( FELLOW_QUALITY[quality], 0 )
                if not _exp:
                    continue
                extra_exp += _exp
            # 1点经验, 等于1个金币, 等于1点仙魂
            total_golds += extra_exp
            total_soul  += extra_exp

        # 返还仙魂、金币、魂玉
        items_return = []
        if total_golds > 0:
            self.user.base_att.golds += total_golds
            items_return.append( [0, ITEM_TYPE_MONEY, ITEM_MONEY_GOLDS, total_golds] )
        if total_soul > 0:
            self.user.base_att.soul  += total_soul 
            items_return.append( [0, ITEM_TYPE_MONEY, ITEM_MONEY_SOUL, total_soul] )
        if total_hunyu > 0:
            self.user.base_att.hunyu += total_hunyu
            items_return.append( [0, ITEM_TYPE_MONEY, ITEM_MONEY_HUNYU, total_hunyu] )
 
        return items_return
Esempio n. 20
0
    def strengthen_by_soul(self, user_fellow_id, upgrade_info):
        ''' 
        @summary: 仙魂强化 1仙魂=1经验,扣1金币
        @param  : upgrade_soul_type-1:仙魂普通强化; 2:仙魂自动强化
        '''
        yield self._load()
        [upgrade_soul_type] = upgrade_info

        attrib = self.__gsattribs.get(user_fellow_id, None)
        if not attrib:
            log.error(
                'Unknown user fellow id. ufid: {0}.'.format(user_fellow_id))
            defer.returnValue(UNKNOWN_FELLOW_ERROR)

        conf = get_fellow_by_fid(attrib.fellow_id)
        if not conf:
            log.error('Can not find the conf. fellow_id: {0}.'.format(
                attrib.fellow_id))
            defer.returnValue(NOT_FOUND_CONF)

        last_level, last_exp = attrib.level, attrib.exp
        user_soul, user_golds, user_level = self.user.base_att.soul, self.user.base_att.golds, self.user.base_att.level

        _count = 1
        _flag = True
        while _flag:
            _roleexp_conf = get_roleexp_by_level(last_level)
            _need_exp = _roleexp_conf.get(FELLOW_QUALITY[conf['Quality']], 0)
            if not _need_exp:
                log.error(
                    "Can not find the roleexp's conf. cur_level: {0}.".format(
                        attrib.level))
                defer.returnValue(NOT_FOUND_CONF)

            _need_soul = (_need_exp -
                          last_exp) if (last_exp < _need_exp) else 0
            if _count == 1:  # 第一次条件不满足时, 返回错误
                if (user_soul < _need_soul):
                    defer.returnValue(CHAR_SOUL_NOT_ENOUGH)
                if (user_golds < _need_soul):
                    defer.returnValue(CHAR_GOLD_NOT_ENOUGH)
                if (user_level <= last_level):
                    defer.returnValue(CHAR_LEVEL_LIMIT)
            # 仙魂不足, 金币不足, 等级已到上限
            if (user_soul < _need_soul) or (user_golds < _need_soul) or (
                    user_level <= last_level):
                break
            _count += 1
            last_level += 1
            last_exp = 0 if (last_exp < _need_exp) else (last_exp - _need_exp)

            user_soul -= _need_soul
            user_golds -= _need_soul
            if 1 == upgrade_soul_type:  # 普通强化
                _flag = False

        syslogger(LOG_FELLOW_STRENGTHEN, self.cid, self.user.level, self.user.vip_level, self.user.alliance_id, user_fellow_id, \
                attrib.fellow_id, attrib.level, last_level, WAY_FELLOW_SOUL_STRENGTHEN, str((self.user.base_att.soul - user_soul)))
        # 升级等级
        attrib.level, attrib.exp = last_level, last_exp
        # 已上阵的伙伴或主角强化 同步camp到redis
        #if attrib.on_troop > 0 or attrib.is_major > 0:
        #    yield self.user.sync_camp_to_redis(update=True)

        # 扣仙魂、金币
        self.user.base_att.soul = user_soul
        #self.user.base_att.golds = user_golds
        if user_golds != self.user.base_att.golds:
            self.user.consume_golds(self.user.base_att.golds - user_golds,
                                    WAY_FELLOW_SOUL_STRENGTHEN)

        defer.returnValue([
            user_fellow_id, attrib.fellow_id, attrib.level, attrib.exp,
            self.user.base_att.golds, self.user.base_att.soul
        ])
Esempio n. 21
0
    def advanced(self, user_fellow_id):
        ''' 伙伴进阶 '''
        attrib = self.__gsattribs.get(user_fellow_id, None)
        if not attrib:
            log.error(
                'Unknown user fellow id. ufid: {0}.'.format(user_fellow_id))
            defer.returnValue(UNKNOWN_FELLOW_ERROR)

        # 主角进阶时取sysconfig['character']的config
        if attrib.is_major > 0:
            conf = get_character_by_leadid(self.user.base_att.lead_id)
            fellow_id = self.user.base_att.lead_id
            attrib.level = self.user.base_att.level
        else:
            conf = get_fellow_by_fid(attrib.fellow_id)
            fellow_id = attrib.fellow_id

        if not conf:
            log.error(
                'Can not find the conf. ufid: {0}.'.format(user_fellow_id))
            defer.returnValue(NOT_FOUND_CONF)

        # 可进阶次数限制
        if attrib.advanced_level >= conf['AdvancedCount']:
            log.error('Fellow advanced count limit. max count: {0}.'.format(
                conf['AdvancedCount']))
            defer.returnValue(ADVANCED_MAX_COUNT)

        advanced_conf = get_fellow_advanced(fellow_id,
                                            attrib.advanced_level + 1)
        if not advanced_conf:
            log.error(
                'Can not find advanced conf. user_fellow_id: {0}.'.format(
                    user_fellow_id))
            defer.returnValue(NOT_FOUND_CONF)
        # 进阶时的伙伴等级限制
        if advanced_conf['FellowLevelLimit'] > attrib.level:
            log.error(
                'fellow level limit. user_fellow_id: {0}, need >= {1}, cur: {2}.'
                .format(user_fellow_id, advanced_conf['FellowLevelLimit'],
                        attrib.level))
            defer.returnValue(REQUEST_LIMIT_ERROR)
        # 金币不足
        if advanced_conf['Gold'] > self.user.base_att.golds:
            log.error('Advanced need golds: {0}, cur golds: {1}.'.format(
                advanced_conf['Gold'], self.user.base_att.golds))
            defer.returnValue(CHAR_GOLD_NOT_ENOUGH)
        # 进阶消耗的道具不足, 含消耗伙伴
        items_list = split_items(advanced_conf['ItemList'])
        for _type, _id, _num in items_list:
            if _type == ITEM_TYPE_ITEM:
                total_num, item_attribs = yield self.user.bag_item_mgr.get_items(
                    _id)
                if _num > total_num:
                    log.error(
                        'item id: {0}, need num: {1}, cur num: {2}.'.format(
                            _id, _num, total_num))
                    defer.returnValue(CHAR_ITEM_NOT_ENOUGH)
            elif _type == ITEM_TYPE_FELLOW:
                total_num, _ = self.get_fellows_by_fid(_id, user_fellow_id)
                if _num > total_num:
                    log.error(
                        'Item id: {0}, need num: {1}, cur_num: {2}.'.format(
                            _id, _num, total_num))
                    defer.returnValue(FELLOW_NOT_ENOUGH)
            else:
                log.error('Unknown advanced item. item: {0}.'.format(
                    (_type, _id, _num)))
                defer.returnValue(UNKNOWN_ITEM_ERROR)

        # 扣金币、扣道具
        #self.user.base_att.golds -= advanced_conf['Gold']
        self.user.consume_golds(advanced_conf['Gold'], WAY_FELLOW_REFINE)
        items_return = []
        for _type, _id, _num in items_list:
            if _type == ITEM_TYPE_ITEM:
                res_err, used_attribs = yield self.user.bag_item_mgr.use(
                    _id, _num)
                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, _type, _id, _a.item_num])
            elif _type == ITEM_TYPE_FELLOW:
                total_num, used_attribs = self.get_fellows_by_fid(
                    _id, user_fellow_id)
                for _a in used_attribs[:_num]:
                    self.delete_table_data(_a.attrib_id)
                    items_return.append([_a.attrib_id, _type, _id, 0])
        # add syslog
        syslogger(LOG_FELLOW_REFINE, self.cid, self.user.level, self.user.vip_level, self.user.alliance_id, user_fellow_id, \
                attrib.fellow_id, attrib.advanced_level, attrib.advanced_level+1, '')

        # 进阶后的属性提高
        attrib.advanced_level += 1

        # 已上阵的伙伴或主角强化 同步camp到redis
        #if attrib.on_troop > 0 or attrib.is_major > 0:
        #    yield self.user.sync_camp_to_redis(update=True)

        # 走马灯的成就广播之神将进阶到+5以上, 神将不含主角
        if (attrib.advanced_level > 4):
            message = [
                RORATE_MESSAGE_ACHIEVE,
                [
                    ACHIEVE_TYPE_ADVANCED,
                    [
                        self.user.base_att.nick_name, attrib.fellow_id,
                        attrib.advanced_level
                    ]
                ]
            ]
            gw_broadcast('sync_broadcast', [message])

        defer.returnValue((user_fellow_id, attrib.advanced_level,
                           self.user.base_att.golds, items_return))
Esempio n. 22
0
    def randcard(self, rand_type):
        ''' 免费抽卡、钻石抽卡 '''
        _status, _data = yield self.status()
        if _status < 0:
            defer.returnValue(LIMIT_FELLOW_NO_ERROR)
        _need_time = self.left_free_timestamp(_data[3], LIMIT_FELLOW_FREE_TIME)
        _last_time = _data[3]
        # 检查抽卡条件是否满足
        _score = yield redis.zscore(SET_LIMIT_FELLOW_NAME_SCORE,
                                    self.user.nick_name)
        _score = int(_score) if _score else 0
        _cost_flag = True  # 扣钻石的标识位
        if rand_type == RANDCARD_TYPE_FREE:
            if _need_time > 0:
                defer.returnValue(LIMIT_FELLOW_FREE_ERROR)
            else:
                _last_time = int(time())
                _cost_flag = False
                _need_time = LIMIT_FELLOW_FREE_TIME
        else:
            # 某积分的整数倍时免费钻石抽卡
            if not _score or _score % RAND_COST_FREE_SCORE != 0:
                if self.user.credits < LIMIT_FELLOW_RAND_COST:
                    defer.returnValue(CHAR_CREDIT_NOT_ENOUGH)
            else:
                _cost_flag = False
        # 卡池升级
        res_err, shrine_data = self.update_shrine(_data[1], _data[2])
        if res_err:
            defer.returnValue(res_err)
        #log.info('For Test. shrine_data: {0}, redis_data: {1}.'.format( shrine_data, _data ))
        # 获取抽卡池并抽卡
        card_conf = self.get_randcard_frompool(_data[1],
                                               shrine_data[3] - _data[2])
        if not card_conf:
            defer.returnValue(NOT_FOUND_CONF)

        # 更新免费时间或扣钻石
        yield redis.hset(
            HASH_LIMIT_FELLOW_SHRINE, self.cid,
            dumps([_data[0], shrine_data[0], shrine_data[1], _last_time]))
        if _cost_flag:
            yield self.user.consume_credits(LIMIT_FELLOW_RAND_COST,
                                            WAY_LIMIT_FELLOW_RANDCARD)
        _score += RANDCARD_ONCE_SCORE
        yield redis.zadd(SET_LIMIT_FELLOW_NAME_SCORE, self.user.nick_name,
                         _score)
        # 新增fellow
        try:
            # args: fellow_id, is_major, camp_id, on_troop
            new_fellow = []
            fellow_id = card_conf['ItemId']
            res_err, attrib = yield self.user.fellow_mgr.create_table_data(
                fellow_id, 0, 0, 0)
            if not res_err:
                new_fellow = [attrib.attrib_id, fellow_id]
                conf = get_fellow_by_fid(fellow_id)
                if conf and conf['Quality'] == QUALITY_PURPLE:
                    syslogger(LOG_FELLOW_GET, self.cid, self.user.level, self.user.vip_level, self.user.alliance_id, \
                            attrib.attrib_id, fellow_id, conf['QualityLevel'], conf['Star'], RANDCARD_TYPE_CREDITS, '')
                    message = [
                        RORATE_MESSAGE_ACHIEVE,
                        [
                            ACHIEVE_TYPE_LIMIT_FELLOW,
                            [self.user.nick_name, fellow_id]
                        ]
                    ]
                    gw_broadcast('sync_broadcast', [message])
        except Exception as e:
            log.warn('Create fellow fail! e:', e)
            defer.returnValue(res_err)

        _rank = yield redis.zrevrank(SET_LIMIT_FELLOW_NAME_SCORE,
                                     self.user.nick_name)
        _rank = int(_rank) + 1 if _rank >= 0 else 0
        _ranklist = yield self.ranklist()
        defer.returnValue([
            self.user.credits, _rank, _score, _need_time, shrine_data[2],
            _ranklist, new_fellow
        ])
Esempio n. 23
0
    def fellow_decomposition(self, user_fellow_ids):
        ''' 
        @summary: 伙伴炼化 
            (1) 已上阵 或 进阶等级大于0的不可炼化, 需要先重生
            (2) 炼化产出道具, 读sysconfig['fellow_decomposition'], 返还金币, 仙魂, 魂玉
            (3) 读sysconfig['roleexp'], 返还强化消耗的经验
            (4) 1点经验=1个金币,  1点经验=1点仙魂, 返还金币、仙魂
            (4) 删除用于炼化的材料, 即伙伴
        '''
        for _ufid in user_fellow_ids:
            attrib = self.user.fellow_mgr.get_fellow(_ufid)
            if not attrib:
                log.error(
                    'Can not find user fellow. user_fellow_id: {0}.'.format(
                        _ufid))
                return UNKNOWN_FELLOW_ERROR
                #defer.returnValue( UNKNOWN_FELLOW_ERROR )
            # 已上阵 或 进阶等级大于0的不可炼化, 需要先重生
            if attrib.camp_id > 0 or attrib.advanced_level > 0:
                log.error(
                    'Fellow advanced level error. ufid: {0}, camp_id: {1}, ad_lvl: {2}.'
                    .format(_ufid, attrib.camp_id, attrib.advanced_level))
                return FELLOW_DECOMPOSITION_ERROR
            fellow_conf = get_fellow_by_fid(attrib.fellow_id)
            if not fellow_conf:
                log.error('Can not find fellow conf. fellow id: {0}.'.format(
                    attrib.fellow_id))
                return NOT_FOUND_CONF
                #defer.returnValue( NOT_FOUND_CONF )

        total_golds, total_soul, total_hunyu = 0, 0, 0
        for _ufid in user_fellow_ids:
            attrib = self.user.fellow_mgr.get_fellow(_ufid)
            if not attrib:
                log.error('Unknown fellow. _ufid: {0}.'.format(_ufid))
                continue
            fellow_conf = get_fellow_by_fid(attrib.fellow_id)
            # 炼化产出道具
            decomposition_conf = get_fellow_decomposition(
                fellow_conf['QualityLevel'])
            if decomposition_conf:
                items_list = split_items(decomposition_conf['ItemList'])
                for _type, _id, _num in items_list:
                    if _type != ITEM_TYPE_MONEY:
                        log.error(
                            'Unknown decomposition item type. item type: {0}.'.
                            format(_type))
                        continue
                    if _id == ITEM_MONEY_GOLDS:
                        total_golds += _num
                    elif _id == ITEM_MONEY_SOUL:
                        total_soul += _num
                    elif _id == ITEM_MONEY_HUNYU:
                        total_hunyu += _num

            # 删除用于炼化的fellow
            self.user.fellow_mgr.delete_table_data(_ufid)
            # add syslog
            syslogger(LOG_FELLOW_DECOMPOSITION, self.cid, self.user.level,
                      self.user.vip_level, self.user.alliance_id, _ufid,
                      attrib.fellow_id, fellow_conf['QualityLevel'],
                      fellow_conf['Star'])

            # 返还仙魂、金币
            extra_exp = fellow_conf['Exp'] + attrib.exp
            quality = fellow_conf['Quality']
            # 返还伙伴强化消耗的经验
            for _level in range(fellow_conf['Level'], attrib.level):
                _conf = get_roleexp_by_level(_level)
                _exp = _conf.get(FELLOW_QUALITY[quality], 0)
                if not _exp:
                    continue
                extra_exp += _exp
            # 1点经验, 等于1个金币, 等于1点仙魂
            total_golds += extra_exp
            total_soul += extra_exp

        # 返还仙魂、金币、魂玉
        items_return = []
        if total_golds > 0:
            self.user.base_att.golds += total_golds
            items_return.append(
                [0, ITEM_TYPE_MONEY, ITEM_MONEY_GOLDS, total_golds])
        if total_soul > 0:
            self.user.base_att.soul += total_soul
            items_return.append(
                [0, ITEM_TYPE_MONEY, ITEM_MONEY_SOUL, total_soul])
        if total_hunyu > 0:
            self.user.base_att.hunyu += total_hunyu
            items_return.append(
                [0, ITEM_TYPE_MONEY, ITEM_MONEY_HUNYU, total_hunyu])

        return items_return
Esempio n. 24
0
    def fellow_reborn(self, user_fellow_id):
        ''' 
        @summary: 伙伴重生 
            (1) 已上阵 或 未进阶的伙伴 不能重生
            (2) 重生后,进阶等级和强化等级清零, 全额返还该伙伴进阶消耗的道具总数和强化消耗的仙魂、金币, 
            (3) 进阶消耗的金币不返还
        '''
        attrib = self.user.fellow_mgr.get_fellow(user_fellow_id)
        if not attrib:
            log.error('Can not find user fellow. user_fellow_id: {0}.'.format(
                user_fellow_id))
            defer.returnValue(UNKNOWN_FELLOW_ERROR)

        fellow_conf = get_fellow_by_fid(attrib.fellow_id)
        if not fellow_conf:
            log.error('Can not find fellow conf. fellow id: {0}.'.format(
                attrib.fellow_id))
            defer.returnValue(NOT_FOUND_CONF)

        # 已上阵 或 未进阶的伙伴 不可重生
        if attrib.camp_id > 0 or attrib.advanced_level == 0:
            log.error(
                'Fellow advanced level or camp id error. ufid: {0}, ad_lvl: {1}, camp id: {2}.'
                .format(user_fellow_id, attrib.advanced_level, attrib.camp_id))
            defer.returnValue(FELLOW_REBORN_ERROR)

        # 判断钻石消耗
        reborn_conf = get_fellow_reborn_conf(fellow_conf['QualityLevel'],
                                             attrib.advanced_level)
        if not reborn_conf:
            log.error(
                'Unknown reborn conf. qLevel: {0}, ad_level: {1}.'.format(
                    fellow_conf['QualityLevel'], attrib.advanced_level))
            defer.returnValue(NOT_FOUND_CONF)
        # 玩家钻石不足
        if self.user.base_att.credits < reborn_conf['Cost']:
            log.error('Need credits: {0}, cur credits: {1}.'.format(
                reborn_conf['Cost'], self.user.base_att.credits))
            defer.returnValue(CHAR_CREDIT_NOT_ENOUGH)
        # 扣钻石
        #self.user.base_att.credits -= reborn_conf['Cost']
        if reborn_conf['Cost']:
            yield self.user.consume_credits(reborn_conf['Cost'],
                                            WAY_FELLOW_REBORN)
        # 返还仙魂、金币
        extra_exp = fellow_conf['Exp'] + attrib.exp
        quality = fellow_conf['Quality']
        # 返还伙伴强化消耗的经验
        for _level in range(fellow_conf['Level'], attrib.level):
            _conf = get_roleexp_by_level(_level)
            _exp = _conf.get(FELLOW_QUALITY[quality], 0)
            if not _exp:
                continue
            extra_exp += _exp
        # 增加1点经验, 需要消耗1个金币,  每1点仙魂, 可以增加1点经验
        #self.user.base_att.golds += extra_exp
        self.user.get_golds(extra_exp, WAY_FELLOW_REBORN)
        self.user.base_att.soul += extra_exp

        # 返还伙伴进阶消耗的道具
        items_list = []
        for _a_level in range(1, attrib.advanced_level + 1):
            advanced_conf = get_fellow_advanced(attrib.fellow_id, _a_level)
            if not advanced_conf:
                log.error(
                    'Can not find fellow advanced conf. fellow id: {0}, advanced_level: {1}.'
                    .format(attrib.fellow_id, _a_level))
                continue
            _list = split_items(advanced_conf['ItemList'])
            for _l in _list:
                items_list = add_new_items(_l, items_list)
        #log.info('For Test. refine_level: {0}, items_list: {1}.'.format( attrib.advanced_level, items_list ))

        items_return = []
        for _type, _id, _num in items_list:
            # 货币类型特殊处理
            if _type == ITEM_TYPE_MONEY:
                continue
            model = ITEM_MODELs.get(_type, None)
            if not model:
                log.error(
                    'Unknown reborn item type. item type: {0}.'.format(_type))
                continue
            res_err, res_value = yield model(self.user,
                                             ItemID=_id,
                                             ItemNum=_num,
                                             AddType=WAY_FELLOW_REBORN,
                                             CapacityFlag=False)
            if not res_err:
                for _v in res_value:
                    items_return = total_new_items(_v, items_return)
        # 进阶等级和强化等级、经验清零
        attrib.level = fellow_conf['Level']
        attrib.exp, attrib.advanced_level = 0, 0
        if extra_exp > 0:
            items_return.append(
                [0, ITEM_TYPE_MONEY, ITEM_MONEY_GOLDS, extra_exp])
            items_return.append(
                [0, ITEM_TYPE_MONEY, ITEM_MONEY_SOUL, extra_exp])

        defer.returnValue((self.user.base_att.credits, items_return))