def dmg_mod(self): """ >>> char = Character(load_yaml('characters', 'bardic_rogue.yaml')) >>> isinstance(char.dmg_mod(), int) True """ ability_mods = FlattenedDict(load_yaml('rules', 'ability_scores.yaml')) strength = self.get('attributes/str', 0) return int(ability_mods.get('/str/%s/dmg' % strength, 0))
def level_up(self): """ >>> char = Character(load_yaml('characters', 'bardic_rogue.yaml')) >>> level = char.get('combat/level-hitdice', 1) >>> hp = char.get('combat/hitpoints', 1) >>> max = char.get('combat/max_hp', 1) >>> debug(char.level_up()) >>> char.get('combat/hitpoints', 1) > hp True >>> char.get('combat/max_hp', 1) > max True >>> char.get('combat/level-hitdice', 1) == level + 1 True """ level = int(self.get('combat/level-hitdice', 1)) level += 1 out = '%s has reached level %s !' % (self.displayname(), level) self.put('combat/level-hitdice', level) ability_scores = load_yaml('rules', 'ability_scores.yaml') con = self.get('attributes/con', 1) out += '<br>Character constitution: %s' % con con_bonus = int(FlattenedDict(ability_scores).get('/con/%s/hit' % con,0)) out += '<br>Constitution Bonus: %s' % con_bonus xp_levels = FlattenedDict(load_yaml('rules', 'xp_levels.yaml')) pclass = self.get('class/parent', '') xp_levels = xp_levels.readall(pclass) hitdice = str(xp_levels.get('%s/%s/hit_dice' % (pclass, level), 1)) debug("Read hitdice as ", hitdice) if '+' not in hitdice: hitdice = hitdice + '+0' hitdice, bonus = hitdice.split('+') dice = int(xp_levels.get('%s/dice' % pclass, 1)) more_hp, roll = rolldice(numdice=int(hitdice), numsides=dice, modifier=con_bonus) out += '<br>%s' % roll more_hp += int(bonus) current_max = int(self.get('combat/max_hp', 1)) new_max = current_max + more_hp out += '<br>Maximum hitpoints increased by %s. Maximum hitpoints now: %s' % (more_hp, new_max) self.put('combat/max_hp', new_max) new_hp = new_max out += '<br>Character hitpoints now %s' % new_hp self.put('combat/hitpoints', new_hp) self.__init__(self()) return out