25 lines
671 B
Python
25 lines
671 B
Python
from __future__ import annotations
|
|
import math
|
|
import random
|
|
|
|
from logging import getLogger
|
|
|
|
logger = getLogger(__file__)
|
|
|
|
class Dice:
|
|
def roll_dice(self, spec: str = "1d6"):
|
|
# supports "1d10", "2d6" etc
|
|
total = 0
|
|
try:
|
|
n, d = map(int, spec.lower().split("d"))
|
|
for _ in range(0,n,1):
|
|
total += random.randint(1,d)
|
|
return total
|
|
except Exception as e:
|
|
logger.error(f"Unable to roll dice spec: {spec} - please use 1d10 or similar")
|
|
return 0
|
|
|
|
def max_of_die(self, spec: str) -> int:
|
|
n, d = map(int, spec.lower().split("d"))
|
|
return n * d
|