diff --git a/rpgpack/commands/__init__.py b/rpgpack/commands/__init__.py index b64224a3..fde32940 100644 --- a/rpgpack/commands/__init__.py +++ b/rpgpack/commands/__init__.py @@ -10,6 +10,7 @@ from .dnditem import DnditemCommand from .dndspell import DndspellCommand from .testhealth import TesthealthCommand from .testfaction import TestfactionCommand +from .dndnewbattle import DndnewbattleCommand # Enter the commands of your Pack here! available_commands = [ diff --git a/rpgpack/commands/dndnewbattle.py b/rpgpack/commands/dndnewbattle.py new file mode 100644 index 00000000..e978ccad --- /dev/null +++ b/rpgpack/commands/dndnewbattle.py @@ -0,0 +1,29 @@ +from typing import * +import royalnet +import royalnet.commands as rc +from ..tables import DndBattle + + +class DndnewbattleCommand(rc.Command): + name: str = "dndnewbattle" + + description: str = "Create a new D&D battle." + + syntax: str = "{name}\n[description]" + + async def run(self, args: rc.CommandArgs, data: rc.CommandData) -> None: + BattleT = self.alchemy.get(DndBattle) + + line_args = args.joined(require_at_least=1).split("\n", 1) + name = line_args[0] + description = line_args[1] if len(line_args) > 1 else None + + battle = BattleT( + name=name, + description=description + ) + + data.session.add(battle) + await data.session_commit() + + await data.reply(f"✅ Battaglia [b]{battle.name}[/b] creata!") diff --git a/rpgpack/commands/testfaction.py b/rpgpack/commands/testfaction.py index e3ebb10c..30bfa5b8 100644 --- a/rpgpack/commands/testfaction.py +++ b/rpgpack/commands/testfaction.py @@ -1,7 +1,7 @@ from typing import * import royalnet import royalnet.commands as rc -from ..utils import FactionColor +from ..utils import Faction class TestfactionCommand(rc.Command): @@ -12,4 +12,4 @@ class TestfactionCommand(rc.Command): syntax: str = "{factionstring}" async def run(self, args: rc.CommandArgs, data: rc.CommandData) -> None: - await data.reply(FactionColor[args[0].upper()].value) + await data.reply(Faction[args[0].upper()].value) diff --git a/rpgpack/tables/__init__.py b/rpgpack/tables/__init__.py index 70dc4390..dd1cd652 100644 --- a/rpgpack/tables/__init__.py +++ b/rpgpack/tables/__init__.py @@ -1,11 +1,15 @@ # Imports go here! from .dndactivecharacters import DndActiveCharacter from .dndcharacters import DndCharacter +from .dndbattle import DndBattle +from .dndbattleunit import DndBattleUnit # Enter the tables of your Pack here! available_tables = [ DndActiveCharacter, DndCharacter, + DndBattle, + DndBattleUnit, ] # Don't change this, it should automatically generate __all__ diff --git a/rpgpack/tables/dndactivebattle.py b/rpgpack/tables/dndactivebattle.py new file mode 100644 index 00000000..9ebfb10c --- /dev/null +++ b/rpgpack/tables/dndactivebattle.py @@ -0,0 +1,26 @@ +from sqlalchemy import * +from sqlalchemy.orm import * +from sqlalchemy.ext.declarative import * + + +class DndActiveBattle: + __tablename__ = "dndactivebattle" + + @declared_attr + def battle_id(self): + return Column(Integer, ForeignKey("dndbattle.id"), primary_key=True) + + @declared_attr + def battle(self): + return relationship("DndCharacter", foreign_keys=self.battle_id, backref="active_in") + + @declared_attr + def interface_name(self): + return Column(String) + + @declared_attr + def interface_data(self): + return Column(LargeBinary) + + def __repr__(self): + return f"<{self.__class__.__qualname__}: {self.battle_id}>" diff --git a/rpgpack/tables/dndbattleunit.py b/rpgpack/tables/dndbattleunit.py new file mode 100644 index 00000000..5f16079b --- /dev/null +++ b/rpgpack/tables/dndbattleunit.py @@ -0,0 +1,56 @@ +from sqlalchemy import * +from sqlalchemy.orm import * +from sqlalchemy.ext.declarative import declared_attr +from ..utils import Health, Faction + + +class DndBattleUnit: + __tablename__ = "dndbattleunit" + + @declared_attr + def id(self): + return Column(Integer, primary_key=True) + + @declared_attr + def battle_id(self): + return Column(Integer, ForeignKey("dndbattle.id")) + + @declared_attr + def battle(self): + return relationship("DndBattle", backref="units") + + @declared_attr + def initiative(self): + return Column(Integer, nullable=False) + + @declared_attr + def health_string(self): + return Column(String) + + @property + def health(self): + return Health.from_text(self.health_string) if self.health_string else None + + @health.setter + def health(self, value: Health): + self.health_string = value.to_text() + + @declared_attr + def faction(self): + return Column(Enum(Faction), nullable=False) + + @declared_attr + def name(self): + return Column(String, nullable=False) + + @declared_attr + def armor_class(self): + return Column(Integer) + + @declared_attr + def extra(self): + return Column(String) + + @declared_attr + def status(self): + return Column(String) diff --git a/rpgpack/utils/__init__.py b/rpgpack/utils/__init__.py index 36b5786a..8aa30fb3 100644 --- a/rpgpack/utils/__init__.py +++ b/rpgpack/utils/__init__.py @@ -1,7 +1,7 @@ from .dndproficiencytype import DndProficiencyType from .parse5etoolsentry import parse_5etools_entry from .getactivechar import get_active_character, get_interface_data -from .factioncolors import FactionColor +from .faction import Faction from .health import Health __all__ = [ @@ -9,6 +9,6 @@ __all__ = [ "parse_5etools_entry", "get_active_character", "get_interface_data", - "FactionColor", + "Faction", "Health", ] diff --git a/rpgpack/utils/factioncolors.py b/rpgpack/utils/faction.py similarity index 87% rename from rpgpack/utils/factioncolors.py rename to rpgpack/utils/faction.py index b3120d47..3cc84e56 100644 --- a/rpgpack/utils/factioncolors.py +++ b/rpgpack/utils/faction.py @@ -2,7 +2,7 @@ from typing import * import enum -class FactionColor(enum.Enum): +class Faction(enum.Enum): RED = "🔴" ORANGE = "🟠" YELLOW = "🟡"