bb158dfa by Barry

Renamed a bunch of txt files to json.

Fixed a lot of issues and added player autoattack and weapon attacks by
player.
1 parent d62558de
...@@ -33,7 +33,7 @@ class CommandHandler(object): ...@@ -33,7 +33,7 @@ class CommandHandler(object):
33 33
34 locals()['next_command'] = None 34 locals()['next_command'] = None
35 # try: 35 # try:
36 if cmd in utils.load_object_from_file('rooms/' + players[id]["room"] + '.txt').get('exits'): 36 if cmd in utils.load_object_from_file('rooms/' + players[id]["room"] + '.json').get('exits'):
37 params = cmd + " " + params.lower().strip() 37 params = cmd + " " + params.lower().strip()
38 cmd = "go" 38 cmd = "go"
39 if cmd == '': 39 if cmd == '':
......
...@@ -3,7 +3,7 @@ def drop(id, tokens, players, mud): ...@@ -3,7 +3,7 @@ def drop(id, tokens, players, mud):
3 if len(tokens) == 0: 3 if len(tokens) == 0:
4 mud.send_message(id, 'What do you want to drop?') 4 mud.send_message(id, 'What do you want to drop?')
5 return True 5 return True
6 room_data = utils.load_object_from_file('rooms/' + room_name + '.txt') 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 8 players[id]['inventory'][tokens[0]] -= 1
9 if players[id]['inventory'][tokens[0]] <= 0: 9 if players[id]['inventory'][tokens[0]] <= 0:
...@@ -12,7 +12,7 @@ def drop(id, tokens, players, mud): ...@@ -12,7 +12,7 @@ def drop(id, tokens, players, mud):
12 room_data['inventory'][tokens[0]] += 1 12 room_data['inventory'][tokens[0]] += 1
13 else: 13 else:
14 room_data['inventory'][tokens[0]] = 1 14 room_data['inventory'][tokens[0]] = 1
15 utils.save_object_to_file(room_data, 'rooms/' + room_name + '.txt') 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
18 if players[pid]["room"] == players[id]["room"]: 18 if players[pid]["room"] == players[id]["room"]:
......
...@@ -3,7 +3,7 @@ def get(id, tokens, players, mud): ...@@ -3,7 +3,7 @@ def get(id, tokens, players, mud):
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 room_data = utils.load_object_from_file('rooms/' + room_name + '.txt') 6 room_data = utils.load_object_from_file('rooms/' + room_name + '.json')
7 if tokens[0] in room_data.get('inventory'): 7 if tokens[0] in room_data.get('inventory'):
8 if tokens[0] in players[id]['inventory']: 8 if tokens[0] in players[id]['inventory']:
9 players[id]['inventory'][tokens[0]] += 1 9 players[id]['inventory'][tokens[0]] += 1
......
...@@ -5,7 +5,7 @@ def go(id, params, players, mud, tokens, command): ...@@ -5,7 +5,7 @@ def go(id, params, players, mud, tokens, command):
5 else: 5 else:
6 params = params.strip() 6 params = params.strip()
7 7
8 room_data = utils.load_object_from_file('rooms/' + players[id]["room"] + '.txt') 8 room_data = utils.load_object_from_file('rooms/' + players[id]["room"] + '.json')
9 exits = room_data['exits'] 9 exits = room_data['exits']
10 # if the specified exit is found in the room's exits list 10 # if the specified exit is found in the room's exits list
11 11
...@@ -27,7 +27,7 @@ def go(id, params, players, mud, tokens, command): ...@@ -27,7 +27,7 @@ def go(id, params, players, mud, tokens, command):
27 mud.send_message(id, "An invisible force prevents you from going in that direction.") 27 mud.send_message(id, "An invisible force prevents you from going in that direction.")
28 return None 28 return None
29 else: 29 else:
30 new_room = utils.load_object_from_file('rooms/' + exits[params] + '.txt') 30 new_room = utils.load_object_from_file('rooms/' + exits[params] + '.json')
31 if not new_room: 31 if not new_room:
32 mud.send_message(id, "An invisible force prevents you from going in that direction.") 32 mud.send_message(id, "An invisible force prevents you from going in that direction.")
33 return None 33 return None
......
1 def look(id, mud, players, tokens): 1 def look(id, mud, players, tokens):
2 room_name = players[id]["room"] 2 room_name = players[id]["room"]
3 room_data = utils.load_object_from_file('rooms/' + room_name + '.txt') 3 room_data = utils.load_object_from_file('rooms/' + room_name + '.json')
4 mud.send_message(id, "") 4 mud.send_message(id, "")
5 if len(tokens) > 0 and tokens[0] == 'at': 5 if len(tokens) > 0 and tokens[0] == 'at':
6 del tokens[0] 6 del tokens[0]
...@@ -13,13 +13,13 @@ def look(id, mud, players, tokens): ...@@ -13,13 +13,13 @@ def look(id, mud, players, tokens):
13 if subject in item: 13 if subject in item:
14 mud.send_message(id, items[item]) 14 mud.send_message(id, items[item])
15 return True 15 return True
16 if subject in ['inventory']: 16 if subject in room_data['inventory']:
17 mud.send_message(id, 'You the area see a {}:'.format(subject)) 17 item = utils.load_object_from_file('inventory/' + subject + '.json')
18 mud.send_message(id, room_data.get('description')) 18 mud.send_message(id, 'You see {}'.format(item.get('description')))
19 return True 19 return True
20 if subject in players[id]['inventory']: 20 if subject in players[id]['inventory']:
21 mud.send_message(id, 'You check your inventory and see a {}:'.format(subject)) 21 item = utils.load_object_from_file('inventory/' + subject + '.json')
22 mud.send_message(id, room_data.get('description')) 22 mud.send_message(id, 'You check your inventory and see {}'.format(item.get('description')))
23 return True 23 return True
24 mud.send_message(id, "That doesn't seem to be here.") 24 mud.send_message(id, "That doesn't seem to be here.")
25 25
...@@ -34,16 +34,16 @@ def look(id, mud, players, tokens): ...@@ -34,16 +34,16 @@ def look(id, mud, players, tokens):
34 playershere.append(players[pid]["name"]) 34 playershere.append(players[pid]["name"])
35 35
36 # send player a message containing the list of players in the room 36 # send player a message containing the list of players in the room
37 mud.send_message(id, "Players here: {}".format( 37 mud.send_message(id, "Players here: {}".format(", ".join(playershere)))
38 ", ".join(playershere)))
39 38
40 # send player a message containing the list of exits from this room 39 # send player a message containing the list of exits from this room
41 mud.send_message(id, "Exits are: {}".format( 40 mud.send_message(id, "Exits are: {}".format(", ".join(room_data.get('exits'))))
42 ", ".join(room_data.get('exits'))))
43 41
44 # send player a message containing the list of exits from this room 42 # send player a message containing the list of exits from this room
45 mud.send_message(id, "Items here: {}".format( 43 mud.send_message(id, "Items here: {}".format(", ".join(room_data.get('inventory').keys())))
46 ", ".join(room_data.get('inventory').keys())))
47 44
45 # send player a message containing the list of players in the room
46 room_monsters = utils.load_object_from_file('rooms/' + room_name + '_monsters.json')
47 mud.send_message(id, "Mobs here: {}".format( ", ".join(room_monsters.keys())))
48 48
49 look(id, mud, players, tokens) 49 look(id, mud, players, tokens)
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -12,5 +12,6 @@ ...@@ -12,5 +12,6 @@
12 "sta": 10, 12 "sta": 10,
13 "aa": "1d2", 13 "aa": "1d2",
14 "mpr": 0.25, 14 "mpr": 0.25,
15 "star": 0.4 15 "star": 0.4,
16 "weapon": null
16 } 17 }
...\ No newline at end of file ...\ No newline at end of file
......
1 {
2 "title": "sword",
3 "description": "a simple hardened steel sword with a slightly sharp edge.",
4 "type": "light",
5 "power": 10,
6 "damage": "2d4",
7 "weight": 10
8 }
...\ No newline at end of file ...\ No newline at end of file
...@@ -66,7 +66,10 @@ while True: ...@@ -66,7 +66,10 @@ while True:
66 # pause for 1/5 of a second on each loop, so that we don't constantly 66 # pause for 1/5 of a second on each loop, so that we don't constantly
67 # use 100% CPU time 67 # use 100% CPU time
68 time.sleep(0.001) 68 time.sleep(0.001)
69 tick += 0.001 69 if 'esp' in sys.platform:
70 tick += 0.001
71 else:
72 tick += 0.0005
70 if spawn >= 30: 73 if spawn >= 30:
71 spawn = 0 74 spawn = 0
72 try: 75 try:
...@@ -168,7 +171,7 @@ while True: ...@@ -168,7 +171,7 @@ while True:
168 171
169 # send the new player the description of their current room 172 # send the new player the description of their current room
170 173
171 mud.send_message(id, utils.load_object_from_file('rooms/' + players[id]["room"] + '.txt')['description']) 174 mud.send_message(id, utils.load_object_from_file('rooms/' + players[id]["room"] + '.json')['description'])
172 175
173 else: 176 else:
174 from commandhandler import CommandHandler 177 from commandhandler import CommandHandler
......
...@@ -21,7 +21,7 @@ def run_mobs(players, mud): ...@@ -21,7 +21,7 @@ def run_mobs(players, mud):
21 att = get_att(attack['dmg']) 21 att = get_att(attack['dmg'])
22 mud.send_message(pid, "%s for %d" % (attack['desc'], att,)) 22 mud.send_message(pid, "%s for %d" % (attack['desc'], att,))
23 bank -= attack['cost'] 23 bank -= attack['cost']
24 return att, bank 24 return att, bank
25 25
26 for pid, player in players.items(): 26 for pid, player in players.items():
27 if not player['name']: 27 if not player['name']:
...@@ -44,6 +44,17 @@ def run_mobs(players, mud): ...@@ -44,6 +44,17 @@ def run_mobs(players, mud):
44 sta += monster_template['star'] 44 sta += monster_template['star']
45 active_monster['sta'] = sta 45 active_monster['sta'] = sta
46 if active_monster['action'] == "attack" and active_monster['target'] == player['name']: 46 if active_monster['action'] == "attack" and active_monster['target'] == player['name']:
47 if player["weapon"]:
48 weapon = utils.load_object_from_file('inventory/{}.json'.format(player['weapon']))
49 if weapon:
50 att = get_att(weapon['damage'])
51 mud.send_message(pid, "Your %s strikes the %s for %d" % (weapon['title'], mon_name, att,))
52 else:
53 att = get_att(player['aa'])
54 else:
55 att = get_att(player['aa'])
56 mud.send_message(pid, "You hit the %s for %d" % (mon_name, att,))
57 hp -= att
47 if hp == 0: 58 if hp == 0:
48 DEAD = 1 59 DEAD = 1
49 att = get_att(monster_template['aa']) 60 att = get_att(monster_template['aa'])
......
1 {"name": "test", "room": "Tavern", "inventory": {"candle": 1}, "prompt": "%hp> ", "aliases": {}, "hp": 953, "mp": 100, "sta": 10, "aa": "1d2", "mpr": 0.25, "star": 0.4, "maxhp": 953, "maxmp": 100, "maxsta": 10}
...\ No newline at end of file ...\ No newline at end of file
1 {"name": "test", "room": "Tavern", "inventory": {"candle": 1}, "prompt": "%hp> ", "aliases": {}, "hp": 596, "mp": 100, "sta": 10, "aa": "1d2", "mpr": 0.25, "star": 0.4, "maxhp": 953, "maxmp": 100, "maxsta": 10, "weapon": "sword"}
...\ No newline at end of file ...\ No newline at end of file
......
1 {}
...\ No newline at end of file ...\ No newline at end of file
1 {"cricket": {"max": 1, "active": [{"hp": 100, "mp": 4.25, "sta": 3.1500000000000314, "maxhp": 100, "maxmp": 10, "maxsta": 10, "action": "attack", "target": "test"}]}}
...\ No newline at end of file ...\ No newline at end of file
1 {"cricket": {"max": 1, "active": [{"hp": 100, "mp": 0.25, "sta": 2.7500000000000715, "maxhp": 100, "maxmp": 10, "maxsta": 10, "action": "attack", "target": "test"}]}}
...\ No newline at end of file ...\ No newline at end of file
......