示例#1
0
def combine(dest, card_ids):
    """Return query to combine cards.

    Args:
        dest: Dictionary of destination card key/value pairs.
        card_ids: List of ids of the cards to combine.

    Returns:
        queries_to_execute: List of (query_string, results_key) pairs.
            query_string: Query to update/retrieve cards from the database.
            results_key: Dictionary key under which to look for the results
                of this query.
    """

    # Var init
    queries_to_execute = []
    value = 100
    xp = 0

    # Loop through cards to consume, generate queries to remove their owners
    cardlogger.debug("Consuming ids: " + str(card_ids))
    for key in card_ids:
        query = db_api_query.update(table_schema, key, {'ownerid': 0,
                                                       'levels': dest['id']})
        queries_to_execute.append((query, 'affected'))
        # pylint: disable=fixme
        # TODO: determine XP granted by level of consumed card instead of using a
        # flat amount
        xp += value

    # add the XP into the destination card
    query = db_api_query.update(table_schema, dest['id'],
                                {'xp01': xp + dest['xp01']})
    queries_to_execute.append((query, 'affected'))
    return queries_to_execute
示例#2
0
def evolve(dest, card_ids):
    """Return query to evolve a card.

    Args:
        dest: Dictionary of destination card key/value pairs.
        card_ids: List of ids of the cards to combine.

    Returns:
        queries_to_execute: List of (query_string, results_key) pairs.
            query_string: Query to update/retrieve cards from the database.
            results_key: Dictionary key under which to look for the results
                of this query.
    """

    # Var init
    queries_to_execute = []

    # Loop through cards to consume, generate queries to remove their owners
    cardlogger.debug("Consuming ids: " + str(card_ids))
    for key in card_ids:
        query = db_api_query.update(table_schema, key, {'ownerid': 0,
                                                       'evolves': dest['id']})
        queries_to_execute.append((query, 'affected'))

    # 'Evolve' the destination card by changing its card type to a rarer one.
    query = db_api_query.update(table_schema, dest['id'],
                                {'type': dest['type'] + 1,
                                 'xp01': 0})
    queries_to_execute.append((query, 'affected'))
    return queries_to_execute
def update(player):
    """Return query to update player row.

    Args:
        player: Dictionary of player stat key/value pairs.

    Returns:
        queries_to_execute: List of (query_string, results_key) pairs.
            query_string: Query to update player in the database.
            results_key: Dictionary key under which to look for the results
                of this query.
    """

    update_player = db_api_query.update(table_schema, player['id'], player)
    return [(update_player, 'affected'), ]
示例#4
0
def update(player):
    """Return query to update player row.

    Args:
        player: Dictionary of player stat key/value pairs.

    Returns:
        queries_to_execute: List of (query_string, results_key) pairs.
            query_string: Query to update player in the database.
            results_key: Dictionary key under which to look for the results
                of this query.
    """

    update_player = db_api_query.update(table_schema, player['id'], player)
    return [
        (update_player, 'affected'),
    ]