make inventories recursive
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
from ttfrog.db.schema.container import Container
|
||||
from ttfrog.db.schema.item import Item, ItemType, Spell
|
||||
|
||||
|
||||
@@ -41,7 +42,15 @@ def test_equipment_inventory(db, carl):
|
||||
# can't equip it twice
|
||||
assert not pole_one.equip()
|
||||
|
||||
# unequip it
|
||||
# can't prepare or cast an item
|
||||
assert not pole_one.prepare()
|
||||
assert not pole_one.unprepare()
|
||||
assert not pole_one.cast()
|
||||
|
||||
# not consumable or attunable
|
||||
assert not pole_one.consume()
|
||||
assert not pole_one.attune()
|
||||
|
||||
assert pole_one.unequip()
|
||||
|
||||
# can't unequip the unequipped ones
|
||||
@@ -123,6 +132,7 @@ def test_spell_slots(db, carl, wizard):
|
||||
assert carl.spellcaster_level == 3
|
||||
|
||||
# cast fireball until he's out of 3rd level slots
|
||||
assert not carl.spells.get(fireball).cast()
|
||||
assert carl.spells.get(fireball).prepare()
|
||||
assert carl.spells.get(fireball).cast()
|
||||
assert carl.spells.get(fireball).cast()
|
||||
@@ -142,3 +152,35 @@ def test_spell_slots(db, carl, wizard):
|
||||
# use the last 3rd level slot
|
||||
assert carl.spells.get(fireball).cast()
|
||||
assert not carl.spells.get(fireball).cast()
|
||||
|
||||
# unprepare it
|
||||
assert carl.spells.get(fireball).unprepare()
|
||||
assert not carl.spells.get(fireball).unprepare()
|
||||
|
||||
|
||||
def test_containers(db, carl):
|
||||
with db.transaction():
|
||||
ten_foot_pole = Item(name="10ft. Pole", item_type=ItemType.ITEM, consumable=False)
|
||||
bag_of_holding = Container(name="Bag of Holding")
|
||||
db.add_or_update([carl, ten_foot_pole, bag_of_holding])
|
||||
|
||||
# add the ten_foot_pole to the bag of holding
|
||||
assert bag_of_holding.inventory.add(ten_foot_pole)
|
||||
db.add_or_update(bag_of_holding)
|
||||
pole_from_bag = bag_of_holding.inventory.get(ten_foot_pole)
|
||||
assert pole_from_bag
|
||||
assert pole_from_bag in bag_of_holding.inventory
|
||||
assert pole_from_bag not in carl.equipment
|
||||
|
||||
# add the bag of holding to carl's equipment
|
||||
assert carl.equipment.add(bag_of_holding)
|
||||
db.add_or_update(bag_of_holding)
|
||||
assert pole_from_bag in carl.equipment
|
||||
|
||||
# test equality of mappings
|
||||
carls_bag = carl.equipment.get(bag_of_holding)
|
||||
carls_pole = carl.equipment.get(ten_foot_pole)
|
||||
assert carls_pole == pole_from_bag
|
||||
|
||||
# remove the pole from the bag
|
||||
assert carls_bag.item.inventory.remove(pole_from_bag)
|
||||
|
||||
+40
-3
@@ -1,5 +1,5 @@
|
||||
from ttfrog.db.schema.constants import DamageType, Defenses
|
||||
from ttfrog.db.schema.item import Armor, ItemProperty, Rarity, RechargeTime, Shield, Weapon
|
||||
from ttfrog.db.schema.item import Armor, Item, ItemProperty, Rarity, RechargeTime, Shield, Weapon
|
||||
from ttfrog.db.schema.modifiers import Modifier
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ def test_charges(db, carl):
|
||||
saving throw. On a failure, the target is forced to grin for one minute. While grinning, the target
|
||||
cannot speak. The target can repeat the saving throw at the start of their turn."
|
||||
""",
|
||||
charge_cost=1,
|
||||
charge_cost=2,
|
||||
)
|
||||
|
||||
# from sqlalchemy.orm import relationship
|
||||
@@ -88,6 +88,29 @@ def test_charges(db, carl):
|
||||
assert len(carls_dagger.charges) == dagger_of_lulz.charges == 6
|
||||
assert len(carls_dagger.charges_available) == dagger_of_lulz.charges == 6
|
||||
assert carls_dagger.use(for_the_lulz)
|
||||
assert len(carls_dagger.charges_available) == 4
|
||||
|
||||
# use the remaining charges
|
||||
assert carls_dagger.use(for_the_lulz)
|
||||
assert carls_dagger.use(for_the_lulz)
|
||||
|
||||
# all out of charges
|
||||
assert len(carls_dagger.charges_available) == 0
|
||||
assert not carls_dagger.use(for_the_lulz)
|
||||
|
||||
|
||||
def test_nocharges(db, carl):
|
||||
smiles = ItemProperty(name="Smile!", description="The target grins for one minute.", charge_cost=None)
|
||||
wand_of_unlimited_smiles = Item(name="Wand of Unlimited Smiles", description="description", properties=[smiles])
|
||||
db.add_or_update(wand_of_unlimited_smiles)
|
||||
|
||||
carl.equipment.add(wand_of_unlimited_smiles)
|
||||
db.add_or_update(carl)
|
||||
|
||||
# no charges means you can use it at will
|
||||
assert carl.equipment.get(wand_of_unlimited_smiles).use(smiles)
|
||||
assert carl.equipment.get(wand_of_unlimited_smiles).use(smiles)
|
||||
assert carl.equipment.get(wand_of_unlimited_smiles).use(smiles)
|
||||
|
||||
|
||||
def test_attunement(db, carl):
|
||||
@@ -139,7 +162,8 @@ def test_attunement(db, carl):
|
||||
assert carl.armor_class == 12
|
||||
assert carls_shield not in carl.attuned_items
|
||||
|
||||
carls_shield.attune()
|
||||
assert carls_shield.attune()
|
||||
assert not carls_shield.attune()
|
||||
assert carl.armor_class == 12
|
||||
assert plus_two_ac in carl.modifiers["armor_class"]
|
||||
assert ranged_resistance in carl.modifiers[DamageType.ranged_weapon_attacks]
|
||||
@@ -149,7 +173,20 @@ def test_attunement(db, carl):
|
||||
assert carl.armor_class == 13
|
||||
|
||||
assert carls_shield.unattune()
|
||||
assert not carls_shield.unattune()
|
||||
assert carl.armor_class == 13
|
||||
assert ranged_resistance not in carl.modifiers[DamageType.ranged_weapon_attacks]
|
||||
assert carls_shield.unequip()
|
||||
assert carl.armor_class == 11
|
||||
|
||||
# can only attune 3 items
|
||||
assert carl.equipment.add(shield)
|
||||
assert carl.equipment.add(shield)
|
||||
assert carl.equipment.add(shield)
|
||||
db.add_or_update(carl)
|
||||
|
||||
assert carl.equipment.get_all(shield)[0].attune()
|
||||
assert carl.equipment.get_all(shield)[1].attune()
|
||||
assert carl.equipment.get_all(shield)[2].attune()
|
||||
assert len(carl.attuned_items) == 3
|
||||
assert not carl.equipment.get_all(shield)[3].attune()
|
||||
|
||||
Reference in New Issue
Block a user