forked from DedSecInside/Awesome-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdndRoller.py
74 lines (60 loc) · 1.78 KB
/
dndRoller.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import random
import sys
def roller(string):
"""
Generate a string.
Args:
string: (str): write your description
"""
plus_or_minus = None
modifier = 0
d_index = string.find('d')
die_amount = int(string[:d_index])
if '+' in string:
mod_index = string.find('+')
die = int(string[d_index+1:mod_index])
modifier = int(string[mod_index+1:])
plus_or_minus = True
elif '-' in string:
mod_index = string.find('-')
die = int(string[d_index+1:mod_index])
modifier = int(string[mod_index+1:])
plus_or_minus = False
else:
die = int(string[d_index+1:])
# list of rolls
dice = [random.randint(1, die) for _ in range(die_amount)]
roll = sum(dice)
if die == 20 and die_amount > 1:
high = max(dice)
low = min(dice)
if modifier > 0 and plus_or_minus == True:
high += modifier
low += modifier
else:
high -= modifier
low -= modifier
if plus_or_minus == True:
roll += modifier
elif plus_or_minus == False:
roll -= modifier
if die_amount == 1 and die == 20:
if 20 in dice:
roll = 'Natural 20'
elif 1 in dice:
roll = 'Natural 1'
if die_amount == 2 and die == 20:
print(f'You rolled: {dice}')
print(f'High: {high}')
print(f'Low: {low}')
elif die_amount > 1:
print(f'You rolled: {dice}')
print(f'Total: {roll}')
elif plus_or_minus == True or plus_or_minus == False:
print(f'You rolled: {dice}')
print(f'You rolled a total of: {roll}')
else:
print(f'You rolled: {roll}')
if __name__ == '__main__':
# python dice.py 1d20, 2d20+2 or 1d20-2
roller(sys.argv[-1])