16ec09b0 by Barry

Added weapon and updated remove and equip to handle weapons.

1 parent 29119a43
...@@ -18,9 +18,9 @@ def equip(id, players, tokens, mud): ...@@ -18,9 +18,9 @@ def equip(id, players, tokens, mud):
18 else: 18 else:
19 gear = utils.load_object_from_file('inventory/' + tokens[0] + '.json') 19 gear = utils.load_object_from_file('inventory/' + tokens[0] + '.json')
20 if gear["type"] == "weapon": 20 if gear["type"] == "weapon":
21 mud.send_message(id, 'That is a weapon and must be "wield".'.format(tokens[0])) 21 mud.send_message(id, 'That is a weapon and must be "wield".')
22 elif gear["type"] != "armor": 22 elif gear["type"] != "armor":
23 mud.send_message(id, 'That cannot be worn.'.format(tokens[0])) 23 mud.send_message(id, 'That cannot be worn.')
24 else: 24 else:
25 players[id]["equipment"][gear['loc']] = tokens[0] 25 players[id]["equipment"][gear['loc']] = tokens[0]
26 mud.send_message(id, 'You wear the {} on your {}.'.format(tokens[0], gear['loc'])) 26 mud.send_message(id, 'You wear the {} on your {}.'.format(tokens[0], gear['loc']))
......
...@@ -13,6 +13,7 @@ def remove(id, players, tokens, mud): ...@@ -13,6 +13,7 @@ def remove(id, players, tokens, mud):
13 else: 13 else:
14 players[id]['inventory'][tokens[0]] = [{"expries": 0}] 14 players[id]['inventory'][tokens[0]] = [{"expries": 0}]
15 mud.send_message(id, 'You remove the {}.'.format(tokens[0])) 15 mud.send_message(id, 'You remove the {}.'.format(tokens[0]))
16 utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"]))
16 return 17 return
17 elif item_list == tokens[0]: 18 elif item_list == tokens[0]:
18 players[id]['equipment'][item] = None 19 players[id]['equipment'][item] = None
...@@ -21,8 +22,18 @@ def remove(id, players, tokens, mud): ...@@ -21,8 +22,18 @@ def remove(id, players, tokens, mud):
21 else: 22 else:
22 players[id]['inventory'][tokens[0]] = [{"expries": 0}] 23 players[id]['inventory'][tokens[0]] = [{"expries": 0}]
23 mud.send_message(id, 'You remove the {}.'.format(tokens[0])) 24 mud.send_message(id, 'You remove the {}.'.format(tokens[0]))
25 utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"]))
24 return 26 return
25 27
28 if tokens[0] == players[id]['weapon']:
29 if tokens[0] in players[id]['inventory']:
30 players[id]['inventory'][tokens[0]].append({"expries": 0})
31 else:
32 players[id]['inventory'][tokens[0]] = [{"expries": 0}]
33 mud.send_message(id, 'You unwield the {}.'.format(tokens[0]))
34 utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"]))
35 return
36
26 mud.send_message(id, 'You are not wearing a {}.'.format(tokens[0])) 37 mud.send_message(id, 'You are not wearing a {}.'.format(tokens[0]))
27 # else: 38 # else:
28 # gear = utils.load_object_from_file('inventory/' + tokens[0] + '.json') 39 # gear = utils.load_object_from_file('inventory/' + tokens[0] + '.json')
......
1 def wield(id, players, tokens, mud):
2 if len(tokens) == 0:
3 mud.send_message(id, " %greenYou are currently wielding: %reset%bold%white{}".format(players[id]['weapon']))
4 else:
5 if tokens[0] not in players[id]["inventory"]:
6 mud.send_message(id, 'You do not have {} in your inventory.'.format(tokens[0]))
7 else:
8 gear = utils.load_object_from_file('inventory/' + tokens[0] + '.json')
9 if gear["type"] == "armor":
10 mud.send_message(id, 'That is armor and must be "equip".')
11 elif gear["type"] != "weapon":
12 mud.send_message(id, 'That cannot be wielded.')
13 else:
14 players[id]["weapon"] = tokens[0]
15 mud.send_message(id, 'You wield the {}!'.format(tokens[0]))
16 players[id]["inventory"][tokens[0]].pop()
17 if len(players[id]["inventory"][tokens[0]]) == 0:
18 del players[id]["inventory"][tokens[0]]
19
20 utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"]))
21
22
23 wield(id, players, tokens, mud)
24 del wield
...\ 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
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}], "sword": [{"expries": 0}]}, "exits": {"behind": "Room001", "dark": "Dark", "outside": "Outside"}, "title": "Tavern"}
...\ No newline at end of file ...\ No newline at end of file
......