From 3a596805e7e0a63caf5e724786c8d169abc70596 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Mon, 16 Mar 2020 20:03:49 +0100 Subject: [PATCH] publish: 5.4 --- pyproject.toml | 2 +- rpgpack/commands/dndactive.py | 9 ++++--- rpgpack/commands/dndedit.py | 11 ++++---- rpgpack/commands/dndinfo.py | 48 ++++++++++++++++++++++++++++++--- rpgpack/tables/dndcharacters.py | 4 +-- rpgpack/version.py | 2 +- 6 files changed, 61 insertions(+), 15 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 98473fd8..7e5734ca 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,7 +2,7 @@ [tool.poetry] name = "rpgpack" - version = "5.3.2" + version = "5.4" description = "A Royalnet Pack to play role-playing-games" authors = ["Stefano Pigozzi "] license = "AGPL-3.0+" diff --git a/rpgpack/commands/dndactive.py b/rpgpack/commands/dndactive.py index 9feb4a57..5bd250f1 100644 --- a/rpgpack/commands/dndactive.py +++ b/rpgpack/commands/dndactive.py @@ -19,6 +19,9 @@ class DndactiveCommand(Command): author = await data.get_author(error_if_none=True) active_character = await get_active_character(data) + DndCharacterT = self.alchemy.get(DndCharacter) + DndActiveCharacterT = self.alchemy.get(DndActiveCharacter) + # Display the active character if identifier is None: if active_character is None: @@ -31,7 +34,7 @@ class DndactiveCommand(Command): try: identifier = int(identifier) except ValueError: - chars = await asyncify(data.session.query(self.alchemy.get(DndCharacter)).filter_by(name=identifier).all) + chars = await asyncify(data.session.query(DndCharacterT).filter_by(name=identifier).all) if len(chars) >= 2: char_string = "\n".join([f"[c]{char.character_id}[/c] (LV {char.level}) by {char.creator})" for char in chars]) raise CommandError(f"Multiple characters share the name {identifier}, " @@ -42,7 +45,7 @@ class DndactiveCommand(Command): char = None else: # Find the character by id - char = await asyncify(data.session.query(self.alchemy.get(DndCharacter)) + char = await asyncify(data.session.query(DndCharacterT) .filter_by(character_id=identifier) .one_or_none) if char is None: @@ -50,7 +53,7 @@ class DndactiveCommand(Command): # Check if the player already has an active character if active_character is None: # Create a new active character - achar = self.alchemy.get(DndActiveCharacter)( + achar = DndActiveCharacterT( character=char, user=author, interface_name=self.interface.name, diff --git a/rpgpack/commands/dndedit.py b/rpgpack/commands/dndedit.py index 4e9797fe..b8b27332 100644 --- a/rpgpack/commands/dndedit.py +++ b/rpgpack/commands/dndedit.py @@ -15,14 +15,15 @@ class DndeditCommand(DndnewCommand): async def run(self, args: CommandArgs, data: CommandData) -> None: character_sheet = args.joined() - if character_sheet == "": - await data.reply(self._syntax()) - return - active_character = await get_active_character(data) + if active_character is None: raise CommandError("You don't have an active character.") - char = active_character.character + char: DndCharacter = active_character.character + + if character_sheet == "": + await data.reply(char.to_edit_string()) + return arguments = self._parse(character_sheet) for key in arguments: diff --git a/rpgpack/commands/dndinfo.py b/rpgpack/commands/dndinfo.py index c1a1f6c9..8f7126fa 100644 --- a/rpgpack/commands/dndinfo.py +++ b/rpgpack/commands/dndinfo.py @@ -12,10 +12,52 @@ class DndinfoCommand(Command): tables = {DndCharacter, DndActiveCharacter} + _p_emoji = { + 0: "🌑", + 0.5: "🌗", + 1: "🌕", + 2: "⭐️", + } + async def run(self, args: CommandArgs, data: CommandData) -> None: active_character = await get_active_character(data) - char = active_character.character - if char is None: + if active_character is None: raise CommandError("You don't have an active character.") - await data.reply(char.character_sheet()) + c: DndCharacter = active_character.character + + r = f"[b]{c.name}[/b]\n" \ + f"🔰 Lv. {c.level}\n" \ + f"\n" \ + f"❤️ {c.current_hp}/{c.max_hp}\n" \ + f"🛡 {c.armor_class}\n" \ + f"\n" \ + f"{self._p_emoji[c.strength_save_proficiency.value]} Strength: [b]{c.strength:+d}[/b] ({c.strength_score})\n" \ + f"{self._p_emoji[c.dexterity_save_proficiency.value]} Dexterity: [b]{c.dexterity:+d}[/b] ({c.dexterity_score})\n" \ + f"{self._p_emoji[c.constitution_save_proficiency.value]} Constitution: [b]{c.constitution:+d}[/b] ({c.constitution_score})\n" \ + f"{self._p_emoji[c.intelligence_save_proficiency.value]} Intelligence: [b]{c.intelligence:+d}[/b] ({c.intelligence_score})\n" \ + f"{self._p_emoji[c.wisdom_save_proficiency.value]} Wisdom: [b]{c.wisdom:+d}[/b] ({c.wisdom_score})\n" \ + f"{self._p_emoji[c.charisma_save_proficiency.value]} Charisma: [b]{c.charisma:+d}[/b] ({c.charisma_score})\n" \ + f"\n" \ + f"{self._p_emoji[c.acrobatics_proficiency.value]} Acrobatics: [b]{c.acrobatics:+d}[/b]\n" \ + f"{self._p_emoji[c.animal_handling_proficiency.value]} Animal Handling: [b]{c.animal_handling:+d}[/b]\n" \ + f"{self._p_emoji[c.arcana_proficiency.value]} Arcana: [b]{c.arcana:+d}[/b]\n" \ + f"{self._p_emoji[c.athletics_proficiency.value]} Athletics: [b]{c.athletics:+d}[/b]\n" \ + f"{self._p_emoji[c.deception_proficiency.value]} Deception: [b]{c.deception:+d}[/b]\n" \ + f"{self._p_emoji[c.history_proficiency.value]} History: [b]{c.history:+d}[/b]\n" \ + f"{self._p_emoji[c.insight_proficiency.value]} Insight: [b]{c.insight:+d}[/b]\n" \ + f"{self._p_emoji[c.intimidation_proficiency.value]} Intimidation: [b]{c.intimidation:+d}[/b]\n" \ + f"{self._p_emoji[c.investigation_proficiency.value]} Investigation: [b]{c.investigation:+d}[/b]\n" \ + f"{self._p_emoji[c.medicine_proficiency.value]} Medicine: [b]{c.medicine:+d}[/b]\n" \ + f"{self._p_emoji[c.nature_proficiency.value]} Nature: [b]{c.nature:+d}[/b]\n" \ + f"{self._p_emoji[c.perception_proficiency.value]} Perception: [b]{c.perception:+d}[/b]\n" \ + f"{self._p_emoji[c.performance_proficiency.value]} Performance: [b]{c.performance:+d}[/b]\n" \ + f"{self._p_emoji[c.persuasion_proficiency.value]} Persuasion: [b]{c.persuasion:+d}[/b]\n" \ + f"{self._p_emoji[c.religion_proficiency.value]} Religion: [b]{c.religion:+d}[/b]\n" \ + f"{self._p_emoji[c.sleight_of_hand_proficiency.value]} Sleight of Hand: [b]{c.sleight_of_hand:+d}[/b]\n" \ + f"{self._p_emoji[c.stealth_proficiency.value]} Stealth: [b]{c.stealth:+d}[/b]\n" \ + f"{self._p_emoji[c.survival_proficiency.value]} Survival: [b]{c.survival:+d}[/b]\n" \ + f"\n" \ + f"{self._p_emoji[c.initiative_proficiency.value]} Initiative: [b]{c.initiative:+d}[/b]\n" + + await data.reply(r) diff --git a/rpgpack/tables/dndcharacters.py b/rpgpack/tables/dndcharacters.py index 0281c228..57261d9e 100644 --- a/rpgpack/tables/dndcharacters.py +++ b/rpgpack/tables/dndcharacters.py @@ -23,7 +23,7 @@ class DndCharacter: @declared_attr def name(self): - return Column(String, nullable=False) + return Column(String, nullable=False, unique=True) @declared_attr def strength_score(self): @@ -299,7 +299,7 @@ class DndCharacter: def __str__(self): return f"{self.name}" - def character_sheet(self) -> str: + def to_edit_string(self) -> str: columns = list(self.__class__.__table__.columns) column_names = [column.name for column in columns if (not column.primary_key and not column.foreign_keys and diff --git a/rpgpack/version.py b/rpgpack/version.py index 5b656d04..03217183 100644 --- a/rpgpack/version.py +++ b/rpgpack/version.py @@ -1 +1 @@ -semantic = "5.3.2" +semantic = "5.4"