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):
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]))
mud.send_message(id, 'That is a weapon and must be "wield".')
elif gear["type"] != "armor":
mud.send_message(id, 'That cannot be worn.'.format(tokens[0]))
mud.send_message(id, 'That cannot be worn.')
else:
players[id]["equipment"][gear['loc']] = tokens[0]
mud.send_message(id, 'You wear the {} on your {}.'.format(tokens[0], gear['loc']))
......
......@@ -13,6 +13,7 @@ def remove(id, players, tokens, mud):
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
......@@ -21,8 +22,18 @@ def remove(id, players, tokens, mud):
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')
......
def wield(id, players, tokens, mud):
if len(tokens) == 0:
mud.send_message(id, " %greenYou are currently wielding: %reset%bold%white{}".format(players[id]['weapon']))
else:
if tokens[0] not in players[id]["inventory"]:
mud.send_message(id, 'You do not have {} in your inventory.'.format(tokens[0]))
else:
gear = utils.load_object_from_file('inventory/' + tokens[0] + '.json')
if gear["type"] == "armor":
mud.send_message(id, 'That is armor and must be "equip".')
elif gear["type"] != "weapon":
mud.send_message(id, 'That cannot be wielded.')
else:
players[id]["weapon"] = tokens[0]
mud.send_message(id, 'You wield the {}!'.format(tokens[0]))
players[id]["inventory"][tokens[0]].pop()
if len(players[id]["inventory"][tokens[0]]) == 0:
del players[id]["inventory"][tokens[0]]
utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"]))
wield(id, players, tokens, mud)
del wield
\ No newline at end of file
{"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
{"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
......