d1d1ff4e by barry

Added put command and bug fixes for look.

1 parent 28639cf7
......@@ -44,6 +44,7 @@ def look(id, mud, players, tokens):
if len(items) > 0:
mud.send_message(id, 'You look in your {} and see:\r\n'.format(subject))
inv_list = []
print(items)
for name, i in items.items():
if len(i) > 1:
inv_list.append(str(len(i)) + " " + name + "s")
......
def put(id, tokens, players, mud):
if len(tokens) == 0:
mud.send_message(id, 'What do you want to put and where do you want to put it?')
return True
subject = tokens[0]
if 'in' == tokens[1]:
del tokens[1]
dest = tokens[1]
room_name = players[id]["room"]
room_data = utils.load_object_from_file('rooms/' + room_name + '.json')
if subject in players[id]['inventory']:
if dest in players[id]['inventory'] or dest in room_data['inventory']:
if dest in room_data['inventory']:
if subject in room_data['inventory'][dest][0]["inventory"].get(subject):
room_data['inventory'][dest][0]["inventory"][subject] = [players[id]['inventory'][subject].pop()]
else:
room_data['inventory'][dest][0]["inventory"][subject].append(players[id]['inventory'][subject].pop())
elif dest in players[id]['inventory']:
if subject in players[id]['inventory'][dest][0]["inventory"].get(subject):
players[id]['inventory'][dest][0]["inventory"][subject] = [players[id]['inventory'][subject].pop()]
else:
players[id]['inventory'][dest][0]["inventory"][subject].append(players[id]['inventory'][subject].pop())
if len(players[id]['inventory'][tokens[0]]) <= 0:
del players[id]['inventory'][tokens[0]]
utils.save_object_to_file(room_data, 'rooms/' + room_name + '.json')
for pid, pl in players.items():
# if they're in the same room as the player
if players[pid]["room"] == players[id]["room"]:
# send them a message telling them what the player said
mud.send_message(pid, "{} put a {} in a {}.".format(players[id]["name"], subject, dest))
utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"]))
else:
mud.send_message(id, 'You cannot put {} in {} since it is not here.'.format(subject, dest))
else:
mud.send_message(id, 'You do not have {} in your inventory.'.format(subject))
put(id, tokens, players, mud)
del put
\ No newline at end of file
{"at": {"kick": {"desc": "You unleash a powerful kick", "dmg": "2d4", "cost": 5}}, "sp": {"fireball": {"desc": "A fireball blasts from your fingertips striking the target", "dmg": "2d4", "cost": 5}}, "mp": 10.0, "prompt": "h %hp m %mp s %st> ", "password": true, "mpr": 0.25, "maxmp": 10, "hp": 74, "maxhp": 953, "star": 0.4, "room": "Outside", "sta": 10.00000000000004, "inventory": {"bag": [{"inventory": {"candle": [{"expires": 0}, {"expires": 0}]}, "expires": 0}], "candle": [{"expires": 0}, {"expires": 0}]}, "maxsta": 10, "aa": "1d2", "weapon": "sword", "aliases": {}, "name": "test"}
\ No newline at end of file
{"mpr": 0.25, "aa": "1d2", "password": true, "sp": {"fireball": {"desc": "A fireball blasts from your fingertips striking the target", "cost": 5, "dmg": "2d4"}}, "maxhp": 953, "maxsta": 10, "inventory": {"bag": [{"expires": 0, "inventory": {"candle": [{"expires": 0}, {"expires": 0}]}}], "candle": [{"age": 0}, {"age": 0}]}, "aliases": {}, "prompt": "h %hp m %mp s %st> ", "name": "test", "hp": 74, "mp": 10.0, "maxmp": 10, "weapon": "sword", "sta": 10.00000000000004, "room": "Room001", "at": {"kick": {"desc": "You unleash a powerful kick", "cost": 5, "dmg": "2d4"}}, "star": 0.4}
\ No newline at end of file
......
{"inventory": {"candle": [{"age": 0}, {"age": 0}]}, "look_items": {"tavern": "A roughly constructed building."}, "title": "Outside the Tavern", "exits": {"tavern": "Tavern"}, "description": "You are standing outside of a simple tavern made of pressed clay and shale roof. The door becons you to come in and have a drink."}
\ No newline at end of file
{"look_items": {"tavern": "A roughly constructed building."}, "description": "You are standing outside of a simple tavern made of pressed clay and shale roof. The door becons you to come in and have a drink.", "inventory": {}, "exits": {"tavern": "Tavern"}, "title": "Outside the Tavern"}
\ No newline at end of file
......
{"description": "The back of the bar gives a full view of the tavern. The bar top is a large wooden plank thrown across some barrels.", "look_items": {"bar": "The bar is a long wooden plank thrown over roughly hewn barrels.", "barrel,barrels": "The old barrels bands are thick with oxidation and stained with the purple of spilled wine.", "wooden,oak,plank": "An old solid oak plank that has a large number of chips and drink marks."}, "title": "Behind the bar", "exits": {"tavern": "Tavern"}, "inventory": {}}
\ 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."}, "description": "The back of the bar gives a full view of the tavern. The bar top is a large wooden plank thrown across some barrels.", "inventory": {"candle": [{"age": 0}]}, "exits": {"tavern": "Tavern"}, "title": "Behind the bar"}
\ No newline at end of file
......
{"cricket": {"active": [{"sta": 10, "target": "", "maxhp": 15, "maxmp": 10, "maxsta": 10, "hp": 15, "mp": 10, "action": "attack"}], "max": 1}}
\ No newline at end of file
{"cricket": {"max": 1, "active": [{"hp": 15, "mp": 10, "maxmp": 10, "maxhp": 15, "sta": 10, "maxsta": 10, "target": "", "action": "attack"}]}}
\ No newline at end of file
......
{"title": "Tavern", "description": "You're in a cozy tavern warmed by an open fire.", "exits": {"outside": "Outside", "behind": "Room001", "dark": "Dark"}, "look_items": {"bar": "The bar is a long wooden plank thrown over roughly hewn barrels.", "barrel,barrels": "The old barrels bands are thick with oxidation and stained with the purple of spilled wine.", "wooden,oak,plank": "An old solid oak plank that has a large number of chips and drink marks.", "fire": "The fire crackles quietly in the corner providing a small amount of light and heat."}, "inventory": {"candle": [{"age": 0}, {"age": 0}, {"age": 0}, {"age": 0}, {"age": 0}, {"age": 0}, {"age": 0}]}}
\ 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}, {"age": 0}, {"age": 0}, {"age": 0}]}, "exits": {"behind": "Room001", "dark": "Dark", "outside": "Outside"}, "title": "Tavern"}
\ No newline at end of file
......
{"cricket": {"active": [{"sta": 10, "target": "", "maxhp": 20, "maxmp": 10, "maxsta": 10, "hp": 20, "mp": 10, "action": "attack"}, {"sta": 10, "target": "", "maxhp": 23, "maxmp": 10, "maxsta": 10, "hp": 23, "mp": 10, "action": "attack"}], "max": 2}}
\ No newline at end of file
{"cricket": {"max": 2, "active": [{"hp": 20, "mp": 10, "maxmp": 10, "maxhp": 20, "sta": 10, "maxsta": 10, "target": "", "action": "attack"}, {"hp": 23, "mp": 10, "maxmp": 10, "maxhp": 23, "sta": 10, "maxsta": 10, "target": "", "action": "attack"}]}}
\ No newline at end of file
......