Lots of updates for help, text wrap and players now have hp / mp and
prompt changes
Showing
18 changed files
with
146 additions
and
18 deletions
... | @@ -129,6 +129,16 @@ class CommandHandler(object): | ... | @@ -129,6 +129,16 @@ class CommandHandler(object): |
129 | self.mud.send_message(id, "Unknown exit '{}'".format(ex)) | 129 | self.mud.send_message(id, "Unknown exit '{}'".format(ex)) |
130 | return True | 130 | return True |
131 | 131 | ||
132 | |||
133 | def prompt(self): | ||
134 | if len(self.tokens) == 0: | ||
135 | self.mud.send_message(self.id, 'No prompt provided, no changes will be made.\r\nEx: prompt %hp>') | ||
136 | |||
137 | self.players[self.id]['prompt'] = self.params + ' ' | ||
138 | utils.save_object_to_file(self.players[self.id], "players/{}.json".format(self.players[self.id]["name"])) | ||
139 | |||
140 | return True | ||
141 | |||
132 | def help(self): | 142 | def help(self): |
133 | if len(self.tokens) > 0: | 143 | if len(self.tokens) > 0: |
134 | filename = 'help/' + self.tokens[0] + '.txt' | 144 | filename = 'help/' + self.tokens[0] + '.txt' |
... | @@ -152,6 +162,15 @@ class CommandHandler(object): | ... | @@ -152,6 +162,15 @@ class CommandHandler(object): |
152 | self.players[self.id]["name"], self.params)) | 162 | self.players[self.id]["name"], self.params)) |
153 | return True | 163 | return True |
154 | 164 | ||
165 | def whisper(self): | ||
166 | # go through every player in the game | ||
167 | for pid, pl in self.players.items(): | ||
168 | # if they're in the same room as the player | ||
169 | if self.players[pid]["name"] == self.tokens[0]: | ||
170 | # send them a message telling them what the player said | ||
171 | self.mud.send_message(pid, "{} whispers: {}".format( | ||
172 | self.players[self.id]["name"], ' '.join(self.tokens[1:]))) | ||
173 | return True | ||
155 | 174 | ||
156 | def quit(self): | 175 | def quit(self): |
157 | # send the player back the list of possible commands | 176 | # send the player back the list of possible commands | ... | ... |
help/aliases.txt
0 → 100644
... | @@ -7,5 +7,5 @@ Commands: | ... | @@ -7,5 +7,5 @@ Commands: |
7 | save - Saves your character | 7 | save - Saves your character |
8 | quit - Saves your character then closes the connection | 8 | quit - Saves your character then closes the connection |
9 | 9 | ||
10 | For general help: | 10 | For a full list of commands and help topics: |
11 | help index | 11 | help index |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
help/look.txt
0 → 100644
help/prompt.txt
0 → 100644
1 | Command: | ||
2 | prompt | ||
3 | |||
4 | Usage: | ||
5 | prompt <prompt> | ||
6 | |||
7 | Description: | ||
8 | The default prompt is to just display a simple > but additional | ||
9 | information can be displayed on your prompt to ease visibility of | ||
10 | specific stats. | ||
11 | |||
12 | Available Stats: | ||
13 | %hp - Displays current hitpoints | ||
14 | %mp - Displays current manapoints | ||
15 | |||
16 | Examples: | ||
17 | |||
18 | prompt hp:%hp mp:%mp> | ||
19 | |||
20 | hp:100 mp:100> | ||
21 | |||
22 | prompt (hp:%hp) => | ||
23 | |||
24 | (hp:100) => |
help/quit.txt
0 → 100644
help/save.txt
0 → 100644
help/say.txt
0 → 100644
help/whisper.txt
0 → 100644
help/who.txt
0 → 100644
... | @@ -50,7 +50,13 @@ roomloader = RoomLoader('rooms') | ... | @@ -50,7 +50,13 @@ roomloader = RoomLoader('rooms') |
50 | def prompt(pid): | 50 | def prompt(pid): |
51 | if "prompt" not in players[pid]: | 51 | if "prompt" not in players[pid]: |
52 | players[pid]["prompt"] = "> " | 52 | players[pid]["prompt"] = "> " |
53 | mud.send_message(pid, "\r\n" + players[pid]["prompt"], '') | 53 | if 'hp' not in players[pid]: |
54 | players[pid]["hp"] = 100 | ||
55 | if 'mp' not in players[pid]: | ||
56 | players[pid]["mp"] = 100 | ||
57 | |||
58 | prompt = players[pid]["prompt"].replace('%hp', str(players[pid]["hp"])).replace('%mp', str(players[pid]["mp"])) | ||
59 | mud.send_message(pid, "\r\n" + prompt, '') | ||
54 | 60 | ||
55 | # main game loop. We loop forever (i.e. until the program is terminated) | 61 | # main game loop. We loop forever (i.e. until the program is terminated) |
56 | while True: | 62 | while True: |
... | @@ -80,6 +86,8 @@ while True: | ... | @@ -80,6 +86,8 @@ while True: |
80 | "inventory": {}, | 86 | "inventory": {}, |
81 | "prompt": "> ", | 87 | "prompt": "> ", |
82 | "aliases": {}, | 88 | "aliases": {}, |
89 | "hp": 100, | ||
90 | "mp": 100, | ||
83 | } | 91 | } |
84 | with open('welcome.txt', 'r', encoding='utf-8') as f: | 92 | with open('welcome.txt', 'r', encoding='utf-8') as f: |
85 | for line in f: | 93 | for line in f: | ... | ... |
... | @@ -188,7 +188,9 @@ class MudServer(object): | ... | @@ -188,7 +188,9 @@ class MudServer(object): |
188 | """ | 188 | """ |
189 | # we make sure to put a newline on the end so the client receives the | 189 | # we make sure to put a newline on the end so the client receives the |
190 | # message on its own line | 190 | # message on its own line |
191 | self._attempt_send(to, message + line_ending) | 191 | chunks, chunk_size = len(message), 80 #len(x)/4 |
192 | lines = [ message[i:i+chunk_size] for i in range(0, chunks, chunk_size) ] | ||
193 | self._attempt_send(to, '\r\n'.join(lines) + line_ending) | ||
192 | 194 | ||
193 | def shutdown(self): | 195 | def shutdown(self): |
194 | """Closes down the server, disconnecting all clients and | 196 | """Closes down the server, disconnecting all clients and | ... | ... |
1 | {"name": "test", "room": "Tavern", "inventory": {}, "prompt": "> ", "aliases": {}} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | {"name": "test", "room": "Tavern", "inventory": {}, "prompt": "hp:%hp mp:%mp> ", "aliases": {}, "hp": 100, "mp": 100} | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
1 | 1 | ||
2 | import os | ||
3 | import json | 2 | import json |
4 | 3 | ||
5 | class RoomLoader(object): | 4 | class RoomLoader(object): |
... | @@ -9,7 +8,7 @@ class RoomLoader(object): | ... | @@ -9,7 +8,7 @@ class RoomLoader(object): |
9 | 8 | ||
10 | def _get_room_file(self, room_name): | 9 | def _get_room_file(self, room_name): |
11 | try: | 10 | try: |
12 | filename = os.path.join(self.directory, room_name) + ".txt" | 11 | filename = self.directory + '/' + room_name + ".txt" |
13 | with open(filename, 'r', encoding='utf-8') as f: | 12 | with open(filename, 'r', encoding='utf-8') as f: |
14 | return json.loads(f.read()) | 13 | return json.loads(f.read()) |
15 | except Exception as e: | 14 | except Exception as e: |
... | @@ -20,10 +19,10 @@ class RoomLoader(object): | ... | @@ -20,10 +19,10 @@ class RoomLoader(object): |
20 | return self._get_room_file(room_name)['title'] | 19 | return self._get_room_file(room_name)['title'] |
21 | 20 | ||
22 | def get_description(self, room_name): | 21 | def get_description(self, room_name): |
23 | desc = self._get_room_file(room_name)['description'] | 22 | return self._get_room_file(room_name)['description'] |
24 | chunks, chunk_size = len(desc), 80 #len(x)/4 | 23 | # chunks, chunk_size = len(desc), 80 #len(x)/4 |
25 | lines = [ desc[i:i+chunk_size] for i in range(0, chunks, chunk_size) ] | 24 | # lines = [ desc[i:i+chunk_size] for i in range(0, chunks, chunk_size) ] |
26 | return '\r\n'.join(lines) | 25 | # return '\r\n'.join(lines) |
27 | 26 | ||
28 | def get_exits(self, room_name): | 27 | def get_exits(self, room_name): |
29 | return self._get_room_file(room_name)['exits'] | 28 | return self._get_room_file(room_name)['exits'] | ... | ... |
... | @@ -4,5 +4,6 @@ | ... | @@ -4,5 +4,6 @@ |
4 | "exits": {"tavern": "Tavern"}, | 4 | "exits": {"tavern": "Tavern"}, |
5 | "look_items": { | 5 | "look_items": { |
6 | "tavern": "A roughly constructed building." | 6 | "tavern": "A roughly constructed building." |
7 | } | 7 | }, |
8 | "inventory": [] | ||
8 | } | 9 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
1 | { | 1 | { |
2 | "title": "Behind the bar", | 2 | "title": "Behind the bar", |
3 | "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.", | 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": {"tavern": "Tavern"}, | 4 | "exits": {"tavern": "Tavern"}, |
5 | "look_items": { | 5 | "look_items": { |
6 | "bar": "The bar is a long wooden plank thrown over roughly hewn barrels.", | 6 | "bar": "The bar is a long wooden plank thrown over roughly hewn barrels.", |
7 | "barrel,barrels": "The old barrels bands are thick with oxidation and stained\r\n with the purple of spilled wine.", | 7 | "barrel,barrels": "The old barrels bands are thick with oxidation and stained with the purple of spilled wine.", |
8 | "wooden,oak,plank": "An old solid oak plank that has a large number of chips\r\n and drink marks." | 8 | "wooden,oak,plank": "An old solid oak plank that has a large number of chips and drink marks." |
9 | } | 9 | }, |
10 | "inventory": [] | ||
10 | } | 11 | } | ... | ... |
... | @@ -4,8 +4,9 @@ | ... | @@ -4,8 +4,9 @@ |
4 | "exits": {"outside": "Outside", "behind bar": "Room001"}, | 4 | "exits": {"outside": "Outside", "behind bar": "Room001"}, |
5 | "look_items": { | 5 | "look_items": { |
6 | "bar": "The bar is a long wooden plank thrown over roughly hewn barrels.", | 6 | "bar": "The bar is a long wooden plank thrown over roughly hewn barrels.", |
7 | "barrel,barrels": "The old barrels bands are thick with oxidation and stained\r\n with the purple of spilled wine.", | 7 | "barrel,barrels": "The old barrels bands are thick with oxidation and stained with the purple of spilled wine.", |
8 | "wooden,oak,plank": "An old solid oak plank that has a large number of chips\r\n and drink marks.", | 8 | "wooden,oak,plank": "An old solid oak plank that has a large number of chips and drink marks.", |
9 | "fire": "The fire crackles quietly in the corner providing a small amount of light and heat." | 9 | "fire": "The fire crackles quietly in the corner providing a small amount of light and heat." |
10 | } | 10 | }, |
11 | "inventory": [] | ||
11 | } | 12 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or sign in to post a comment