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):
locals()['next_command'] = None
# try:
if cmd in utils.load_object_from_file('rooms/' + players[id]["room"] + '.txt').get('exits'):
if cmd in utils.load_object_from_file('rooms/' + players[id]["room"] + '.json').get('exits'):
params = cmd + " " + params.lower().strip()
cmd = "go"
if cmd == '':
......
......@@ -3,7 +3,7 @@ def drop(id, tokens, players, mud):
if len(tokens) == 0:
mud.send_message(id, 'What do you want to drop?')
return True
room_data = utils.load_object_from_file('rooms/' + room_name + '.txt')
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:
......@@ -12,7 +12,7 @@ def drop(id, tokens, players, mud):
room_data['inventory'][tokens[0]] += 1
else:
room_data['inventory'][tokens[0]] = 1
utils.save_object_to_file(room_data, 'rooms/' + room_name + '.txt')
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"]:
......
......@@ -3,7 +3,7 @@ def get(id, tokens, players, mud):
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 + '.txt')
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
......
......@@ -5,7 +5,7 @@ def go(id, params, players, mud, tokens, command):
else:
params = params.strip()
room_data = utils.load_object_from_file('rooms/' + players[id]["room"] + '.txt')
room_data = utils.load_object_from_file('rooms/' + players[id]["room"] + '.json')
exits = room_data['exits']
# if the specified exit is found in the room's exits list
......@@ -27,7 +27,7 @@ def go(id, params, players, mud, tokens, command):
mud.send_message(id, "An invisible force prevents you from going in that direction.")
return None
else:
new_room = utils.load_object_from_file('rooms/' + exits[params] + '.txt')
new_room = utils.load_object_from_file('rooms/' + exits[params] + '.json')
if not new_room:
mud.send_message(id, "An invisible force prevents you from going in that direction.")
return None
......
def look(id, mud, players, tokens):
room_name = players[id]["room"]
room_data = utils.load_object_from_file('rooms/' + room_name + '.txt')
room_data = utils.load_object_from_file('rooms/' + room_name + '.json')
mud.send_message(id, "")
if len(tokens) > 0 and tokens[0] == 'at':
del tokens[0]
......@@ -13,13 +13,13 @@ def look(id, mud, players, tokens):
if subject in item:
mud.send_message(id, items[item])
return True
if subject in ['inventory']:
mud.send_message(id, 'You the area see a {}:'.format(subject))
mud.send_message(id, room_data.get('description'))
if subject in room_data['inventory']:
item = utils.load_object_from_file('inventory/' + subject + '.json')
mud.send_message(id, 'You see {}'.format(item.get('description')))
return True
if subject in players[id]['inventory']:
mud.send_message(id, 'You check your inventory and see a {}:'.format(subject))
mud.send_message(id, room_data.get('description'))
item = utils.load_object_from_file('inventory/' + subject + '.json')
mud.send_message(id, 'You check your inventory and see {}'.format(item.get('description')))
return True
mud.send_message(id, "That doesn't seem to be here.")
......@@ -34,16 +34,16 @@ def look(id, mud, players, tokens):
playershere.append(players[pid]["name"])
# send player a message containing the list of players in the room
mud.send_message(id, "Players here: {}".format(
", ".join(playershere)))
mud.send_message(id, "Players here: {}".format(", ".join(playershere)))
# send player a message containing the list of exits from this room
mud.send_message(id, "Exits are: {}".format(
", ".join(room_data.get('exits'))))
mud.send_message(id, "Exits are: {}".format(", ".join(room_data.get('exits'))))
# send player a message containing the list of exits from this room
mud.send_message(id, "Items here: {}".format(
", ".join(room_data.get('inventory').keys())))
mud.send_message(id, "Items here: {}".format(", ".join(room_data.get('inventory').keys())))
# send player a message containing the list of players in the room
room_monsters = utils.load_object_from_file('rooms/' + room_name + '_monsters.json')
mud.send_message(id, "Mobs here: {}".format( ", ".join(room_monsters.keys())))
look(id, mud, players, tokens)
\ No newline at end of file
......
......@@ -12,5 +12,6 @@
"sta": 10,
"aa": "1d2",
"mpr": 0.25,
"star": 0.4
"star": 0.4,
"weapon": null
}
\ No newline at end of file
......
{
"title": "sword",
"description": "a simple hardened steel sword with a slightly sharp edge.",
"type": "light",
"power": 10,
"damage": "2d4",
"weight": 10
}
\ No newline at end of file
......@@ -66,7 +66,10 @@ while True:
# pause for 1/5 of a second on each loop, so that we don't constantly
# use 100% CPU time
time.sleep(0.001)
tick += 0.001
if 'esp' in sys.platform:
tick += 0.001
else:
tick += 0.0005
if spawn >= 30:
spawn = 0
try:
......@@ -168,7 +171,7 @@ while True:
# send the new player the description of their current room
mud.send_message(id, utils.load_object_from_file('rooms/' + players[id]["room"] + '.txt')['description'])
mud.send_message(id, utils.load_object_from_file('rooms/' + players[id]["room"] + '.json')['description'])
else:
from commandhandler import CommandHandler
......
......@@ -21,7 +21,7 @@ def run_mobs(players, mud):
att = get_att(attack['dmg'])
mud.send_message(pid, "%s for %d" % (attack['desc'], att,))
bank -= attack['cost']
return att, bank
return att, bank
for pid, player in players.items():
if not player['name']:
......@@ -44,6 +44,17 @@ def run_mobs(players, mud):
sta += monster_template['star']
active_monster['sta'] = sta
if active_monster['action'] == "attack" and active_monster['target'] == player['name']:
if player["weapon"]:
weapon = utils.load_object_from_file('inventory/{}.json'.format(player['weapon']))
if weapon:
att = get_att(weapon['damage'])
mud.send_message(pid, "Your %s strikes the %s for %d" % (weapon['title'], mon_name, att,))
else:
att = get_att(player['aa'])
else:
att = get_att(player['aa'])
mud.send_message(pid, "You hit the %s for %d" % (mon_name, att,))
hp -= att
if hp == 0:
DEAD = 1
att = get_att(monster_template['aa'])
......
{"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
{"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
{"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
{"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
......