adding containers
This commit is contained in:
parent
709b0f5ad0
commit
01a4360dca
|
@ -1,6 +1,7 @@
|
|||
from .character import *
|
||||
from .classes import *
|
||||
from .constants import *
|
||||
from .container import *
|
||||
from .log import *
|
||||
from .modifiers import *
|
||||
from .skill import *
|
||||
|
|
|
@ -277,7 +277,6 @@ class Character(BaseObject, SlugMixin, ModifierMixin):
|
|||
def spells(self):
|
||||
return self.inventories[InventoryType.SPELL]
|
||||
|
||||
|
||||
@property
|
||||
def prepared_spells(self):
|
||||
hashmap = dict([(mapping.item.name, mapping) for mapping in self.spells if mapping.prepared])
|
||||
|
|
21
src/ttfrog/db/schema/container.py
Normal file
21
src/ttfrog/db/schema/container.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
from sqlalchemy import ForeignKey
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from ttfrog.db.schema.inventory import Inventory, InventoryType
|
||||
from ttfrog.db.schema.item import Item, ItemType
|
||||
|
||||
__all__ = [
|
||||
"Container",
|
||||
]
|
||||
|
||||
|
||||
class Container(Item):
|
||||
__tablename__ = "container"
|
||||
__mapper_args__ = {"polymorphic_identity": ItemType.CONTAINER}
|
||||
id: Mapped[int] = mapped_column(ForeignKey("item.id"), primary_key=True, init=False)
|
||||
item_type: Mapped[ItemType] = ItemType.CONTAINER
|
||||
inventory: Mapped["Inventory"] = relationship(
|
||||
cascade="all,delete,delete-orphan",
|
||||
lazy="immediate",
|
||||
default_factory=lambda: Inventory(inventory_type=InventoryType.EQUIPMENT),
|
||||
)
|
|
@ -32,16 +32,19 @@ def inventory_map_creator(fields):
|
|||
|
||||
class Inventory(BaseObject):
|
||||
__tablename__ = "inventory"
|
||||
__table_args__ = (UniqueConstraint("character_id", "inventory_type"),)
|
||||
__table_args__ = (UniqueConstraint("character_id", "container_id", "inventory_type"),)
|
||||
id: Mapped[int] = mapped_column(init=False, primary_key=True, autoincrement=True)
|
||||
character_id: Mapped[int] = mapped_column(ForeignKey("character.id"))
|
||||
inventory_type: Mapped[InventoryType] = mapped_column(nullable=False)
|
||||
|
||||
items: Mapped[List["InventoryMap"]] = relationship(
|
||||
uselist=True, cascade="all,delete,delete-orphan", lazy="immediate", default_factory=lambda: []
|
||||
)
|
||||
|
||||
character_id: Mapped[int] = mapped_column(ForeignKey("character.id"), nullable=True, default=None)
|
||||
container_id: Mapped[int] = mapped_column(ForeignKey("item.id"), nullable=True, default=None)
|
||||
|
||||
character = relationship("Character", init=False, viewonly=True, lazy="immediate")
|
||||
container = relationship("Item", init=False, viewonly=True, lazy="immediate")
|
||||
|
||||
def get(self, item):
|
||||
return self.get_all(item)[0]
|
||||
|
|
|
@ -21,6 +21,7 @@ ITEM_TYPES = [
|
|||
"WEAPON",
|
||||
"ARMOR",
|
||||
"SHIELD",
|
||||
"CONTAINER",
|
||||
]
|
||||
|
||||
RECHARGE_TIMES = [
|
||||
|
|
Loading…
Reference in New Issue
Block a user