mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 11:34:18 +00:00
Implement Battle Units table and newbattle command
This commit is contained in:
parent
5f26184ebf
commit
0fdba9aca0
8 changed files with 121 additions and 5 deletions
|
@ -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 = [
|
||||
|
|
29
rpgpack/commands/dndnewbattle.py
Normal file
29
rpgpack/commands/dndnewbattle.py
Normal file
|
@ -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!")
|
|
@ -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)
|
||||
|
|
|
@ -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__
|
||||
|
|
26
rpgpack/tables/dndactivebattle.py
Normal file
26
rpgpack/tables/dndactivebattle.py
Normal file
|
@ -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}>"
|
56
rpgpack/tables/dndbattleunit.py
Normal file
56
rpgpack/tables/dndbattleunit.py
Normal file
|
@ -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)
|
|
@ -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",
|
||||
]
|
||||
|
|
|
@ -2,7 +2,7 @@ from typing import *
|
|||
import enum
|
||||
|
||||
|
||||
class FactionColor(enum.Enum):
|
||||
class Faction(enum.Enum):
|
||||
RED = "🔴"
|
||||
ORANGE = "🟠"
|
||||
YELLOW = "🟡"
|
Loading…
Reference in a new issue