我正在Evennia构建一个文本游戏。我添加了一个名为Prop
. 目前,它只有一个 command wear
。然后,我创建了几个Props
原型并使用@spawn
. 当我只拿着一个道具时,它的穿戴命令工作正常:wear glove
返回“你现在戴着手套。” 但是一旦我有多个道具,我得到的只是.search()
消歧菜单,而我输入的任何内容似乎都没有真正消除歧义。
我很确定这与 cmdset 合并有关,但就我所知。我究竟做错了什么?
泥/命令/prop_commands.py
"""
Prop commands
"""
from evennia import CmdSet
from command import Command
class CmdWear(Command):
"""
Wear or remove a prop
Usage:
wear <prop>
don <prop>
doff <prop>
Causes you to wear or remove the prop. {wdon{n and {wdoff{n will only put the prop on or off; {wwear{n form will toggle between worn and unworn.
"""
key = "wear"
aliases = ["don", "doff"]
locks = "cmd:holds()"
help_category = "Objects"
def parse(self):
"""Trivial parser"""
self.target = self.args.strip()
def func(self):
caller = self.caller
if not self.target:
caller.msg("Wear what?")
return
target = caller.search(self.target)
if not target:
caller.msg("Couldn't find any %s." % self.target)
return
# assumes it's a Prop typeclass, so assumes it has this attribute
if not target.db.wearable:
caller.msg("That doesn't make any sense.")
return
if self.cmdstring in ("don", "doff"):
should_wear = True if self.cmdstring == "don" else False
else:
should_wear = not target.db.worn
if target.db.worn ^ should_wear:
target.db.worn = should_wear
caller.msg("You're %s wearing %s." % (
"now" if target.db.worn else "no longer",
target))
else:
caller.msg("You're %s wearing %s." % (
"already" if target.db.worn else "not",
target))
class PropCmdSet(CmdSet):
def at_cmdset_creation(self):
self.add(CmdWear())
泥/typeclasses/props.py
"""
Props are items that can be held, worn, etc.
"""
from evennia import DefaultObject
from commands import prop_commands
class Prop(DefaultObject):
"""
Props are items that can be held, worn, stood on, and more.
"""
def at_object_creation(self):
self.cmdset.add(prop_commands.PropCmdSet, permanent=True)
self.db.wearable = True
self.db.worn = False