Skip to content

Commit

Permalink
feat(gameplay): add /gameplay damage for damage effects
Browse files Browse the repository at this point in the history
  • Loading branch information
natelandau committed Nov 16, 2023
1 parent 80e16c5 commit af45534
Show file tree
Hide file tree
Showing 17 changed files with 85 additions and 30 deletions.
7 changes: 4 additions & 3 deletions src/valentina/characters/chargen.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
)
from valentina.models import Campaign, Character, CharacterSheetSection, CharacterTrait, User
from valentina.models.bot import Valentina, ValentinaContext
from valentina.utils import random_num
from valentina.utils.helpers import (
divide_total_randomly,
fetch_random_name,
Expand Down Expand Up @@ -455,22 +456,22 @@ async def generate_base_character(

# Grab a random class
if char_class is None:
percentile = _rng.integers(1, 101)
percentile = random_num(100)
char_class = CharClass.get_member_by_value(percentile)

name_nick = char_class.value.name if nickname_is_class else None

# Grab a random concept
if concept is None:
percentile = _rng.integers(1, 101)
percentile = random_num(100)
concept = CharacterConcept.get_member_by_value(percentile)

# Grab class specific information
if char_class == CharClass.VAMPIRE and not clan:
clan = VampireClan.random_member()

if char_class == CharClass.HUNTER and not creed:
percentile = _rng.integers(1, 101)
percentile = random_num(100)
creed = HunterCreed.get_member_by_value(percentile)

character = Character(
Expand Down
3 changes: 1 addition & 2 deletions src/valentina/cogs/characters.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
Emoji,
RNGCharLevel,
)
from valentina.models import Character, CharacterSheetSection, User
from valentina.models.aws import AWSService
from valentina.models import AWSService, Character, CharacterSheetSection, User
from valentina.models.bot import Valentina, ValentinaContext
from valentina.utils import errors
from valentina.utils.autocomplete import (
Expand Down
3 changes: 1 addition & 2 deletions src/valentina/cogs/developer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@

from valentina.characters import RNGCharGen
from valentina.constants import MAX_CHARACTER_COUNT, EmbedColor
from valentina.models import Character, GlobalProperty, Guild, RollProbability, User
from valentina.models.aws import AWSService
from valentina.models import AWSService, Character, GlobalProperty, Guild, RollProbability, User
from valentina.models.bot import Valentina, ValentinaContext
from valentina.utils.autocomplete import (
select_aws_object_from_guild,
Expand Down
55 changes: 55 additions & 0 deletions src/valentina/cogs/gameplay.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
# mypy: disable-error-code="valid-type"
"""Gameplay cog for Valentina."""

import random

import discord
from discord.commands import Option
from discord.ext import commands

from valentina.constants import DEFAULT_DIFFICULTY, DiceType
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.perform_roll import perform_roll
from valentina.views import present_embed


class Roll(commands.Cog):
Expand All @@ -18,6 +22,7 @@ class Roll(commands.Cog):
def __init__(self, bot: Valentina) -> None:
self.bot: Valentina = bot

### DICEROLL COMMANDS ###
roll = discord.SlashCommandGroup("roll", "Roll dice")

@roll.command(description="Throw a roll of d10s")
Expand Down Expand Up @@ -152,6 +157,56 @@ async def roll_macro(
character=character,
)

### GAMEPLAY COMMANDS ###
gameplay = discord.SlashCommandGroup("gameplay", "Gameplay commands")

@gameplay.command(name="damage", description="determine damage")
async def damage(
self,
ctx: ValentinaContext,
damage: Option(
int,
name="damage",
description="Damage taken",
required=True,
),
soak: Option(
int,
name="soak",
description="Soak to apply",
required=False,
default=0,
),
) -> None:
"""Determine damage."""
damage = damage + random_num(10) - soak

if damage <= 0:
result = ("No Damage", "Miracles happen, no damage taken")

if 1 <= damage <= 6: # noqa: PLR2004
result = ("Stunned", "Spend 1 Willpower or lose one turn.")

elif 7 <= damage <= 8: # noqa: PLR2004
result = ("Severe head trauma", "Physical rolls lose 1 die; Mental rolls lose 2.")

elif 9 <= damage <= 10: # noqa: PLR2004
one = ("Broken limb or joint", "Rolls using the affected limb lose 3 dice.")
two = ("Blinded", "Vision-related rolls lose 3 dice.")
result = random.choice([one, two])

elif damage == 11: # noqa: PLR2004
result = ("Massive wound", "All rolls lose 2 dice. Add 1 to all damage suffered.")

elif damage == 12: # noqa: PLR2004
result = ("Crippled", "Limb is lost or mangled beyond use. Lose 3 dice when using it.")

elif damage >= 13: # noqa: PLR2004
result = ("Death or torpor", "Mortals die. Vampires enter immediate torpor.")

title, description = result
await present_embed(ctx, title, description, level="info")


def setup(bot: Valentina) -> None:
"""Add the cog to the bot."""
Expand Down
3 changes: 1 addition & 2 deletions src/valentina/cogs/storyteller.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
DiceType,
EmbedColor,
)
from valentina.models import Character, User
from valentina.models.aws import AWSService
from valentina.models import AWSService, Character, User
from valentina.models.bot import Valentina, ValentinaContext
from valentina.utils.autocomplete import (
select_any_player_character,
Expand Down
2 changes: 1 addition & 1 deletion src/valentina/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

from .aws import AWSService # isort: skip
from .statistics import Statistics, RollStatistic # isort: skip
from .probability import Probability, RollProbability # isort: skip
from .dicerolls import DiceRoll # isort: skip
from .probability import Probability, RollProbability # isort: skip

__all__ = [
"AWSService",
Expand Down
7 changes: 3 additions & 4 deletions src/valentina/models/dicerolls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
import discord
import inflect
from loguru import logger
from numpy.random import default_rng

from valentina.constants import DiceType, EmbedColor, RollResultType
from valentina.models import Character, Guild, RollStatistic
from valentina.utils import errors
from valentina.utils import errors, random_num

p = inflect.engine()
_rng = default_rng()

_max_pool_size = 100


Expand Down Expand Up @@ -154,7 +153,7 @@ def result_type(self) -> RollResultType:
def roll(self) -> list[int]:
"""Roll the dice and return the results."""
if not self._roll:
self._roll = list(map(int, _rng.integers(1, self.dice_type.value + 1, self.pool)))
self._roll = [random_num(self.dice_type.value) for x in range(self.pool)]

return self._roll

Expand Down
2 changes: 1 addition & 1 deletion src/valentina/models/probability.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pydantic import Field

from valentina.constants import EmbedColor, RollResultType
from valentina.models.dicerolls import DiceRoll
from valentina.models import DiceRoll
from valentina.utils.helpers import time_now

# Constants for emoji thresholds
Expand Down
3 changes: 2 additions & 1 deletion src/valentina/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Utility functions for Valentina."""

from .helpers import random_num
from .logging import InterceptHandler

__all__ = ["Context", "InterceptHandler"]
__all__ = ["Context", "InterceptHandler", "random_num"]
3 changes: 1 addition & 2 deletions src/valentina/utils/autocomplete.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
TraitCategory,
VampireClan,
)
from valentina.models import Campaign, Character, Guild, User
from valentina.models.aws import AWSService
from valentina.models import AWSService, Campaign, Character, Guild, User
from valentina.models.bot import Valentina
from valentina.utils.changelog_parser import ChangelogParser
from valentina.utils.helpers import truncate_string
Expand Down
11 changes: 9 additions & 2 deletions src/valentina/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,21 @@
from datetime import UTC, datetime
from urllib.parse import urlencode

import aiohttp
from aiohttp import ClientSession
from loguru import logger
from numpy.random import default_rng

from valentina.constants import MaxTraitValue, XPMultiplier, XPNew
from valentina.utils import errors
from valentina.utils.config import CONFIG

_rng = default_rng()


def random_num(ceiling: int = 100) -> int:
"""Get a random number between 1 and ceiling."""
return _rng.integers(1, ceiling + 1)


def get_config_value(key: str, default: str | None = None, pass_none: bool = False) -> str:
"""Get an environment variable and check if it exists.
Expand Down Expand Up @@ -215,7 +222,7 @@ def get_trait_new_value(trait: str, category: str) -> int:

async def fetch_data_from_url(url: str) -> io.BytesIO: # pragma: no cover
"""Fetch data from a URL to be used to upload to Amazon S3."""
async with aiohttp.ClientSession() as session, session.get(url) as resp:
async with ClientSession() as session, session.get(url) as resp:
if resp.status != 200: # noqa: PLR2004
msg = f"Could not fetch data from {url}"
raise errors.URLNotAvailableError(msg)
Expand Down
3 changes: 1 addition & 2 deletions src/valentina/utils/perform_roll.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
"""Perform a diceroll."""

from valentina.models import Character, CharacterTrait
from valentina.models import Character, CharacterTrait, DiceRoll
from valentina.models.bot import ValentinaContext
from valentina.models.dicerolls import DiceRoll
from valentina.views import ReRollButton, RollDisplay


Expand Down
4 changes: 1 addition & 3 deletions src/valentina/views/character_sheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@
Emoji,
TraitCategory,
)
from valentina.models import Character, CharacterTrait
from valentina.models.aws import AWSService
from valentina.models import AWSService, Character, CharacterTrait, Statistics
from valentina.models.bot import ValentinaContext
from valentina.models.statistics import Statistics


def __embed1( # noqa: C901
Expand Down
3 changes: 1 addition & 2 deletions src/valentina/views/roll_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
import discord
import inflect

from valentina.models import CharacterTrait
from valentina.models import CharacterTrait, DiceRoll
from valentina.models.bot import ValentinaContext
from valentina.models.dicerolls import DiceRoll

p = inflect.engine()

Expand Down
3 changes: 1 addition & 2 deletions src/valentina/views/s3_image_review.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
from loguru import logger

from valentina.constants import EmbedColor, Emoji
from valentina.models import Character
from valentina.models.aws import AWSService
from valentina.models import AWSService, Character
from valentina.models.bot import ValentinaContext


Expand Down
2 changes: 1 addition & 1 deletion tests/models/test_dicerolls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pytest

from valentina.constants import RollResultType
from valentina.models.dicerolls import DiceRoll, RollStatistic
from valentina.models import DiceRoll, RollStatistic
from valentina.utils import errors


Expand Down
1 change: 1 addition & 0 deletions user_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ Macros are a powerful tool to enhance your gaming experience, allowing for quick
- **Roll Dice**: Use `/roll` for various types of rolls, including stats, traits, macros, D10s, or arbitrary dice.
- **Create Campaign NPCs**: As you meet an important NPC, take a note of them with `/campaign npc create`.
- **Add Campaign Notes**: Keep track of important information by creating notes during gameplay with `/campaign note create`.
- **Determine damage**: Use `/gameplay damage [damage]` to determine the effects of damage.

### Dice Rolling

Expand Down

0 comments on commit af45534

Please sign in to comment.