def test_read_dice_str(self): out = dice.read_dice_str("1d6") self.assertEqual(out.faces, 6) self.assertEqual(out.num, 1) # Multiple digits out = dice.read_dice_str("15d10") self.assertEqual(out.faces, 10) self.assertEqual(out.num, 15) # Check a bad value with self.assertRaises(DiceError): dice.read_dice_str("Ed15")
def update_max_hp(self): # Update max HP based on the class max_hp_fld = self.getForm('ABILITIES').max_hp if max_hp_fld.value == '': # Calculate the new value hit_dice = dice.read_dice_str(self.character.hit_dice) const = self.character.constitution.modifier max_hp = hit_dice.faces + const for d in range(hit_dice.num - 1): max_hp += math.ceil(hit_dice.faces/2) + const log.debug("Updating max hp: %d", max_hp) max_hp_fld.value = str(max_hp)
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 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 += math.ceil(hd.faces / 2) + const log.debug("Updating max hp: %d", hp_max) abil.hp_max.value = str(hp_max) abil.display()
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()