Example #1
0
def cmdStand(ch, cmd, args): 

    if ch._position == POS_STANDING:
	ch.writeToSelf("You're already standing.\r\n")
	return 1

    if ch._position in [POS_RESTING, POS_SITTING]:
	ch._position = POS_STANDING
	location = ch.getLocation()
	if isinstance(location, Furniture):
	    location.performStand(ch)
	ch.writeToSelf("You stand up.\r\n")
	ch.writeToOthers(ch.getName()+" stands up.\r\n")

	event = Event(EVN_POSITION, ch)
	event.position = POS_STANDING
	ch.getLocation().handleEvent(event)


    if ch._position == POS_SLEEPING:
	ch._position = POS_STANDING
	location = ch.getLocation()
	if isinstance(location, Furniture):
	    location.performStand(ch)

	ch.writeToSelf("You wake and stand up.\r\n")
	ch.writeToOthers(ch.getName()+" wakes and stands up.\r\n")

	event = Event(EVN_POSITION, ch)
	event.position = POS_STANDING
	ch.getLocation().handleEvent(event)

    return 1
Example #2
0
def cmdSit(ch, cmd, args):

    argL = utils.splitArgs(args)

    if not argL:
	if ch._position == POS_RESTING:
	    ch.writeToSelf("Please stand up first.\r\n")
	    return 1

	if ch._position == POS_SITTING:
	    ch.writeToSelf("You're already sitting.\r\n")
	    return 1
			
	if ch._position == POS_SLEEPING:
	    ch.writeToSelf("In your dreams or what?.\r\n")
	    return 1

	if ch._position == POS_STANDING:
	    ch._position = POS_SITTING
	    ch.writeToSelf("You sit down on the floor.\r\n")
	    event = Event(EVN_POSITION, ch)
	    event.position = POS_SITTING
	    ch.getLocation().handleEvent(event)
		
	return 1

    if argL[0] != 'on' or len(argL) < 2:
	ch.writeToSelf("What do you want to sit ON?\r\n")
	return 1

    sitting = ch.findObject(argL[1])
    if not sitting:
	ch.writeToSelf("You cant find a "+argL[1]+" here.\r\n")
	return 1
    if ch._position == POS_RESTING:
	ch.writeToSelf("Please stand up first.\r\n")
    if ch._position == POS_SITTING:
	ch.writeToSelf("You're already sitting.\r\n")
	return 1
    if ch._position == POS_SLEEPING:
	ch.writeToSelf("In your dreams or what?\r\n")
	return 1
    if ch._position == POS_STANDING:
	if sitting.performSit(ch):
	    ch._position = POS_SITTING
	    ch.writeToSelf("You sit on "+sitting.getName()+".\r\n")
	    ch.writeToOthers(ch.getName()+" sits down on "+sitting.getName()
			+".\r\n")
	    event = Event(EVN_POSITION, ch)
	    event.position = POS_SITTING
	    ch.getPlace().handleEvent(event)

    return 1
Example #3
0
def cmdWake(ch, cmd, args): 

    argL = utils.splitArgs(args)

    if not argL:
	if ch._position in [POS_RESTING, POS_SITTING, POS_STANDING]:
	    ch.writeToSelf("You're already awake and standing.\r\n")
	    return 1

	if ch._position == POS_SLEEPING:
	    ch._position = POS_RESTING

	    ch.writeToSelf("You wake up.\r\n")
	    ch.writeToOthers(ch.getName()+" wakes up.\r\n")

	    event = Event(EVN_POSITION, ch)
	    event.position = POS_RESTING
	    ch.getLocation().handleEvent(event)


	return 1


    marmote = ch.findVictim(argL[0])
    if not marmote:
	ch.writeToSelf(argL[0]+" is not around.\r\n")
	return 1

    if marmote._position  in [POS_RESTING, POS_SITTING, POS_STANDING]:
	ch.writeToSelf(string.capitalize(marmote.he())+"'s already awake.\r\n")
	return 1

    if marmote._position == POS_SLEEPING:
	marmote._position = POS_RESTING
	location = ch.getLocation()
	if isinstance(location, Furniture):
	    location.performStand(ch)
	ch.writeToSelf("You wake "+marmote.getName()+".\r\n")
	marmote.writeToSelf(ch.getName()+" wakes you up.\r\n", WRI_SLEEPING)

	event = Event(EVN_POSITION, ch)
	event.position = POS_RESTING
	ch.getLocation().handleEvent(event)


    return 1
Example #4
0
def cmdSleep(ch, cmd, args):

    if ch._position == POS_SLEEPING:
	ch.writeToSelf("You're already sleeping.\r\n", WRI_SLEEPING)
	return 1

    argL = utils.splitArgs(args)

    if not argL:
	if ch._position in [POS_SITTING, POS_RESTING, POS_STANDING]:
	    ch.writeToSelf("You go to sleep.\r\n")
	    ch.writeToOthers(ch.getName()+" goes to sleep.\r\n")
	    ch._position = POS_SLEEPING
	    ch.sleep()

	    event = Event(EVN_POSITION, ch)
	    event.position = POS_SLEEPING
	    ch.getLocation().handleEvent(event)

	return 1


    if argL[0] != 'on' or len(argL) < 2:
	ch.writeToSelf("What do you want to sleep ON?\r\n")
	return 1

    obj = ch.findObject(argL[1])
    if not obj:
	ch.writeToSelf("You cant find a "+argL[1]+" here.\r\n")
	return 1

    if ch._position in [POS_SITTING, POS_RESTING, POS_STANDING]:
	if obj.performSleep(ch):
	    ch.writeToSelf("You sleep on "+obj.getName()+".\r\n")
	    ch.writeToOthers(ch.getName()+" sleeps on "+obj.getName()+".\r\n")
	    ch._position = POS_SLEEPING
	    event = Event(EVN_POSITION, ch)
	    event.position = POS_SLEEPING
	    ch.getPlace().handleEvent(event)

    return 1
Example #5
0
def cmdRest(ch, cmd, args):
    
    if ch._position == POS_RESTING:
	ch.writeToSelf("You're already resting and relaxed enough.\r\n")
	return 1

    if ch._position == POS_SITTING:
	ch.writeToSelf("You're already resting and relaxed enough.\r\n")
	return 1

    if ch._position == POS_STANDING:
	ch.writeToSelf("You sit down and rest.\r\n")
	ch.writeToOthers(ch.getName()+" sits down and rests.\r\n")

	ch._position = POS_RESTING

	event = Event(EVN_POSITION, ch)
	event.position = POS_RESTING
	ch.getLocation().handleEvent(event)

    
    return 1
def cmdLook(ch, cmd, args):
    """
    Look at something, in something or the current room.
    """

    argL = utils.splitArgs(args)

    room = ch.getPlace()

    if argL == []:
	_lookAround(ch)

	event = Event(EVN_LOOK, ch)
	event.target = None
	room.handleEvent(event)

	return 1

    if argL[0] == "in":
	if len(argL) < 2:
	    ch.writeToSelf("Look in what?\r\n")
	else:
	    obj = ch.findCarriedObject(argL[1])
	    if not obj:
		obj = ch.findObject(argL[1])
	    if obj:
		descr = obj.getDescriptionForLookIn()
		if not descr:
		    ch.writeToSelf("You can't look inside that.\r\n")
		else:
		    ch.writeToSelf(descr+"\r\n")
		    ch.writeToOthers(ch.getName()+" looks in "
			    +obj.getName()+".\r\n")
	    else:
		ch.writeToSelf("You don't see that here.\r\n")

    else:
	if argL[0] == "at":
	    i = 1
	    if len(argL) < 2:
		ch.writeToSelf("Look at what?\r\n")
		return 1
	else:
	    i = 0

	found = 0

	# character
	if argL[i][-2:] == "'s":
	    name = argL[i][:-2]
	else:
	    name = argL[i]

	target = ch.findVictim(name)
	if target:
	    _lookAtCharacter(ch, target, argL[i+1:])
	    found = 1

	# room description
	if not found:
	    descr = room.getDescriptionForLookAt(argL[i])
	    if descr:
		ch.writeToSelf(descr+"\r\n")
		found = 1

	# worn objects
	if not found:
	    r = ch.findDescriptionForWornObject(argL[i])
	    if r:
		target, descr = r
		ch.writeToSelf(descr+"\r\n")
		found = 1

	# carried objects
	if not found:
	    r = ch.findDescriptionForCarriedObject(argL[i])
	    if r:
		target, descr = r
		ch.writeToSelf(descr+"\r\n")
		found = 1

	# objects in room
	if not found:
	    r = room.findDescriptionForContainedObject(argL[i])
	    if r:
		target, descr = r
		ch.writeToSelf(descr+"\r\n")
		found = 1

	if not found:
	    # worn objects
	    target = ch.findWornObject(argL[i])
	    # carried objects
	    if not target:
		target = ch.findCarriedObject(argL[i])
	    # room objects
	    if not target:
		target = ch.findObject(argL[i])
	    if target:
		ch.writeToSelf("You don't see anything special about it.\r\n")
		found = 1

	if found:
	    event = Event(EVN_LOOK, ch)
	    event.target = target
	    room.handleEvent(event)
	else:
	    ch.writeToSelf("You don't see that here.\r\n")


    return 1
Example #7
0
def cmdSocial(ch, cmd, args):
    """
    Perform the social given by the command.
    """

    #
    # Find the wanted social in the Social table
    #
    for item in Social:
	if item[0] == cmd:
	    break

    cmd, toSelfNoVictim, toOtherNoVictim, toSelfNotFound, toOtherNotFound,\
    	toSelf, toVictim, toOthers, toSelfFromSelf, toOtherFromSelf = item

    argL = utils.splitArgs(args)

    selfMsg = None
    otherMsg = None
    victimMsg = None

    if len(argL) > 0:
	# has a victim
	victim = ch.findVictim(argL[0])

	# victim is ourself
	if victim == ch:
	    selfMsg = toSelfFromSelf
	    otherMsg = toOtherFromSelf
	# victim was not found
	elif victim == None:
	    selfMsg = toSelfNotFound
	    otherMsg = toOtherNotFound
	else:
	    selfMsg = toSelf
	    otherMsg = toOthers
	    victimMsg = toVictim
    else:
	victim = None
	# no victim
	selfMsg = toSelfNoVictim
	otherMsg = toOtherNoVictim

    room = ch.getPlace()

    if selfMsg:
	ch.writeToSelf(string.capitalize(utils.substNames(selfMsg, 
		ch, victim, None))+"\r\n")
    if otherMsg:
	room.writeToRoom(string.capitalize(utils.substNames(otherMsg,
				 ch, victim, None))+"\r\n", [ch, victim])
    if victimMsg:
	victim.writeToSelf(string.capitalize(utils.substNames(victimMsg,
				 ch, victim, None))+"\r\n", WRI_DEAD)

    event = Event(EVN_SOCIAL, ch)
    event.command = cmd
    event.victim = victim

    room.handleEvent(event)

    return 1
Example #8
0
    def execInstruction(self, instruction):
        # returns the next address or -1 if the
        # loop should be broken

        def getOffset(self, text):
            if text[0] == "@":
                label = text[1:]
                return self._labels[label]
            elif text == "end":
                return len(self._script) + 1
            elif text[0] == "+" or text[0] == "-":
                return self._scriptPtr + int(text)
            else:
                return int(text)

        def push(self, value):
            self._stack.insert(0, value)

        def pop(self):
            if self._stack == []:
                self.warning("Stack underflow.")
                return None
            val = self._stack[0]
            del self._stack[0]

            return val

        token = string.split(instruction)

        nextPtr = self._scriptPtr + 1

        # :dprint <<expression>>
        #
        # Print some debugging info in the server stdout.
        #
        if token[0] == ":dprint":
            print "DPRINT[" + self._id + "." + ` self._oid ` + "]:", self.evalExpr(string.join(token[1:]))

        # :reset
        #
        #
        elif token[0] == ":reset":
            self.reset()

        # :write <<expression>>
        #
        # Write the expression result into the room.
        #
        elif token[0] == ":write":
            room = self.getLocation()
            room.writeToRoom(self.evalExpr(string.join(token[1:])) + "\r\n")

        # :putcookie <<Character>> <cookie>
        #
        # Adds a piece of arbitrary string to a character cookie box.
        #
        elif token[0] == ":putcookie":
            char = self.evalExpr(token[1])
            char.putCookie(token[2])

        # :hascookie <<Character>> <cookie> <command>
        #
        # Checks whether the character has the cookie and executes the
        # command if yes.
        #
        elif token[0] == ":hascookie":
            char = self.evalExpr(token[1])
            if char.hasCookie(token[2]):
                nextPtr = self.execInstruction(string.join(token[3:]))

                # :removecookie <<Character>> <cookie>
                #
                # Removes the cookie from the character's cookie box if it's there.
                #
        elif token[0] == ":removecookie":
            char = self.evalExpr(token[1])
            char.removeCookie(token[2])

        # :addquest <<Character>> <quest descr>
        #
        # Adds a quest description to the character.
        #
        elif token[0] == ":addquest":
            char = self.evalExpr(token[1])
            char._quests.append(token[2])

        # :removequest <<Character>> <keyword>
        #
        # Remove a quest description that contains the keyword from
        # the character.
        #
        elif token[0] == ":removequest":
            char = self.evalExpr(token[1])
            for q in char._quests:
                if string.find(q, token[2]) >= 0:
                    char._quests.remove(q)
                    break

                # :do <mud command> <<expression>>
                #
                # Execute a MUD command using the expression result as argument.
                #
        elif token[0] == ":do":
            self._commandQueue.append(token[1] + " " + self.evalExpr(string.join(token[2:])))

        # :goto <position> | :goto +/- <offset> | :goto end | :goto @label
        #
        # Go to another part of the script.
        #
        elif token[0] == ":goto":
            nextPtr = getOffset(self, token[1])
            print "goto", nextPtr, self._state

        # :gosub <position> | :gosub +/-<offset>
        #
        # Go to another part of the script and save current position.
        # Can be returned later into this position with :return.
        #
        elif token[0] == ":gosub":
            push(self, nextPtr)
            nextPtr = getOffset(self, token[1])

        # :return
        #
        # Return to a place where a :gosub was called
        #
        elif token[0] == ":return":
            nextPtr = pop(self)

        # :delay <<seconds>>
        #
        # Delay for some time
        #
        elif token[0] == ":delay":
            if self._commandQueue:  # must wait the queue to be empty,
                # so the delay will actually happen
                return -1

            if self._delay == 0:
                self._delay = self.evalExpr(token[1]) + 1
                return -1
            else:
                self._delay = self._delay - 1
                if self._delay > 0:
                    return -1

                # :wait <event type> [from <<Mobile>>]
                #
                # Wait for an event of specified type and optionally
                # from the specified Mobile.
                #
        elif token[0] == ":wait":
            self._waitingEvent = token[1]
            if len(token) == 4:
                if token[2] == "from":
                    self._waitingEventFrom = self.evalExpr(token[3])

            return -1

        # :on <event> [from <<Mobile>>] <command>
        #
        # Set a event handler for the specified event, making it jump to
        # position when it occurs.
        #
        elif token[0] == ":on":
            event = token[1]
            if len(token) > 2:
                if token[2] == "from":
                    mob = self.evalExpr(token[3])
                    cmd = string.join(token[4:])
                else:
                    mob = None
                    cmd = string.join(token[2:])

                self._onHandlers[event] = (mob, cmd)
            else:
                self._onHandlers[event] = None

                # :set <identifier> <<expression>>
                #
                # Assign expression result into variable
                #
        elif token[0] == ":set":
            self._variables.__dict__[token[1]] = self.evalExpr(string.join(token[2:]))

        # :match <<string1>> <<string2>> <position>
        #
        # Try to match the strings and jump to position if they do.
        #
        elif token[0] == ":match":
            parts1 = string.split(string.lower(self.evalExpr(token[1])))
            parts2 = string.split(string.lower(self.evalExpr(token[2])))

            if len(parts1) == len(parts2):
                ok = 1
                for i in range(len(parts1)):
                    if parts1[i] != parts2[i]:
                        ok = 0
                        break
                if ok:
                    nextPtr = getOffset(self, token[3])

                # :speed <seconds>
                #
                # Set the speed (delay between commands) of the script to be executed.
                #
        elif token[0] == ":speed":
            self._speed = max(int(token[1]), 1)

        # :case <<expression>> <<value1>> <pos1> <<value2>> <pos2> ...

        # :if <<expression>> then <position>
        #
        # If result of expression is true, jump to position, else continue.
        #
        elif token[0] == ":if":
            i = token.index("then")
            if self.evalExpr(string.join(token[1:i])):
                nextPtr = getOffset(self, token[i + 1])

                # :label <identifier>
                #
                # Set a label. (handled on startup, so its ignored here)
                #
        elif token[0] == ":label":
            pass

        # :message <target id> <message>
        #
        # Sends a message to a target.
        #
        elif token[0] == ":message":
            event = Event(EVN_MESSAGE, self)
            event.message = token[2]

            for m in self._world._mobiles:
                if m._id == token[1]:
                    m.handleEvent(event)

        else:
            self.warning("Invalid command in mob script " + token[0])

        return nextPtr