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): ...@@ -5,13 +5,13 @@ def drop(id, tokens, players, mud):
5 return True 5 return True
6 room_data = utils.load_object_from_file('rooms/' + room_name + '.json') 6 room_data = utils.load_object_from_file('rooms/' + room_name + '.json')
7 if tokens[0] in players[id]['inventory']: 7 if tokens[0] in players[id]['inventory']:
8 players[id]['inventory'][tokens[0]] -= 1
9 if players[id]['inventory'][tokens[0]] <= 0:
10 del players[id]['inventory'][tokens[0]]
11 if tokens[0] in room_data['inventory']: 8 if tokens[0] in room_data['inventory']:
12 room_data['inventory'][tokens[0]] += 1 9 room_data['inventory'][tokens[0]].append(players[id]['inventory'][tokens[0]].pop())
13 else: 10 else:
14 room_data['inventory'][tokens[0]] = 1 11 room_data['inventory'][tokens[0]] = [players[id]['inventory'][tokens[0]].pop()]
12 if len(players[id]['inventory'][tokens[0]]) <= 0:
13 del players[id]['inventory'][tokens[0]]
14
15 utils.save_object_to_file(room_data, 'rooms/' + room_name + '.json') 15 utils.save_object_to_file(room_data, 'rooms/' + room_name + '.json')
16 for pid, pl in players.items(): 16 for pid, pl in players.items():
17 # if they're in the same room as the player 17 # if they're in the same room as the player
......
1 def get(id, tokens, players, mud): 1 def get(id, params, tokens, players, mud):
2 room_name = players[id]["room"] 2 room_name = players[id]["room"]
3 if len(tokens) == 0: 3 if len(tokens) == 0:
4 mud.send_message(id, 'What do you want to get?') 4 mud.send_message(id, 'What do you want to get?')
5 return True 5 return True
6
6 room_data = utils.load_object_from_file('rooms/' + room_name + '.json') 7 room_data = utils.load_object_from_file('rooms/' + room_name + '.json')
7 if tokens[0] in room_data.get('inventory'): 8
8 if tokens[0] in players[id]['inventory']: 9 container = None
9 players[id]['inventory'][tokens[0]] += 1 10 if any(x in params for x in ['from', 'out of']):
11 if 'out of' in params:
12 container = params.split('out of')[1].strip()
13 else:
14 container = params.split('from')[1].strip()
15 if room_data["inventory"].get(container) is None and players[id]["inventory"].get(container) is None:
16 mud.send_message(id, 'You do not see the container {} here.'.format(container))
17 return True
18
19 if container:
20 found = False
21 if container in players[id]["inventory"]:
22 if tokens[0] in players[id]['inventory'][container][0]['inventory']:
23 found = True
24 if tokens[0] in players[id]['inventory']:
25 print(players[id]['inventory'][container][0]['inventory'][tokens[0]])
26 players[id]['inventory'][tokens[0]].append(players[id]['inventory'][container][0]['inventory'][tokens[0]].pop())
27 else:
28 players[id]['inventory'][tokens[0]] = [players[id]['inventory'][container][0]['inventory'][tokens[0]].pop()]
29 if len(players[id]['inventory'][container][0]['inventory'][tokens[0]]) <= 0:
30 del players[id]['inventory'][container][0]['inventory'][tokens[0]]
31 elif container in room_data["inventory"]:
32 if tokens[0] in room_data['inventory'][container][0]['inventory']:
33 found = True
34 if tokens[0] in players[id]['inventory']:
35 players[id]['inventory'][tokens[0]].append(room_data['inventory'][container][0]['inventory'][tokens[0]].pop())
36 else:
37 players[id]['inventory'][tokens[0]] = [room_data['inventory'][container][0]['inventory'][tokens[0]].pop()]
38 if len(room_data['inventory'][container][0]['inventory'][tokens[0]]) <= 0:
39 del room_data['inventory'][container][0]['inventory'][tokens[0]]
40 if not found:
41 mud.send_message(id, 'You do not see a {} in the container {}.'.format(tokens[0], container))
10 else: 42 else:
11 players[id]['inventory'][tokens[0]] = 1 43 for pid, pl in players.items():
12 room_data['inventory'][tokens[0]] -= 1 44 # if they're in the same room as the player
13 if room_data['inventory'][tokens[0]] <= 0: 45 if players[pid]["room"] == players[id]["room"]:
14 del room_data['inventory'][tokens[0]] 46 # send them a message telling them what the player said
15 for pid, pl in players.items(): 47 mud.send_message(pid, "{} picked up a {} from a {}.".format(players[id]["name"], tokens[0], container))
16 # if they're in the same room as the player 48 utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"]))
17 if players[pid]["room"] == players[id]["room"]: 49 utils.save_object_to_file(room_data, 'rooms/' + room_name + '.json')
18 # send them a message telling them what the player said 50 return True
19 mud.send_message(pid, "{} picked up a {}.".format(
20 players[id]["name"], tokens[0]))
21 utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"]))
22 utils.save_object_to_file(room_data, 'rooms/' + room_name + '.json')
23 else: 51 else:
24 mud.send_message(id, 'There is no {} here to get.'.format(tokens[0])) 52 if tokens[0] in room_data.get('inventory'):
53 if tokens[0] in players[id]['inventory']:
54 players[id]['inventory'][tokens[0]].append(room_data['inventory'][tokens[0]].pop())
55 else:
56 players[id]['inventory'][tokens[0]] = [room_data['inventory'][tokens[0]].pop()]
57
58 if len(room_data['inventory'][tokens[0]]) <= 0:
59 del room_data['inventory'][tokens[0]]
60 for pid, pl in players.items():
61 # if they're in the same room as the player
62 if players[pid]["room"] == players[id]["room"]:
63 # send them a message telling them what the player said
64 mud.send_message(pid, "{} picked up a {}.".format(
65 players[id]["name"], tokens[0]))
66 utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"]))
67 utils.save_object_to_file(room_data, 'rooms/' + room_name + '.json')
68 else:
69 mud.send_message(id, 'There is no {} here to get.'.format(tokens[0]))
25 70
26 get(id, tokens, players, mud)
...\ No newline at end of file ...\ No newline at end of file
71 get(id, params.lower().strip(), tokens, players, mud)
...\ No newline at end of file ...\ No newline at end of file
......
1 def inventory(id, players, mud): 1 def inventory(id, players, mud):
2 mud.send_message(id, '\r\n-Item----------=Inventory=-----------Qty-\r\n') 2 mud.send_message(id, '\r\n-Item----------=Inventory=-----------Qty-\r\n')
3 for item, qty in players[id]['inventory'].items(): 3 for item, item_list in players[id]['inventory'].items():
4 mud.send_message(id, '{} {}'.format("%-37s" % item, qty)) 4 mud.send_message(id, '{} {}'.format("%-37s" % item, len(item_list)))
5 mud.send_message(id, '\r\n-----------------------------------------') 5 mud.send_message(id, '\r\n-----------------------------------------')
6 6
7 inventory(id, players, mud) 7 inventory(id, players, mud)
......
...@@ -52,7 +52,13 @@ def look(id, mud, players, tokens): ...@@ -52,7 +52,13 @@ def look(id, mud, players, tokens):
52 # send player a message containing the list of exits from this room 52 # send player a message containing the list of exits from this room
53 if len(room_data.get('inventory')) > 0: 53 if len(room_data.get('inventory')) > 0:
54 mud.send_message(id, "%boldItems here:%reset ", line_ending='') 54 mud.send_message(id, "%boldItems here:%reset ", line_ending='')
55 mud.send_list(id, room_data.get('inventory').keys(), "look") 55 inv_list = []
56 for name, i in room_data.get('inventory').items():
57 if len(i) > 1:
58 inv_list.append(str(len(i)) + " " + name + "s")
59 else:
60 inv_list.append(name)
61 mud.send_list(id, inv_list, "look")
56 62
57 # send player a message containing the list of players in the room 63 # send player a message containing the list of players in the room
58 for mon_name, monster in room_monsters.items(): 64 for mon_name, monster in room_monsters.items():
......
1 {
2 "title": "bag",
3 "description": "A roughly hewn sack sewn together with a cord and another cord used to draw the opening closed.",
4 "type": "container",
5 "power": 10,
6 "damage": 0,
7 "weight": 2
8 }
...\ No newline at end of file ...\ No newline at end of file
...@@ -240,12 +240,19 @@ class MudServer(object): ...@@ -240,12 +240,19 @@ class MudServer(object):
240 def send_list(self, clid, list_items, command=''): 240 def send_list(self, clid, list_items, command=''):
241 if self._clients[clid].MXP_ENABLED: 241 if self._clients[clid].MXP_ENABLED:
242 output = "" 242 output = ""
243 if command != '':
244 command = command + ' '
245 for idx, item in enumerate(list_items): 243 for idx, item in enumerate(list_items):
246 if idx > 0: 244 if idx > 0:
247 output += ", " 245 output += ", "
248 output += "<send \"{}&text;\">{}</send>".format(command, item) 246 parts = item.split(' ')
247 mod_item = item
248 if len(parts) > 1:
249 try:
250 num = int(parts[0])
251 mod_item = ' '.join(parts[1:])[:-1]
252 except ValueError:
253 pass
254
255 output += "<send \"{} {}\">{}</send>".format(command, mod_item, item)
249 self.mxp_secure(clid, output) 256 self.mxp_secure(clid, output)
250 else: 257 else:
251 self.send_message(clid, ', '.join(list_items)) 258 self.send_message(clid, ', '.join(list_items))
......
1 {"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 ...\ No newline at end of file
1 {"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 ...\ No newline at end of file
......
1 {"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 ...\ No newline at end of file
1 {"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 ...\ No newline at end of file
......
1 {"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 ...\ No newline at end of file
1 {
2 "title": "Behind the bar",
3 "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.",
4 "exits": {
5 "tavern": "Tavern"
6 },
7 "look_items": {
8 "bar": "The bar is a long wooden plank thrown over roughly hewn barrels.",
9 "barrel,barrels": "The old barrels bands are thick with oxidation and stained with the purple of spilled wine.",
10 "wooden,oak,plank": "An old solid oak plank that has a large number of chips and drink marks."
11 },
12 "inventory": {}
13 }
...\ No newline at end of file ...\ No newline at end of file
......
1 {"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 ...\ No newline at end of file
1 {"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 ...\ No newline at end of file
......