Protect against some sorts of throws
This commit is contained in:
parent
50e1acc8fc
commit
d815b27ce9
1 changed files with 15 additions and 9 deletions
24
roller.py
24
roller.py
|
|
@ -114,25 +114,31 @@ class Roller:
|
|||
|
||||
@staticmethod
|
||||
def throw(amount, sides):
|
||||
results = [random.randint(1, sides) for _ in range(amount)]
|
||||
result = sum(results)
|
||||
resultstr = "(" + "+".join(str(r) for r in results) + ")"
|
||||
if 0 < amount <= 100 and 0 < sides <= 10000:
|
||||
results = [random.randint(1, sides) for _ in range(amount)]
|
||||
result = sum(results)
|
||||
resultstr = "(" + "+".join(str(r) for r in results) + ")"
|
||||
else:
|
||||
result = 0
|
||||
resultstr = "[invalid throw]"
|
||||
return result, resultstr
|
||||
|
||||
@staticmethod
|
||||
def advantage(dis, amount, sides):
|
||||
results = [random.randint(1, sides) for _ in range(amount)]
|
||||
result = min(results) if dis else max(results)
|
||||
resultstr = "(" + ",".join(str(r) for r in results) + ")"
|
||||
resultstr = ("d" if dis else "a") + resultstr
|
||||
if 0 < amount <= 100 and 0 < sides <= 10000:
|
||||
results = [random.randint(1, sides) for _ in range(amount)]
|
||||
result = min(results) if dis else max(results)
|
||||
resultstr = "(" + ",".join(str(r) for r in results) + ")"
|
||||
resultstr = ("d" if dis else "a") + resultstr
|
||||
else:
|
||||
result = 0
|
||||
resultstr = "[invalid throw]"
|
||||
return result, resultstr
|
||||
|
||||
@staticmethod
|
||||
def number(number):
|
||||
return number, str(number)
|
||||
|
||||
|
||||
|
||||
class RollerBot(yaboli.Bot):
|
||||
SHORT_HELP = Roller.SHORT_DESCRIPTION
|
||||
LONG_HELP = Roller.DESCRIPTION + Roller.COMMANDS + "\n" + Roller.SYNTAX + "\n" + Roller.EXAMPLES + "\n" + Roller.AUTHOR + Roller.CREDITS
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue