drop.txt
1.31 KB
def drop(id, tokens, players, mud):
room_name = players[id]["room"]
if len(tokens) == 0:
mud.send_message(id, 'What do you want to drop?')
return True
room_data = utils.load_object_from_file('rooms/' + room_name + '.json')
if tokens[0] in players[id]['inventory']:
if tokens[0] in room_data['inventory']:
room_data['inventory'][tokens[0]].append(players[id]['inventory'][tokens[0]].pop())
else:
room_data['inventory'][tokens[0]] = [players[id]['inventory'][tokens[0]].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, "{} dropped a {}.".format(
players[id]["name"], tokens[0]))
utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"]))
else:
mud.send_message(id, 'You do not have {} in your inventory.'.format(tokens[0]))
drop(id, tokens, players, mud)
del drop