2020-02-21 19:32:24 +00:00
|
|
|
from sqlalchemy import *
|
|
|
|
from sqlalchemy.orm import *
|
|
|
|
from sqlalchemy.ext.declarative import declared_attr
|
2020-02-22 01:16:54 +00:00
|
|
|
from ..types import Health, Faction
|
2020-02-21 19:32:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
class DndBattleUnit:
|
|
|
|
__tablename__ = "dndbattleunit"
|
|
|
|
|
|
|
|
@declared_attr
|
|
|
|
def id(self):
|
|
|
|
return Column(Integer, primary_key=True)
|
|
|
|
|
2020-03-04 18:29:33 +00:00
|
|
|
@declared_attr
|
|
|
|
def linked_character_id(self):
|
|
|
|
return Column(Integer, ForeignKey("dndcharacters.character_id"))
|
|
|
|
|
|
|
|
@declared_attr
|
|
|
|
def linked_character(self):
|
|
|
|
return relationship("DndCharacter", foreign_keys=self.linked_character_id, backref="as_battle_unit")
|
|
|
|
|
2020-02-21 19:32:24 +00:00
|
|
|
@declared_attr
|
|
|
|
def battle_id(self):
|
|
|
|
return Column(Integer, ForeignKey("dndbattle.id"))
|
|
|
|
|
|
|
|
@declared_attr
|
|
|
|
def battle(self):
|
2020-02-22 01:16:54 +00:00
|
|
|
return relationship("DndBattle", foreign_keys=self.battle_id, backref="units")
|
2020-02-21 19:32:24 +00:00
|
|
|
|
|
|
|
@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)
|
2020-03-04 00:00:55 +00:00
|
|
|
|
|
|
|
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})>"
|