Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gameplay): roll desperation dice #120

Merged
merged 6 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
204 changes: 89 additions & 115 deletions poetry.lock

Large diffs are not rendered by default.

120 changes: 118 additions & 2 deletions src/valentina/cogs/gameplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@
from valentina.models import User
from valentina.models.bot import Valentina, ValentinaContext
from valentina.utils import random_num
from valentina.utils.autocomplete import select_char_trait, select_char_trait_two, select_macro
from valentina.utils.autocomplete import (
select_char_trait,
select_char_trait_two,
select_desperation_dice,
select_macro,
)
from valentina.utils.converters import ValidTraitFromID
from valentina.utils.perform_roll import perform_roll
from valentina.views import present_embed
Expand All @@ -37,6 +42,13 @@ async def throw(
required=False,
default=DEFAULT_DIFFICULTY,
),
desperation: Option(
int,
description="Add desperation dice",
required=False,
default=0,
autocomplete=select_desperation_dice,
),
comment: Option(str, "A comment to display with the roll", required=False, default=None),
) -> None:
"""Roll the dice.
Expand All @@ -45,12 +57,33 @@ async def throw(
comment (str, optional): A comment to display with the roll. Defaults to None.
ctx (ValentinaContext): The context of the command
difficulty (int): The difficulty of the roll
desperation (int): Add x desperation dice to the roll
pool (int): The number of dice to roll
"""
# Grab the player's active character for statistic logging purposes
character = await ctx.fetch_active_character(raise_error=False)

await perform_roll(ctx, pool, difficulty, DiceType.D10.value, comment, character=character)
if desperation > 0:
active_campaign = await ctx.fetch_active_campaign()
if active_campaign.desperation == 0 or desperation > 5: # noqa: PLR2004
await present_embed(
ctx,
title="Can not roll desperation",
description="The current desperation level is 0. No dice to roll.",
level="error",
ephemeral=True,
)
return

await perform_roll(
ctx,
pool,
difficulty,
DiceType.D10.value,
comment,
character=character,
desperation_pool=desperation,
)

@roll.command(name="traits", description="Throw a roll based on trait names")
async def traits(
Expand All @@ -76,6 +109,13 @@ async def traits(
required=False,
default=DEFAULT_DIFFICULTY,
),
desperation: Option(
int,
description="Add desperation dice",
required=False,
default=0,
autocomplete=select_desperation_dice,
),
comment: Option(str, "A comment to display with the roll", required=False, default=None),
) -> None:
"""Roll the total number of d10s for two given traits against a difficulty."""
Expand All @@ -88,6 +128,18 @@ async def traits(
LogLevel.DEBUG,
)

if desperation > 0:
active_campaign = await ctx.fetch_active_campaign()
if active_campaign.desperation == 0 or desperation > 5: # noqa: PLR2004
await present_embed(
ctx,
title="Can not roll desperation",
description="The current desperation level is 0. No dice to roll.",
level="error",
ephemeral=True,
)
return

await perform_roll(
ctx,
pool,
Expand All @@ -97,6 +149,7 @@ async def traits(
trait_one=trait_one,
trait_two=trait_two,
character=character,
desperation_pool=desperation,
)

@roll.command(description="Simple dice roll of any size.")
Expand Down Expand Up @@ -134,6 +187,13 @@ async def roll_macro(
required=False,
default=DEFAULT_DIFFICULTY,
),
desperation: Option(
int,
description="Add desperation dice",
required=False,
default=0,
autocomplete=select_desperation_dice,
),
comment: Option(str, "A comment to display with the roll", required=False, default=None),
) -> None:
"""Roll a macro."""
Expand All @@ -148,6 +208,18 @@ async def roll_macro(
msg = "Macro traits not found on character"
raise commands.BadArgument(msg)

if desperation > 0:
active_campaign = await ctx.fetch_active_campaign()
if active_campaign.desperation == 0 or desperation > 5: # noqa: PLR2004
await present_embed(
ctx,
title="Can not roll desperation",
description="The current desperation level is 0. No dice to roll.",
level="error",
ephemeral=True,
)
return

ctx.log_command(
f"Macro: {macro.name}: {trait_one.name} ({trait_one.id}) + {trait_two.name} ({trait_two.id})",
LogLevel.DEBUG,
Expand All @@ -164,6 +236,50 @@ async def roll_macro(
trait_one=trait_one,
trait_two=trait_two,
character=character,
desperation_pool=desperation,
)

@roll.command(name="desperation", description="Roll desperation")
async def roll_desperation(
self,
ctx: ValentinaContext,
desperation: Option(
int,
description="Add desperation dice",
required=True,
autocomplete=select_desperation_dice,
),
difficulty: Option(
int,
"The difficulty of the roll",
required=False,
default=DEFAULT_DIFFICULTY,
),
comment: Option(str, "A comment to display with the roll", required=False, default=None),
) -> None:
"""Roll desperation dice."""
active_campaign = await ctx.fetch_active_campaign()
if active_campaign.desperation == 0 or desperation > 5: # noqa: PLR2004
await present_embed(
ctx,
title="Can not roll desperation",
description="The current desperation level is 0. No dice to roll.",
level="error",
ephemeral=True,
)
return

# Grab the player's active character for statistic logging purposes
character = await ctx.fetch_active_character(raise_error=False)

await perform_roll(
ctx,
0,
difficulty,
DiceType.D10.value,
comment,
character=character,
desperation_pool=desperation,
)

### GAMEPLAY COMMANDS ###
Expand Down
33 changes: 19 additions & 14 deletions src/valentina/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,7 @@


### Single constants ###
COOL_POINT_VALUE = 10 # 1 cool point equals this many xp
DEFAULT_DIFFICULTY = 6 # Default difficulty for a roll
MAX_BUTTONS_PER_ROW = 5
MAX_DOT_DISPLAY = 5 # number of dots to display on a character sheet before converting to text
MAX_FIELD_COUNT = 1010
MAX_OPTION_LIST_SIZE = 25 # maximum number of options in a discord select menu
PREF_MAX_EMBED_CHARACTERS = 1950 # Preferred maximum number of characters in an embed
ABS_MAX_EMBED_CHARACTERS = 3900 # Absolute maximum number of characters in an embed -100 for safety
VALID_IMAGE_EXTENSIONS = frozenset(["png", "jpg", "jpeg", "gif", "webp"])
CHANGELOG_PATH = Path(__file__).parent / "../../CHANGELOG.md"
CHANGELOG_EXCLUDE_CATEGORIES = [
"docs",
"refactor",
Expand All @@ -36,6 +27,17 @@
"ci",
"build",
]
CHANGELOG_PATH = Path(__file__).parent / "../../CHANGELOG.md"
COOL_POINT_VALUE = 10 # 1 cool point equals this many xp
DEFAULT_DIFFICULTY = 6 # Default difficulty for a roll
MAX_BUTTONS_PER_ROW = 5
MAX_DOT_DISPLAY = 5 # number of dots to display on a character sheet before converting to text
MAX_FIELD_COUNT = 1010
MAX_OPTION_LIST_SIZE = 25 # maximum number of options in a discord select menu
MAX_POOL_SIZE = 100 # maximum number of dice that can be rolled
PREF_MAX_EMBED_CHARACTERS = 1950 # Preferred maximum number of characters in an embed
SPACER = "\u200b" # Zero-width space
VALID_IMAGE_EXTENSIONS = frozenset(["png", "jpg", "jpeg", "gif", "webp"])


### ENUMS ###
Expand Down Expand Up @@ -92,25 +94,28 @@ class Emoji(Enum):
CANCEL = "🚫"
COOL_POINT = "🆒"
DEAD = "💀"
DESPAIR = "😰"
DICE = "🎲"
ERROR = "❌"
GHOST = "👻"
HUNTER = "🧑🏹"
MAGE = "🧙🪄"
MONSTER = "👹"
MORTAL = "🧑"
NO = "❌"
PENCIL = "✏️"
OTHER = "🤷"
OVERREACH = "😱"
PENCIL = "✏️"
QUESTION = "❓"
RECYCLE = "♻️"
RELOAD = "🔄"
SETTING = "⚙️"
SUCCESS = "👍"
VAMPIRE = "🧛"
WARNING = "⚠️"
WEREWOLF = "🐺"
YES = "✅"
SETTING = "⚙️"
RECYCLE = "♻️"
RELOAD = "🔄"
DICE = "🎲"
FACEPALM = "🤦"


class GithubIssueLabels(Enum):
Expand Down
Loading
Loading