def attack_roll(self, advantage=False, disadvantage=False): if advantage and disadvantage: advantage = False disadvantage = False # Determine modification if self.attack_mod: dice_mod = self.attack_mod else: dice_mod = self._get_ability() if self.owner.is_proficient(self): dice_mod += self.owner.proficiency # Roll the d20 dice = Dice("1d20") if advantage: roll = max((dice * 2).roll()) elif disadvantage: roll = min((dice * 2).roll()) else: roll = dice.roll()[0] return roll + dice_mod, roll == 20
def test_add_dynamic_modifiers_to_dice(): modifier = Modifier(1) dice = Dice("d1") + modifier assert dice.roll() == [2] modifier.mod = 2 assert dice.roll() == [3]