remove.txt
2.83 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
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]))
utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"]))
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]))
utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"]))
return
if tokens[0] == players[id]['weapon']:
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 unwield the {}.'.format(tokens[0]))
utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"]))
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