remove.txt 2.18 KB
def remove(id, players, tokens, mud):
    if len(tokens) == 0:
        mud.send_message(id, 'What do you want to stop wearing?')
    else:
        for item, item_list in players[id]['equipment'].items():
            if isinstance(item_list, list):
                for idx, li in enumerate(item_list):
                    print(li)
                    if li == tokens[0]:
                        item_list[idx] = None
                        if tokens[0] in players[id]['inventory']:
                            players[id]['inventory'][tokens[0]].append({"expries": 0})
                        else:
                            players[id]['inventory'][tokens[0]] = [{"expries": 0}]
                        mud.send_message(id, 'You remove the {}.'.format(tokens[0]))
                        return
            elif item_list == tokens[0]:
                players[id]['equipment'][item] = None
                if tokens[0] in players[id]['inventory']:
                    players[id]['inventory'][tokens[0]].append({"expries": 0})
                else:
                    players[id]['inventory'][tokens[0]] = [{"expries": 0}]
                mud.send_message(id, 'You remove the {}.'.format(tokens[0]))
                return

        mud.send_message(id, 'You are not wearing a {}.'.format(tokens[0]))
        # else:
        #     gear = utils.load_object_from_file('inventory/' + tokens[0] + '.json')
        #     if gear["type"] == "weapon":
        #         mud.send_message(id, 'That is a weapon and must be "wield".'.format(tokens[0]))
        #     elif gear["type"] != "armor":
        #         mud.send_message(id, 'That cannot be worn.'.format(tokens[0]))
        #     else:
        #         players[id]["equipment"][gear['loc']] = tokens[0]
        #         mud.send_message(id, 'You wear the {} on your {}.'.format(tokens[0], gear['loc']))
        #         if len(players[id]["inventory"][tokens[0]]) == 0:
        #             del players[id]["inventory"][tokens[0]]
        #         else:
        #             players[id]["inventory"][tokens[0]].pop()
        #         utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"]))


remove(id, players, tokens, mud)
del remove