init commit
This commit is contained in:
24
app/game/utils/common.py
Normal file
24
app/game/utils/common.py
Normal file
@@ -0,0 +1,24 @@
|
||||
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
|
||||
Reference in New Issue
Block a user