mirror of
https://github.com/Threnklyn/dungeon-sheets.git
synced 2026-06-07 21:23:31 +02:00
added HP roller to GUI
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
"""This file describes the heroic adventurer Ben.
|
||||
|
||||
It's used primarily for saving characters from create-character,
|
||||
where there will be many missing sections.
|
||||
|
||||
Modify this file as you level up and then re-generate the character
|
||||
sheet by running ``makesheets`` from the command line.
|
||||
|
||||
"""
|
||||
|
||||
dungeonsheets_version = "0.9.4"
|
||||
|
||||
name = "Ben"
|
||||
player_name = "Ben"
|
||||
|
||||
# Be sure to list Primary class first
|
||||
classes = ['Cleric', 'Barbarian'] # ex: ['Wizard'] or ['Rogue', 'Fighter']
|
||||
levels = [5, 10] # ex: [10] or [3, 2]
|
||||
subclasses = ["Light Domain", "Path of the Battlerager"] # ex: ['Necromacy'] or ['Thief', None]
|
||||
background = "Criminal"
|
||||
race = "High Elf"
|
||||
alignment = "Chaotic good"
|
||||
|
||||
xp = 0
|
||||
hp_max = 100
|
||||
inspiration = 0 # integer inspiration value
|
||||
|
||||
# Ability Scores
|
||||
strength = 10
|
||||
dexterity = 12
|
||||
constitution = 18
|
||||
intelligence = 11
|
||||
wisdom = 10
|
||||
charisma = 10
|
||||
|
||||
# Select what skills you're proficient with
|
||||
# ex: skill_proficiencies = ('athletics', 'acrobatics', 'arcana')
|
||||
skill_proficiencies = ('insight', 'medicine', 'deception', 'stealth', 'perception')
|
||||
|
||||
# Any skills you have "expertise" (Bard/Rogue) in
|
||||
skill_expertise = ()
|
||||
|
||||
# Named features / feats that aren't part of your classes, race, or background.
|
||||
# Also include Eldritch Invocations and features you make multiple selection of
|
||||
# (like Maneuvers for Fighter, Metamagic for Sorcerors, Trick Shots for
|
||||
# Gunslinger, etc.)
|
||||
# Example:
|
||||
# features = ('Tavern Brawler',) # take the optional Feat from PHB
|
||||
features = ()
|
||||
|
||||
# If selecting among multiple feature options: ex Fighting Style
|
||||
# Example (Fighting Style):
|
||||
# feature_choices = ('Archery',)
|
||||
feature_choices = ()
|
||||
|
||||
# Weapons/other proficiencies not given by class/race/background
|
||||
weapon_proficiencies = () # ex: ('shortsword', 'quarterstaff')
|
||||
_proficiencies_text = () # ex: ("thieves' tools",)
|
||||
|
||||
# Proficiencies and languages
|
||||
languages = """Common, Elvish, [choose one]"""
|
||||
|
||||
# Inventory
|
||||
# TODO: Get yourself some money
|
||||
cp = 0
|
||||
sp = 0
|
||||
ep = 0
|
||||
gp = 0
|
||||
pp = 0
|
||||
|
||||
# TODO: Put your equipped weapons and armor here
|
||||
weapons = ["Greatclub"] # Example: ('shortsword', 'longsword')
|
||||
magic_items = () # Example: ('ring of protection',)
|
||||
armor = "Padded Armor" # Eg "leather armor"
|
||||
shield = "None" # Eg "shield"
|
||||
|
||||
equipment = """TODO: list the equipment and magic items your character carries"""
|
||||
|
||||
attacks_and_spellcasting = """TODO: Describe how your character usually attacks
|
||||
or uses spells."""
|
||||
|
||||
# List of known spells
|
||||
# Example: spells_prepared = ('magic missile', 'mage armor')
|
||||
spells_prepared = () # Todo: Learn some spells
|
||||
|
||||
# Which spells have not been prepared
|
||||
__spells_unprepared = ()
|
||||
|
||||
# all spells known
|
||||
spells = spells_prepared + __spells_unprepared
|
||||
|
||||
# Wild shapes for Druid
|
||||
wild_shapes = () # Ex: ('ape', 'wolf', 'ankylosaurus')
|
||||
|
||||
# Backstory
|
||||
# Describe your backstory here
|
||||
personality_traits = """TODO: Describe how your character behaves, interacts with others"""
|
||||
|
||||
ideals = """TODO: Describe what values your character believes in."""
|
||||
|
||||
bonds = """TODO: Describe your character's commitments or ongoing quests."""
|
||||
|
||||
flaws = """TODO: Describe your character's interesting flaws."""
|
||||
|
||||
features_and_traits = """TODO: Describe other features and abilities your
|
||||
character has."""
|
||||
@@ -7,6 +7,7 @@ import logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
import math
|
||||
import numpy as np
|
||||
import os
|
||||
from random import randint
|
||||
import subprocess
|
||||
@@ -92,6 +93,43 @@ class App(npyscreen.NPSAppManaged):
|
||||
self.character.to_pdf(filename)
|
||||
subprocess.call(['makesheets', filename])
|
||||
|
||||
def update_max_hp_roll(self):
|
||||
abil = self.getForm("ABILITIES")
|
||||
# Update max HP based on the class
|
||||
hit_dice = [dice.read_dice_str(d)
|
||||
for d in self.character.hit_dice.split(' + ')]
|
||||
const = int((int(abil.constitution.value) - 10)/2)
|
||||
hp_max = f"{hit_dice[0].faces + self.character.level*const}"
|
||||
hds = {}
|
||||
for i, hd in enumerate(hit_dice):
|
||||
num = hd.num
|
||||
if i == 0:
|
||||
num -= 1
|
||||
if hd.faces not in hds:
|
||||
hds[hd.faces] = 0
|
||||
hds[hd.faces] += num
|
||||
for faces, num in hds.items():
|
||||
hp_max += f' + {num}d{faces}'
|
||||
abil.hp_roll_text.value = "Enter (or roll) your Max HP: " + hp_max
|
||||
abil.display()
|
||||
|
||||
def reroll_max_hp(self):
|
||||
abil = self.getForm("ABILITIES")
|
||||
# Update max HP based on the class
|
||||
hit_dice = [dice.read_dice_str(d)
|
||||
for d in self.character.hit_dice.split(' + ')]
|
||||
const = int((int(abil.constitution.value) - 10)/2)
|
||||
# Assume first hd given is from primary class
|
||||
hp_max = hit_dice[0].faces + const
|
||||
for i, hd in enumerate(hit_dice):
|
||||
num = hd.num
|
||||
if i == 0:
|
||||
num -= 1
|
||||
for d in range(num):
|
||||
hp_max += np.random.randint(low=1, high=hd.faces+1) + const
|
||||
abil.hp_max.value = str(hp_max)
|
||||
abil.display()
|
||||
|
||||
def set_default_hp_max(self):
|
||||
abil = self.getForm("ABILITIES")
|
||||
# Update max HP based on the class
|
||||
@@ -99,12 +137,16 @@ class App(npyscreen.NPSAppManaged):
|
||||
for d in self.character.hit_dice.split(' + ')]
|
||||
const = int((int(abil.constitution.value) - 10)/2)
|
||||
# Assume first hd given is from primary class
|
||||
hp_max = math.floor(hit_dice[0].faces/2) + const
|
||||
for hd in hit_dice:
|
||||
for d in range(hd.num):
|
||||
hp_max = hit_dice[0].faces + const
|
||||
for i, hd in enumerate(hit_dice):
|
||||
num = hd.num
|
||||
if i == 0:
|
||||
num -= 1
|
||||
for d in range(num):
|
||||
hp_max += math.ceil(hd.faces/2) + const
|
||||
log.debug("Updating max hp: %d", hp_max)
|
||||
abil.hp_max.value = str(hp_max)
|
||||
abil.display()
|
||||
|
||||
def onStart(self):
|
||||
self.character = character.Character()
|
||||
@@ -402,6 +444,10 @@ class AbilityScoreForm(LinkedListForm):
|
||||
self.default_button.value = True
|
||||
self.default_button.update()
|
||||
|
||||
def reroll_hp(self, widget=None):
|
||||
self.parentApp.reroll_max_hp()
|
||||
self.parentApp.update_max_hp_roll()
|
||||
|
||||
def create(self):
|
||||
self.roll_text = self.add(npyscreen.FixedText, editable=False,
|
||||
value="Take the six rolls below and assign each one to an ability.")
|
||||
@@ -436,7 +482,13 @@ class AbilityScoreForm(LinkedListForm):
|
||||
name=name,
|
||||
begin_entry_at=24, value='10')
|
||||
setattr(self, attr, new_fld)
|
||||
self.hp_roll_text = self.add(npyscreen.FixedText, editable=False,
|
||||
value="")
|
||||
self.hp_reroll_buttom = self.add(npyscreen.MiniButtonPress,
|
||||
name="Reroll Max HP",
|
||||
when_pressed_function=self.reroll_hp)
|
||||
self.hp_max = self.add(npyscreen.TitleText, name="Max HP:")
|
||||
self.parentApp.update_max_hp_roll()
|
||||
self.parentApp.set_default_hp_max()
|
||||
|
||||
def on_ok(self):
|
||||
|
||||
Reference in New Issue
Block a user