예제 #1
0
def character_edit(char_id):

    character = Character.query.get(char_id)
    form = CharacterForm(request.form)

    if not form.validate():
        return render_template("characters/edit.html",
                               form=form,
                               character=character)

    race_id = form.race.data
    class_id = form.class_id.data

    name = form.name.data

    str = int(form.strength.data)
    dex = int(form.dexterity.data)
    con = int(form.constitution.data)
    intel = int(form.intelligence.data)
    wis = int(form.wisdom.data)
    cha = int(form.charisma.data)

    if character.class_id != class_id.id or character.race_id != race_id.id:
        hp = class_id.hitdice + StaticMethods.getModifier(con +
                                                          race_id.constitution)
    else:
        hp = character.maxhp

    character.edit_character(name, str, dex, con, intel, wis, cha, class_id.id,
                             race_id.id, hp)

    db.session().commit()

    return redirect(url_for("character_view", char_id=char_id))
예제 #2
0
def character_create():
    form = CharacterForm(request.form)
    race_id = form.race.data
    class_id = form.class_id.data

    if not form.validate():
        return render_template("characters/new.html", form=form)

    name = form.name.data

    str = int(form.strength.data)
    dex = int(form.dexterity.data)
    con = int(form.constitution.data)
    intel = int(form.intelligence.data)
    wis = int(form.wisdom.data)
    cha = int(form.charisma.data)

    hp = class_id.hitdice + StaticMethods.getModifier(con +
                                                      race_id.constitution)

    c = Character(name, hp, str, dex, con, intel, wis, cha)

    c.race_id = race_id.id
    c.class_id = class_id.id
    c.account_id = current_user.id

    db.session().add(c)
    db.session().commit()

    return redirect(url_for("characters_index"))
예제 #3
0
def characters_create(campaign_id):
    if request.method == "GET":
        return render_template("characters/new.html",
                               campaign=Campaign.query.get(campaign_id),
                               form=CharacterForm())

    form = CharacterForm(request.form)

    if not form.validate():
        return render_template("characters/new.html",
                               campaign=Campaign.query.get(campaign_id),
                               form=form)

    character = Character(form.name.data,
                          Campaign.query.get(campaign_id).starting_points)
    character.account_id = current_user.id
    character.campaign_id = campaign_id

    db.session.add(character)
    db.session.commit()

    return redirect(url_for("characters_index", character_id=character.id))