added inventory management ui
This commit is contained in:
+10
-4
@@ -106,7 +106,13 @@ def bootstrap(db):
|
||||
db.add_or_update([foo, bar])
|
||||
|
||||
@pytest.fixture
|
||||
def carl(db, bootstrap):
|
||||
tiefling = db.Ancestry.filter_by(name="tiefling").one()
|
||||
carl = schema.Character(name="Carl", ancestry=tiefling)
|
||||
return carl
|
||||
def carl(db, bootstrap, tiefling):
|
||||
return schema.Character(name="Carl", ancestry=tiefling)
|
||||
|
||||
@pytest.fixture
|
||||
def tiefling(db, bootstrap):
|
||||
return db.Ancestry.filter_by(name="tiefling").one()
|
||||
|
||||
@pytest.fixture
|
||||
def human(db, bootstrap):
|
||||
return db.Ancestry.filter_by(name="human").one()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from ttfrog.db.schema.item import Item, ItemType
|
||||
from ttfrog.db.schema.item import Item, Spell, ItemType
|
||||
|
||||
|
||||
def test_equipment_inventory(db, carl):
|
||||
@@ -6,11 +6,80 @@ def test_equipment_inventory(db, carl):
|
||||
# trigger the creation of inventory mappings
|
||||
db.add_or_update(carl)
|
||||
|
||||
# create an item
|
||||
# create some items
|
||||
ten_foot_pole = Item(name="10ft. Pole", item_type=ItemType.ITEM, consumable=False)
|
||||
db.add_or_update(ten_foot_pole)
|
||||
fireball = Spell(name="Fireball", level=3, concentration=False)
|
||||
db.add_or_update([ten_foot_pole, fireball])
|
||||
|
||||
# add the item to carl's inventory
|
||||
# add the pole to carl's equipment, and the spell to his spell list.
|
||||
assert carl.equipment.add(ten_foot_pole)
|
||||
assert carl.spells.add(fireball)
|
||||
|
||||
# can't mix and match inventory item types
|
||||
assert not carl.equipment.add(fireball)
|
||||
assert not carl.spells.add(ten_foot_pole)
|
||||
|
||||
# add two more 10 foot poles. You can never have too many.
|
||||
carl.equipment.add(ten_foot_pole)
|
||||
carl.equipment.add(ten_foot_pole)
|
||||
db.add_or_update(carl)
|
||||
|
||||
all_carls_poles = carl.equipment.get(ten_foot_pole)
|
||||
assert len(all_carls_poles) == 3
|
||||
|
||||
# check the "contains" logic
|
||||
assert ten_foot_pole in carl.equipment
|
||||
assert ten_foot_pole not in carl.spells
|
||||
assert fireball in carl.spells
|
||||
assert fireball not in carl.equipment
|
||||
|
||||
# equip one pole
|
||||
assert carl.equip(all_carls_poles[0])
|
||||
|
||||
# can't equip it twice
|
||||
assert not carl.equip(all_carls_poles[0])
|
||||
|
||||
# unequip it
|
||||
assert carl.unequip(all_carls_poles[0])
|
||||
|
||||
# can't unequip the unequipped ones
|
||||
assert not carl.unequip(all_carls_poles[1])
|
||||
assert not carl.unequip(all_carls_poles[2])
|
||||
|
||||
# drop one pole
|
||||
assert carl.equipment.remove(all_carls_poles[0])
|
||||
assert ten_foot_pole in carl.equipment
|
||||
|
||||
# drop the remaining poles
|
||||
assert carl.equipment.remove(all_carls_poles[1])
|
||||
assert carl.equipment.remove(all_carls_poles[2])
|
||||
assert ten_foot_pole not in carl.equipment
|
||||
|
||||
# can't drop what you don't have
|
||||
assert not carl.equipment.remove(all_carls_poles[0])
|
||||
|
||||
|
||||
def test_inventory_bundles(db, carl):
|
||||
with db.transaction():
|
||||
arrows = Item(name="Arrows", item_type=ItemType.ITEM, consumable=True, count=20)
|
||||
db.add_or_update([carl, arrows])
|
||||
quiver = carl.equipment.add(arrows)
|
||||
db.add_or_update(carl)
|
||||
|
||||
# full quiver
|
||||
assert arrows in carl.equipment
|
||||
assert quiver.count == 20
|
||||
|
||||
# use one
|
||||
assert quiver.use(1) == 19
|
||||
assert quiver.count == 19
|
||||
|
||||
# cannot use more than you have
|
||||
assert not quiver.use(20)
|
||||
|
||||
# cannot use a negative amount
|
||||
assert not quiver.use(-1)
|
||||
|
||||
# consume all remaining arrows
|
||||
assert quiver.use(19) == 0
|
||||
assert arrows not in carl.equipment
|
||||
|
||||
+8
-15
@@ -205,13 +205,10 @@ def test_ancestries(db, bootstrap):
|
||||
assert grognak.check_modifier(strength, save=True) == 1
|
||||
|
||||
|
||||
def test_modifiers(db, bootstrap):
|
||||
def test_modifiers(db, bootstrap, carl, tiefling, human):
|
||||
with db.transaction():
|
||||
human = db.Ancestry.filter_by(name="human").one()
|
||||
tiefling = db.Ancestry.filter_by(name="tiefling").one()
|
||||
|
||||
# no modifiers; speed is ancestry speed
|
||||
carl = schema.Character(name="Carl", ancestry=tiefling)
|
||||
marx = schema.Character(name="Marx", ancestry=human)
|
||||
db.add_or_update([carl, marx])
|
||||
assert carl.speed == carl.ancestry.speed == 30
|
||||
@@ -335,10 +332,9 @@ def test_modifiers(db, bootstrap):
|
||||
assert not carl.remove_skill(athletics, proficient=True, expert=False, character_class=None)
|
||||
|
||||
|
||||
def test_defenses(db, bootstrap):
|
||||
def test_defenses(db, bootstrap, tiefling, carl):
|
||||
with db.transaction():
|
||||
tiefling = db.Ancestry.filter_by(name="tiefling").one()
|
||||
carl = schema.Character(name="Carl", ancestry=tiefling)
|
||||
db.add_or_update(carl)
|
||||
assert carl.resistant(DamageType.fire)
|
||||
carl.apply_damage(5, DamageType.fire)
|
||||
assert carl.hit_points == 8 # half damage
|
||||
@@ -387,13 +383,12 @@ def test_defenses(db, bootstrap):
|
||||
assert carl.hit_points == 8 # half damage
|
||||
|
||||
|
||||
def test_condition_immunity(db, bootstrap):
|
||||
def test_condition_immunity(db, bootstrap, carl, tiefling):
|
||||
"""
|
||||
Test immunities prevent conditions from being applied
|
||||
"""
|
||||
with db.transaction():
|
||||
tiefling = db.Ancestry.filter_by(name="tiefling").one()
|
||||
carl = schema.Character(name="Carl", ancestry=tiefling)
|
||||
db.add_or_update(carl)
|
||||
poisoned = schema.Condition(name=DamageType.poison)
|
||||
poison_immunity = schema.Modifier("Poison Immunity", target=DamageType.poison, new_value=Defenses.immune)
|
||||
db.add_or_update([carl, poisoned, poison_immunity])
|
||||
@@ -423,11 +418,13 @@ def test_condition_immunity(db, bootstrap):
|
||||
assert carl.has_condition(poisoned)
|
||||
|
||||
|
||||
def test_partial_immunities(db, bootstrap):
|
||||
def test_partial_immunities(db, bootstrap, carl, tiefling):
|
||||
"""
|
||||
Test that individual modifiers applied by a condition can be negated even if not immune to the condition.
|
||||
"""
|
||||
with db.transaction():
|
||||
db.add_or_update(carl)
|
||||
|
||||
# Create some modifiers and conditions for this test
|
||||
fly = schema.Modifier(target="fly_speed", absolute_value=30, name="Fly Spell")
|
||||
cannot_move = schema.Modifier(name="Cannot Move (Petrified", target="speed", absolute_value=0)
|
||||
@@ -449,10 +446,6 @@ def test_partial_immunities(db, bootstrap):
|
||||
assert petrified.add_condition(incapacitated)
|
||||
db.add_or_update([fly, cannot_move, poisoned, poison_immunity, incapacitated, petrified])
|
||||
|
||||
# hi carl
|
||||
tiefling = db.Ancestry.filter_by(name="tiefling").one()
|
||||
carl = schema.Character(name="Carl", ancestry=tiefling)
|
||||
|
||||
# carl casts fly!
|
||||
assert carl.fly_speed is None
|
||||
assert carl.add_modifier(fly)
|
||||
|
||||
Reference in New Issue
Block a user