def _initialize_spellbook(self): """Sets up a character's spellbook override. @:raises OutdatedSheet if sheet does not have spellbook.""" try: assert self.character.get('spellbook') is not None except AssertionError: raise OutdatedSheet()
def get_spell_ab(self): """@:returns int - the character's spell attack bonus. @:raises OutdatedSheet if character does not have spellbook.""" try: assert 'spellbook' in self.character except AssertionError: raise OutdatedSheet() return self.character.get('spellbook', {}).get('attackBonus', 0)
def get_save_dc(self): """@:returns int - the character's spell save DC. @:raises OutdatedSheet if character does not have spellbook.""" try: assert 'spellbook' in self.character except AssertionError: raise OutdatedSheet() return self.character.get('spellbook', {}).get('dc', 0)
def get_spell_list(self): """@:returns list - a list of the names of all spells the character can cast. @:raises OutdatedSheet if character does not have spellbook.""" try: assert 'spellbook' in self.character except AssertionError: raise OutdatedSheet() return self.character.get('spellbook', {}).get('spells', [])
def get_max_spellslots(self, level: int): """@:returns the maximum number of spellslots of level level a character has. @:returns 0 if none. @:raises OutdatedSheet if character does not have spellbook.""" try: assert 'spellbook' in self.character except AssertionError: raise OutdatedSheet() return int(self.character.get('spellbook', {}).get('spellslots', {}).get(str(level), 0))
def get_spell_list(self): """@:returns list - a list of the names of all spells the character can cast. @:raises OutdatedSheet if character does not have spellbook.""" try: assert 'spellbook' in self.character except AssertionError: raise OutdatedSheet() spells = self.get_raw_spells() out = [] for spell in spells: if isinstance(spell, dict): out.append(spell['name']) else: out.append(spell) return out
def update_cached_spell_list_id(self, new_id): """Updates the cached Dicecloud spell list ID.""" if not 'spellbook' in self.character: raise OutdatedSheet() self.character['spellbook']['dicecloud_id'] = new_id