0

我正在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
4

1 回答 1

0

事实证明,我没有得到.search歧义。相反,它是命令本身被消除歧义。解决方案是将 CmdSet 移动到对象以外的位置。那么无论范围内有多少对象,都只有一个命令。

于 2015-03-22T16:58:53.563 回答