adding weapons with charges

This commit is contained in:
evilchili
2024-08-29 15:14:47 -07:00
parent 5d9fde949d
commit 5c80565264
5 changed files with 160 additions and 27 deletions
+7 -7
View File
@@ -24,7 +24,7 @@ def test_equipment_inventory(db, carl):
carl.equipment.add(ten_foot_pole)
db.add_or_update(carl)
all_carls_poles = carl.equipment.get(ten_foot_pole)
all_carls_poles = carl.equipment.get_all(ten_foot_pole)
assert len(all_carls_poles) == 3
# check the "contains" logic
@@ -71,17 +71,17 @@ def test_inventory_bundles(db, carl):
assert quiver.count == 20
# use one
assert quiver.use(1) == 19
assert quiver.consume(1) == 19
assert quiver.count == 19
# cannot use more than you have
assert not quiver.use(20)
assert not quiver.consume(20)
# cannot use a negative amount
assert not quiver.use(-1)
assert not quiver.consume(-1)
# consume all remaining arrows
assert quiver.use(19) == 0
assert quiver.consume(19) == 0
assert arrows not in carl.equipment
@@ -107,12 +107,12 @@ def test_spell_slots(db, carl, wizard):
assert fireball not in carl.prepared_spells
# prepare the cantrip
carls_prestidigitation = carl.spells.get(prestidigitation)[0]
carls_prestidigitation = carl.spells.get(prestidigitation)
assert carl.prepare(carls_prestidigitation)
assert carl.cast(carls_prestidigitation)
# prepare() and cast() require a spell from the spell inventory
carls_fireball = carl.spells.get(fireball)[0]
carls_fireball = carl.spells.get(fireball)
# can't prepare a 3rd level spell if you don't have 3rd level slots
assert carl.spellcaster_level == 1
+53 -3
View File
@@ -1,5 +1,5 @@
from ttfrog.db.schema.constants import DamageType, Defenses
from ttfrog.db.schema.item import Armor, Rarity, Shield, Weapon
from ttfrog.db.schema.item import Armor, ItemProperty, Rarity, RechargeTime, Shield, Weapon
from ttfrog.db.schema.modifiers import Modifier
@@ -40,6 +40,56 @@ def test_weapons(db):
assert dagger.melee
def test_charges(db, carl):
with db.transaction():
for_the_lulz = ItemProperty(
name="For the Lulz",
description="""
On a hit against a creature with a mouth, spend one charge to force the target to roll a DC 13 Wisdom
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,
)
# from sqlalchemy.orm import relationship
# help(relationship)
dagger_of_lulz = Weapon(
name="Dagger of Lulz",
description="This magical dagger has 6 charges. It regains 1d6 charges after a short rest.",
damage_die="1d4",
damage_type=DamageType.slashing,
melee=True,
finesse=True,
light=True,
thrown=True,
attack_range=20,
attack_range_long=60,
magical=True,
charges=6,
recharge_time=RechargeTime.SHORT_REST,
recharge_amount="1d6",
rarity=Rarity["Very Rare"],
requires_attunement=True,
properties=[for_the_lulz],
)
db.add_or_update([carl, dagger_of_lulz])
assert for_the_lulz in dagger_of_lulz.properties
assert carl.equipment.add(dagger_of_lulz)
db.add_or_update(carl)
carls_dagger = carl.equipment.get(dagger_of_lulz)
assert carl.equip(carls_dagger)
assert carl.attune(carls_dagger)
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)
def test_attunement(db, carl):
with db.transaction():
helm = Armor(
@@ -77,7 +127,7 @@ def test_attunement(db, carl):
assert carl.equipment.add(helm)
db.add_or_update(carl)
carls_shield = carl.equipment.get(shield)[0]
carls_shield = carl.equipment.get(shield)
assert carl.armor_class == 10
assert len(carl.attuned_items) == 0
@@ -95,7 +145,7 @@ def test_attunement(db, carl):
assert ranged_resistance in carl.modifiers[DamageType.ranged_weapon_attacks]
assert carls_shield in carl.attuned_items
assert carl.equip(carl.equipment.get(helm)[0])
assert carl.equip(carl.equipment.get(helm))
assert carl.armor_class == 13
assert carl.unattune(carls_shield)