|
|
|
|
|
|
|
|
spaces in expression are ignored |
|
|
spaces in expression are ignored |
|
|
Example: |
|
|
Example: |
|
|
.roll 2d20h1 + 7 # Rolls two D20s takes the highest 1, then adds 7 |
|
|
.roll 2d20h1 + 7 # Rolls two D20s takes the highest 1, then adds 7 |
|
|
.roll #will give brief overview of dice expression format |
|
|
|
|
|
|
|
|
.help roll #will give brief overview of dice expression format |
|
|
|
|
|
|
|
|
Dice expression format: |
|
|
Dice expression format: |
|
|
An expression can consist of many sub expressions added together and then a multiplier at the end to indicate how many times the expression should be rolled. |
|
|
An expression can consist of many sub expressions added together and then a multiplier at the end to indicate how many times the expression should be rolled. |
|
|
|
|
|
|
|
|
add r<number> #reroll any rolls below <number> |
|
|
add r<number> #reroll any rolls below <number> |
|
|
add h<number> #only sum the <number> highest rolls rather than all of them |
|
|
add h<number> #only sum the <number> highest rolls rather than all of them |
|
|
add l<number> #only sum the <number> lowest rolls rather than all of them |
|
|
add l<number> #only sum the <number> lowest rolls rather than all of them |
|
|
+<number> # Add this number to the sum. |
|
|
|
|
|
x<number> #only use at the end. roll the rest of the expression <number> times(max 10)") |
|
|
|
|
|
|
|
|
x<number> #only use at the end. roll the rest of the expression <number> times(max 10) |
|
|
Credit: TBTerra#5677 |
|
|
Credit: TBTerra#5677 |
|
|
""" |
|
|
""" |
|
|
rollMaxRolls = 10 |
|
|
rollMaxRolls = 10 |
|
|
|
|
|
|
|
|
except ValueError:#probably an input syntax error. safest to just roll once. |
|
|
except ValueError:#probably an input syntax error. safest to just roll once. |
|
|
times = 1 |
|
|
times = 1 |
|
|
response += "*Warning:* was unable to resolve how many times this command was meant to run. defaulted to once.\n" |
|
|
response += "*Warning:* was unable to resolve how many times this command was meant to run. defaulted to once.\n" |
|
|
m=re.findall('(-?)((?:(\d*)d(\d*))|\d+)(r\d*)?([h,l]{1}\d*)?',parts[0])#voodoo magic regex (matches A,dB,AdB,AdBrC and AdBh/lD all at once, and splits them up to be processed) |
|
|
|
|
|
|
|
|
m=re.findall('(-?)((?:(\d*)d(\d+))|\d+)(r\d+)?([h,l]{1}\d+)?',parts[0])#voodoo magic regex (matches A,dB,AdB,AdBrC and AdBh/lD all at once, and splits them up to be processed) |
|
|
if m == []:#either there were no arguments, or the expression contained nothing that could be seen as a number or roll |
|
|
if m == []:#either there were no arguments, or the expression contained nothing that could be seen as a number or roll |
|
|
return await ctx.send("Expression missing. If you are unsure of what the format should be, please use `{}help roll`".format(ctx.prefix)) |
|
|
return await ctx.send("Expression missing. If you are unsure of what the format should be, please use `{}help roll`".format(ctx.prefix)) |
|
|
dice = []#this is the list of all dice sets to be rolled |
|
|
dice = []#this is the list of all dice sets to be rolled |
|
|
|
|
|
|
|
|
temp = [0]*5 |
|
|
temp = [0]*5 |
|
|
temp[0] = 1 if item[0] == '' else -1#if theres a - at the beginning of the sub expression there needs to be a -1 multiplier applied to the sub expression total |
|
|
temp[0] = 1 if item[0] == '' else -1#if theres a - at the beginning of the sub expression there needs to be a -1 multiplier applied to the sub expression total |
|
|
if 'd' in item[1]:#if its a dice/set of dice rather than a number |
|
|
if 'd' in item[1]:#if its a dice/set of dice rather than a number |
|
|
|
|
|
temp[2] = int(item[3]) |
|
|
|
|
|
if temp[3] == 0:#safety check for things like 2d0 + 1 (0 sided dice) |
|
|
|
|
|
return await ctx.send("cant roll a zero sided dice") |
|
|
if item[2] == '':#if its just a dY rather than an XdY |
|
|
if item[2] == '':#if its just a dY rather than an XdY |
|
|
temp[1] = 1 |
|
|
temp[1] = 1 |
|
|
temp[2] = int(item[3]) |
|
|
|
|
|
else:#its a XdY type unknown if it has r,h,l modifyers, but they dont matter when sorting out the number and sides of dice |
|
|
else:#its a XdY type unknown if it has r,h,l modifyers, but they dont matter when sorting out the number and sides of dice |
|
|
temp[1] = int(item[2]) |
|
|
temp[1] = int(item[2]) |
|
|
if temp[1] > rollMaxDice:#if there are an unreasonable number of dice, error out. almost no-one needs to roll 9999d20 |
|
|
if temp[1] > rollMaxDice:#if there are an unreasonable number of dice, error out. almost no-one needs to roll 9999d20 |
|
|
return await ctx.send("I'm sorry {}, I'm afraid I cant do that. (To many dice to roll, max {})".format(self.bot.user.name,rollMaxDice)) |
|
|
return await ctx.send("I'm sorry {}, I'm afraid I cant do that. (To many dice to roll, max {})".format(self.bot.user.name,rollMaxDice)) |
|
|
if temp[1] > rollMaxVerbose and rollVerbose == True:#if there is a sub expression that involves lots of rolls then turn off verbose mode |
|
|
|
|
|
|
|
|
if temp[1] > rollMaxVerbose and rollVerbose:#if there is a sub expression that involves lots of rolls then turn off verbose mode |
|
|
rollVerbose = False |
|
|
rollVerbose = False |
|
|
response += '*Warning:* large number of rolls detected, will not use verbose rolling.\n' |
|
|
response += '*Warning:* large number of rolls detected, will not use verbose rolling.\n' |
|
|
temp[2] = int(item[3]) |
|
|
|
|
|
else:#numbers are stored as N, 1 sided dice |
|
|
else:#numbers are stored as N, 1 sided dice |
|
|
temp[1] = int(item[1]) |
|
|
temp[1] = int(item[1]) |
|
|
temp[2] = 1 |
|
|
temp[2] = 1 |
|
|
|
|
|
|
|
|
response += 'Roll {}: '.format(i+1) |
|
|
response += 'Roll {}: '.format(i+1) |
|
|
else: |
|
|
else: |
|
|
response += 'Rolled: ' |
|
|
response += 'Rolled: ' |
|
|
for j in range(len(dice)):#for each dice set in the expression |
|
|
|
|
|
|
|
|
for j, die in enumerate(dice):#for each dice set in the expression |
|
|
if j != 0 and rollVerbose:#dont need the + before the first element |
|
|
if j != 0 and rollVerbose:#dont need the + before the first element |
|
|
response += ' + ' |
|
|
response += ' + ' |
|
|
if dice[j][0] == -1 and rollVerbose:#all the dice sets will return positive numbers so the sign is set entirely by the sign value (element 0) |
|
|
|
|
|
|
|
|
if die[0] == -1 and rollVerbose:#all the dice sets will return positive numbers so the sign is set entirely by the sign value (element 0) |
|
|
response += '-' |
|
|
response += '-' |
|
|
if dice[j][2] == 1:#its just a number |
|
|
|
|
|
|
|
|
if die[2] == 1:#its just a number |
|
|
if rollVerbose: |
|
|
if rollVerbose: |
|
|
response += '{}'.format(dice[j][1]) |
|
|
|
|
|
total += dice[j][0] * dice[j][1] |
|
|
|
|
|
|
|
|
response += '{}'.format(die[1]) |
|
|
|
|
|
total += die[0] * die[1] |
|
|
else:#its a dice or set of dice |
|
|
else:#its a dice or set of dice |
|
|
if rollVerbose: |
|
|
if rollVerbose: |
|
|
response += '(' |
|
|
response += '(' |
|
|
temp = [] |
|
|
temp = [] |
|
|
for k in range(dice[j][1]):#for each dice in number of dice |
|
|
|
|
|
|
|
|
for k in range(die[1]):#for each dice in number of dice |
|
|
t = [0,''] |
|
|
t = [0,''] |
|
|
t[0] = random.randint(1,dice[j][2])#roll the dice |
|
|
|
|
|
|
|
|
t[0] = random.randint(1,die[2])#roll the dice |
|
|
t[1] = '{}'.format(t[0]) |
|
|
t[1] = '{}'.format(t[0]) |
|
|
if t[0] <= dice[j][3]:#if its below or equal to the re-roll value, then re-roll it |
|
|
|
|
|
t[0] = random.randint(1,dice[j][2]) |
|
|
|
|
|
|
|
|
if t[0] <= die[3]:#if its below or equal to the re-roll value, then re-roll it |
|
|
|
|
|
t[0] = random.randint(1,die[2]) |
|
|
t[1] += '__{}__'.format(t[0])#underline the re-roll so its clear thats the one to pay attention to |
|
|
t[1] += '__{}__'.format(t[0])#underline the re-roll so its clear thats the one to pay attention to |
|
|
temp.append(t) |
|
|
temp.append(t) |
|
|
def takeFirst(ele): |
|
|
def takeFirst(ele): |
|
|
return ele[0] |
|
|
return ele[0] |
|
|
if dice[j][4] > 0:#if its selecting highest |
|
|
|
|
|
|
|
|
if die[4] > 0:#if its selecting highest |
|
|
temp.sort(key=takeFirst, reverse=True)#sort the rolled dice. highest first |
|
|
temp.sort(key=takeFirst, reverse=True)#sort the rolled dice. highest first |
|
|
for k in range(len(temp)): |
|
|
|
|
|
if k >= dice[j][4]:#if the position in the sorted list is greater than the number of dice wanted, cross it out, and make it not count towards the total |
|
|
|
|
|
temp[k][1] = '~~' + temp[k][1] + '~~' |
|
|
|
|
|
temp[k][0] = 0 |
|
|
|
|
|
if dice[j][4] < 0:#if its selecting lowest |
|
|
|
|
|
|
|
|
for k, val in enumerate(temp): |
|
|
|
|
|
if k >= die[4]:#if the position in the sorted list is greater than the number of dice wanted, cross it out, and make it not count towards the total |
|
|
|
|
|
val[1] = '~~' + val[1] + '~~' |
|
|
|
|
|
val[0] = 0 |
|
|
|
|
|
if die[4] < 0:#if its selecting lowest |
|
|
temp.sort(key=takeFirst) |
|
|
temp.sort(key=takeFirst) |
|
|
for k in range(len(temp)):#sort the rolled dice. lowest first |
|
|
|
|
|
if k >= -dice[j][4]:#if the position in the sorted list is greater than the number of dice wanted, cross it out, and make it not count towards the total |
|
|
|
|
|
temp[k][1] = '~~' + temp[k][1] + '~~' |
|
|
|
|
|
temp[k][0] = 0 |
|
|
|
|
|
for k in range(len(temp)):##loop through all dice rolled and add them to the total. also print them if in verbose mode |
|
|
|
|
|
|
|
|
for k, val in enumerate(temp):#sort the rolled dice. lowest first |
|
|
|
|
|
if k >= -die[4]:#if the position in the sorted list is greater than the number of dice wanted, cross it out, and make it not count towards the total |
|
|
|
|
|
val[1] = '~~' + val[1] + '~~' |
|
|
|
|
|
val[0] = 0 |
|
|
|
|
|
for k, val in enumerate(temp):##loop through all dice rolled and add them to the total. also print them if in verbose mode |
|
|
if rollVerbose: |
|
|
if rollVerbose: |
|
|
response += '{},'.format(temp[k][1]) |
|
|
|
|
|
total+= dice[j][0] * temp[k][0] |
|
|
|
|
|
|
|
|
response += '{},'.format(val[1]) |
|
|
|
|
|
total+= die[0] * val[0] |
|
|
if rollVerbose: |
|
|
if rollVerbose: |
|
|
response = response[:-1] + ')'#clip the trailing ',' and replace it with a ')' |
|
|
response = response[:-1] + ')'#clip the trailing ',' and replace it with a ')' |
|
|
if rollVerbose: |
|
|
if rollVerbose: |
|
|
response += ' Totaling: {}'.format(total) |
|
|
response += ' Totaling: {}'.format(total) |
|
|
else: |
|
|
else: |
|
|
response += ' Total: {}'.format(total) |
|
|
response += ' Total: {}'.format(total) |
|
|
if i < (times-1): response += '\n' |
|
|
|
|
|
|
|
|
if i < (times-1): |
|
|
|
|
|
response += '\n' |
|
|
return await ctx.send(response) |
|
|
return await ctx.send(response) |
|
|
|
|
|
|
|
|
@roxbot.checks.isnt_anal() |
|
|
@roxbot.checks.isnt_anal() |