diff --git a/royalnet/packs/rpg/commands/dndactive.py b/royalnet/packs/rpg/commands/dndactive.py new file mode 100644 index 00000000..0094b963 --- /dev/null +++ b/royalnet/packs/rpg/commands/dndactive.py @@ -0,0 +1,12 @@ +from royalnet.commands import * + + +class DndactiveCommand(Command): + name: str = "dndactive" + + description: str = "Set the active D&D character." + + aliases = ["da", "dnda", "active"] + + async def run(self, args: CommandArgs, data: CommandData) -> None: + ... diff --git a/royalnet/packs/rpg/commands/dndnew.py b/royalnet/packs/rpg/commands/dndnew.py new file mode 100644 index 00000000..3cfca885 --- /dev/null +++ b/royalnet/packs/rpg/commands/dndnew.py @@ -0,0 +1,29 @@ +from royalnet.commands import * +from ..tables import DndCharacter + + +class DndnewCommand(Command): + name: str = "dndnew" + + description: str = "Create a new D&D character." + + aliases = ["dn", "dndn", "new"] + + syntax = "{name}\n" \ + "LV {level}\n" \ + "\n" \ + "STR {strength}\n" \ + "DEX {dexterity}\n" \ + "CON {constitution}\n" \ + "INT {intelligence}\n" \ + "WIS {wisdom}\n" \ + "CHA {charisma}\n" \ + "\n" \ + "MAXHP {maxhp}\n" \ + "AC {armorclass}" + + tables = {} + + async def run(self, args: CommandArgs, data: CommandData) -> None: + name = args[0] + ... \ No newline at end of file diff --git a/royalnet/packs/rpg/tables/__init__.py b/royalnet/packs/rpg/tables/__init__.py index 23bc7c24..908752c8 100644 --- a/royalnet/packs/rpg/tables/__init__.py +++ b/royalnet/packs/rpg/tables/__init__.py @@ -1,9 +1,11 @@ # Imports go here! - +from .dndactivecharacters import DndActiveCharacter +from .dndcharacters import DndCharacter # Enter the tables of your Pack here! available_tables = [ - + DndActiveCharacter, + DndCharacter, ] # Don't change this, it should automatically generate __all__ diff --git a/royalnet/packs/rpg/tables/dndactivecharacters.py b/royalnet/packs/rpg/tables/dndactivecharacters.py new file mode 100644 index 00000000..32955e93 --- /dev/null +++ b/royalnet/packs/rpg/tables/dndactivecharacters.py @@ -0,0 +1,26 @@ +from sqlalchemy import * +from sqlalchemy.orm import * +from sqlalchemy.ext.declarative import * + + +class DndActiveCharacter: + __tablename__ = "dndactivecharacters" + + @declared_attr + def character_id(self): + return Column(Integer, ForeignKey("dndcharacters.character_id"), primary_key=True) + + @declared_attr + def user_id(self): + return Column(Integer, ForeignKey("users.uid"), primary_key=True) + + @declared_attr + def character(self): + return relationship("DndCharacter", foreign_keys=self.character_id, backref="activations", use_scalar=True) + + @declared_attr + def user(self): + return relationship("User", foreign_keys=self.user_id, backref="active_dnd_character", use_scalar=True) + + def __repr__(self): + return f"<{self.__class__.__qualname__} for {self.user_id}: {self.character_id}>" diff --git a/royalnet/packs/rpg/tables/dndcharacters.py b/royalnet/packs/rpg/tables/dndcharacters.py new file mode 100644 index 00000000..5f5ffab6 --- /dev/null +++ b/royalnet/packs/rpg/tables/dndcharacters.py @@ -0,0 +1,102 @@ +from sqlalchemy import * +from sqlalchemy.orm import * +from sqlalchemy.ext.declarative import * + + +class DndCharacter: + __tablename__ = "dndcharacters" + + @declared_attr + def character_id(self): + return Column(Integer, primary_key=True) + + @declared_attr + def creator_id(self): + return Column(Integer, ForeignKey("users.uid")) + + @declared_attr + def creator(self): + return relationship("User", foreign_keys=self.creator_id, backref="dndcharacters_created") + + @declared_attr + def name(self): + return Column(String) + + @declared_attr + def strength(self): + return Column(Integer) + + @property + def strength_mod(self): + return (self.strength - 10) // 2 + + @declared_attr + def dexterity(self): + return Column(Integer) + + @property + def dexterity_mod(self): + return (self.dexterity - 10) // 2 + + @declared_attr + def constitution(self): + return Column(Integer) + + @property + def constitution_mod(self): + return (self.constitution - 10) // 2 + + @declared_attr + def intelligence(self): + return Column(Integer) + + @property + def intelligence_mod(self): + return (self.intelligence - 10) // 2 + + @declared_attr + def wisdom(self): + return Column(Integer) + + @property + def wisdom_mod(self): + return (self.wisdom - 10) // 2 + + @declared_attr + def charisma(self): + return Column(Integer) + + @property + def charisma_mod(self): + return (self.charisma - 10) // 2 + + @declared_attr + def level(self): + return Column(Integer) + + @property + def proficiency_bonus(self): + return ((self.level - 1) // 4) + 2 + + @declared_attr + def max_hp(self): + return Column(Integer) + + @declared_attr + def armor_class(self): + return Column(Integer) + + def __repr__(self): + return f"<{self.__class__.__qualname__} {self.name}>" + + def __str__(self): + return f"{self.name}\n" \ + f"LV {self.level}\n\n" \ + f"STR {self.strength}\n" \ + f"DEX {self.dexterity}\n" \ + f"CON {self.constitution}\n" \ + f"INT {self.intelligence}\n" \ + f"WIS {self.wisdom}\n" \ + f"CHA {self.charisma}\n\n" \ + f"MAXHP {self.max_hp}\n" \ + f"AC {self.armor_class}\n" \