예제 #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 character_view(char_id):
    character = Character.query.get(char_id)
    charClass = CharacterClass.query.get(character.class_id)
    form = LevelUpForm(maxhp=charClass.hitdice)
    form.maxhp = charClass.hitdice
    return render_template("sheets/sheet.html",
                           sheet=CharacterSheet(char_id),
                           form=form,
                           armorform=ArmorForm(),
                           editform=CharacterForm(),
                           weaponform=EquipWeaponForm())
예제 #4
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))
예제 #5
0
def character_edit_form(char_id):
    character = Character.query.get(char_id)
    form = CharacterForm(race=character.race_id, class_id=character.class_id)

    form.name.data = character.name
    form.race.data = character.race_id
    form.class_id.data = character.class_id
    form.strength.data = character.strength
    form.dexterity.data = character.dexterity
    form.constitution.data = character.constitution
    form.intelligence.data = character.intelligence
    form.wisdom.data = character.wisdom
    form.charisma.data = character.charisma

    return render_template("characters/edit.html",
                           form=form,
                           character=character)
예제 #6
0
def character_level_up(char_id):
    form = LevelUpForm(request.form)
    character = Character.query.get(char_id)
    race = Race.query.get(character.race_id)
    charclass = CharacterClass.query.get(character.class_id)
    form.max = charclass.hitdice
    if not form.validate():
        return render_template("sheets/sheet.html",
                               sheet=CharacterSheet(char_id),
                               form=form,
                               armorform=ArmorForm(),
                               editform=CharacterForm())

    constitution = character.constitution + race.constitution
    conmod = StaticMethods.getModifier(constitution)

    if character.level < 20:
        hp = int(form.hpfield.data) + conmod
        if hp <= 0:
            hp = 1
        character.level_up(hp)
        db.session().commit()

    return redirect(url_for("character_view", char_id=char_id))
예제 #7
0
def character_form():
    return render_template("characters/new.html", form=CharacterForm())