29119a43 by Barry

Added equipment wearing remove and even more item bug fixes.

1 parent 8671340f
......@@ -13,7 +13,9 @@ global_aliases = {
'inv': 'inventory',
'attack': 'kill',
',': 'emote',
'social': 'emote'
'social': 'emote',
'equipment': 'equip',
'wear': 'equip'
}
......
def equip(id, players, tokens, mud):
if len(tokens) == 0:
mud.send_message(id, " %green+-Item---------------------=Equipment=------------------Loc----+", nowrap=True)
if players[id].get('equipment'):
for item, item_list in players[id]['equipment'].items():
if isinstance(item_list, list):
vals = [val for val in item_list if val]
if len(vals) > 0:
mud.send_message(id, ' %green|%reset {} {} %green|'.format("%-51s" % ', '.join(vals), item.rjust(8, ' ')))
else:
mud.send_message(id, ' %green|%reset {} {} %green|'.format("%-51s" % 'None', item.rjust(8, ' ')))
else:
mud.send_message(id, ' %green|%reset {} {} %green|'.format("%-51s" % item_list or "None", item.rjust(8, ' ')))
mud.send_message(id, " %green+--------------------------------------------------------------+", nowrap=True)
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"] == "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']))
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"]))
equip(id, players, tokens, mud)
del equip
\ No newline at end of file
......@@ -38,7 +38,7 @@ def get(id, params, tokens, players, mud):
if len(room_data['inventory'][container][0]['inventory'][tokens[0]]) <= 0:
del room_data['inventory'][container][0]['inventory'][tokens[0]]
if not found:
mud.send_message(id, 'You do not see a {} in the container {}.'.format(tokens[0], container))
mud.send_message(id, 'You do not see a {} in the {}.'.format(tokens[0], container))
else:
for pid, pl in players.items():
# if they're in the same room as the player
......
def inventory(id, players, mud):
mud.send_message(id, '\r\n-Item----------=Inventory=-----------Qty-\r\n')
mud.send_message(id, " %green+-Item---------------------=Inventory=--------------------Qty--+", nowrap=True)
for item, item_list in players[id]['inventory'].items():
mud.send_message(id, '{} {}'.format("%-37s" % item, len(item_list)))
mud.send_message(id, '\r\n-----------------------------------------')
mud.send_message(id, ' %green|%reset {} {} %green|'.format("%-55s" % item, str(len(item_list)).center(4, ' ')))
mud.send_message(id, " %green+--------------------------------------------------------------+", nowrap=True)
inventory(id, players, mud)
del inventory
\ No newline at end of file
......
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
\ No newline at end of file
......@@ -2,10 +2,24 @@
"name": null,
"password": null,
"room": null,
"equipment": {
"finger": [null, null],
"hand": [null, null],
"arm": [null, null],
"leg": [null, null],
"foot": [null, null],
"head": null,
"neck": null,
"back": null,
"body": null,
"waist": null
},
"inventory": {
"bag": [{
"expires": 0,
"inventory": {}
"inventory": {
"shirt": [{"expires": 0}]
}
}]
},
"prompt": "hp %hp mp %mp> ",
......
{
"title": "shirt",
"description": "A roughly woven bag made of simple hemp that is rough and not very warm.",
"type": "armor",
"loc": "body",
"armor": 1,
"weight": 10
}
\ No newline at end of file
{
"title": "sword",
"description": "a simple hardened steel sword with a slightly sharp edge.",
"type": "light",
"type": "weapon",
"power": 10,
"damage": "2d4",
"weight": 10
......
{"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
{"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
......