init commit

This commit is contained in:
2025-11-02 01:14:41 -05:00
commit 7bf81109b3
31 changed files with 2387 additions and 0 deletions

24
app/game/utils/common.py Normal file
View 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