Skip to content

Commit

Permalink
Implement double impact for d10/d12 rolls >=10, closing #27 (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
freiheit authored Nov 27, 2023
1 parent 49092bb commit 7d42c60
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions mvkdicebot.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ async def roll(ctx, *, dicestr: str):
}

dicerolls = {}
flatdicerolls = []
flatdicerolls = [] # all dice
# dice d4-d12 are called "Character Dice" and the d20 is called the "Fortune Die"
characterdicerolls = [] # non-d20 dice
fortunedicerolls = [] # d20s

pattern_ndn = re.compile(r"([0-9]*) *[dD]([0-9]+)")

Expand All @@ -109,8 +112,6 @@ async def roll(ctx, *, dicestr: str):
else:
await ctx.send(f"Invalid dice size d{size}")

flatdicerolls = []

for size in dicecounts:
if dicecounts[size] > 0:
# logger.debug(f"rolling: d{size}={dicecounts[size]}")
Expand All @@ -123,8 +124,14 @@ async def roll(ctx, *, dicestr: str):
result = random.randint(1, size)
dicerolls[size].append(result)
flatdicerolls.append(result)
if size == 20:
fortunedicerolls.append(result)
else:
characterdicerolls.append(result)

flatdicerolls.sort(reverse=True)
fortunedicerolls.sort(reverse=True)
characterdicerolls.sort(reverse=True)

if len(dicerolls) > 0:
answer = ""
Expand Down Expand Up @@ -158,9 +165,13 @@ async def roll(ctx, *, dicestr: str):
action_total = sum(action_dice)
answer += f"**Action Total:** {str(action_total)} {str(action_dice)}\n"

impact = sum(1 for p in flatdicerolls if p >= 4)
# die results of 10 or higher on a d10 or 12 give two impact. It doesn't happen on a d20.
fortuneimpact = sum(1 for p in fortunedicerolls if p >= 4)
doublecharacterimpact = sum(2 for p in characterdicerolls if p >= 10)
characterimpact = sum(1 for p in characterdicerolls if p >= 4 and p < 10)
impact = fortuneimpact + doublecharacterimpact + characterimpact
impact = max(impact, 1)
answer += f"**Impact:** {impact}"
answer += f"**Impact:** {impact} (fortune={fortuneimpact} 2x={doublecharacterimpact} 1x={characterimpact})"

if cheat:
answer += "\n# Cheating"
Expand Down

0 comments on commit 7d42c60

Please sign in to comment.