Beispiel #1
0
    def ability_describe(self, sentence):
        """describe object
this will prompt you for a description.  enter something."""

        obj = sentence.directObject()

        def setdesc(desc, obj=obj):
            obj.description = desc

        def forgetit():
            pass

        c = pb.Referenceable()
        c.obj = obj
        c.remote_ok = setdesc
        c.remote_cancel = forgetit

        desc = obj.get_description()
        if desc != "<not a string>":
            self.request("Please describe %s" % obj.nounPhrase(self), desc, c)
        else:
            self.hears(
                "That object's description is a dynamic property -- "
                "you probably shouldn't mess "
                "with it directly.  Take a look at the source for details."
            )
Beispiel #2
0
    def ability_import(self, sentence):
        """import (object|.python.object) [to varname]

If you have a pathname that starts with a '.', this will attempt to load a
module and import the last thing on the dotted path.  (For example, if you say
'import .twisted.reality.thing.Thing', that would be equivalent to 'from
twisted.reality.thing import Thing'.  Otherwise, it attempts to search for an object
and import it as the synonym you specify. (Spaces will be replaced with
underscores.) """

        ds = sentence.directString()
        if ds[0] == ".":
            ds = ds[1:]
            if ds:
                dt = string.split(ds, ".")
                dt = map(string.strip, dt)
                if len(dt) == 1:
                    st = "import %s" % dt[0]
                else:
                    st = "from %s import %s" % (string.join(dt[:-1], "."), dt[-1])
                self.runcode(st)
                self.hears("%s: success." % st)
        else:
            dt = sentence.directObject()
            ds = string.replace(ds, " ", "_")
            self.code_space[ds] = dt
            self.hears("You remember %s as %s." % (dt.nounPhrase(self), repr(ds)))
Beispiel #3
0
 def ability_drop(self, sentence):
     """Place an object currently in this player into the Room which contains them.
     """
     object = sentence.directObject()
     if object.location == self:
         object.move(destination=self.place, actor=self)
         self.hears(object, ": Dropped.")
     else:
         self.hears("You weren't holding that.")
Beispiel #4
0
 def ability_take(self, sentence):
     """Place an object in this Player.
     """
     object = sentence.directObject()
     if object.location is self:
         error.Failure("You were already holding that.")
     else:
         object.move(destination=self, actor=self)
         self.hears(object, ": Taken.")
Beispiel #5
0
    def ability_destroy(self, sentence):
        """destroy {name}

Destroys the named Thing, unless Author has 'trashcan' set, in which
case the object is relocated to the specified trashcan. See also
"create"."""
        obj = sentence.directObject()
        if self.code_space.has_key("trashcan") and self.code_space["trashcan"] is not None:
            obj.location = self.code_space["trashcan"]
            self.hears("*kchunk* ", obj.nounPhrase, " was trashcanned.")
        else:
            obj.destroy()
            self.hears("*foop* ", obj.nounPhrase, " was destroyed.")
Beispiel #6
0
    def ability_mutate(self, sentence):
        """mutate object to new_type

This will mutate an object into a different type of object. """
        mutator = sentence.directObject()
        try:
            newtype = sentence.indirectString("to")
            newtype = self.code_space[newtype]
        except:
            error.Failure("You don't know of any such type.")
        newtype = reflect.getcurrent(newtype)
        x = issubclass(newtype, reflect.getcurrent(thing.Thing))
        assert x, "You shouldn't mutate Things to types which are not Things."
        if not reflect.isinst(mutator, newtype):
            mutator.__class__ = newtype
Beispiel #7
0
    def ability_scrutinize(self, sentence):
        """scrutinize object

display some code which may be helpful..."""

        object = sentence.directObject()

        stio = StringIO.StringIO()
        object.printSource(stio.write)

        # This should print to 'hears' until requestResponse works in
        # the telnet client (I have no idea how that should work yet,
        # really... tf's editing support for other MOOs should be an
        # inspiration)

        self.hears(stio.getvalue())
Beispiel #8
0
    def ability_rebuild(self, sentence):
        """rebuild (name|.python.name)

This will rebuild either a Thing (reloading its toplevel module (the one that
its class is in) and changing its class as appropriate.), an object in your
namespace, or a qualified python module name (prefixed with a dot).  """

        ds = sentence.directString()

        if ds[0] == ".":
            module = string.replace(ds[1:], " ", "")
            rebuild.rebuild(reflect.namedModule(module))
        else:
            try:
                object = self.code_space[ds]
            except:
                object = sentence.directObject()

            if reflect.isinst(object, thing.Thing):
                rebuild.rebuild(reflect.namedModule(object.__class__.__module__))
            else:
                rebuild.rebuild(object)
Beispiel #9
0
    def ability_nail(self, sentence):
        """nail object
this sets the component bit of an object."""
        sentence.directObject().component = 1