コード例 #1
0
def brawl_update_monster():
    """
    Update a monsters stats
    """

    # grab required form elements from POST
    name = request.form['name']
    color = request.form['color']
    identifier = request.form['identifier']
    armor_class = int(request.form['armor_class'])
    hit_points = request.form['hit_points']
    notes = request.form.get('notes') or ''
    conditions = [c for c in get_conditions() if c in request.form]

    # handle blank initiaive
    initiative = request.form['initiative']
    if initiative:
        initiative = int(initiative)

    # load brawl from cookie
    brawl = get_brawl_cookie(request)

    # update monster
    brawl = update_monster(
        name, brawl, identifier, initiative, armor_class, hit_points,
        notes, conditions, color)

    # render brawl
    return set_brawl_cookie(brawl)
コード例 #2
0
def brawl_add_character():
    """
    Add character to brawl
    """

    # grab required form elements from POST
    name = request.form['name']
    initiative_modifier = request.form['initiative_modifier']
    armor_class = int(request.form['armor_class'])
    hit_points = int(request.form['hit_points'])

    # load brawl from cookie
    brawl = get_brawl_cookie(request)

    # if - or + operator not added to initiative, set it positive modifier
    if not re.search('^[\-|\+]', initiative_modifier):
        initiative_modifier = '+%s' % int(initiative_modifier)

    if 'url' in request.form:
        url = request.form['url']
    else:
        url = None

    # handle multiple monsters
    try:
        brawl = add_character(
            brawl, name, initiative_modifier, armor_class, hit_points, url)
    except CookieLimit:
        return render_template('error.html',
            message='Browser cookie do not support more monsters'), 409

    # render brawl
    return set_brawl_cookie(brawl)
コード例 #3
0
def brawl_add_monster():
    """
    Add monster to brawl
    """

    # required url params
    slug_name = request.args['slug_name']
    quantity = int(request.args.get('quantity', 1))

    # load brawl from cookie
    brawl = get_brawl_cookie(request)

    # perform a search
    monster = find_one('monsters', slug_name=slug_name)

    # if we have a result render monster
    if monster:

        # handle multiple monsters
        try:
            brawl = add_monsters(brawl, monster, quantity)
        except CookieLimit:
            return render_template('error.html',
                message='Browser cookie do not support more monsters'), 409

        # render brawl
        return set_brawl_cookie(brawl)

    # if we do not have a result render error
    return render_template('error.html',
        message='Monster %s not found' % slug_name), 404
コード例 #4
0
def brawl_roll_initiative():
    """
    Roll initiative for brawl
    """

    # load brawl from cookie
    brawl = get_brawl_cookie(request)

    # roll initiaive
    brawl = roll_initiative(brawl)

    # render brawl
    return set_brawl_cookie(brawl)
コード例 #5
0
def brawl_reset():
    """
    Clear monsters from brawl and reset initiative
    """

    # load brawl from cookie
    brawl = get_brawl_cookie(request)

    # remove monsters and initative from brawl
    brawl = remove_monsters(brawl)
    brawl = remove_initative(brawl)

    # render brawl
    return set_brawl_cookie(brawl)
コード例 #6
0
def brawl_set_turn():
    """
    Set monsters turn
    """

    # grab required form elements from POST
    identifier = request.form['identifier']

    # load brawl from cookie
    brawl = get_brawl_cookie(request)

    # roll initiaive
    brawl = set_turn(brawl, identifier)

    # render brawl
    return set_brawl_cookie(brawl)
コード例 #7
0
def brawl_remove_monster():
    """
    Remove monster from brawl
    """

    # grab required form elements from POST
    identifier = request.args['identifier']

    # load brawl from cookie
    brawl = get_brawl_cookie(request)

    # roll initiaive
    brawl = remove_monster(brawl, identifier)

    # render brawl
    return set_brawl_cookie(brawl)
コード例 #8
0
def brawl_add_random_monster():
    """
    Add random monster to brawl
    """

    if request.method == 'POST':
        min_cr = request.form.get('min_cr')
        max_cr = request.form.get('max_cr')
        quantity = int(request.form.get('quantity', 1))
        environment = request.form.get('environment')

    elif request.method == 'GET':
        min_cr = request.args.get('min_cr')
        max_cr = request.args.get('max_cr')
        quantity = int(request.args.get('quantity', 1))
        environment = request.args.get('environment')

    # load brawl from cookie
    brawl = get_brawl_cookie(request)

    # handle multiple monsters
    for _ in range(quantity):

        # get a random monster
        try:
            monster = find_random_monster(min_cr, max_cr, environment)
        except NoMonster:
            return render_template('error.html',
                message='No monster with challage rating found'), 404

        # add monster to brawl
        try:
            brawl = add_monsters(brawl, monster, 1)
        except CookieLimit:
            return render_template('error.html',
                message='Browser cookie do not support more monsters'), 409

    # render brawl
    return set_brawl_cookie(brawl)