def get_champions_map(connection):
    """Get formatted champion details from sql database."""

    champions_map = {}

    # Process database rows
    for row in get_sql_rows(connection, 'champions'):
        # Helper functions
        def get_tips(string):
            return [tip for tip in string.split('*') if tip]

        def get_description(string):
            # The description often contains '' instead of "
            return string.replace("''", '"')

        # Main data
        # Stats, skins, and abilities come from other sources
        champion = {
            'id': row.id,
            'internal_name': row.name,
            'name': row.displayName,
            'title': row.title,
            'icon': row.iconPath,
            'lore': {
                'desc': get_description(row.description),
                'quote': row.quote,
                'quote_author': row.quoteAuthor,
            },
            'tips': {
                'as': get_tips(row.tips),
                'against': get_tips(row.opponentTips),
            },
            'rating': {
                'attack': row.ratingAttack,
                'defense': row.ratingDefense,
                'magic': row.ratingMagic,
                'difficulty': row.ratingDifficulty,
            },
            # TODO: videos?
            # TODO: selection sound name?
            'select_sound': row.selectSoundPath,
        }

        # Tags
        # A set would be ideal but is not supported by JSON
        tags = row.tags.split(',')
        tags_map = dict((tag, True) for tag in tags)
        champion['tags'] = tags_map

        # For convenience, champions should be accessible via ascii variable
        # names; any groups of invalid characters will be replaced by _
        name = row.displayName.lower()
        name = re.sub('[^a-z0-9]+', '_', name)
        # name = re.sub('^[0-9]', '', name)
        champion['aliases'] = [name]

        # Store by id
        champions_map[row.id] = champion

    return champions_map
Example #2
0
def get_skins_map(connection):
    """Get formatted champion skin details from sql database."""

    skins_map = {}

    for row in get_sql_rows(connection, 'championSkins'):
        skin = {
            'id': row.id,
            'name': row.displayName,
            'internal_name': row.name,
            'portrait': row.portraitPath,
            'splash': row.splashPath,
            'base': bool(row.isBase),
        }

        # Add to temporary skins table
        champion_id = row.championId
        if champion_id not in skins_map:
            skins_map[champion_id] = {}
        skins_map[champion_id][row.rank] = skin

    return skins_map
Example #3
0
def get_items_map(connection):
    """Get formatted item details from sql database."""

    items_map = {}

    # Basic item details
    for row in get_sql_rows(connection, 'items'):
        item = {
            'id': row.id,
            'name': row.name,
            'icon': row.iconPath,
            'cost': row.price,
            'tooltip': row.description,
            'stats': None,
            'tier': row.epicness,
            'categories': {},
            'recipe': [],
        }

        # Stats
        # Ignored: Dodge , EXPBonus
        stats = {}
        stats_table = [
            ('ap', 'AbilityPower'),
            ('armor', 'Armor'),
            ('ad', 'AttackDamage'),
            ('aspd', 'AttackSpeed'),
            ('crit', 'CritChance'),
            ('crit_dmg', 'CritDamage'),
            ('hp', 'HPPool'),
            ('hp5', 'HPRegen'),
            ('mr', 'MagicResist'),
            ('mspd', 'MovementSpeed'),
            ('mana', 'MPPool'),
            ('mp5', 'MPRegen'),
        ]
        row_dict = row._asdict()

        for name, key in stats_table:
            stats[name] = {
                'flat': row_dict['flat%sMod' % key],
                'percentage': row_dict['percent%sMod' % key] * 100,
            }
            if name.endswith('p5'):
                # Database stores values as per second
                stats[name]['flat'] *= 5
                stats[name]['percentage'] *= 5
        item['stats'] = stats

        # Convenience alias
        name = item['name'].lower()
        name = re.sub('[^a-z0-9]+', '_', name)
        item['aliases'] = [name]

        # Store by id
        items_map[row.id] = item

    # Recipes
    for row in get_sql_rows(connection, 'itemRecipes'):
        if row.buildsToItemId not in items_map:
            print "ERROR: Missing recipe result, item id", row.buildsToItemId
            continue
        if row.recipeItemId not in items_map:
            print ("ERROR: Missing recipe component for %s, component id %d." %
                   (row.buildsToItemId, row.recipeItemId))
            continue
        item = items_map[row.buildsToItemId]
        item['recipe'].append(row.recipeItemId)

    # Categories
    categories = {}
    for row in get_sql_rows(connection, 'itemCategories'):
        categories[row.id] = row.name
    for row in get_sql_rows(connection, 'itemItemCategories'):
        if row.itemId not in items_map:
            print "ERROR: Missing category item, item id", row.itemId
            continue
        if row.itemCategoryId not in categories:
            print "ERROR: Missing category", row.itemCategoryId
        category_name = categories[row.itemCategoryId]
        items_map[row.itemId]['categories'][category_name] = True

    return items_map