Example #1
0
parser.add_argument('-a', help='roll width advantage', action='store_true')
parser.add_argument('-d', help='roll width disadvantage', action='store_true')

args = parser.parse_args()

repeats = 1
if args.c is not None:
    if args.c >= 1:
        repeats = args.c

try:
    for i in range(repeats):
        target_ac = int(args.target_ac)

        attack_dice, attack_bonus = du.parse_roll_line(args.attack_roll)
        attack_result = du.roll_batch(attack_dice[0])
        if args.a:
            attack_result = max(attack_result, du.roll_batch(attack_dice[0]))
        elif args.d:
            attack_result = max(attack_result, du.roll_batch(attack_dice[0]))

        attack_roll = attack_result + attack_bonus
        print("Attack roll:     {} vs AC {}".format(attack_roll, target_ac))

        damage_dice, damage_bonus = du.parse_roll_line(args.damage_roll)
        damage = du.roll_all(damage_dice) + damage_bonus
        if attack_result == 20:
            damage += du.roll_all(damage_dice)

        if attack_result == 20:
            print("CRITICAL HIT!")
Example #2
0
parser.add_argument('-a', help='roll width advantage', action='store_true')
parser.add_argument('-d', help='roll width disadvantage', action='store_true')

args = parser.parse_args()

repeats = 1
if args.c is not None:
    if args.c >= 1:
        repeats = args.c

try:
    for i in range(repeats):
        target_ac = int(args.target_ac)

        attack_dice, attack_bonus = du.parse_roll_line(args.attack_roll)
        attack_result = du.roll_batch(attack_dice[0])
        if args.a:
            attack_result = max(attack_result, du.roll_batch(attack_dice[0]))
        elif args.d:
            attack_result = max(attack_result, du.roll_batch(attack_dice[0]))

        attack_roll = attack_result + attack_bonus
        print("Attack roll:     {} vs AC {}".format(attack_roll, target_ac))

        damage_dice, damage_bonus = du.parse_roll_line(args.damage_roll)
        damage = du.roll_all(damage_dice) + damage_bonus
        if attack_result == 20:
            damage += du.roll_all(damage_dice)

        if attack_result == 20:
            print("CRITICAL HIT!")
Example #3
0
        die, bonus = du.parse_roll_line(die_code)
        parsed_dice.append((die, bonus))

    rolls = []
    for i in range(repeats):
        rolls.append([])
        for dice, bonus in parsed_dice:
            if len(dice) == 0:
                rolls[i].append(bonus)
            elif args.advantage:
                if dice[0][1] > 1 or dice[0][2] != 20:
                    raise DiceArgumentException(
                        "Can only do a 1d20+x type of roll with advantage.")

                rolls[i].append(
                    max(du.roll_batch(dice[0]), du.roll_batch(dice[0])) +
                    bonus)
            elif args.disadvantage:
                if dice[0][1] > 1 or dice[0][2] != 20:
                    raise DiceArgumentException(
                        "Can only do a 1d20+x type of roll with disadvantage.")

                rolls[i].append(
                    max(du.roll_batch(dice[0]), du.roll_batch(dice[0])) +
                    bonus)
            elif args.best is not None:
                if len(dice) > 1:
                    raise DiceArgumentException(
                        "You can use only one type of die.")
                elif dice[0][1] < int(args.best):
                    raise DiceArgumentException(
Example #4
0
    parsed_dice = []
    for die_code in args.die_code:
        die, bonus = du.parse_roll_line(die_code)
        parsed_dice.append((die, bonus))

    rolls = []
    for i in range(repeats):
        rolls.append([])
        for dice, bonus in parsed_dice:
            if len(dice) == 0:
                rolls[i].append(bonus)
            elif args.advantage:
                if dice[0][1] > 1 or dice[0][2] != 20:
                    raise DiceArgumentException("Can only do a 1d20+x type of roll with advantage.")

                rolls[i].append(max(du.roll_batch(dice[0]), du.roll_batch(dice[0])) + bonus)
            elif args.disadvantage:
                if dice[0][1] > 1 or dice[0][2] != 20:
                    raise DiceArgumentException("Can only do a 1d20+x type of roll with disadvantage.")

                rolls[i].append(max(du.roll_batch(dice[0]), du.roll_batch(dice[0])) + bonus)
            elif args.best is not None:
                if len(dice) > 1:
                    raise DiceArgumentException("You can use only one type of die.")
                elif dice[0][1] < int(args.best):
                    raise DiceArgumentException("You can't pick out more dice than you roll.")

                rolls[i].append(
                    sum(sorted(du.roll_batch(dice[0], sumup=False), reverse=True)[: int(args.best)]) + bonus
                )
            elif args.worst is not None: