def _transform_attack(attack) -> Attack: desc = html_to_md(attack['desc']) if attack['saveDc'] is not None and attack['saveStat'] is not None: stat = constants.STAT_ABBREVIATIONS[attack['saveStat'] - 1] for_half = desc and 'half' in desc the_attack = automation.Save(stat, fail=[automation.Damage("{damage}")], success=[] if not for_half else [automation.Damage("{damage}/2")], dc=str(attack['saveDc'])) # attack, then save if attack['toHit'] is not None: the_attack = automation.Attack(hit=[the_attack], attackBonus=str( attack['toHit']), miss=[]) # target and damage meta target = automation.Target('each', [the_attack]) damage_roll = automation.Roll(attack['damage'] or '0', 'damage') effects = [damage_roll, target] # description text if desc: effects.append(automation.Text(desc)) return Attack(attack['name'], automation.Automation(effects)) else: return Attack.new(attack['name'], attack['toHit'], attack['damage'] or '0', desc)
def old_to_automation(bonus=None, damage=None, details=None): """Returns an Automation instance representing an old attack.""" from cogs5e.models import automation if damage is not None: damage = automation.Damage(damage) if bonus is not None: hit = [damage] if damage else [] attack_eff = [automation.Attack(hit=hit, miss=[], attackBonus=str(bonus).strip('{}<>'))] else: attack_eff = [damage] if damage else [] effects = [automation.Target('each', attack_eff)] if attack_eff else [] if details: # noinspection PyTypeChecker # PyCharm thinks this should be a list of Target instead of a list of Effect effects.append(automation.Text(details)) return automation.Automation(effects)