29119a43 by Barry

Added equipment wearing remove and even more item bug fixes.

1 parent 8671340f
...@@ -13,7 +13,9 @@ global_aliases = { ...@@ -13,7 +13,9 @@ global_aliases = {
13 'inv': 'inventory', 13 'inv': 'inventory',
14 'attack': 'kill', 14 'attack': 'kill',
15 ',': 'emote', 15 ',': 'emote',
16 'social': 'emote' 16 'social': 'emote',
17 'equipment': 'equip',
18 'wear': 'equip'
17 } 19 }
18 20
19 21
......
1 def equip(id, players, tokens, mud):
2 if len(tokens) == 0:
3 mud.send_message(id, " %green+-Item---------------------=Equipment=------------------Loc----+", nowrap=True)
4 if players[id].get('equipment'):
5 for item, item_list in players[id]['equipment'].items():
6 if isinstance(item_list, list):
7 vals = [val for val in item_list if val]
8 if len(vals) > 0:
9 mud.send_message(id, ' %green|%reset {} {} %green|'.format("%-51s" % ', '.join(vals), item.rjust(8, ' ')))
10 else:
11 mud.send_message(id, ' %green|%reset {} {} %green|'.format("%-51s" % 'None', item.rjust(8, ' ')))
12 else:
13 mud.send_message(id, ' %green|%reset {} {} %green|'.format("%-51s" % item_list or "None", item.rjust(8, ' ')))
14 mud.send_message(id, " %green+--------------------------------------------------------------+", nowrap=True)
15 else:
16 if tokens[0] not in players[id]["inventory"]:
17 mud.send_message(id, 'You do not have {} in your inventory.'.format(tokens[0]))
18 else:
19 gear = utils.load_object_from_file('inventory/' + tokens[0] + '.json')
20 if gear["type"] == "weapon":
21 mud.send_message(id, 'That is a weapon and must be "wield".'.format(tokens[0]))
22 elif gear["type"] != "armor":
23 mud.send_message(id, 'That cannot be worn.'.format(tokens[0]))
24 else:
25 players[id]["equipment"][gear['loc']] = tokens[0]
26 mud.send_message(id, 'You wear the {} on your {}.'.format(tokens[0], gear['loc']))
27 players[id]["inventory"][tokens[0]].pop()
28 if len(players[id]["inventory"][tokens[0]]) == 0:
29 del players[id]["inventory"][tokens[0]]
30
31 utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"]))
32
33
34 equip(id, players, tokens, mud)
35 del equip
...\ No newline at end of file ...\ No newline at end of file
...@@ -38,7 +38,7 @@ def get(id, params, tokens, players, mud): ...@@ -38,7 +38,7 @@ def get(id, params, tokens, players, mud):
38 if len(room_data['inventory'][container][0]['inventory'][tokens[0]]) <= 0: 38 if len(room_data['inventory'][container][0]['inventory'][tokens[0]]) <= 0:
39 del room_data['inventory'][container][0]['inventory'][tokens[0]] 39 del room_data['inventory'][container][0]['inventory'][tokens[0]]
40 if not found: 40 if not found:
41 mud.send_message(id, 'You do not see a {} in the container {}.'.format(tokens[0], container)) 41 mud.send_message(id, 'You do not see a {} in the {}.'.format(tokens[0], container))
42 else: 42 else:
43 for pid, pl in players.items(): 43 for pid, pl in players.items():
44 # if they're in the same room as the player 44 # if they're in the same room as the player
......
1 def inventory(id, players, mud): 1 def inventory(id, players, mud):
2 mud.send_message(id, '\r\n-Item----------=Inventory=-----------Qty-\r\n') 2 mud.send_message(id, " %green+-Item---------------------=Inventory=--------------------Qty--+", nowrap=True)
3 for item, item_list in players[id]['inventory'].items(): 3 for item, item_list in players[id]['inventory'].items():
4 mud.send_message(id, '{} {}'.format("%-37s" % item, len(item_list))) 4 mud.send_message(id, ' %green|%reset {} {} %green|'.format("%-55s" % item, str(len(item_list)).center(4, ' ')))
5 mud.send_message(id, '\r\n-----------------------------------------') 5 mud.send_message(id, " %green+--------------------------------------------------------------+", nowrap=True)
6 6
7 inventory(id, players, mud) 7 inventory(id, players, mud)
8 del inventory 8 del inventory
...\ No newline at end of file ...\ No newline at end of file
......
1 def remove(id, players, tokens, mud):
2 if len(tokens) == 0:
3 mud.send_message(id, 'What do you want to stop wearing?')
4 else:
5 for item, item_list in players[id]['equipment'].items():
6 if isinstance(item_list, list):
7 for idx, li in enumerate(item_list):
8 print(li)
9 if li == tokens[0]:
10 item_list[idx] = None
11 if tokens[0] in players[id]['inventory']:
12 players[id]['inventory'][tokens[0]].append({"expries": 0})
13 else:
14 players[id]['inventory'][tokens[0]] = [{"expries": 0}]
15 mud.send_message(id, 'You remove the {}.'.format(tokens[0]))
16 return
17 elif item_list == tokens[0]:
18 players[id]['equipment'][item] = None
19 if tokens[0] in players[id]['inventory']:
20 players[id]['inventory'][tokens[0]].append({"expries": 0})
21 else:
22 players[id]['inventory'][tokens[0]] = [{"expries": 0}]
23 mud.send_message(id, 'You remove the {}.'.format(tokens[0]))
24 return
25
26 mud.send_message(id, 'You are not wearing a {}.'.format(tokens[0]))
27 # else:
28 # gear = utils.load_object_from_file('inventory/' + tokens[0] + '.json')
29 # if gear["type"] == "weapon":
30 # mud.send_message(id, 'That is a weapon and must be "wield".'.format(tokens[0]))
31 # elif gear["type"] != "armor":
32 # mud.send_message(id, 'That cannot be worn.'.format(tokens[0]))
33 # else:
34 # players[id]["equipment"][gear['loc']] = tokens[0]
35 # mud.send_message(id, 'You wear the {} on your {}.'.format(tokens[0], gear['loc']))
36 # if len(players[id]["inventory"][tokens[0]]) == 0:
37 # del players[id]["inventory"][tokens[0]]
38 # else:
39 # players[id]["inventory"][tokens[0]].pop()
40 # utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"]))
41
42
43 remove(id, players, tokens, mud)
44 del remove
...\ No newline at end of file ...\ No newline at end of file
...@@ -2,10 +2,24 @@ ...@@ -2,10 +2,24 @@
2 "name": null, 2 "name": null,
3 "password": null, 3 "password": null,
4 "room": null, 4 "room": null,
5 "equipment": {
6 "finger": [null, null],
7 "hand": [null, null],
8 "arm": [null, null],
9 "leg": [null, null],
10 "foot": [null, null],
11 "head": null,
12 "neck": null,
13 "back": null,
14 "body": null,
15 "waist": null
16 },
5 "inventory": { 17 "inventory": {
6 "bag": [{ 18 "bag": [{
7 "expires": 0, 19 "expires": 0,
8 "inventory": {} 20 "inventory": {
21 "shirt": [{"expires": 0}]
22 }
9 }] 23 }]
10 }, 24 },
11 "prompt": "hp %hp mp %mp> ", 25 "prompt": "hp %hp mp %mp> ",
......
1 {
2 "title": "shirt",
3 "description": "A roughly woven bag made of simple hemp that is rough and not very warm.",
4 "type": "armor",
5 "loc": "body",
6 "armor": 1,
7 "weight": 10
8 }
...\ No newline at end of file ...\ No newline at end of file
1 { 1 {
2 "title": "sword", 2 "title": "sword",
3 "description": "a simple hardened steel sword with a slightly sharp edge.", 3 "description": "a simple hardened steel sword with a slightly sharp edge.",
4 "type": "light", 4 "type": "weapon",
5 "power": 10, 5 "power": 10,
6 "damage": "2d4", 6 "damage": "2d4",
7 "weight": 10 7 "weight": 10
......
1 {"look_items": {"wooden,oak,plank": "An old solid oak plank that has a large number of chips and drink marks.", "barrel,barrels": "The old barrels bands are thick with oxidation and stained with the purple of spilled wine.", "bar": "The bar is a long wooden plank thrown over roughly hewn barrels.", "fire": "The fire crackles quietly in the corner providing a small amount of light and heat."}, "description": "You're in a cozy tavern warmed by an open fire.", "inventory": {"candle": [{"age": 0}, {"age": 0}, {"age": 0}, {"age": 0}]}, "exits": {"behind": "Room001", "dark": "Dark", "outside": "Outside"}, "title": "Tavern"}
...\ No newline at end of file ...\ No newline at end of file
1 {"look_items": {"wooden,oak,plank": "An old solid oak plank that has a large number of chips and drink marks.", "barrel,barrels": "The old barrels bands are thick with oxidation and stained with the purple of spilled wine.", "bar": "The bar is a long wooden plank thrown over roughly hewn barrels.", "fire": "The fire crackles quietly in the corner providing a small amount of light and heat."}, "description": "You're in a cozy tavern warmed by an open fire.", "inventory": {"candle": [{"age": 0}, {"age": 0}]}, "exits": {"behind": "Room001", "dark": "Dark", "outside": "Outside"}, "title": "Tavern"}
...\ No newline at end of file ...\ No newline at end of file
......