Esempio n. 1
0
def handle_list_logged_robberies():
    """
    Inputs:
           &skip=[number]
           &limit=[number]
           &name_search=[single word]
    Returns:
    log_id#character_name#last_robber_name#loot_value#rob_attempts#rob_deaths
    ....
    more_pages
    OK
    """
    skip = int(request.values["skip"])
    limit = int(request.values["limit"])
    search = request.values["name_search"]

    targets = []

    robberies = request.user.robberies

    for robbery in robberies[skip : skip + limit]:
        targets.append([robbery.id, "", robbery.name, robbery.loot_value, 0, 0])

    lines = "\n".join(map(format_list, targets))
    more_pages = int(len(robberies) > skip + limit + 1)

    return format_results("lines more_pages", locals())
Esempio n. 2
0
def handle_list_houses():
    """
    Inputs:
         &skip=[number]
         &limit=[number]
         &name_search=[single word]
    Returns:
    user_id#character_name#last_robber_name#loot_value#rob_attempts#rob_deaths
    ....
    more_pages
    OK
    """

    skip = int(request.values["skip"])
    limit = int(request.values["limit"])
    search = request.values["name_search"]

    house_query = db.session.query(House)
    houses = house_query.order_by("current_balance").slice(skip, limit)

    targets = []

    for house in houses:
        # note that we're returning house_id instead of user_id,
        # so you can rob a specific instance of a house
        targets.append([house.id, "%s (%d)" % (house.name, house.id), "", house.current_balance, 0, 0])

    lines = "\n".join(map(format_list, targets))
    more_pages = int(len(house_query.all()) > skip + limit + 1)

    return format_results("lines more_pages", locals())
Esempio n. 3
0
def handle_end_rob_house():
    """
    Inputs:
       &success=[0(die) or 1(hit vault) or 2(leave)]
       &wife_killed=[0/1]
       &wife_robbed=[0/1]
       &any_family_killed=[0/1]
       &backpack_contents=[contents]
       &move_list=[move list]
       &house_map=[house map]
    """

    previous_house = request.user.state.current_house

    robbery = Robbery(
        request.user,
        previous_house,
        request.values["house_map"],
        request.values["move_list"],
        request.values["backpack_contents"],
    )
    db.session.add(robbery)
    db.session.commit()

    money_taken = 0
    stuff_taken = []
    gallery_stuff_taken = []

    return format_results("money_taken stuff_taken gallery_stuff_taken", locals())
Esempio n. 4
0
def handle_list_houses():
    '''
    Inputs:
         &skip=[number]
         &limit=[number]
         &name_search=[single word]
    Returns:
    user_id#character_name#last_robber_name#loot_value#rob_attempts#rob_deaths
    ....
    more_pages
    OK
    '''

    skip = int(request.values['skip'])
    limit = int(request.values['limit'])
    search = request.values['name_search']

    house_query = db.session.query(House)
    houses = house_query.order_by('current_balance').slice(skip, limit)

    targets = []

    for house in houses:
        # note that we're returning house_id instead of user_id,
        # so you can rob a specific instance of a house
        targets.append([
            house.id,
            '%s (%d)' % (house.name, house.id), '', house.current_balance, 0, 0
        ])

    lines = '\n'.join(map(format_list, targets))
    more_pages = int(len(house_query.all()) > skip + limit + 1)

    return format_results('lines more_pages', locals())
Esempio n. 5
0
def handle_end_rob_house():
    '''
    Inputs:
       &success=[0(die) or 1(hit vault) or 2(leave)]
       &wife_killed=[0/1]
       &wife_robbed=[0/1]
       &any_family_killed=[0/1]
       &backpack_contents=[contents]
       &move_list=[move list]
       &house_map=[house map]
    '''

    previous_house = request.user.state.current_house

    robbery = Robbery(request.user, previous_house,
                      request.values['house_map'], request.values['move_list'],
                      request.values['backpack_contents'])
    db.session.add(robbery)
    db.session.commit()

    money_taken = 0
    stuff_taken = []
    gallery_stuff_taken = []

    return format_results('money_taken stuff_taken gallery_stuff_taken',
                          locals())
Esempio n. 6
0
def handle_list_logged_robberies():
    '''
    Inputs:
           &skip=[number]
           &limit=[number]
           &name_search=[single word]
    Returns:
    log_id#character_name#last_robber_name#loot_value#rob_attempts#rob_deaths
    ....
    more_pages
    OK
    '''
    skip = int(request.values['skip'])
    limit = int(request.values['limit'])
    search = request.values['name_search']

    targets = []

    robberies = request.user.robberies

    for robbery in robberies[skip:skip + limit]:
        targets.append(
            [robbery.id, '', robbery.name, robbery.loot_value, 0, 0])

    lines = '\n'.join(map(format_list, targets))
    more_pages = int(len(robberies) > skip + limit + 1)

    return format_results('lines more_pages', locals())
Esempio n. 7
0
    def format_log(self):
        data = get_row_dict(self.house)
        data.update(get_row_dict(self))
        data['victim_name'] = self.house.name

        items = ('name victim_name house_map'
                 ' backpack_contents move_list loot_value wife_money'
                 ' music_seed wife_name son_name daughter_name')
        return format_results(items, data)
Esempio n. 8
0
    def format_log(self):
        data = get_row_dict(self.house)
        data.update(get_row_dict(self))
        data['victim_name'] = self.house.name

        items = ('name victim_name house_map'
                 ' backpack_contents move_list loot_value wife_money'
                 ' music_seed wife_name son_name daughter_name')
        return format_results(items, data)
Esempio n. 9
0
def handle_check_user():
    email = request.values["email"]
    users = db.session.query(User).filter_by(email=email).all()
    if not users:  # new user, inject
        user = User(email=email)
    else:
        user = users[0]
    minVersionNumber = 5
    userID = user.id
    sequenceNumber = 0
    adminStatus = 0
    return format_results("minVersionNumber userID sequenceNumber" " adminStatus", locals())
Esempio n. 10
0
def handle_check_user():
    email = request.values['email']
    users = db.session.query(User).filter_by(email=email).all()
    if not users:  # new user, inject
        user = User(email=email)
    else:
        user = users[0]
    minVersionNumber = 5
    userID = user.id
    sequenceNumber = 0
    adminStatus = 0
    return format_results(
        'minVersionNumber userID sequenceNumber'
        ' adminStatus', locals())