resolve warnings
This commit is contained in:
parent
9f75630c74
commit
5d9fde949d
|
@ -75,8 +75,9 @@ class SQLDatabaseManager:
|
||||||
return base64.urlsafe_b64encode(sha1bytes.digest()).decode("ascii")[:10]
|
return base64.urlsafe_b64encode(sha1bytes.digest()).decode("ascii")[:10]
|
||||||
|
|
||||||
def init(self):
|
def init(self):
|
||||||
self.session.configure(bind=self.engine)
|
|
||||||
self.metadata.bind = self.engine
|
self.metadata.bind = self.engine
|
||||||
|
self.session.remove()
|
||||||
|
self.session.configure(bind=self.engine)
|
||||||
self.metadata.create_all(self.engine)
|
self.metadata.create_all(self.engine)
|
||||||
|
|
||||||
def dump(self, names: list = []):
|
def dump(self, names: list = []):
|
||||||
|
|
|
@ -53,18 +53,20 @@ class Spell(Item):
|
||||||
__tablename__ = "spell"
|
__tablename__ = "spell"
|
||||||
__mapper_args__ = {"polymorphic_identity": ItemType.SPELL}
|
__mapper_args__ = {"polymorphic_identity": ItemType.SPELL}
|
||||||
id: Mapped[int] = mapped_column(ForeignKey("item.id"), primary_key=True, init=False)
|
id: Mapped[int] = mapped_column(ForeignKey("item.id"), primary_key=True, init=False)
|
||||||
|
item_type: Mapped[ItemType] = ItemType.SPELL
|
||||||
|
|
||||||
level: Mapped[int] = mapped_column(nullable=False, info={"min": 0, "max": 9}, default=0)
|
level: Mapped[int] = mapped_column(nullable=False, info={"min": 0, "max": 9}, default=0)
|
||||||
concentration: Mapped[bool] = mapped_column(default=False)
|
concentration: Mapped[bool] = mapped_column(default=False)
|
||||||
item_type: Mapped[ItemType] = mapped_column(default=ItemType.SPELL, init=False)
|
|
||||||
|
|
||||||
|
|
||||||
class Weapon(Item):
|
class Weapon(Item):
|
||||||
__tablename__ = "weapon"
|
__tablename__ = "weapon"
|
||||||
__mapper_args__ = {"polymorphic_identity": ItemType.WEAPON}
|
__mapper_args__ = {"polymorphic_identity": ItemType.WEAPON}
|
||||||
id: Mapped[int] = mapped_column(ForeignKey("item.id"), primary_key=True, init=False)
|
id: Mapped[int] = mapped_column(ForeignKey("item.id"), primary_key=True, init=False)
|
||||||
|
item_type: Mapped[ItemType] = ItemType.WEAPON
|
||||||
|
|
||||||
damage_die: Mapped[str] = mapped_column(nullable=False, default="1d6")
|
damage_die: Mapped[str] = mapped_column(nullable=False, default="1d6")
|
||||||
damage_type: Mapped[DamageType] = mapped_column(nullable=False, default=DamageType.slashing)
|
damage_type: Mapped[DamageType] = mapped_column(nullable=False, default=DamageType.slashing)
|
||||||
item_type: Mapped[ItemType] = mapped_column(default=ItemType.WEAPON)
|
|
||||||
attack_range: Mapped[int] = mapped_column(nullable=False, info={"min": 0}, default=0)
|
attack_range: Mapped[int] = mapped_column(nullable=False, info={"min": 0}, default=0)
|
||||||
attack_range_long: Mapped[int] = mapped_column(nullable=True, info={"min": 0}, default=None)
|
attack_range_long: Mapped[int] = mapped_column(nullable=True, info={"min": 0}, default=None)
|
||||||
targets: Mapped[int] = mapped_column(nullable=False, info={"min": 1}, default=1)
|
targets: Mapped[int] = mapped_column(nullable=False, info={"min": 1}, default=1)
|
||||||
|
@ -85,3 +87,17 @@ class Weapon(Item):
|
||||||
@property
|
@property
|
||||||
def ranged(self):
|
def ranged(self):
|
||||||
return self.attack_range > 0
|
return self.attack_range > 0
|
||||||
|
|
||||||
|
|
||||||
|
class Shield(Item):
|
||||||
|
__tablename__ = "shield"
|
||||||
|
__mapper_args__ = {"polymorphic_identity": ItemType.SHIELD}
|
||||||
|
id: Mapped[int] = mapped_column(ForeignKey("item.id"), primary_key=True, init=False)
|
||||||
|
item_type: Mapped[ItemType] = ItemType.SHIELD
|
||||||
|
|
||||||
|
|
||||||
|
class Armor(Item):
|
||||||
|
__tablename__ = "armor"
|
||||||
|
__mapper_args__ = {"polymorphic_identity": ItemType.ARMOR}
|
||||||
|
id: Mapped[int] = mapped_column(ForeignKey("item.id"), primary_key=True, init=False)
|
||||||
|
item_type: Mapped[ItemType] = ItemType.ARMOR
|
||||||
|
|
|
@ -9,7 +9,7 @@ def test_dump_load(db, bootstrap):
|
||||||
|
|
||||||
# clear the database and reinitialize
|
# clear the database and reinitialize
|
||||||
db.metadata.drop_all(bind=db.engine)
|
db.metadata.drop_all(bind=db.engine)
|
||||||
db.init()
|
db.metadata.create_all(db.engine)
|
||||||
|
|
||||||
# load the dump
|
# load the dump
|
||||||
db.load(data)
|
db.load(data)
|
||||||
|
|
|
@ -96,8 +96,6 @@ def test_spell_slots(db, carl, wizard):
|
||||||
db.add_or_update(carl)
|
db.add_or_update(carl)
|
||||||
|
|
||||||
# verify carl has the spell slots granted by wizard at 1st level
|
# verify carl has the spell slots granted by wizard at 1st level
|
||||||
print(carl.levels)
|
|
||||||
print(carl.spell_slots)
|
|
||||||
assert len(carl.spell_slots) == 2
|
assert len(carl.spell_slots) == 2
|
||||||
assert carl.spell_slots[0].spell_level == 1
|
assert carl.spell_slots[0].spell_level == 1
|
||||||
assert carl.spell_slots[1].spell_level == 1
|
assert carl.spell_slots[1].spell_level == 1
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from ttfrog.db.schema.constants import DamageType, Defenses
|
from ttfrog.db.schema.constants import DamageType, Defenses
|
||||||
from ttfrog.db.schema.item import Item, ItemType, Rarity, Weapon
|
from ttfrog.db.schema.item import Armor, Rarity, Shield, Weapon
|
||||||
from ttfrog.db.schema.modifiers import Modifier
|
from ttfrog.db.schema.modifiers import Modifier
|
||||||
|
|
||||||
|
|
||||||
|
@ -42,14 +42,13 @@ def test_weapons(db):
|
||||||
|
|
||||||
def test_attunement(db, carl):
|
def test_attunement(db, carl):
|
||||||
with db.transaction():
|
with db.transaction():
|
||||||
helm = Item(
|
helm = Armor(
|
||||||
name="Iron Helm",
|
name="Iron Helm",
|
||||||
item_type=ItemType.ARMOR,
|
|
||||||
rarity=Rarity.Common,
|
rarity=Rarity.Common,
|
||||||
)
|
)
|
||||||
helm.add_modifier(Modifier("+1 AC (helmet)", target="armor_class", relative_value=1, stacks=True))
|
helm.add_modifier(Modifier("+1 AC (helmet)", target="armor_class", relative_value=1, stacks=True))
|
||||||
|
|
||||||
shield = Item(
|
shield = Shield(
|
||||||
name="Shield of Missile Attraction",
|
name="Shield of Missile Attraction",
|
||||||
description="""
|
description="""
|
||||||
While holding this shield, you have resistance to damage from ranged weapon attacks.
|
While holding this shield, you have resistance to damage from ranged weapon attacks.
|
||||||
|
@ -58,7 +57,6 @@ def test_attunement(db, carl):
|
||||||
or similar magic. Removing the shield fails to end the curse on you. Whenever a ranged weapon attack is made
|
or similar magic. Removing the shield fails to end the curse on you. Whenever a ranged weapon attack is made
|
||||||
against a target within 10 feet of you, the curse causes you to become the target instead.
|
against a target within 10 feet of you, the curse causes you to become the target instead.
|
||||||
""",
|
""",
|
||||||
item_type=ItemType.SHIELD,
|
|
||||||
rarity=Rarity.Rare,
|
rarity=Rarity.Rare,
|
||||||
requires_attunement=True,
|
requires_attunement=True,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user