adca0e9f by Barry

Added containers to items. Still need to add put command

1 parent fb785eda
......@@ -5,13 +5,13 @@ def drop(id, tokens, players, mud):
return True
room_data = utils.load_object_from_file('rooms/' + room_name + '.json')
if tokens[0] in players[id]['inventory']:
players[id]['inventory'][tokens[0]] -= 1
if players[id]['inventory'][tokens[0]] <= 0:
del players[id]['inventory'][tokens[0]]
if tokens[0] in room_data['inventory']:
room_data['inventory'][tokens[0]] += 1
room_data['inventory'][tokens[0]].append(players[id]['inventory'][tokens[0]].pop())
else:
room_data['inventory'][tokens[0]] = 1
room_data['inventory'][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(room_data, 'rooms/' + room_name + '.json')
for pid, pl in players.items():
# if they're in the same room as the player
......
def get(id, tokens, players, mud):
def get(id, params, tokens, players, mud):
room_name = players[id]["room"]
if len(tokens) == 0:
mud.send_message(id, 'What do you want to get?')
return True
room_data = utils.load_object_from_file('rooms/' + room_name + '.json')
if tokens[0] in room_data.get('inventory'):
if tokens[0] in players[id]['inventory']:
players[id]['inventory'][tokens[0]] += 1
container = None
if any(x in params for x in ['from', 'out of']):
if 'out of' in params:
container = params.split('out of')[1].strip()
else:
container = params.split('from')[1].strip()
if room_data["inventory"].get(container) is None and players[id]["inventory"].get(container) is None:
mud.send_message(id, 'You do not see the container {} here.'.format(container))
return True
if container:
found = False
if container in players[id]["inventory"]:
if tokens[0] in players[id]['inventory'][container][0]['inventory']:
found = True
if tokens[0] in players[id]['inventory']:
print(players[id]['inventory'][container][0]['inventory'][tokens[0]])
players[id]['inventory'][tokens[0]].append(players[id]['inventory'][container][0]['inventory'][tokens[0]].pop())
else:
players[id]['inventory'][tokens[0]] = [players[id]['inventory'][container][0]['inventory'][tokens[0]].pop()]
if len(players[id]['inventory'][container][0]['inventory'][tokens[0]]) <= 0:
del players[id]['inventory'][container][0]['inventory'][tokens[0]]
elif container in room_data["inventory"]:
if tokens[0] in room_data['inventory'][container][0]['inventory']:
found = True
if tokens[0] in players[id]['inventory']:
players[id]['inventory'][tokens[0]].append(room_data['inventory'][container][0]['inventory'][tokens[0]].pop())
else:
players[id]['inventory'][tokens[0]] = [room_data['inventory'][container][0]['inventory'][tokens[0]].pop()]
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))
else:
players[id]['inventory'][tokens[0]] = 1
room_data['inventory'][tokens[0]] -= 1
if room_data['inventory'][tokens[0]] <= 0:
del room_data['inventory'][tokens[0]]
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, "{} picked up a {}.".format(
players[id]["name"], tokens[0]))
utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"]))
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, "{} picked up a {} from a {}.".format(players[id]["name"], tokens[0], container))
utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"]))
utils.save_object_to_file(room_data, 'rooms/' + room_name + '.json')
return True
else:
mud.send_message(id, 'There is no {} here to get.'.format(tokens[0]))
if tokens[0] in room_data.get('inventory'):
if tokens[0] in players[id]['inventory']:
players[id]['inventory'][tokens[0]].append(room_data['inventory'][tokens[0]].pop())
else:
players[id]['inventory'][tokens[0]] = [room_data['inventory'][tokens[0]].pop()]
if len(room_data['inventory'][tokens[0]]) <= 0:
del room_data['inventory'][tokens[0]]
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, "{} picked up a {}.".format(
players[id]["name"], tokens[0]))
utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"]))
utils.save_object_to_file(room_data, 'rooms/' + room_name + '.json')
else:
mud.send_message(id, 'There is no {} here to get.'.format(tokens[0]))
get(id, tokens, players, mud)
\ No newline at end of file
get(id, params.lower().strip(), tokens, players, mud)
\ No newline at end of file
......
def inventory(id, players, mud):
mud.send_message(id, '\r\n-Item----------=Inventory=-----------Qty-\r\n')
for item, qty in players[id]['inventory'].items():
mud.send_message(id, '{} {}'.format("%-37s" % item, qty))
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-----------------------------------------')
inventory(id, players, mud)
......
......@@ -52,7 +52,13 @@ def look(id, mud, players, tokens):
# send player a message containing the list of exits from this room
if len(room_data.get('inventory')) > 0:
mud.send_message(id, "%boldItems here:%reset ", line_ending='')
mud.send_list(id, room_data.get('inventory').keys(), "look")
inv_list = []
for name, i in room_data.get('inventory').items():
if len(i) > 1:
inv_list.append(str(len(i)) + " " + name + "s")
else:
inv_list.append(name)
mud.send_list(id, inv_list, "look")
# send player a message containing the list of players in the room
for mon_name, monster in room_monsters.items():
......
{
"title": "bag",
"description": "A roughly hewn sack sewn together with a cord and another cord used to draw the opening closed.",
"type": "container",
"power": 10,
"damage": 0,
"weight": 2
}
\ No newline at end of file
......@@ -240,12 +240,19 @@ class MudServer(object):
def send_list(self, clid, list_items, command=''):
if self._clients[clid].MXP_ENABLED:
output = ""
if command != '':
command = command + ' '
for idx, item in enumerate(list_items):
if idx > 0:
output += ", "
output += "<send \"{}&text;\">{}</send>".format(command, item)
parts = item.split(' ')
mod_item = item
if len(parts) > 1:
try:
num = int(parts[0])
mod_item = ' '.join(parts[1:])[:-1]
except ValueError:
pass
output += "<send \"{} {}\">{}</send>".format(command, mod_item, item)
self.mxp_secure(clid, output)
else:
self.send_message(clid, ', '.join(list_items))
......
{"name": "test", "password": true, "room": "Tavern", "inventory": {"candle": 1}, "prompt": "h %hp m %mp s %st> ", "aliases": {}, "hp": 74, "mp": 10.0, "sta": 10.00000000000004, "aa": "1d2", "mpr": 0.25, "star": 0.4, "maxhp": 953, "maxmp": 10, "maxsta": 10, "weapon": "sword", "sp": {"fireball": {"cost": 5, "dmg": "2d4", "desc": "A fireball blasts from your fingertips striking the target"}}, "at": {"kick": {"cost": 5, "dmg": "2d4", "desc": "You unleash a powerful kick"}}}
\ No newline at end of file
{"name": "test", "password": true, "room": "Outside", "inventory": {"candle": [{"expires": 0}, {"expires": 0}]}, "prompt": "h %hp m %mp s %st> ", "aliases": {}, "hp": 74, "mp": 10.0, "sta": 10.00000000000004, "aa": "1d2", "mpr": 0.25, "star": 0.4, "maxhp": 953, "maxmp": 10, "maxsta": 10, "weapon": "sword", "sp": {"fireball": {"cost": 5, "dmg": "2d4", "desc": "A fireball blasts from your fingertips striking the target"}}, "at": {"kick": {"cost": 5, "dmg": "2d4", "desc": "You unleash a powerful kick"}}}
\ No newline at end of file
......
{"title": "Outside the 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.", "exits": {"tavern": "Tavern"}, "look_items": {"tavern": "A roughly constructed building."}, "inventory": {"candle": 1}}
\ No newline at end of file
{"title": "Outside the 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.", "exits": {"tavern": "Tavern"}, "look_items": {"tavern": "A roughly constructed building."}, "inventory": {"candle": [{"age": 0}, {"age": 0}], "bag": [{"expires": 0, "inventory": {}}]}}
\ No newline at end of file
......
{"title": "Behind the bar", "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.", "exits": {"tavern": "Tavern"}, "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."}, "inventory": {}}
\ No newline at end of file
{
"title": "Behind the bar",
"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.",
"exits": {
"tavern": "Tavern"
},
"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."
},
"inventory": {}
}
\ 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": 13}}
\ 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
......