Better read object message
And some refactoring.
This commit is contained in:
parent
73f3c17d68
commit
60dc1da080
2 changed files with 19 additions and 19 deletions
|
|
@ -9,7 +9,6 @@ from evennia.commands.default.muxcommand import MuxCommand
|
||||||
from evennia.contrib.rpg.rpsystem import send_emote
|
from evennia.contrib.rpg.rpsystem import send_emote
|
||||||
from evennia.utils import iter_to_str, logger
|
from evennia.utils import iter_to_str, logger
|
||||||
|
|
||||||
from typeclasses.readables import find_book
|
|
||||||
from typeclasses.characters import Character
|
from typeclasses.characters import Character
|
||||||
from utils.word_list import routput, paragraph, choices
|
from utils.word_list import routput, paragraph, choices
|
||||||
|
|
||||||
|
|
@ -277,6 +276,23 @@ class CmdRead(Command):
|
||||||
|
|
||||||
key = "read"
|
key = "read"
|
||||||
|
|
||||||
|
def find_readable(self, searcher, readable_str):
|
||||||
|
targets = searcher.search(readable_str, quiet=True)
|
||||||
|
if not targets:
|
||||||
|
searcher.msg(f"You don't see {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"Too many things match, '{readable_str}'. "
|
||||||
|
"Can you narrow it down with a title?")
|
||||||
|
|
||||||
def func(self):
|
def func(self):
|
||||||
"""Return the 'inside' attribute."""
|
"""Return the 'inside' attribute."""
|
||||||
target_str = self.args.strip()
|
target_str = self.args.strip()
|
||||||
|
|
@ -284,7 +300,7 @@ class CmdRead(Command):
|
||||||
self.caller.msg("Usage: |gread <object>|n")
|
self.caller.msg("Usage: |gread <object>|n")
|
||||||
return
|
return
|
||||||
|
|
||||||
book = find_book(self.caller, target_str)
|
book = self.find_readable(self.caller, target_str)
|
||||||
if book:
|
if book:
|
||||||
self.caller.msg(book.db.inside)
|
self.caller.msg(book.db.inside)
|
||||||
|
|
||||||
|
|
@ -358,7 +374,7 @@ class CmdDrink(Command):
|
||||||
if len(containers) == 1:
|
if len(containers) == 1:
|
||||||
containers[0].do_drink(self.caller)
|
containers[0].do_drink(self.caller)
|
||||||
elif len(containers) > 1:
|
elif len(containers) > 1:
|
||||||
self.caller.msg("You have two many things you can drink. "
|
self.caller.msg("You have too many things you can drink. "
|
||||||
"Which one do you want?")
|
"Which one do you want?")
|
||||||
else:
|
else:
|
||||||
self.caller.msg("You have nothing to drink.")
|
self.caller.msg("You have nothing to drink.")
|
||||||
|
|
|
||||||
|
|
@ -66,22 +66,6 @@ BOOKS = {
|
||||||
"The Wyrm in the Willows": "small dragon from the countryside who learns to cook without burning the meal first",
|
"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):
|
class CmdLookBook(Command):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue