ce1ef4e7 by Barry

Lots of updates for help, text wrap and players now have hp / mp and

prompt changes
1 parent 27842ac9
......@@ -129,6 +129,16 @@ class CommandHandler(object):
self.mud.send_message(id, "Unknown exit '{}'".format(ex))
return True
def prompt(self):
if len(self.tokens) == 0:
self.mud.send_message(self.id, 'No prompt provided, no changes will be made.\r\nEx: prompt %hp>')
self.players[self.id]['prompt'] = self.params + ' '
utils.save_object_to_file(self.players[self.id], "players/{}.json".format(self.players[self.id]["name"]))
return True
def help(self):
if len(self.tokens) > 0:
filename = 'help/' + self.tokens[0] + '.txt'
......@@ -152,6 +162,15 @@ class CommandHandler(object):
self.players[self.id]["name"], self.params))
return True
def whisper(self):
# go through every player in the game
for pid, pl in self.players.items():
# if they're in the same room as the player
if self.players[pid]["name"] == self.tokens[0]:
# send them a message telling them what the player said
self.mud.send_message(pid, "{} whispers: {}".format(
self.players[self.id]["name"], ' '.join(self.tokens[1:])))
return True
def quit(self):
# send the player back the list of possible commands
......
Aliases are a short form of many other commands. They are
used to provide a convenient way to type a common command
easily.
Default Aliases:
n: north
s: south
e: east
w: west
u: up
d: down
l: look
': say
......@@ -7,5 +7,5 @@ Commands:
save - Saves your character
quit - Saves your character then closes the connection
For general help:
For a full list of commands and help topics:
help index
\ No newline at end of file
......
......@@ -7,5 +7,6 @@ Help Topics:
look
quit
save
whisper
say
who
......
Command:
look
Usage:
look
look <thing>
look at <thing>
Description:
The command will let you inspect an object to get additional information
such as a detailed description or in some cases a detailed view that may
show additional details.
Command:
prompt
Usage:
prompt <prompt>
Description:
The default prompt is to just display a simple > but additional
information can be displayed on your prompt to ease visibility of
specific stats.
Available Stats:
%hp - Displays current hitpoints
%mp - Displays current manapoints
Examples:
prompt hp:%hp mp:%mp>
hp:100 mp:100>
prompt (hp:%hp) =>
(hp:100) =>
Command:
quit
Usage:
quit
Description:
The command will save your character and close the connection
with the mud.
Command:
save
Usage:
save
Description:
The command will save your character information.
Command:
say
Usage:
say <message>
' <message>
Description:
The command will cause your message to be relayed to everyone in your
current room. There is an alias of a single quote which behaves in the
same way.
Command:
whisper
Usage:
whisper <person> <message>
Description:
This command will silently carry a message to any other player and
will only be visible by that one person.
Command:
who
Usage:
who
Description:
The who command displays the list of currently connected players
and total count of players.
......@@ -50,7 +50,13 @@ roomloader = RoomLoader('rooms')
def prompt(pid):
if "prompt" not in players[pid]:
players[pid]["prompt"] = "> "
mud.send_message(pid, "\r\n" + players[pid]["prompt"], '')
if 'hp' not in players[pid]:
players[pid]["hp"] = 100
if 'mp' not in players[pid]:
players[pid]["mp"] = 100
prompt = players[pid]["prompt"].replace('%hp', str(players[pid]["hp"])).replace('%mp', str(players[pid]["mp"]))
mud.send_message(pid, "\r\n" + prompt, '')
# main game loop. We loop forever (i.e. until the program is terminated)
while True:
......@@ -80,6 +86,8 @@ while True:
"inventory": {},
"prompt": "> ",
"aliases": {},
"hp": 100,
"mp": 100,
}
with open('welcome.txt', 'r', encoding='utf-8') as f:
for line in f:
......
......@@ -188,7 +188,9 @@ class MudServer(object):
"""
# we make sure to put a newline on the end so the client receives the
# message on its own line
self._attempt_send(to, message + line_ending)
chunks, chunk_size = len(message), 80 #len(x)/4
lines = [ message[i:i+chunk_size] for i in range(0, chunks, chunk_size) ]
self._attempt_send(to, '\r\n'.join(lines) + line_ending)
def shutdown(self):
"""Closes down the server, disconnecting all clients and
......
{"name": "test", "room": "Tavern", "inventory": {}, "prompt": "> ", "aliases": {}}
\ No newline at end of file
{"name": "test", "room": "Tavern", "inventory": {}, "prompt": "hp:%hp mp:%mp> ", "aliases": {}, "hp": 100, "mp": 100}
\ No newline at end of file
......
import os
import json
class RoomLoader(object):
......@@ -9,7 +8,7 @@ class RoomLoader(object):
def _get_room_file(self, room_name):
try:
filename = os.path.join(self.directory, room_name) + ".txt"
filename = self.directory + '/' + room_name + ".txt"
with open(filename, 'r', encoding='utf-8') as f:
return json.loads(f.read())
except Exception as e:
......@@ -20,10 +19,10 @@ class RoomLoader(object):
return self._get_room_file(room_name)['title']
def get_description(self, room_name):
desc = self._get_room_file(room_name)['description']
chunks, chunk_size = len(desc), 80 #len(x)/4
lines = [ desc[i:i+chunk_size] for i in range(0, chunks, chunk_size) ]
return '\r\n'.join(lines)
return self._get_room_file(room_name)['description']
# chunks, chunk_size = len(desc), 80 #len(x)/4
# lines = [ desc[i:i+chunk_size] for i in range(0, chunks, chunk_size) ]
# return '\r\n'.join(lines)
def get_exits(self, room_name):
return self._get_room_file(room_name)['exits']
......
......@@ -4,5 +4,6 @@
"exits": {"tavern": "Tavern"},
"look_items": {
"tavern": "A roughly constructed building."
}
},
"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\r\n top is a large wooden plank thrown across some 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.",
"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\r\n with the purple of spilled wine.",
"wooden,oak,plank": "An old solid oak plank that has a large number of chips\r\n and drink marks."
}
"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": []
}
......
......@@ -4,8 +4,9 @@
"exits": {"outside": "Outside", "behind bar": "Room001"},
"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\r\n with the purple of spilled wine.",
"wooden,oak,plank": "An old solid oak plank that has a large number of chips\r\n and drink marks.",
"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": []
}
\ No newline at end of file
......