look.txt
5.26 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
def look(id, mud, players, tokens):
room_name = players[id]["room"]
room_data = utils.load_object_from_file('rooms/' + room_name + '.json')
room_monsters = utils.load_object_from_file('rooms/' + room_name + '_monsters.json')
mud.send_message(id, "")
if len(tokens) > 0 and tokens[0] == 'at':
del tokens[0]
container = False
if len(tokens) > 0 and tokens[0] == 'in':
del tokens[0]
container = True
if len(tokens) == 0:
exits = {}
for exit_name, exit in room_data.get('exits').items():
exits[exit_name] = exit[1]
print(room_data)
# clid, name, zone, terrain, description, exits, coords
mud.send_room(id, room_data.get('num'), room_data.get('title'), room_data.get('zone'),
'City', '', exits, room_data.get('coords'))
mud.send_message(id, room_data.get('title'), color=['bold', 'green'])
mud.send_message(id, room_data.get('description'), line_ending='\r\n\r\n', color='green')
else:
subject = tokens[0]
items = room_data.get('look_items')
for item in items:
if subject in item:
mud.send_message(id, items[item])
return True
if subject in room_data['inventory']:
if container and room_data["inventory"][subject][0].get("inventory") is not None:
items = room_data["inventory"][subject][0]["inventory"]
if len(items) > 0:
mud.send_message(id, 'You look in the {} and see:\r\n'.format(subject))
inv_list = []
for name, i in items.items():
if len(i) > 1:
inv_list.append(str(len(i)) + " " + name + "s")
else:
inv_list.append(name)
mud.send_list(id, inv_list, "look")
else:
mud.send_message(id, 'You look in the {} and see nothing.'.format(subject))
else:
item = utils.load_object_from_file('inventory/' + subject + '.json')
mud.send_message(id, 'You see {}'.format(item.get('description')))
return True
if subject in players[id]['inventory']:
if container and players[id]["inventory"][subject][0].get("inventory") is not None:
items = players[id]["inventory"][subject][0]["inventory"]
if len(items) > 0:
mud.send_message(id, 'You look in your {} and see:\r\n'.format(subject))
inv_list = []
print(items)
for name, i in items.items():
if len(i) > 1:
inv_list.append(str(len(i)) + " " + name + "s")
else:
inv_list.append(name)
mud.send_list(id, inv_list, "look")
else:
mud.send_message(id, 'You look in your {} and see nothing.'.format(subject))
else:
item = utils.load_object_from_file('inventory/' + subject + '.json')
mud.send_message(id, 'You check your inventory and see {}'.format(item.get('description')))
return True
if subject in room_monsters:
if len(room_monsters[subject]['active']) > 0:
monster_template = utils.load_object_from_file('mobs/{}.json'.format(subject))
if monster_template:
mud.send_message(id, 'You see {}'.format(monster_template.get('desc').lower()))
return True
mud.send_message(id, "That doesn't seem to be here.")
return
playershere = []
# go through every player in the game
for pid, pl in players.items():
# if they're in the same room as the player
if players[pid]["room"] == players[id]["room"]:
# ... and they have a name to be shown
if players[pid]["name"] is not None and players[id]["name"] != players[pid]["name"]:
# add their name to the list
playershere.append(players[pid]["name"])
# send player a message containing the list of players in the room
if len(playershere) > 0:
mud.send_message(id, "%boldPlayers here:%reset {}".format(", ".join(playershere)))
mud.send_message(id, "%boldObvious Exits:%reset ", line_ending='')
mud.send_list(id, room_data.get('exits'), "go")
# send player a message containing the list of exits from this room
if len(room_data.get('inventory')) > 0:
mud.send_message(id, "%boldItems here:%reset ", line_ending='')
inv_list = []
for name, i in room_data.get('inventory').items():
if len(i) > 1:
inv_list.append(str(len(i)) + " " + name + "s")
else:
inv_list.append(name)
mud.send_list(id, inv_list, "look")
# send player a message containing the list of players in the room
for mon_name, monster in room_monsters.items():
count = len(monster['active'])
if count > 1:
mud.send_message(id, "{} {} are here.".format(count, mon_name))
elif count > 0:
mud.send_message(id, "a {} is here.".format(mon_name))
look(id, mud, players, tokens)
del look