def get_attack(self, atkIn): """Calculates and returns a dict.""" if self.character is None: raise Exception('You must call get_character() first.') character = self.character attack = {'attackBonus': '0', 'damage': '0', 'name': ''} attack['name'] = character.get('Attack' + str(atkIn)) attack['attackBonus'] = character.get('AtkBonus' + str(atkIn)) attack['damage'] = character.get('Damage' + str(atkIn)) if attack['name'] is None: return None if attack['damage'] is "": attack['damage'] = None else: damageTypes = [ 'acid', 'bludgeoning', 'cold', 'fire', 'force', 'lightning', 'necrotic', 'piercing', 'poison', 'psychic', 'radiant', 'slashing', 'thunder' ] dice, comment = get_roll_comment(attack['damage']) if any(d in comment.lower() for d in damageTypes): attack['damage'] = "{}[{}]".format(dice, comment) else: attack['damage'] = dice if comment.strip(): attack['details'] = comment.strip() attack['attackBonus'] = attack['attackBonus'].replace( '+', '', 1) if attack['attackBonus'] is not None else None return attack
def parse_attack(self, name_index, bonus_index, damage_index, sheet=None): """Calculates and returns a dict.""" if self.character_data is None: raise Exception('You must call get_character() first.') wksht = sheet or self.character_data name = wksht.cell(name_index).value damage = wksht.cell(damage_index).value bonus = wksht.cell(bonus_index).value details = None if not name: return None if not damage: damage = None else: details = None if '|' in damage: damage, details = damage.split('|', 1) dice, comment = get_roll_comment(damage) if details: details = details.strip() if any(d in comment.lower() for d in DAMAGE_TYPES): damage = "{}[{}]".format(dice, comment) else: damage = dice if comment.strip() and not details: damage = comment.strip() bonus_calc = None if bonus: try: bonus = int(bonus) except (TypeError, ValueError): bonus_calc = bonus bonus = None else: bonus = None attack = Attack(name, bonus, damage, details, bonus_calc) return attack
def get_attack(self, name_index, bonus_index, damage_index, sheet=None): """Calculates and returns a dict.""" if self.character is None: raise Exception('You must call get_character() first.') wksht = sheet or self.character attack = { 'attackBonus': wksht.cell(bonus_index).value, 'damage': wksht.cell(damage_index).value, 'name': wksht.cell(name_index).value } if attack['name'] is "": return None if attack['damage'] is "": attack['damage'] = None else: damageTypes = [ 'acid', 'bludgeoning', 'cold', 'fire', 'force', 'lightning', 'necrotic', 'piercing', 'poison', 'psychic', 'radiant', 'slashing', 'thunder' ] details = None if '|' in attack['damage']: attack['damage'], details = attack['damage'].split('|', 1) dice, comment = get_roll_comment(attack['damage']) if details: attack['details'] = details.strip() if any(d in comment.lower() for d in damageTypes): attack['damage'] = "{}[{}]".format(dice, comment) else: attack['damage'] = dice if comment.strip() and not details: attack['details'] = comment.strip() attack['attackBonus'] = attack['attackBonus'].strip( '+') if attack['attackBonus'] is not '' else None return attack