mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 19:44:20 +00:00
Some progress on the initiative tracker
This commit is contained in:
parent
fb8d5fddb5
commit
479657d6ee
6 changed files with 81 additions and 3 deletions
|
@ -12,6 +12,7 @@ from .testhealth import TesthealthCommand
|
||||||
from .testfaction import TestfactionCommand
|
from .testfaction import TestfactionCommand
|
||||||
from .dndnewbattle import DndnewbattleCommand
|
from .dndnewbattle import DndnewbattleCommand
|
||||||
from .dndactivebattle import DndactivebattleCommand
|
from .dndactivebattle import DndactivebattleCommand
|
||||||
|
from .dndaddunit import DndaddunitCommand
|
||||||
|
|
||||||
# Enter the commands of your Pack here!
|
# Enter the commands of your Pack here!
|
||||||
available_commands = [
|
available_commands = [
|
||||||
|
@ -28,6 +29,7 @@ available_commands = [
|
||||||
TestfactionCommand,
|
TestfactionCommand,
|
||||||
DndnewbattleCommand,
|
DndnewbattleCommand,
|
||||||
DndactivebattleCommand,
|
DndactivebattleCommand,
|
||||||
|
DndaddunitCommand
|
||||||
]
|
]
|
||||||
|
|
||||||
# Don't change this, it should automatically generate __all__
|
# Don't change this, it should automatically generate __all__
|
||||||
|
|
45
rpgpack/commands/dndaddunit.py
Normal file
45
rpgpack/commands/dndaddunit.py
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
from typing import *
|
||||||
|
import royalnet
|
||||||
|
import royalnet.commands as rc
|
||||||
|
import royalnet.utils as ru
|
||||||
|
from ..types import Faction, Health
|
||||||
|
from ..tables import DndBattleUnit
|
||||||
|
from ..utils import get_active_battle
|
||||||
|
|
||||||
|
|
||||||
|
class DndaddunitCommand(rc.Command):
|
||||||
|
name: str = "dndaddunit"
|
||||||
|
|
||||||
|
description: str = "Add an Unit to a Battle."
|
||||||
|
|
||||||
|
aliases = ["dau", "dndau", "daddunit", ""]
|
||||||
|
|
||||||
|
syntax: str = "{faction} {name} {initiative} {health} {armorclass}"
|
||||||
|
|
||||||
|
async def run(self, args: rc.CommandArgs, data: rc.CommandData) -> None:
|
||||||
|
faction = Faction[args[0].upper()]
|
||||||
|
name = args[1]
|
||||||
|
initiative = int(args[2])
|
||||||
|
health = args[3]
|
||||||
|
armor_class = int(args[4])
|
||||||
|
|
||||||
|
DndBattleUnitT = self.alchemy.get(DndBattleUnit)
|
||||||
|
|
||||||
|
active_battle = await get_active_battle(data)
|
||||||
|
if active_battle is None:
|
||||||
|
raise rc.CommandError("No battle is active in this chat.")
|
||||||
|
|
||||||
|
dbu = DndBattleUnitT(
|
||||||
|
initiative=initiative,
|
||||||
|
faction=faction,
|
||||||
|
name=name,
|
||||||
|
health_string=health,
|
||||||
|
armor_class=armor_class,
|
||||||
|
battle=active_battle.battle
|
||||||
|
)
|
||||||
|
|
||||||
|
data.session.add(dbu)
|
||||||
|
await data.session_commit()
|
||||||
|
|
||||||
|
await data.reply(f"✅ [b]{dbu.name}[/b] joined the battle!\n"
|
||||||
|
f"{dbu}")
|
|
@ -6,9 +6,13 @@ from sqlalchemy.ext.declarative import *
|
||||||
class DndActiveBattle:
|
class DndActiveBattle:
|
||||||
__tablename__ = "dndactivebattle"
|
__tablename__ = "dndactivebattle"
|
||||||
|
|
||||||
|
@declared_attr
|
||||||
|
def active_battle_id(self):
|
||||||
|
return Column(Integer, primary_key=True)
|
||||||
|
|
||||||
@declared_attr
|
@declared_attr
|
||||||
def battle_id(self):
|
def battle_id(self):
|
||||||
return Column(Integer, ForeignKey("dndbattle.id"), primary_key=True)
|
return Column(Integer, ForeignKey("dndbattle.id"))
|
||||||
|
|
||||||
@declared_attr
|
@declared_attr
|
||||||
def battle(self):
|
def battle(self):
|
||||||
|
|
|
@ -6,13 +6,17 @@ from sqlalchemy.ext.declarative import *
|
||||||
class DndActiveCharacter:
|
class DndActiveCharacter:
|
||||||
__tablename__ = "dndactivecharacters"
|
__tablename__ = "dndactivecharacters"
|
||||||
|
|
||||||
|
@declared_attr
|
||||||
|
def active_character_id(self):
|
||||||
|
return Column(Integer, primary_key=True)
|
||||||
|
|
||||||
@declared_attr
|
@declared_attr
|
||||||
def character_id(self):
|
def character_id(self):
|
||||||
return Column(Integer, ForeignKey("dndcharacters.character_id"), primary_key=True)
|
return Column(Integer, ForeignKey("dndcharacters.character_id"))
|
||||||
|
|
||||||
@declared_attr
|
@declared_attr
|
||||||
def user_id(self):
|
def user_id(self):
|
||||||
return Column(Integer, ForeignKey("users.uid"), primary_key=True)
|
return Column(Integer, ForeignKey("users.uid"))
|
||||||
|
|
||||||
@declared_attr
|
@declared_attr
|
||||||
def character(self):
|
def character(self):
|
||||||
|
|
|
@ -28,4 +28,7 @@ class DndBattle:
|
||||||
string = []
|
string = []
|
||||||
string.append(f"⚔️ [b]{self.name}[/b]\n")
|
string.append(f"⚔️ [b]{self.name}[/b]\n")
|
||||||
string.append(f"{self.description}\n")
|
string.append(f"{self.description}\n")
|
||||||
|
string.append("\n")
|
||||||
|
for unit in sorted(self.units, key=lambda u: -u.initiative):
|
||||||
|
string.append(f"{unit}\n")
|
||||||
return "".join(string)
|
return "".join(string)
|
||||||
|
|
|
@ -54,3 +54,23 @@ class DndBattleUnit:
|
||||||
@declared_attr
|
@declared_attr
|
||||||
def status(self):
|
def status(self):
|
||||||
return Column(String)
|
return Column(String)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
string = [
|
||||||
|
f"{self.faction.value}",
|
||||||
|
f"[b]{self.name}[/b]",
|
||||||
|
f"[{self.initiative}]",
|
||||||
|
]
|
||||||
|
|
||||||
|
if self.health:
|
||||||
|
string.append(f"{self.health}")
|
||||||
|
if self.armor_class:
|
||||||
|
string.append(f"🛡 {self.armor_class}")
|
||||||
|
if self.extra:
|
||||||
|
string.append(f"💠 {self.extra}")
|
||||||
|
if self.status:
|
||||||
|
string.append(f"💫 {self.status}")
|
||||||
|
return " ".join(string)
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return f"<DndBattleUnit {self.id} ({self.name})>"
|
||||||
|
|
Loading…
Reference in a new issue