go.txt
2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
def go(id, params, players, mud, tokens):
# store the exit name
params = params.lower().strip()
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)