From c0bb9c45c0684eca21753d02a9eae1ebe002aae0 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Wed, 23 Oct 2019 11:54:45 +0200 Subject: [PATCH] Add dndrolladv and dndrolldis --- royalnet/packs/rpg/commands/__init__.py | 4 ++++ royalnet/packs/rpg/commands/dndroll.py | 10 +++++++-- royalnet/packs/rpg/commands/dndrolladv.py | 26 +++++++++++++++++++++++ royalnet/packs/rpg/commands/dndrolldis.py | 26 +++++++++++++++++++++++ 4 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 royalnet/packs/rpg/commands/dndrolladv.py create mode 100644 royalnet/packs/rpg/commands/dndrolldis.py diff --git a/royalnet/packs/rpg/commands/__init__.py b/royalnet/packs/rpg/commands/__init__.py index db8cc1ec..569bae5e 100644 --- a/royalnet/packs/rpg/commands/__init__.py +++ b/royalnet/packs/rpg/commands/__init__.py @@ -6,6 +6,8 @@ from .dndinfo import DndinfoCommand from .dndnew import DndnewCommand from .dndedit import DndeditCommand from .dndroll import DndrollCommand +from .dndrolladv import DndrolladvCommand +from .dndrolldis import DndrolldisCommand # Enter the commands of your Pack here! available_commands = [ @@ -16,6 +18,8 @@ available_commands = [ DndnewCommand, DndeditCommand, DndrollCommand, + DndrolladvCommand, + DndrolldisCommand, ] # Don't change this, it should automatically generate __all__ diff --git a/royalnet/packs/rpg/commands/dndroll.py b/royalnet/packs/rpg/commands/dndroll.py index 286ca230..348b34a4 100644 --- a/royalnet/packs/rpg/commands/dndroll.py +++ b/royalnet/packs/rpg/commands/dndroll.py @@ -16,6 +16,12 @@ class DndrollCommand(Command): tables = {DndCharacter, DndActiveCharacter} + @staticmethod + def _roll(): + return random.randrange(1, 21) + + _roll_string = "1d20" + async def run(self, args: CommandArgs, data: CommandData) -> None: author = await data.get_author(error_if_none=True) if author.dnd_active_character is None: @@ -73,12 +79,12 @@ class DndrollCommand(Command): total_mod = stat_mod + proficiency_mod + extra_mod - roll = random.randrange(1, 21) + roll = self._roll() result = roll + total_mod await data.reply(f"🎲 Rolling {stat_name}{proficiency_name}{plusformat(extra_mod, empty_if_zero=True)}:\n" - f"1d20" + f"{self._roll_string}" f"{plusformat(stat_mod, empty_if_zero=True)}" f"{plusformat(proficiency_mod, empty_if_zero=True)}" f"{plusformat(extra_mod, empty_if_zero=True)}" diff --git a/royalnet/packs/rpg/commands/dndrolladv.py b/royalnet/packs/rpg/commands/dndrolladv.py new file mode 100644 index 00000000..9d918597 --- /dev/null +++ b/royalnet/packs/rpg/commands/dndrolladv.py @@ -0,0 +1,26 @@ +import typing +import random +from royalnet.commands import * +from royalnet.utils import plusformat +from .dndroll import DndrollCommand +from ..tables import DndCharacter, DndActiveCharacter + + +class DndrolladvCommand(DndrollCommand): + name: str = "dndrolladv" + + description: str = "Roll with advantage as the active DnD character." + + aliases = ["dra", "dndra", "drolladv"] + + syntax = "{stat} [proficiency] [modifier]" + + tables = {DndCharacter, DndActiveCharacter} + + @staticmethod + def _roll(): + first = random.randrange(1, 21) + second = random.randrange(1, 21) + return max(first, second) + + _roll_string = "2d20h1" diff --git a/royalnet/packs/rpg/commands/dndrolldis.py b/royalnet/packs/rpg/commands/dndrolldis.py new file mode 100644 index 00000000..e195c34d --- /dev/null +++ b/royalnet/packs/rpg/commands/dndrolldis.py @@ -0,0 +1,26 @@ +import typing +import random +from royalnet.commands import * +from royalnet.utils import plusformat +from .dndroll import DndrollCommand +from ..tables import DndCharacter, DndActiveCharacter + + +class DndrolldisCommand(DndrollCommand): + name: str = "dndrolldis" + + description: str = "Roll with disadvantage as the active DnD character." + + aliases = ["drd", "dndrd", "drolldis"] + + syntax = "{stat} [proficiency] [modifier]" + + tables = {DndCharacter, DndActiveCharacter} + + @staticmethod + def _roll(): + first = random.randrange(1, 21) + second = random.randrange(1, 21) + return min(first, second) + + _roll_string = "2d20l1"