go.txt 2.22 KB
def go(id, params, players, mud, tokens, command):
    # store the exit name
    if params == '':
      params = command

    room_data = utils.load_object_from_file('rooms/' + players[id]["room"] + '.txt')
    exits = room_data['exits']
    # if the specified exit is found in the room's exits list

    if params in exits:
        # go through all the players in the game
        for pid, pl in players.items():
            # if player is in the same room and isn't the player
            # sending the command
            if players[pid]["room"] == players[id]["room"] \
                    and pid != id:
                # send them a message telling them that the player
                # left the room
                mud.send_message(pid, "{} left via exit '{}'".format(
                                              players[id]["name"], params))

        # update the player's current room to the one the exit leads to
        
        if room_data['exits'][params] == None:
            mud.send_message(id, "An invisible force prevents you from going in that direction.")
            return None
        else:
            players[id]["room"] = exits[params]
            room = params

        # go through all the players in the game
        for pid, pl in players.items():
            # if player is in the same (new) room and isn't the player
            # sending the command
            if players[pid]["room"] == players[id]["room"] \
                    and pid != id:
                # send them a message telling them that the player
                # entered the room
                mud.send_message(pid,
                                 "{} arrived via exit '{}'".format(
                                              players[id]["name"], params))

        # send the player a message telling them where they are now
        title = utils.load_object_from_file('rooms/' + players[id]["room"] + '.txt')['title']
        mud.send_message(id, "You arrive at '{}'".format(title))
        tokens = []
        return 'look'
    # the specified exit wasn't found in the current room
    else:
        # send back an 'unknown exit' message
        mud.send_message(id, "Unknown exit '{}'".format(params))
next_command = go(id, params, players, mud, tokens, command)