def guild_contribution_data_handler(table, fields, dataset):
    _data = {}

    for row in dataset:
        _contribute = dict(zip(fields, row))
        _contribute['GuildAward'] = split_items(_contribute['GuildAward'])
        _contribute['PersonAward'] = split_items(_contribute['PersonAward'])
        _data[row[0]] = _contribute

    return _data
Example #2
0
def guild_contribution_data_handler(table, fields, dataset):
    _data = {}

    for row in dataset:
        _contribute = dict(zip(fields, row))
        _contribute['GuildAward'] = split_items( _contribute['GuildAward'] )
        _contribute['PersonAward'] = split_items( _contribute['PersonAward'] )
        _data[row[0]] = _contribute

    return _data
Example #3
0
def translate_lookup_ids(items, request, lookup_dict=False, separator='%2C'):
    if items:
        items = utils.split_items(items)
        temp_list = ''
        for item in items:
            query = None
            item_id = None
            if request:  # If we don't have TMDb IDs then look them up
                if lookup_dict:  # Check if we should be looking up in a stored dict
                    if request.get(item):
                        item_id = str(request.get(item))
                else:  # Otherwise lookup IDs via a TMDb search request
                    query = tmdb_api_request_longcache(request, query=item)
                    if query:
                        if query.get('results') and query.get('results')[0]:
                            item_id = query.get('results')[0].get('id')
            else:  # Otherwise we assume that each item is a TMDb ID
                item_id = item
            if item_id:
                if separator:  # If we've got a url separator then concatinate the list with it
                    temp_list = '{0}{1}{2}'.format(
                        temp_list, separator,
                        item_id) if temp_list else item_id
                else:  # If no separator, assume that we just want to use the first found ID
                    temp_list = str(item_id)
                    break  # Stop once we have a item
        if temp_list:
            return temp_list
def guild_sacrifice_data_handler(table, fields, dataset):
    _data = {}
    for row in dataset:
        if _data.has_key(row[0]):
            continue
        _data[row[0]] = split_items(row[1])

    return _data
Example #5
0
def guild_sacrifice_data_handler(table, fields, dataset):
    _data = {}
    for row in dataset:
        if _data.has_key(row[0]):
            continue
        _data[row[0]] = split_items( row[1] )

    return _data
Example #6
0
    def get_rank_award(self, rank):
        ''' 返回竞技场中排名对应的奖励配置 '''
        award_gold, award_prestige = 1000, 50

        rank_award_conf = get_arena_rank_award( rank )
        if rank_award_conf:
            items_list = split_items( rank_award_conf['ArenaRankList'] )
            for _type, _id, _num in items_list:
                if _type == ITEM_TYPE_MONEY and _id == ITEM_MONEY_GOLDS:
                    award_gold = _num
                if _type == ITEM_TYPE_MONEY and _id == ITEM_MONEY_PRESTIGE:
                    award_prestige = _num
        return award_gold, award_prestige
Example #7
0
def gs_gm_sync_pay_activity_conf(p, req):

    res_err = {'result': 1, 'error_id':0}
    all_new_conf, = req

    all_old_conf = {}

    try:
        dataset  = {} # 被修改的活动配置
        for _new_conf in all_new_conf:
            _id = int(_new_conf['id']) # 注意数据类型
            _old_conf = {}
            _old_conf['ID'] = int(_id)
            _old_conf['GroupID']  = int(_new_conf['group_id'])
            _old_conf['TotalPay']  = int(_new_conf['pay'])
            _old_conf['AwardList'] = split_items(_new_conf['award_list'])
            for item_type, item_id, add_count in _old_conf['AwardList']:
                _model = check_item_id_and_type(item_id, item_type)
                if not _model:
                    res_err = {'result':OSS_ITEM_TYPE_IS_WRONG, 'error_id':_id}
                    return res_err
            # 获取被修改的活动信息
            dataset[_id] = [_new_conf["group_id"], _new_conf['pay'], _new_conf['award_list']] 
            if not all_old_conf.has_key(int(_new_conf['group_id'])):
                all_old_conf[int(_new_conf['group_id'])] = {}
            all_old_conf[int(_new_conf['group_id'])][_id] = _old_conf
        # 没有修改
        if not dataset:
            log.info('Pay activity conf oss conf no changed.')
            return res_err
    except Exception as e:
        log.exception()
        res_err['result'] = OSS_PAY_ACTIVITY_CONF_ERROR
        return res_err

    # 更新内存中的 sysconfig
    sysconfig['pay_activity_oss'] = all_old_conf

    # 更新db
    conn   = MySQLdb.connect(**sysconfig_db_conf)
    cursor = conn.cursor()
    sql_delete = "TRUNCATE table tb_pay_activity_oss"
    cursor.execute(sql_delete)
    conn.commit()
    sql_update = "INSERT INTO tb_pay_activity_oss (GroupID, TotalPay, AwardList) VALUES(%s, %s, %s)"

    cursor.executemany( sql_update, dataset.values() )
    conn.commit()

    cursor.close()
    return res_err
Example #8
0
    def scene_star_reward(self, scene_id, scene_star_count):
        ''' 领取副本宝箱奖励 '''
        had_star = 0
        scene = yield self.get_scene(scene_id)
        if scene:
            for gsattrib in scene.itervalues():
                had_star += gsattrib.dungeon_star
        # 判断能否领取奖励
        if scene_star_count > had_star:
            log.error(
                'Can not get scene star reward. cur had star count: {0}.'.
                format(had_star))
            defer.returnValue(REQUEST_LIMIT_ERROR)

        # 判断是否重复领取
        rewarded_data = yield self.get_star_rewarded(scene_id)
        if scene_star_count in rewarded_data:
            log.error(
                'Scene star had been rewarded. rewarded_data: {0}.'.format(
                    rewarded_data))
            defer.returnValue(REPEAT_REWARD_ERROR)
        # 更新领奖记录
        yield self.update_star_rewarded(scene_id, scene_star_count)

        # 奖励conf
        reward_conf = get_scene_star_reward(scene_id, scene_star_count)
        if not reward_conf:
            log.error('Can not find star count reward conf.')
            defer.returnValue(NOT_FOUND_CONF)

        # 奖励
        items_return = []
        items_list = split_items(reward_conf['Reward'])
        for _type, _id, _num in items_list:
            model = ITEM_MODELs.get(_type, None)
            if not model:
                log.error('Unknown item type. item type: {0}.'.format(_type))
                continue
            res_err, value = yield model(self.user,
                                         ItemID=_id,
                                         ItemNum=_num,
                                         AddType=WAY_SCENE_CHEST,
                                         WayOthers=str(
                                             (scene_id, scene_star_count)),
                                         CapacityFlag=False)
            if not res_err and value:
                for _v in value:
                    items_return = total_new_items(_v, items_return)

        defer.returnValue(items_return)
Example #9
0
    def scene_star_reward(self, scene_id, scene_star_count):
        ''' 领取副本宝箱奖励 '''
        had_star = 0
        scene    =  yield self.get_scene( scene_id )
        if scene:
            for gsattrib in scene.itervalues():
                had_star += gsattrib.dungeon_star
        # 判断能否领取奖励
        if scene_star_count > had_star:
            log.error('Can not get scene star reward. cur had star count: {0}.'.format( had_star ))
            defer.returnValue( REQUEST_LIMIT_ERROR )

        # 判断是否重复领取
        rewarded_data = yield self.get_star_rewarded( scene_id )
        if scene_star_count in rewarded_data:
            log.error('Scene star had been rewarded. rewarded_data: {0}.'.format( rewarded_data ))
            defer.returnValue( REPEAT_REWARD_ERROR )
        # 更新领奖记录
        yield self.update_star_rewarded(scene_id, scene_star_count)

        # 奖励conf
        reward_conf = get_scene_star_reward(scene_id, scene_star_count)
        if not reward_conf:
            log.error('Can not find star count reward conf.')
            defer.returnValue( NOT_FOUND_CONF )

        # 奖励
        items_return = []
        items_list   = split_items( reward_conf['Reward'] )
        for _type, _id, _num in items_list:
            model = ITEM_MODELs.get( _type, None )
            if not model:
                log.error('Unknown item type. item type: {0}.'.format( _type ))
                continue
            res_err, value = yield model(self.user, ItemID=_id, ItemNum=_num, AddType=WAY_SCENE_CHEST, WayOthers=str((scene_id, scene_star_count)), CapacityFlag=False)
            if not res_err and value:
                for _v in value:
                    items_return = total_new_items( _v, items_return )

        defer.returnValue( items_return )
Example #10
0
    def treasure_reborn(self, user_treasure_id):
        '''
        @summary: 宝物重生 
            (1) 已穿戴 或 未精炼的宝物 不能重生
            (2) 返还该宝物精炼消耗的道具和强化消耗的经验道具, 强化消耗的道具返还为经验宝物 
            (3) 精炼消耗的金币不返还 
        '''
        treasure = yield self.user.bag_treasure_mgr.get( user_treasure_id )
        if not treasure:
            log.error('Can not find user treasure.')
            defer.returnValue( UNKNOWN_TREASURE_ERROR )
        # 已穿戴 或 未精炼的宝物不可重生
        if treasure.camp_id > 0 or treasure.refine_level <= 0:
            log.error('Treasure reborn error. camp_id: {0}, refine level: {1}.'.format( treasure.camp_id, treasure.refine_level ))
            defer.returnValue( TREASURE_REBORN_ERROR )

        # 宝物的conf
        treasure_conf = get_item_by_itemid( treasure.item_id )
        if not treasure_conf:
            log.error('Can not find conf. item id: {0}.'.format( treasure.item_id ))
            defer.returnValue( UNKNOWN_ITEM_ERROR )
        total_exp = treasure.exp

        # 扣钻石
        reborn_conf = get_treasure_reborn_conf( treasure_conf['QualityLevel'], treasure.refine_level )
        if reborn_conf:
            yield self.user.consume_credits( reborn_conf['Cost'], WAY_TREASURE_REBORN )

        # 返还宝物强化消耗的经验
        for _level in range( 1, treasure.level + 1):
            _conf = get_treasure_exp_conf( _level )
            _exp  = _conf.get( ITEM_STRENGTHEN_COST[treasure_conf['Quality']], 0 )
            if not _exp:
                continue
            total_exp += _exp
 
        # 用经验值兑换经验马或经验书, 增加1点经验, 需要消耗5个金币
        total_golds = total_exp * TREASURE_STRENGTHEN_EXP_TO_GOLDS
        self.user.get_golds( total_golds, WAY_TREASURE_REBORN )

        items_return = []
        _err, _value = yield self.user.bag_treasure_mgr.add_exp_treasure( treasure.item_type, total_exp )
        if not _err:
            items_return = _value

        # 返还精炼消耗的道具
        items_list = [] # 消耗的道具列表
        for _refine_level in range(1, treasure.refine_level + 1):
            refine_conf = get_treasure_refine_conf(treasure.item_id, _refine_level)
            if not refine_conf:
                log.error('Can not find refine conf. item_id: {0}, refine_level: {1}.'.format( treasure.item_id, _refine_level ))
                continue
            _list = split_items( refine_conf['CostItemList'] )
            for _l in _list:
                items_list = add_new_items( _l, items_list )
        #log.info('For Test. refine_level: {0}, items_list: {1}.'.format( treasure.refine_level, items_list ))

        # 道具类型格式:道具ID:道具数量
        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_TREASURE_REBORN, CapacityFlag=False)
            if not res_err:
                for _v in res_value:
                    items_return = total_new_items(_v, items_return)

        # 强化、精炼属性清零
        treasure.level, treasure.exp, treasure.refine_level = 0, 0, 0
        if total_golds > 0:
            items_return.append( [0, ITEM_TYPE_MONEY, ITEM_MONEY_GOLDS, total_golds] )
 
        defer.returnValue( (self.user.base_att.credits, items_return) )
Example #11
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
Example #12
0
    def treasure_decomposition(self, user_treasure_ids):
        ''' 
        @summary: 宝物炼化 相同类型
            (1) 已穿戴 或 精炼属性大于0的不可炼化, 需要先重生, 经验马 经验书不能也炼化
            (2) 炼化产出道具, 读sysconfig['item_decomposition'], 返还道具
            (3) 返还宝物强化消耗的经验, 并将其折算成经验马或经验书, 返还金币
            (4) 删除用于炼化的材料, 即宝物
        '''
        for _utid in user_treasure_ids:
            treasure = yield self.user.bag_treasure_mgr.get( _utid )
            if not treasure:
                log.error('Can not find user treasure. user_treasure_id: {0}.'.format( _utid ))
                defer.returnValue( UNKNOWN_TREASURE_ERROR )
            # 所选宝物 类型必须为书或马
            if treasure.item_type not in BAG_TREASURE:
                log.error('Selected treasure type not horse or bookwar.')
                defer.returnValue( UNKNOWN_TREASURE_ERROR )
            # 经验马、经验书不能炼化
            if treasure.item_id == EXP_HORSE_ID or treasure.item_id == EXP_BOOKWAR_ID:
                log.error('EXP_HORSE or EXP_BOOKWAR could not be decomposition. item id: {0}.'.format( treasure.item_id ))
                defer.returnValue( TREASURE_DECOMPOSITION_ERROR )

            # 已穿戴 或 精炼属性大于0的不可炼化, 需要先重生
            if treasure.camp_id > 0 or treasure.refine_level > 0:
                log.error('Treasure refine level error. ufid: {0}, refine level: {1}.'.format( _utid, treasure.refine_level ))
                defer.returnValue( TREASURE_DECOMPOSITION_ERROR )

            # 宝物的conf
            treasure_conf = get_item_by_itemid( treasure.item_id )
            if not treasure_conf:
                log.error('Can not find conf. item id: {0}.'.format( treasure.item_id ))
                defer.returnValue( UNKNOWN_ITEM_ERROR )

        total_golds, horse_exp, bookwar_exp = 0, 0, 0
        items_return = []
        for _utid in user_treasure_ids:
            treasure  = yield self.user.bag_treasure_mgr.get( _utid )
            extra_exp = treasure.exp
            treasure_conf = get_item_by_itemid( treasure.item_id )
            # 宝物自身经验
            for _attr in treasure_conf['attributes']:
                if _attr['AttributeID'] in (ATTRIBUTE_TYPE_HORSE_EXP, ATTRIBUTE_TYPE_BOOKWAR_EXP):
                    extra_exp += _attr['Value']
                    break

            # 炼化产出的道具
            decomposition_conf = get_item_decomposition( treasure.item_type, treasure_conf['QualityLevel'] )
            for _dec in decomposition_conf:
                items_list = split_items( _dec['ItemList'] )
                #log.info('For Test. _utid: {0}, items_list: {1}.'.format( _utid, items_list ))
                for _type, _id, _num in items_list:
                    # 货币类型特殊处理
                    if _type == ITEM_TYPE_MONEY:
                        if _id == ITEM_MONEY_GOLDS:
                            total_golds += _num
                        continue
                    model = ITEM_MODELs.get( _type, None )
                    if not model:
                        log.error('Unknown decomposition item type. item type: {0}.'.format( _type ))
                        continue
                    res_err, res_value = model(self.user, ItemID=_id, ItemNum=_num, AddType=WAY_TREASURE_DECOMPOSITION, CapacityFlag=False)
                    if not res_err:
                        for _v in res_value:
                            items_return = total_new_items(_v, items_return)

            # 返还宝物强化消耗的经验, 并折算成经验马或经验书
            for _level in range(1, treasure.level + 1):
                _conf = get_treasure_exp_conf( _level )
                extra_exp += _conf.get( ITEM_STRENGTHEN_COST[treasure_conf['Quality']], 0 )
            if treasure.item_type == ITEM_TYPE_HORSE:
                horse_exp += extra_exp
            else:
                bookwar_exp += extra_exp

            # 删除用于炼化的treasure
            self.user.bag_treasure_mgr.delete_table_data( _utid )
            # add syslog
            syslogger(LOG_ITEM_LOSE, self.cid, self.user.level, self.user.vip_level, self.user.alliance_id, _utid, treasure.item_id, 1, WAY_TREASURE_DECOMPOSITION)

        # 返还金币
        total_golds += (horse_exp + bookwar_exp) * TREASURE_STRENGTHEN_EXP_TO_GOLDS
        #self.user.base_att.golds += total_golds
        self.user.get_golds( total_golds, WAY_TREASURE_REFINE )
        # 用经验值兑换经验马或经验书
        if horse_exp > 0:
            res_err, res_value = yield self.user.bag_treasure_mgr.add_exp_treasure( ITEM_TYPE_HORSE, horse_exp )
            if not res_err:
                for _v in res_value:
                    items_return = total_new_items(_v, items_return)
        if bookwar_exp > 0:
            res_err, res_value = yield self.user.bag_treasure_mgr.add_exp_treasure( ITEM_TYPE_BOOKWAR, bookwar_exp )
            if not res_err:
                for _v in res_value:
                    items_return = total_new_items(_v, items_return)
        if total_golds > 0:
            items_return.append( [0, ITEM_TYPE_MONEY, ITEM_MONEY_GOLDS, total_golds] )

        defer.returnValue( items_return )
Example #13
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) )
Example #14
0
    def treasure_decomposition(self, user_treasure_ids):
        ''' 
        @summary: 宝物炼化 相同类型
            (1) 已穿戴 或 精炼属性大于0的不可炼化, 需要先重生, 经验马 经验书不能也炼化
            (2) 炼化产出道具, 读sysconfig['item_decomposition'], 返还道具
            (3) 返还宝物强化消耗的经验, 并将其折算成经验马或经验书, 返还金币
            (4) 删除用于炼化的材料, 即宝物
        '''
        for _utid in user_treasure_ids:
            treasure = yield self.user.bag_treasure_mgr.get(_utid)
            if not treasure:
                log.error('Can not find user treasure. user_treasure_id: {0}.'.
                          format(_utid))
                defer.returnValue(UNKNOWN_TREASURE_ERROR)
            # 所选宝物 类型必须为书或马
            if treasure.item_type not in BAG_TREASURE:
                log.error('Selected treasure type not horse or bookwar.')
                defer.returnValue(UNKNOWN_TREASURE_ERROR)
            # 经验马、经验书不能炼化
            if treasure.item_id == EXP_HORSE_ID or treasure.item_id == EXP_BOOKWAR_ID:
                log.error(
                    'EXP_HORSE or EXP_BOOKWAR could not be decomposition. item id: {0}.'
                    .format(treasure.item_id))
                defer.returnValue(TREASURE_DECOMPOSITION_ERROR)

            # 已穿戴 或 精炼属性大于0的不可炼化, 需要先重生
            if treasure.camp_id > 0 or treasure.refine_level > 0:
                log.error(
                    'Treasure refine level error. ufid: {0}, refine level: {1}.'
                    .format(_utid, treasure.refine_level))
                defer.returnValue(TREASURE_DECOMPOSITION_ERROR)

            # 宝物的conf
            treasure_conf = get_item_by_itemid(treasure.item_id)
            if not treasure_conf:
                log.error('Can not find conf. item id: {0}.'.format(
                    treasure.item_id))
                defer.returnValue(UNKNOWN_ITEM_ERROR)

        total_golds, horse_exp, bookwar_exp = 0, 0, 0
        items_return = []
        for _utid in user_treasure_ids:
            treasure = yield self.user.bag_treasure_mgr.get(_utid)
            extra_exp = treasure.exp
            treasure_conf = get_item_by_itemid(treasure.item_id)
            # 宝物自身经验
            for _attr in treasure_conf['attributes']:
                if _attr['AttributeID'] in (ATTRIBUTE_TYPE_HORSE_EXP,
                                            ATTRIBUTE_TYPE_BOOKWAR_EXP):
                    extra_exp += _attr['Value']
                    break

            # 炼化产出的道具
            decomposition_conf = get_item_decomposition(
                treasure.item_type, treasure_conf['QualityLevel'])
            for _dec in decomposition_conf:
                items_list = split_items(_dec['ItemList'])
                #log.info('For Test. _utid: {0}, items_list: {1}.'.format( _utid, items_list ))
                for _type, _id, _num in items_list:
                    # 货币类型特殊处理
                    if _type == ITEM_TYPE_MONEY:
                        if _id == ITEM_MONEY_GOLDS:
                            total_golds += _num
                        continue
                    model = ITEM_MODELs.get(_type, None)
                    if not model:
                        log.error(
                            'Unknown decomposition item type. item type: {0}.'.
                            format(_type))
                        continue
                    res_err, res_value = model(
                        self.user,
                        ItemID=_id,
                        ItemNum=_num,
                        AddType=WAY_TREASURE_DECOMPOSITION,
                        CapacityFlag=False)
                    if not res_err:
                        for _v in res_value:
                            items_return = total_new_items(_v, items_return)

            # 返还宝物强化消耗的经验, 并折算成经验马或经验书
            for _level in range(1, treasure.level + 1):
                _conf = get_treasure_exp_conf(_level)
                extra_exp += _conf.get(
                    ITEM_STRENGTHEN_COST[treasure_conf['Quality']], 0)
            if treasure.item_type == ITEM_TYPE_HORSE:
                horse_exp += extra_exp
            else:
                bookwar_exp += extra_exp

            # 删除用于炼化的treasure
            self.user.bag_treasure_mgr.delete_table_data(_utid)
            # add syslog
            syslogger(LOG_ITEM_LOSE, self.cid, self.user.level,
                      self.user.vip_level, self.user.alliance_id, _utid,
                      treasure.item_id, 1, WAY_TREASURE_DECOMPOSITION)

        # 返还金币
        total_golds += (horse_exp +
                        bookwar_exp) * TREASURE_STRENGTHEN_EXP_TO_GOLDS
        #self.user.base_att.golds += total_golds
        self.user.get_golds(total_golds, WAY_TREASURE_REFINE)
        # 用经验值兑换经验马或经验书
        if horse_exp > 0:
            res_err, res_value = yield self.user.bag_treasure_mgr.add_exp_treasure(
                ITEM_TYPE_HORSE, horse_exp)
            if not res_err:
                for _v in res_value:
                    items_return = total_new_items(_v, items_return)
        if bookwar_exp > 0:
            res_err, res_value = yield self.user.bag_treasure_mgr.add_exp_treasure(
                ITEM_TYPE_BOOKWAR, bookwar_exp)
            if not res_err:
                for _v in res_value:
                    items_return = total_new_items(_v, items_return)
        if total_golds > 0:
            items_return.append(
                [0, ITEM_TYPE_MONEY, ITEM_MONEY_GOLDS, total_golds])

        defer.returnValue(items_return)
Example #15
0
    def equip_decomposition(self, user_equip_ids):
        ''' 
        @summary: 装备炼化 
            (1) 已穿戴 或 洗炼属性大于0的不可炼化, 需要先重生
            (2) 炼化产出道具, 读sysconfig['item_decomposition'], 返还道具
            (3) 返还强化消耗的金币
            (4) 删除用于炼化的材料, 即装备
        '''
        for _ueid in user_equip_ids:
            equip = yield self.user.bag_equip_mgr.get( _ueid )
            if not equip:
                log.error('Can not find user equip. user_equip_id: {0}.'.format( _ueid ))
                defer.returnValue( UNKNOWN_EQUIP_ERROR )

            # 已穿戴 或 洗炼属性大于0的不可炼化, 需要先重生
            if (equip.camp_id > 0):
                log.error('Equip refine level error. ueid: {0}, camp_id: {1}, refine_attr: {2}.'.format( _ueid, equip.camp_id, loads(equip.refine_attribute) ))
                defer.returnValue( EQUIP_DECOMPOSITION_ERROR )

            for _attr in loads(equip.refine_attribute):
                if _attr[1] > 0:
                    defer.returnValue( EQUIP_DECOMPOSITION_ERROR )

            # 装备的conf
            equip_conf = get_item_by_itemid( equip.item_id )
            if not equip_conf:
                log.error('Can not find conf. item id: {0}.'.format( equip.item_id ))
                defer.returnValue( UNKNOWN_ITEM_ERROR )

        items_return = []
        total_golds  = 0
        for _ueid in user_equip_ids:
            equip = yield self.user.bag_equip_mgr.get( _ueid )
            equip_conf = get_item_by_itemid( equip.item_id )
            # 返还强化消耗的金币
            total_golds += equip.strengthen_cost

            # 炼化产出的道具
            decomposition_conf = get_item_decomposition( equip.item_type, equip_conf['QualityLevel'] )
            for _dec in decomposition_conf:
                items_list = split_items( _dec['ItemList'] )
                for _type, _id, _num in items_list:
                    # character attribute需要单独处理
                    if _type == ITEM_TYPE_MONEY:
                        if _id == ITEM_MONEY_GOLDS:
                            total_golds += _num
                        continue
                    model = ITEM_MODELs.get( _type, None )
                    if not model:
                        log.error('Unknown decomposition item type. item type: {0}.'.format( _type ))
                        continue
                    res_err, res_value = yield model(self.user, ItemID=_id, ItemNum=_num, AddType=WAY_EQUIP_DECOMPOSITION, CapacityFlag=False)
                    if not res_err:
                        for _v in res_value:
                            items_return = total_new_items(_v, items_return)
            # 删除用于炼化的equip
            self.user.bag_equip_mgr.delete_table_data( _ueid )
            # add syslog
            syslogger(LOG_ITEM_LOSE, self.cid, self.user.level, self.user.vip_level, self.user.alliance_id, _ueid, equip.item_id, 1, WAY_EQUIP_DECOMPOSITION)

        # 返还金币
        if total_golds > 0:
            #self.user.base_att.golds += total_golds
            self.user.get_golds( total_golds, WAY_EQUIP_REFINE )
            items_return.append( [0, ITEM_TYPE_MONEY, ITEM_MONEY_GOLDS, total_golds] )

        defer.returnValue( items_return )
Example #16
0
    def refine(self, user_treasure_id):
        '''
        @summary:  只有精炼等级为0, 强化等级为0的宝物才可作消耗材料
              只有品级(QualityLevel)大于7的才可以精炼
        '''
        res_err = UNKNOWN_TREASURE_ERROR

        attrib = yield self.get( user_treasure_id )
        if not attrib:
            log.error('Can not find user treasure. user_treasure_id: {0}.'.format( user_treasure_id ))
            defer.returnValue( res_err )

        refine_conf = get_treasure_refine_conf(attrib.item_id, attrib.refine_level+1)
        if not refine_conf:
            log.error('Can not find refine conf. item_id: {0}, refine level: {1}.'.format( attrib.item_id, attrib.refine_level+1 ))
            defer.returnValue( NOT_FOUND_CONF )
        # 道具配置 自身品级不满足
        item_conf = get_item_by_itemid(attrib.item_id)
        if (not item_conf) or (item_conf['QualityLevel'] <= TREASURE_REFINE_QUALITYLEVEL_MAX):
            log.error('Can not refine treasure. No conf or quality_level limit. item_id: {0}.'.format( attrib.item_id ))
            defer.returnValue( CLIENT_DATA_ERROR )

        # 金币不足
        if refine_conf['CostGold'] > self.user.base_att.golds:
            log.error('user golds not enough. need_golds: {0}, cur_golds: {1}.'.format( refine_conf['CostGold'], self.user.base_att.golds ))
            defer.returnValue( CHAR_GOLD_NOT_ENOUGH )

        # 消耗道具不足, 道具类型格式:道具ID:道具数量
        items_list = split_items( refine_conf['CostItemList'] )
        cost_attribs = [] # 要消耗的宝物
        for _type, _id, _num in items_list:
            if _type in BAG_TREASURE:
                all_attribs = yield self.get_item_to_refine( user_treasure_id, _id )
                if len(all_attribs) < _num:
                    log.error('user item not enough. item_id: {2}, cur_item_num: {0}, need_item_num: {1}.'.format( len(all_attribs), _num, _id ))
                    defer.returnValue( CHAR_ITEM_NOT_ENOUGH )
                cost_attribs.extend( all_attribs[:_num] )
            elif _type == ITEM_TYPE_ITEM:
                total_num, item_attribs = yield self.user.bag_item_mgr.get_items( _id )
                if total_num < _num:
                    log.error('user item not enough. cid:{0}, item_id:{1}, need:{2}, curr:{3}.'.format( self.cid, _id, _num, total_num ))
                    defer.returnValue( CHAR_ITEM_NOT_ENOUGH )
            else:
                log.error("Unknown item type. cost item: {0}.".format( refine_conf['CostItemList'] ))
                defer.returnValue( UNKNOWN_ITEM_ERROR )
        # 扣宝物
        items_return = []
        for _attrib in cost_attribs:
            self.delete_table_data( _attrib.attrib_id )
            items_return.append( _attrib.attrib_id )
        # 扣道具
        left_items = []
        for _type, _id, _num in items_list:
            if _type != ITEM_TYPE_ITEM:
                continue
            res_err, used_attribs = yield self.user.bag_item_mgr.use( _id, _num )
            if res_err:
                log.error('Use item error. cid:{0}, _type:{1}, _id:{2}, _num:{3}.'.format( self.cid, _type, _id, _num ))
            # used_attribs-已使用的道具
            for _a in used_attribs:
                left_items.append( [_a.attrib_id, _a.item_type, _a.item_id, _a.item_num] )

        # 扣金币
        #self.user.base_att.golds -= refine_conf['CostGold']
        self.user.consume_golds( refine_conf['CostGold'], WAY_TREASURE_REFINE )
        attrib.refine_level += 1

        # add syslog
        way_others = str(tuple(items_return))
        syslogger(LOG_TREASURE_REFINE, self.cid, self.user.level, self.user.vip_level, self.user.alliance_id, user_treasure_id, attrib.item_id, attrib.refine_level-1, attrib.refine_level, way_others)

        # 同步camp到redis
        #if attrib.camp_id:
        #    yield self.user.sync_camp_to_redis(update=True)
        yield self.user.achievement_mgr.update_achievement_status(ACHIEVEMENT_QUEST_ID_33, attrib.refine_level) 
        defer.returnValue( (user_treasure_id, attrib.item_id, attrib.refine_level, self.user.base_att.golds, items_return, left_items) )
Example #17
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))
Example #18
0
    def equip_decomposition(self, user_equip_ids):
        ''' 
        @summary: 装备炼化 
            (1) 已穿戴 或 洗炼属性大于0的不可炼化, 需要先重生
            (2) 炼化产出道具, 读sysconfig['item_decomposition'], 返还道具
            (3) 返还强化消耗的金币
            (4) 删除用于炼化的材料, 即装备
        '''
        for _ueid in user_equip_ids:
            equip = yield self.user.bag_equip_mgr.get(_ueid)
            if not equip:
                log.error(
                    'Can not find user equip. user_equip_id: {0}.'.format(
                        _ueid))
                defer.returnValue(UNKNOWN_EQUIP_ERROR)

            # 已穿戴 或 洗炼属性大于0的不可炼化, 需要先重生
            if (equip.camp_id > 0):
                log.error(
                    'Equip refine level error. ueid: {0}, camp_id: {1}, refine_attr: {2}.'
                    .format(_ueid, equip.camp_id,
                            loads(equip.refine_attribute)))
                defer.returnValue(EQUIP_DECOMPOSITION_ERROR)

            for _attr in loads(equip.refine_attribute):
                if _attr[1] > 0:
                    defer.returnValue(EQUIP_DECOMPOSITION_ERROR)

            # 装备的conf
            equip_conf = get_item_by_itemid(equip.item_id)
            if not equip_conf:
                log.error('Can not find conf. item id: {0}.'.format(
                    equip.item_id))
                defer.returnValue(UNKNOWN_ITEM_ERROR)

        items_return = []
        total_golds = 0
        for _ueid in user_equip_ids:
            equip = yield self.user.bag_equip_mgr.get(_ueid)
            equip_conf = get_item_by_itemid(equip.item_id)
            # 返还强化消耗的金币
            total_golds += equip.strengthen_cost

            # 炼化产出的道具
            decomposition_conf = get_item_decomposition(
                equip.item_type, equip_conf['QualityLevel'])
            for _dec in decomposition_conf:
                items_list = split_items(_dec['ItemList'])
                for _type, _id, _num in items_list:
                    # character attribute需要单独处理
                    if _type == ITEM_TYPE_MONEY:
                        if _id == ITEM_MONEY_GOLDS:
                            total_golds += _num
                        continue
                    model = ITEM_MODELs.get(_type, None)
                    if not model:
                        log.error(
                            'Unknown decomposition item type. item type: {0}.'.
                            format(_type))
                        continue
                    res_err, res_value = yield model(
                        self.user,
                        ItemID=_id,
                        ItemNum=_num,
                        AddType=WAY_EQUIP_DECOMPOSITION,
                        CapacityFlag=False)
                    if not res_err:
                        for _v in res_value:
                            items_return = total_new_items(_v, items_return)
            # 删除用于炼化的equip
            self.user.bag_equip_mgr.delete_table_data(_ueid)
            # add syslog
            syslogger(LOG_ITEM_LOSE, self.cid, self.user.level,
                      self.user.vip_level, self.user.alliance_id, _ueid,
                      equip.item_id, 1, WAY_EQUIP_DECOMPOSITION)

        # 返还金币
        if total_golds > 0:
            #self.user.base_att.golds += total_golds
            self.user.get_golds(total_golds, WAY_EQUIP_REFINE)
            items_return.append(
                [0, ITEM_TYPE_MONEY, ITEM_MONEY_GOLDS, total_golds])

        defer.returnValue(items_return)
Example #19
0
    def refine(self, user_treasure_id):
        '''
        @summary:  只有精炼等级为0, 强化等级为0的宝物才可作消耗材料
              只有品级(QualityLevel)大于7的才可以精炼
        '''
        res_err = UNKNOWN_TREASURE_ERROR

        attrib = yield self.get(user_treasure_id)
        if not attrib:
            log.error(
                'Can not find user treasure. user_treasure_id: {0}.'.format(
                    user_treasure_id))
            defer.returnValue(res_err)

        refine_conf = get_treasure_refine_conf(attrib.item_id,
                                               attrib.refine_level + 1)
        if not refine_conf:
            log.error(
                'Can not find refine conf. item_id: {0}, refine level: {1}.'.
                format(attrib.item_id, attrib.refine_level + 1))
            defer.returnValue(NOT_FOUND_CONF)
        # 道具配置 自身品级不满足
        item_conf = get_item_by_itemid(attrib.item_id)
        if (not item_conf) or (item_conf['QualityLevel'] <=
                               TREASURE_REFINE_QUALITYLEVEL_MAX):
            log.error(
                'Can not refine treasure. No conf or quality_level limit. item_id: {0}.'
                .format(attrib.item_id))
            defer.returnValue(CLIENT_DATA_ERROR)

        # 金币不足
        if refine_conf['CostGold'] > self.user.base_att.golds:
            log.error(
                'user golds not enough. need_golds: {0}, cur_golds: {1}.'.
                format(refine_conf['CostGold'], self.user.base_att.golds))
            defer.returnValue(CHAR_GOLD_NOT_ENOUGH)

        # 消耗道具不足, 道具类型格式:道具ID:道具数量
        items_list = split_items(refine_conf['CostItemList'])
        cost_attribs = []  # 要消耗的宝物
        for _type, _id, _num in items_list:
            if _type in BAG_TREASURE:
                all_attribs = yield self.get_item_to_refine(
                    user_treasure_id, _id)
                if len(all_attribs) < _num:
                    log.error(
                        'user item not enough. item_id: {2}, cur_item_num: {0}, need_item_num: {1}.'
                        .format(len(all_attribs), _num, _id))
                    defer.returnValue(CHAR_ITEM_NOT_ENOUGH)
                cost_attribs.extend(all_attribs[:_num])
            elif _type == ITEM_TYPE_ITEM:
                total_num, item_attribs = yield self.user.bag_item_mgr.get_items(
                    _id)
                if total_num < _num:
                    log.error(
                        'user item not enough. cid:{0}, item_id:{1}, need:{2}, curr:{3}.'
                        .format(self.cid, _id, _num, total_num))
                    defer.returnValue(CHAR_ITEM_NOT_ENOUGH)
            else:
                log.error("Unknown item type. cost item: {0}.".format(
                    refine_conf['CostItemList']))
                defer.returnValue(UNKNOWN_ITEM_ERROR)
        # 扣宝物
        items_return = []
        for _attrib in cost_attribs:
            self.delete_table_data(_attrib.attrib_id)
            items_return.append(_attrib.attrib_id)
        # 扣道具
        left_items = []
        for _type, _id, _num in items_list:
            if _type != ITEM_TYPE_ITEM:
                continue
            res_err, used_attribs = yield self.user.bag_item_mgr.use(_id, _num)
            if res_err:
                log.error(
                    'Use item error. cid:{0}, _type:{1}, _id:{2}, _num:{3}.'.
                    format(self.cid, _type, _id, _num))
            # used_attribs-已使用的道具
            for _a in used_attribs:
                left_items.append(
                    [_a.attrib_id, _a.item_type, _a.item_id, _a.item_num])

        # 扣金币
        #self.user.base_att.golds -= refine_conf['CostGold']
        self.user.consume_golds(refine_conf['CostGold'], WAY_TREASURE_REFINE)
        attrib.refine_level += 1

        # add syslog
        way_others = str(tuple(items_return))
        syslogger(LOG_TREASURE_REFINE, self.cid, self.user.level,
                  self.user.vip_level, self.user.alliance_id, user_treasure_id,
                  attrib.item_id, attrib.refine_level - 1, attrib.refine_level,
                  way_others)

        # 同步camp到redis
        #if attrib.camp_id:
        #    yield self.user.sync_camp_to_redis(update=True)
        yield self.user.achievement_mgr.update_achievement_status(
            ACHIEVEMENT_QUEST_ID_33, attrib.refine_level)
        defer.returnValue(
            (user_treasure_id, attrib.item_id, attrib.refine_level,
             self.user.base_att.golds, items_return, left_items))
Example #20
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) )
Example #21
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
Example #22
0
    def treasure_reborn(self, user_treasure_id):
        '''
        @summary: 宝物重生 
            (1) 已穿戴 或 未精炼的宝物 不能重生
            (2) 返还该宝物精炼消耗的道具和强化消耗的经验道具, 强化消耗的道具返还为经验宝物 
            (3) 精炼消耗的金币不返还 
        '''
        treasure = yield self.user.bag_treasure_mgr.get(user_treasure_id)
        if not treasure:
            log.error('Can not find user treasure.')
            defer.returnValue(UNKNOWN_TREASURE_ERROR)
        # 已穿戴 或 未精炼的宝物不可重生
        if treasure.camp_id > 0 or treasure.refine_level <= 0:
            log.error(
                'Treasure reborn error. camp_id: {0}, refine level: {1}.'.
                format(treasure.camp_id, treasure.refine_level))
            defer.returnValue(TREASURE_REBORN_ERROR)

        # 宝物的conf
        treasure_conf = get_item_by_itemid(treasure.item_id)
        if not treasure_conf:
            log.error('Can not find conf. item id: {0}.'.format(
                treasure.item_id))
            defer.returnValue(UNKNOWN_ITEM_ERROR)
        total_exp = treasure.exp

        # 扣钻石
        reborn_conf = get_treasure_reborn_conf(treasure_conf['QualityLevel'],
                                               treasure.refine_level)
        if reborn_conf:
            yield self.user.consume_credits(reborn_conf['Cost'],
                                            WAY_TREASURE_REBORN)

        # 返还宝物强化消耗的经验
        for _level in range(1, treasure.level + 1):
            _conf = get_treasure_exp_conf(_level)
            _exp = _conf.get(ITEM_STRENGTHEN_COST[treasure_conf['Quality']], 0)
            if not _exp:
                continue
            total_exp += _exp

        # 用经验值兑换经验马或经验书, 增加1点经验, 需要消耗5个金币
        total_golds = total_exp * TREASURE_STRENGTHEN_EXP_TO_GOLDS
        self.user.get_golds(total_golds, WAY_TREASURE_REBORN)

        items_return = []
        _err, _value = yield self.user.bag_treasure_mgr.add_exp_treasure(
            treasure.item_type, total_exp)
        if not _err:
            items_return = _value

        # 返还精炼消耗的道具
        items_list = []  # 消耗的道具列表
        for _refine_level in range(1, treasure.refine_level + 1):
            refine_conf = get_treasure_refine_conf(treasure.item_id,
                                                   _refine_level)
            if not refine_conf:
                log.error(
                    'Can not find refine conf. item_id: {0}, refine_level: {1}.'
                    .format(treasure.item_id, _refine_level))
                continue
            _list = split_items(refine_conf['CostItemList'])
            for _l in _list:
                items_list = add_new_items(_l, items_list)
        #log.info('For Test. refine_level: {0}, items_list: {1}.'.format( treasure.refine_level, items_list ))

        # 道具类型格式:道具ID:道具数量
        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_TREASURE_REBORN,
                                             CapacityFlag=False)
            if not res_err:
                for _v in res_value:
                    items_return = total_new_items(_v, items_return)

        # 强化、精炼属性清零
        treasure.level, treasure.exp, treasure.refine_level = 0, 0, 0
        if total_golds > 0:
            items_return.append(
                [0, ITEM_TYPE_MONEY, ITEM_MONEY_GOLDS, total_golds])

        defer.returnValue((self.user.base_att.credits, items_return))
Example #23
0
def get_award_conf(award_type, *args):
    '''
    @summary: 1.检查是否过期 2.返回items_list
    @param  : award_type-奖励类型。
    @param  : args-默认奖励类型的参数格式为[timestamp, items_list]
    '''
    items_list = []
    if not args:
        return AWARD_TIME_EXPIRE, []
    # 检查时间是否过期, 14天改为3天
    if check_valid_time(args[0], hour=AWARD_VALID_HOURS):
        return AWARD_TIME_EXPIRE, []

    if award_type == AWARD_TYPE_FIRSTPAY:
        reward_conf = get_firstpay_reward()
        if reward_conf:
            items_list = [[_r['ItemType'], _r['ItemID'], _r['ItemNum']]
                          for _r in reward_conf]
    elif award_type == AWARD_TYPE_ARENARANK:
        #award_time, _rank = args
        arena_rank_conf = get_arena_rank_award(args[1])
        if arena_rank_conf:
            items_list = split_items(arena_rank_conf['ArenaRankList'])
    elif award_type == AWARD_TYPE_CLIMBING:
        for _layer in args[1]:
            climbing_conf = get_climbing_conf(_layer)
            if climbing_conf:
                items_list = add_new_items([1, 1, climbing_conf['RewardGold']],
                                           items_list)
                items_list = add_new_items([1, 4, climbing_conf['RewardSoul']],
                                           items_list)
                for _v in climbing_conf['BonusList']:
                    items_list = add_new_items(_v, items_list)
    elif award_type == AWARD_TYPE_MONTGLY_CARD:
        back_credits = get_monthly_card_conf(MONTHLY_CARD_NORMAL)
        if back_credits:
            items_list = [[ITEM_TYPE_MONEY, ITEM_MONEY_CREDITS, back_credits]]
    elif award_type == AWARD_TYPE_VIP_WELFARE:
        pass
        #welfare_conf = get_vip_welfare_conf()
        #items_list   = welfare_conf.get(args[1], [])
    elif award_type in [
            AWARD_TYPE_LIMIT_FELLOW_RANK, AWARD_TYPE_LIMIT_FELLOW_SCORE
    ]:
        limit_fellow_conf = get_limit_fellow_award_conf(args[1])
        items_list = limit_fellow_conf.get(args[2], {}).get('AwardList', [])
    elif award_type == AWARD_TYPE_PAY_ACTIVITY:
        _award_conf = get_pay_activity_award_conf(args[2])
        items_list = _award_conf.get('AwardList', [])
    elif award_type == AWARD_TYPE_CONSUME_ACTIVITY:
        _award_conf = get_consume_activity_award_conf(args[2])
        items_list = _award_conf.get('AwardList', [])
    elif award_type == AWARD_TYPE_SCENE_SWEEP:
        items_list = args[2]
    elif award_type == AWARD_TYPE_DAILY_QUEST:
        for reward_id in args[1]:
            _reward_conf = get_daily_quest_reward_conf(reward_id)
            if not _reward_conf:
                continue
            for _v in _reward_conf['Reward']:
                items_list = add_new_items(_v, items_list)
    elif award_type == AWARD_TYPE_PAY_LOGIN:
        _award_conf = get_pay_login_package_conf(args[1])
        items_list = _award_conf.get('RewardList', [])
    elif award_type == AWARD_TYPE_JOUSTRANK:
        items_list = get_joust_reward_conf(args[1])
    elif award_type == AWARD_TYPE_GROUP_BUY:
        items_list = []
        for buy_type, buy_count in args[2]:
            _reward = get_group_buy_reward_list_conf(buy_type, buy_count)
            _item_type, _item_id, _item_num = _reward.split(":")
            items_list.append([int(_item_type), int(_item_id), int(_item_num)])
    elif award_type == AWARD_TYPE_RESOURCE_REWARD:
        items_list = [[ITEM_TYPE_PACKAGE, RESOURCE_PACKAGE_ID, 1]]
    else:
        items_list = args[1]

    return NO_ERROR, items_list
Example #24
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))