我正在Evennia建立一个文字游戏。我添加了一个名为Prop
的新类型类。目前,它只有一个命令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())
泥浆/类型类/ 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
答案 0 :(得分:0)
事实证明,我没有得到.search
消除歧义。相反,这是命令本身被消除歧义。解决方案是将CmdSet移动到除对象之外的其他内容。然后,无论有多少对象在范围内,都只有一个命令。