示例#1
0
文件: player.py 项目: lhl/songclub
 def ability_say(self, sentence):
     """Say a text string.
     """
     self.broadcastToOne(
         to_subject=('You say, "%s".' % sentence.directString()),
         to_other=(self, ' says, "%s"' % sentence.directString()),
     )
示例#2
0
文件: player.py 项目: lhl/songclub
    def ability_persist(self, sentence):
        """persist {mapname}

        This will create a file called mapname.rp, containing the
        saved state of the current game."""
        if self.code_space.has_key("log_persist") and self.code_space["log_persist"] is not None:
            self.code_space["log_persist"](self.name, self.reality, sentence.directString(), time.time())
        file = open(sentence.directString() + ".rp", "wb")
        cPickle.dump(self.reality, file)
        file.flush()
        file.close()

        self.hears('Saved "%s.rp".' % sentence.directString())
示例#3
0
文件: player.py 项目: lhl/songclub
    def ability_snippet(self, sentence):
        """snippet {name}
This creates an arbitrarily named string in your namespace from a
response-request and runs it as a block of python code.  BE CAREFUL when using
this; do not define functions, for example, or they will render your map
unpickleable.
        """
        snipname = sentence.directString()

        def cancel(self):
            pass

        def ok(self, code, o=self, snipname=snipname):
            cs = o.code_space
            cs[snipname] = code
            try:
                code = compile(code, "$$" + o.name + "$$", "exec")
                exec code in cs, cs
            except:
                sio = StringIO.StringIO()
                traceback.print_exc(file=sio)
                o.hears(sio.getvalue())

        c = Referenceable()
        c.remote_ok = ok
        c.remote_cancel = cancel

        code = self.code_space.get(snipname, "")
        self.request("Snippet %s" % snipname, code, c)
示例#4
0
文件: player.py 项目: lhl/songclub
    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)))
示例#5
0
文件: player.py 项目: lhl/songclub
    def ability_adduser(self, sentence):
        """adduser (name)
Adds a new user to the map.
"""
        name = sentence.directString()
        p = Player(name)
        p.location = self.place
        self.hears("poof")
示例#6
0
文件: player.py 项目: lhl/songclub
    def ability_create(self, sentence):
        """create {name}

Creates a new Thing with the name you provide. See also "destroy"."""
        if self.code_space.has_key("log_create") and self.code_space["log_create"] is not None:
            self.code_space["log_create"](self.name, obj, time.time())
        obj = thing.Thing(sentence.directString())
        obj.location = self
        self.hears("*poof* ", obj.nounPhrase, " was created.")
示例#7
0
文件: player.py 项目: lhl/songclub
    def ability_source(self, sentence):
        """source {thing}
This creates a file called thing.py, containing the source for the thing in question."""
        file = open(sentence.directString() + "_rp.py", "wb")

        def writeln(bytes, file=file):
            file.write(bytes)

        self.reality.printSource(writeln)
示例#8
0
文件: player.py 项目: lhl/songclub
    def ability_undig(self, sentence):
        """undig {direction}
Undig is the opposite of dig, in that it will close off the exit in the given direction, as well as destroying the room it leads to, so use it carefully. See also Dig, compare \"untunnel\", \"barricade\"."""
        direction = sentence.directString()
        otherPlace = self.place.findExit(direction)
        self.place.disconnectExit(direction)
        if self.code_space.has_key("trashcan") and self.code_space["trashcan"] is not None:
            otherPlace.location = self.code_space["trashcan"]
        else:
            otherPlace.destroy()
示例#9
0
文件: player.py 项目: lhl/songclub
    def ability_go(self, sentence):
        """Move in a direction.
        """
        direct = sentence.directString()
        where = self.location.findExit(direct)

        # TODO: calculations as to whether I will *fit* in
        # this wonderful new place I've discovered

        self.hears("You go ", direct, ".")
        self.location = where
示例#10
0
文件: player.py 项目: lhl/songclub
    def ability_untunnel(self, sentence):
        """untunnel {direction}

Untunnel removes both directions of the exit in the given direction. (e.g. If
you "untunnel west", it will block the exit leading west, as well as the exit
leading east from the room that the west exit used to connect to.) See also
"tunnel", compare "barricade", "undig"."""

        direction = sentence.directString()
        otherPlace = self.place.findExit(direction)
        self.place.disconnectExit(direction)
        otherPlace.disconnectExit(geometry.reverse(direction))
示例#11
0
文件: player.py 项目: lhl/songclub
    def ability_help(self, sentence):
        """help {commandname}
For help with a command, type help followed by the command you would like help
with. For example, for help with the dig command, type "help dig"."""
        try:
            toHelpWith = sentence.directString()
        except error.NoString:
            error.Failure(self.ability_help.__doc__)
        try:
            vb = self.getAbility(toHelpWith)
            self.hears(vb.__doc__)
            return
        except AttributeError:
            pass
        self.hears("I'm not familiar with that ability.")
示例#12
0
文件: player.py 项目: lhl/songclub
    def ability_dig(self, sentence):
        """dig {direction}

Dig creates a new room (and an exit to that room from the current room, and
back again) in the direction specified. See also "undig" to totally undo this
process, or "tunnel" and "barricade" to edit or create new exits for your
new room."""
        direction = sentence.directString()
        try:
            name = sentence.indirectString("to")
        except:
            name = "Untitled Room"
        p = self.place
        r = room.Room(name, self.reality)
        p.connectExit(direction, r)
        r.connectExit(geometry.reverse(direction), p)
        if self.code_space.has_key("log_dig") and self.code_space["log_dig"] is not None:
            self.code_space["log_dig"](self.name, r, time.time())
示例#13
0
文件: player.py 项目: lhl/songclub
    def ability_portal(self, sentence):
        """portal {direction} to {room}

Portal creates a new, one-way passage from the room you are currently in to the
room specified by "to". (For example, "portal east to mansion basement" would
create a new exit to the east, leading to the "mansion basement" room. Note
that this would NOT create a corresponding exit in "mansion basement" leading
back to the room you were in.) This can be undone with "barricade". See also
"tunnel" and "dig"."""

        direction = sentence.directString()
        try:
            rs = sentence.indirectString("to")
            r = self.reality.get(rs)
            p = self.place
            p.connectExit(direction, r)
        except:
            self.hears('Please specify a destination room! (For example, "dig west to mansion cellar")')
示例#14
0
文件: player.py 项目: lhl/songclub
    def ability_tunnel(self, sentence):
        """untunnel {direction} to {room}

Tunnel creates a new, two-way passage in the room you are currently in, which
links to the room specified with "to" and back again. (For example, "tunnel
west to mansion cellar" would create a new exit to the west, leading to the
"mansion cellar" room, and also add an east exit to "mansion cellar" that led
back to the room you're currently in.) This can be easily undone with
"untunnel". Compare "dig" and ""."""

        direction = sentence.directString()
        try:
            rs = sentence.indirectString("to")
            r = self.reality.get(rs)
            p = self.place
            p.connectExit(direction, r)
            r.connectExit(geometry.reverse(direction), p)
        except:
            self.hears('Please specify a destination room! (For example, "dig west to mansion cellar")')
示例#15
0
文件: player.py 项目: lhl/songclub
    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)
示例#16
0
文件: player.py 项目: lhl/songclub
    def ability_barricade(self, sentence):
        """barricade {direction}
Barricade will close the exit leading in the given direction, if it exists. Note that this will only close the direction you have specified, and not the way back (if there is one.) Compare \"untunnel\", see also \"undig\"."""
        direction = sentence.directString()
        self.place.disconnectExit(direction)
示例#17
0
文件: player.py 项目: lhl/songclub
 def ability_emote(self, sentence):
     """`emote' a text string (perform an arbitrary action with no effect on the world).
     """
     self.location.allHear("* ", self, " ", sentence.directString())