go.txt
2.5 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
51
52
53
54
55
56
57
58
59
def go(id, params, players, mud, tokens, command):
# store the exit name
if params == '':
params = command.strip()
else:
params = params.strip()
room_data = utils.load_object_from_file('rooms/' + players[id]["room"] + '.json')
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:
new_room = utils.load_object_from_file('rooms/' + exits[params] + '.json')
if not new_room:
mud.send_message(id, "An invisible force prevents you from going in that direction.")
return None
else:
players[id]["room"] = exits[params]
mud.send_message(id, "You arrive at '{}'".format(new_room['title']))
# 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
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))
if command is None and cmd is not None:
command = cmd
next_command = go(id, params, players, mud, tokens, command)