move spell management to CharacterSpellInventory
This commit is contained in:
+47
-23
@@ -7,12 +7,37 @@ def test_spell_inventory(db, carl):
|
||||
fireball = prototypes.BaseSpell(name="Fireball", level=3, concentration=False)
|
||||
db.add_or_update([fireball, carl])
|
||||
|
||||
assert carl.spells.add(fireball)
|
||||
assert fireball not in carl.spells
|
||||
assert carl.spells.learn(fireball)
|
||||
db.add_or_update(carl)
|
||||
|
||||
assert not carl.equipment.add(fireball)
|
||||
assert fireball in carl.spells
|
||||
assert fireball not in carl.equipment
|
||||
assert fireball in carl.spells.known
|
||||
assert fireball in carl.spells.available
|
||||
assert fireball not in carl.spells.prepared
|
||||
|
||||
prestidigitation = prototypes.BaseSpell(name="Prestidigitation", level=0, concentration=False)
|
||||
wish = prototypes.BaseSpell(name="Wish", level=9, concentration=False)
|
||||
|
||||
spellbook = prototypes.BaseItem(name="Spell Book", inventory_type=InventoryType.SPELL)
|
||||
db.add_or_update([wish, spellbook])
|
||||
|
||||
assert wish not in carl.spells
|
||||
|
||||
grimoire = carl.equipment.add(spellbook)
|
||||
db.add_or_update(carl)
|
||||
grimoire.inventory.add(wish)
|
||||
grimoire.inventory.add(prestidigitation)
|
||||
db.add_or_update(carl)
|
||||
|
||||
assert wish in carl.spells.available
|
||||
assert wish not in carl.spells.known
|
||||
|
||||
assert prestidigitation in carl.spells.available
|
||||
assert prestidigitation not in carl.spells.known
|
||||
|
||||
assert carl.spells.get(wish)
|
||||
assert carl.spells.get(prestidigitation)
|
||||
|
||||
|
||||
def test_equipment_inventory(db, carl):
|
||||
@@ -28,7 +53,7 @@ def test_equipment_inventory(db, carl):
|
||||
assert carl.equipment.add(ten_foot_pole)
|
||||
|
||||
# can't mix and match inventory item types
|
||||
assert not carl.spells.add(ten_foot_pole)
|
||||
assert not carl.spells.learn(ten_foot_pole)
|
||||
|
||||
# add two more 10 foot poles. You can never have too many.
|
||||
assert carl.equipment.add(ten_foot_pole)
|
||||
@@ -108,8 +133,8 @@ def test_spell_slots(db, carl, wizard):
|
||||
fireball = prototypes.BaseSpell(name="Fireball", level=3, concentration=False)
|
||||
db.add_or_update([carl, prestidigitation, fireball])
|
||||
|
||||
carl.spells.add(prestidigitation)
|
||||
carl.spells.add(fireball)
|
||||
carl.spells.learn(prestidigitation)
|
||||
carl.spells.learn(fireball)
|
||||
db.add_or_update(carl)
|
||||
|
||||
# verify carl has the spell slots granted by wizard at 1st level
|
||||
@@ -120,17 +145,16 @@ def test_spell_slots(db, carl, wizard):
|
||||
# carl knows the spells but hasn't prepared them
|
||||
assert prestidigitation in carl.spells
|
||||
assert fireball in carl.spells
|
||||
assert prestidigitation not in carl.prepared_spells
|
||||
assert fireball not in carl.prepared_spells
|
||||
assert prestidigitation not in carl.spells.prepared
|
||||
assert fireball not in carl.spells.prepared
|
||||
|
||||
# prepare the cantrip
|
||||
carls_prestidigitation = carl.spells.get(prestidigitation)
|
||||
assert carls_prestidigitation.prepare()
|
||||
assert carls_prestidigitation.cast()
|
||||
assert carl.spells.prepare(prestidigitation)
|
||||
assert carl.spells.cast(prestidigitation)
|
||||
|
||||
# can't prepare a 3rd level spell if you don't have 3rd level slots
|
||||
assert carl.spellcaster_level == 1
|
||||
assert not carl.spells.get(fireball).prepare()
|
||||
assert not carl.spells.prepare(fireball)
|
||||
|
||||
# make carl a 5th level wizard so he gets a 3rd level spell slot
|
||||
carl.level_up(wizard, num_levels=4)
|
||||
@@ -138,11 +162,11 @@ 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()
|
||||
assert not carl.spells.get(fireball).cast()
|
||||
assert not carl.spells.cast(fireball)
|
||||
assert carl.spells.prepare(fireball)
|
||||
assert carl.spells.cast(fireball)
|
||||
assert carl.spells.cast(fireball)
|
||||
assert not carl.spells.cast(fireball)
|
||||
|
||||
# level up to 7th level, gaining 1 4th level slot and 1 more 3rd level slot
|
||||
carl.add_class(wizard)
|
||||
@@ -152,16 +176,16 @@ def test_spell_slots(db, carl, wizard):
|
||||
assert len(carl.spell_slots_available[3]) == 1
|
||||
|
||||
# cast at 4th level
|
||||
assert carl.spells.get(fireball).cast(level=4)
|
||||
assert not carl.spells.get(fireball).cast(level=4)
|
||||
assert carl.spells.cast(fireball, level=4)
|
||||
assert not carl.spells.cast(fireball, level=4)
|
||||
|
||||
# use the last 3rd level slot
|
||||
assert carl.spells.get(fireball).cast()
|
||||
assert not carl.spells.get(fireball).cast()
|
||||
assert carl.spells.cast(fireball)
|
||||
assert not carl.spells.cast(fireball)
|
||||
|
||||
# unprepare it
|
||||
assert carl.spells.get(fireball).unprepare()
|
||||
assert not carl.spells.get(fireball).unprepare()
|
||||
assert carl.spells.unprepare(fireball)
|
||||
assert not carl.spells.unprepare(fireball)
|
||||
|
||||
|
||||
def test_containers(db, carl):
|
||||
|
||||
Reference in New Issue
Block a user