put.txt
2.16 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
def put(id, tokens, players, mud):
if len(tokens) == 0:
mud.send_message(id, 'What do you want to put and where do you want to put it?')
return True
subject = tokens[0]
if 'in' == tokens[1]:
del tokens[1]
dest = tokens[1]
room_name = players[id]["room"]
room_data = utils.load_object_from_file('rooms/' + room_name + '.json')
if subject in players[id]['inventory']:
if dest in players[id]['inventory'] or dest in room_data['inventory']:
if dest in room_data['inventory']:
if subject in room_data['inventory'][dest][0]["inventory"].get(subject):
room_data['inventory'][dest][0]["inventory"][subject] = [players[id]['inventory'][subject].pop()]
else:
room_data['inventory'][dest][0]["inventory"][subject].append(players[id]['inventory'][subject].pop())
elif dest in players[id]['inventory']:
if subject in players[id]['inventory'][dest][0]["inventory"].get(subject):
players[id]['inventory'][dest][0]["inventory"][subject] = [players[id]['inventory'][subject].pop()]
else:
players[id]['inventory'][dest][0]["inventory"][subject].append(players[id]['inventory'][subject].pop())
if len(players[id]['inventory'][tokens[0]]) <= 0:
del players[id]['inventory'][tokens[0]]
utils.save_object_to_file(room_data, 'rooms/' + room_name + '.json')
for pid, pl in players.items():
# if they're in the same room as the player
if players[pid]["room"] == players[id]["room"]:
# send them a message telling them what the player said
mud.send_message(pid, "{} put a {} in a {}.".format(players[id]["name"], subject, dest))
utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"]))
else:
mud.send_message(id, 'You cannot put {} in {} since it is not here.'.format(subject, dest))
else:
mud.send_message(id, 'You do not have {} in your inventory.'.format(subject))
put(id, tokens, players, mud)
del put