get.txt 1.03 KB
def get(id, tokens, players, mud):
    room_name = players[id]["room"]
    if len(tokens) == 0:
        mud.send_message(id, 'What do you want to get?')
        return True
    room_data = utils.load_object_from_file('rooms/' + room_name + '.json')
    if tokens[0] in room_data.get('inventory'):
        if tokens[0] in players[id]['inventory']:
            players[id]['inventory'][tokens[0]] += 1
        else:
            players[id]['inventory'][tokens[0]] = 1
        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, "{} picked up 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, 'There is no {} here to get.'.format(tokens[0]))

get(id, tokens, players, mud)