Fix reading of multiple books
This makes a better use of 'dropping' generated items, like books, the letter, glasses, etc.
This commit is contained in:
parent
4ab02c7bd5
commit
5c01a15a17
6 changed files with 100 additions and 81 deletions
|
|
@ -9,6 +9,7 @@ from evennia.commands.default.muxcommand import MuxCommand
|
|||
from evennia.contrib.rpg.rpsystem import send_emote
|
||||
from evennia.utils import iter_to_str, logger
|
||||
|
||||
from typeclasses.readables import find_book
|
||||
from utils.word_list import routput, paragraph, choices
|
||||
|
||||
def speech_effect(speech, verb, target, effects):
|
||||
|
|
@ -262,12 +263,9 @@ class CmdRead(Command):
|
|||
self.caller.msg("Usage: |gread <object>|n")
|
||||
return
|
||||
|
||||
target = self.caller.search(target_str)
|
||||
if target:
|
||||
if target.db.inside:
|
||||
self.caller.msg(target.db.inside)
|
||||
else:
|
||||
self.caller.msg(f"Nothing to read on {target.get_display_name(self.caller)}")
|
||||
book = find_book(self.caller, target_str)
|
||||
if book:
|
||||
self.caller.msg(book.db.inside)
|
||||
|
||||
|
||||
class CmdTake(Command, NumberedTargetCommand):
|
||||
|
|
|
|||
|
|
@ -78,6 +78,12 @@ class TeaCup(Object):
|
|||
|
||||
drinker.msg(choices(FILL_TEA_MSGS, tea_type, tea_details))
|
||||
|
||||
def at_pre_drop(self, dropper):
|
||||
if dropper.location.key == "Dabbler's House":
|
||||
dropper.msg("You place the teacup on the trolley with the others.")
|
||||
self.delete()
|
||||
else:
|
||||
return True
|
||||
|
||||
class Teapot(Object):
|
||||
def at_object_creation(self):
|
||||
|
|
@ -303,4 +309,4 @@ class Cocktail(Object):
|
|||
)
|
||||
self.delete()
|
||||
else:
|
||||
dropper.msg(f"You put the {self.name} down.")
|
||||
return True
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ class Puppet(Character):
|
|||
"""
|
||||
self.msg("\nNo longer puppeting |c{name}|n.\n".format(name=self.key))
|
||||
|
||||
def return_appearance(self, viewer, **kwargs):
|
||||
def get_display_desc(self, _, **kwargs):
|
||||
"""
|
||||
Return one of two appearances based on if it is being puppeted or not.
|
||||
|
||||
|
|
|
|||
|
|
@ -66,6 +66,22 @@ BOOKS = {
|
|||
"The Wyrm in the Willows": "small dragon from the countryside who learns to cook without burning the meal first",
|
||||
}
|
||||
|
||||
def find_book(searcher, readable_str):
|
||||
targets = searcher.search(readable_str, quiet=True)
|
||||
if targets == []:
|
||||
searcher.msg(f"You can't find anything readable on {readable_str}.")
|
||||
return None
|
||||
|
||||
label_targets = [t for t in targets if t.db.inside]
|
||||
|
||||
if len(label_targets) == 1:
|
||||
return label_targets[0]
|
||||
|
||||
if len(label_targets) == 0:
|
||||
searcher.msg(f"You can't find anything readable on {readable_str}.")
|
||||
else:
|
||||
searcher.msg(f"You can read too many things that match '{readable_str}'. Can you narrow it down with a title?")
|
||||
|
||||
|
||||
class CmdLookBook(Command):
|
||||
"""
|
||||
|
|
@ -91,27 +107,6 @@ class CmdTakeBook(Command):
|
|||
self.obj.do_take(self.caller)
|
||||
|
||||
|
||||
class CmdBurnBook(Command):
|
||||
"""
|
||||
Destroy the instance of the book
|
||||
"""
|
||||
key = "burn"
|
||||
|
||||
def func(self):
|
||||
self.obj.do_burn(self.caller)
|
||||
|
||||
|
||||
class CmdDropBook(Command):
|
||||
"""
|
||||
Drop the instance of the book
|
||||
"""
|
||||
priority = 3
|
||||
key = "drop"
|
||||
|
||||
def func(self):
|
||||
self.obj.do_burn(self.caller, drop=True)
|
||||
|
||||
|
||||
class CmdSetRead(CmdSet):
|
||||
def at_cmdset_creation(self):
|
||||
pass # self.add(CmdReadBook)
|
||||
|
|
@ -119,8 +114,9 @@ class CmdSetRead(CmdSet):
|
|||
|
||||
class CmdSetBook(CmdSet):
|
||||
def at_cmdset_creation(self):
|
||||
self.add(CmdBurnBook)
|
||||
self.add(CmdDropBook)
|
||||
# self.add(CmdBurnBook)
|
||||
# self.add(CmdDropBook)
|
||||
pass
|
||||
|
||||
|
||||
class CmdSetShelf(CmdSet):
|
||||
|
|
@ -154,14 +150,10 @@ class Letter(Readable):
|
|||
self.cmdset.add_default(CmdSetBook)
|
||||
|
||||
def at_pre_drop(self, dropper):
|
||||
dropper.msg("Hrm ... you don't want to litter in such an idyllic location. But you can |gburn|n it.")
|
||||
return False
|
||||
|
||||
def do_burn(self, thrower, drop=False):
|
||||
if isinstance(thrower.location, DabblersRoom):
|
||||
thrower.msg(f"You throw {self.name} into the fire to burn it.")
|
||||
if dropper.location.key == "Dabbler's House":
|
||||
dropper.msg(f"You throw your {self.get_display_name(dropper)} into the fire and burn it.")
|
||||
else:
|
||||
thrower.msg(f"You throw {self.name} away.")
|
||||
dropper.msg(f"You throw your {self.get_display_name(dropper)} away.")
|
||||
self.delete()
|
||||
|
||||
|
||||
|
|
@ -176,18 +168,12 @@ class Book(Readable):
|
|||
super().do_read(reader)
|
||||
reader.announce_action("reads |p book.")
|
||||
|
||||
def do_burn(self, reader, drop=False):
|
||||
if isinstance(reader.location, DabblersRoom):
|
||||
if drop:
|
||||
reader.msg("""You drop the book, and it flaps its pages, and flies back to a section on the shelf.
|
||||
Gotta keep the room organized.""")
|
||||
else:
|
||||
reader.msg("You throw the book in the fireplace. It immediately yelps, flaps its pages, and flies back to a section on the shelf.")
|
||||
def at_pre_drop(self, reader):
|
||||
if reader.location.key == "Dabbler's House":
|
||||
reader.msg("You drop the book, but it flaps its pages, and flies back to a section on the shelf.")
|
||||
self.delete()
|
||||
else:
|
||||
if not drop:
|
||||
reader.msg("I think you would need to go to Dabbler's House and burn the book in the fireplace there.")
|
||||
self.delete()
|
||||
return True
|
||||
|
||||
|
||||
class Books(Object):
|
||||
|
|
@ -212,8 +198,7 @@ class Books(Object):
|
|||
""", title),
|
||||
routput(
|
||||
"""
|
||||
You <<open ^ open up ^ crack open>> your book, entitled,
|
||||
|w{0}|n, and read the {1} {2} of {3}.
|
||||
You <<open ^ open up ^ crack open>> your book, entitled, |w{0}|n, and read the {1} {2} of {3}.
|
||||
""",
|
||||
title,
|
||||
random.choice(BOOK_EMOTIONS),
|
||||
|
|
@ -231,6 +216,7 @@ class Books(Object):
|
|||
if self.db.last_title:
|
||||
booktype = self.book_prototype
|
||||
booktype['desc'] = self.db.last_desc
|
||||
booktype['aliases'] = [self.db.last_title]
|
||||
|
||||
book = spawn(booktype)[0]
|
||||
book.db.inside = self.db.last_inside
|
||||
|
|
|
|||
|
|
@ -1328,102 +1328,101 @@ Looks good for being out in the weather.
|
|||
|
||||
|
||||
# [[file:../../../projects/mud.org::*Character: Dabbler][Character: Dabbler:2]]
|
||||
py bt = self.search('gnome'); bt.db.gender = 'male'; bt.db.pose = 'smiling at you'
|
||||
@set gnome/gender = 'male'
|
||||
# Character: Dabbler:2 ends here
|
||||
|
||||
|
||||
|
||||
# Work around the =pose= bug:
|
||||
|
||||
|
||||
# [[file:../../../projects/mud.org::*Character: Dabbler][Character: Dabbler:3]]
|
||||
py bt = self.search('gnome'); bt.db.pose = 'smiling at you'
|
||||
# Character: Dabbler:3 ends here
|
||||
|
||||
|
||||
|
||||
# And give him the powers he deserves:
|
||||
|
||||
|
||||
# [[file:../../../projects/mud.org::*Character: Dabbler][Character: Dabbler:3]]
|
||||
@perm gnome = Admin
|
||||
# Character: Dabbler:3 ends here
|
||||
|
||||
# [[file:../../../projects/mud.org::*Character: Dabbler][Character: Dabbler:4]]
|
||||
@perm gnome = Admin
|
||||
# Character: Dabbler:4 ends here
|
||||
|
||||
# [[file:../../../projects/mud.org::*Character: Dabbler][Character: Dabbler:5]]
|
||||
@set gnome/_sdesc = "old gnome"
|
||||
#
|
||||
@set gnome/pose_default = "sleeping soundly in a large, overstuffed chair"
|
||||
# Character: Dabbler:4 ends here
|
||||
# Character: Dabbler:5 ends here
|
||||
|
||||
|
||||
|
||||
# And a good description that I can rework:
|
||||
|
||||
|
||||
# [[file:../../../projects/mud.org::*Character: Dabbler][Character: Dabbler:5]]
|
||||
# [[file:../../../projects/mud.org::*Character: Dabbler][Character: Dabbler:6]]
|
||||
@desc gnome = A small, hunched old man with a gray vandyke and an eye twinkle.
|
||||
|
||||
Spectacles perched precariously on the end of his hooked nose, wobble with his head. A jaunty crimson cap contrasts with his dark brown cloak.
|
||||
# Character: Dabbler:5 ends here
|
||||
# Character: Dabbler:6 ends here
|
||||
|
||||
|
||||
|
||||
# And an unpuppeted, sleeping, description:
|
||||
|
||||
|
||||
# [[file:../../../projects/mud.org::*Character: Dabbler][Character: Dabbler:6]]
|
||||
# [[file:../../../projects/mud.org::*Character: Dabbler][Character: Dabbler:7]]
|
||||
@set gnome/desc_unpuppeted = "A small, hunched old man with a gray vandyke snoring soundly in one of the overstuffed chairs.\n\nSpectacles perched precariously on the end of his hooked nose, wobble with each breath. A jaunty crimson cap contrasts with his dark brown blanket covering his legs."
|
||||
# Character: Dabbler:6 ends here
|
||||
# Character: Dabbler:7 ends here
|
||||
|
||||
|
||||
|
||||
# And we create a couple of objects, like a cap:
|
||||
|
||||
|
||||
# [[file:../../../projects/mud.org::*Character: Dabbler][Character: Dabbler:7]]
|
||||
# [[file:../../../projects/mud.org::*Character: Dabbler][Character: Dabbler:8]]
|
||||
@create cap
|
||||
#
|
||||
@desc cap = It's crimson. It's jaunty.
|
||||
#
|
||||
@give cap = gnome
|
||||
# Character: Dabbler:7 ends here
|
||||
# Character: Dabbler:8 ends here
|
||||
|
||||
|
||||
|
||||
# And my staff:
|
||||
|
||||
|
||||
# [[file:../../../projects/mud.org::*Character: Dabbler][Character: Dabbler:8]]
|
||||
# [[file:../../../projects/mud.org::*Character: Dabbler][Character: Dabbler:9]]
|
||||
@create gnarled staff;staff: typeclasses.things.Wand
|
||||
#
|
||||
@desc staff = An oaken staff with a sprig of two leaves next to a swirling ball of crystal embedded near the top.
|
||||
#
|
||||
@give staff = gnome
|
||||
# Character: Dabbler:8 ends here
|
||||
# Character: Dabbler:9 ends here
|
||||
|
||||
|
||||
|
||||
# And his special teacup:
|
||||
|
||||
|
||||
# [[file:../../../projects/mud.org::*Character: Dabbler][Character: Dabbler:9]]
|
||||
# [[file:../../../projects/mud.org::*Character: Dabbler][Character: Dabbler:10]]
|
||||
@create teacup;cup : typeclasses.drinkables.TeaCup
|
||||
#
|
||||
@desc teacup = A rustic teacup crafted from clay etched with leaves and runes, with an olive green and brown glaze.
|
||||
#
|
||||
@give teacup = gnome
|
||||
# Character: Dabbler:9 ends here
|
||||
# Character: Dabbler:10 ends here
|
||||
|
||||
|
||||
|
||||
# And his spells:
|
||||
|
||||
|
||||
# [[file:../../../projects/mud.org::*Character: Dabbler][Character: Dabbler:10]]
|
||||
# [[file:../../../projects/mud.org::*Character: Dabbler][Character: Dabbler:11]]
|
||||
@set gnome/disappear_msg = "After a raspberry sound, the gnome, Dabbler, disappears in a wisp of smoke."
|
||||
#
|
||||
@set gnome/reappear_msg = "<<White ^ Light blue ^ Gray>> mist appears...along with the smell of sulphur... ;; When the smoke clears, an old gnome <<emerges ^ materializes ^ shows up, looking a bit confused>>."
|
||||
# Character: Dabbler:10 ends here
|
||||
|
||||
|
||||
|
||||
# And help with the =fly= spell:
|
||||
|
||||
|
||||
# [[file:../../../projects/mud.org::*Character: Dabbler][Character: Dabbler:11]]
|
||||
# nick/object meadow = Frog Meadow
|
||||
# nick meadow = ^fly Frog Meadow
|
||||
# Character: Dabbler:11 ends here
|
||||
|
||||
# Pipe
|
||||
|
|
@ -1566,7 +1565,7 @@ Spectacles perched precariously on the end of his hooked nose, wobble with his h
|
|||
# With a good description:
|
||||
|
||||
# [[file:../../../projects/mud.org::*Books][Books:4]]
|
||||
@desc books = Books of different sizes and colors. So many books. Perhaps you want to simply |glook|n at a |gbook|n at random?
|
||||
@desc books = Books of different sizes and colors. So many books. Perhaps you want to |glook|n at a single |gbook|n at random?
|
||||
# Books:4 ends here
|
||||
|
||||
# Trolley of Scones
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@
|
|||
# [[file:../../../projects/mud-rpg.org::*Portal][Portal:1]]
|
||||
@teleport mp05
|
||||
#
|
||||
@open follow the glowing orbs;orbs;light;glowing orbs = Wyldwood Bar
|
||||
@open follow the glowing orbs;orbs;light;glowing orbs;follow = Wyldwood Bar
|
||||
# Portal:1 ends here
|
||||
|
||||
|
||||
|
|
@ -156,6 +156,36 @@ py bt = self.search('Bartender'); bt.db.gender = 'male'; bt.db._sdesc = 'blonde
|
|||
@detail mushroom;mushroom man = A stubby mushroom with an enormous red cap and a friendly looking face. Amazing how he can balance cocktails on its head.
|
||||
# Or a Mushroom Bartender:4 ends here
|
||||
|
||||
# Pixie Quartet
|
||||
|
||||
# A haughty elf named Elendil
|
||||
|
||||
# [[file:../../../projects/mud-rpg.org::*Pixie Quartet][Pixie Quartet:1]]
|
||||
@create/drop quartet of pixies;quartet;pixies;pixie: typeclasses.puppets.Puppet
|
||||
# Pixie Quartet:1 ends here
|
||||
|
||||
|
||||
|
||||
# And all the RP system stuff:
|
||||
|
||||
|
||||
# [[file:../../../projects/mud-rpg.org::*Pixie Quartet][Pixie Quartet:2]]
|
||||
py bt = self.search('pixies'); bt.db.pose_default = 'playing music atop a giant fieldcap mushroom'; bt.db.pose = 'playing music'
|
||||
# Pixie Quartet:2 ends here
|
||||
|
||||
# [[file:../../../projects/mud-rpg.org::*Pixie Quartet][Pixie Quartet:3]]
|
||||
@desc pixies = Atop a giant fieldcap mushroom, a quartet of pixies playing the strangest instruments you've never seen, fill the room with music.
|
||||
# Pixie Quartet:3 ends here
|
||||
|
||||
|
||||
|
||||
# And give him the powers he deserves:
|
||||
|
||||
|
||||
# [[file:../../../projects/mud-rpg.org::*Pixie Quartet][Pixie Quartet:4]]
|
||||
@perm pixies = Admin
|
||||
# Pixie Quartet:4 ends here
|
||||
|
||||
# Awakened Shrub
|
||||
# Next great NPC will a cameo from the Awakened Shrub.
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue