Big change to move all the commands to the command handler so it could be
pushed to the flash.
Showing
30 changed files
with
720 additions
and
751 deletions
... | @@ -18,10 +18,681 @@ global_aliases = { | ... | @@ -18,10 +18,681 @@ global_aliases = { |
18 | 'equipment': 'equip', | 18 | 'equipment': 'equip', |
19 | 'wear': 'equip', | 19 | 'wear': 'equip', |
20 | 'eq': 'equip', | 20 | 'eq': 'equip', |
21 | 'goto': 'go' | 21 | 'goto': 'go', |
22 | 'sc': 'score' | ||
22 | } | 23 | } |
23 | 24 | ||
24 | 25 | ||
26 | class Commands(object): | ||
27 | |||
28 | |||
29 | def actions(self, id, params, players, mud, tokens, command): | ||
30 | mud.send_message(id, '\r\n-Action----------=Actions=-----------Cost-\r\n') | ||
31 | for name, action in players[id]['at'].items(): | ||
32 | mud.send_message(id, '{} {}'.format("%-37s" % name, action['cost'])) | ||
33 | mud.send_message(id, '\r\n------------------------------------------\r\n') | ||
34 | mud.send_message(id, 'For more detail on a specific action use "help [action]"') | ||
35 | |||
36 | |||
37 | # for now spells can only be cast on the thing you are fighting since I don't have a good lexer to pull | ||
38 | # out targets. This also means that spells are offensive only since you cant cast on 'me' | ||
39 | # TODO: Add proper parsing so you can do: cast fireball on turkey or even better, cast fireball on the first turkey | ||
40 | def cast(self, id, params, players, mud, tokens, command): | ||
41 | if params == '': | ||
42 | params = command.strip() | ||
43 | else: | ||
44 | params = params.strip() | ||
45 | if len(params) == 0: | ||
46 | mud.send_message(id, 'What spell do you want to cast?') | ||
47 | return True | ||
48 | spell = players[id]['sp'].get(params) | ||
49 | if not spell: | ||
50 | mud.send_message(id, 'You do not appear to know how to cast %s.' % (params,)) | ||
51 | return True | ||
52 | mp = players[id]['mp'] | ||
53 | if mp > 0 and mp > spell['cost']: | ||
54 | room_monsters = utils.load_object_from_file('rooms/{}_monsters.json'.format(players[id]['room'])) | ||
55 | if not room_monsters: | ||
56 | mud.send_message(id, 'There is nothing here to cast that spell on.') | ||
57 | for mon_name, monster in room_monsters.items(): | ||
58 | monster_template = utils.load_object_from_file('mobs/{}.json'.format(mon_name)) | ||
59 | if not monster_template: | ||
60 | continue | ||
61 | fighting = False | ||
62 | for active_monster_idx, active_monster in enumerate(monster['active']): | ||
63 | if active_monster['action'] == "attack" and active_monster['target'] == players[id]['name']: | ||
64 | fighting = True | ||
65 | att, mp = utils.calc_att(mud, id, [], mp, spell) | ||
66 | |||
67 | players[id]['mp'] = mp | ||
68 | active_monster['hp'] -= att | ||
69 | # don't let them off without saving cheating sons of bees | ||
70 | utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"])) | ||
71 | room_monsters[mon_name]['active'][active_monster_idx] = active_monster | ||
72 | if not fighting: | ||
73 | mud.send_message(id, 'You are not currently in combat') | ||
74 | return True | ||
75 | |||
76 | utils.save_object_to_file(room_monsters, 'rooms/{}_monsters.json'.format(players[id]['room'])) | ||
77 | else: | ||
78 | mud.send_message(id, 'You do not have enough mana to cast that spell.') | ||
79 | |||
80 | def drop(self, id, params, players, mud, tokens, command): | ||
81 | room_name = players[id]["room"] | ||
82 | if len(tokens) == 0: | ||
83 | mud.send_message(id, 'What do you want to drop?') | ||
84 | return True | ||
85 | room_data = utils.load_object_from_file('rooms/' + room_name + '.json') | ||
86 | if tokens[0] in players[id]['inventory']: | ||
87 | if tokens[0] in room_data['inventory']: | ||
88 | room_data['inventory'][tokens[0]].append(players[id]['inventory'][tokens[0]].pop()) | ||
89 | else: | ||
90 | room_data['inventory'][tokens[0]] = [players[id]['inventory'][tokens[0]].pop()] | ||
91 | if len(players[id]['inventory'][tokens[0]]) <= 0: | ||
92 | del players[id]['inventory'][tokens[0]] | ||
93 | |||
94 | utils.save_object_to_file(room_data, 'rooms/' + room_name + '.json') | ||
95 | for pid, pl in players.items(): | ||
96 | # if they're in the same room as the player | ||
97 | if players[pid]["room"] == players[id]["room"]: | ||
98 | # send them a message telling them what the player said | ||
99 | mud.send_message(pid, "{} dropped a {}.".format( | ||
100 | players[id]["name"], tokens[0])) | ||
101 | utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"])) | ||
102 | else: | ||
103 | mud.send_message(id, 'You do not have {} in your inventory.'.format(tokens[0])) | ||
104 | |||
105 | |||
106 | def emote(self, id, params, players, mud, tokens, command): | ||
107 | # go through every player in the game | ||
108 | for pid, pl in players.items(): | ||
109 | # if they're in the same room as the player | ||
110 | if players[pid]["room"] == players[id]["room"]: | ||
111 | # send them a message telling them what the player said | ||
112 | mud.send_message(pid, "{} {}".format(players[id]["name"], params)) | ||
113 | |||
114 | |||
115 | def equip(self, id, params, players, mud, tokens, command): | ||
116 | if len(tokens) == 0: | ||
117 | mud.send_message(id, " %green+-Item---------------------=Equipment=------------------Loc----+", nowrap=True) | ||
118 | if players[id].get('equipment'): | ||
119 | for item, item_list in players[id]['equipment'].items(): | ||
120 | if isinstance(item_list, list): | ||
121 | vals = [val for val in item_list if val] | ||
122 | if len(vals) > 0: | ||
123 | mud.send_message(id, ' %green|%reset {} {} %green|'.format("%-51s" % ', '.join(vals), '{0: <8}'.format(item))) | ||
124 | else: | ||
125 | mud.send_message(id, ' %green|%reset {} {} %green|'.format("%-51s" % 'None', '{0: <8}'.format(item))) | ||
126 | else: | ||
127 | mud.send_message(id, ' %green|%reset {} {} %green|'.format("%-51s" % item_list or "None", '{0: <8}'.format(item))) | ||
128 | mud.send_message(id, ' %green|%reset {} {} %green|'.format("%-51s" % players[id]['weapon'] or "None", '{0: <8}'.format('weapon'))) | ||
129 | mud.send_message(id, " %green+--------------------------------------------------------------+", nowrap=True) | ||
130 | else: | ||
131 | if tokens[0] not in players[id]["inventory"]: | ||
132 | mud.send_message(id, 'You do not have {} in your inventory.'.format(tokens[0])) | ||
133 | else: | ||
134 | gear = utils.load_object_from_file('inventory/' + tokens[0] + '.json') | ||
135 | if gear["type"] == "weapon": | ||
136 | mud.send_message(id, 'That is a weapon and must be "wield".') | ||
137 | elif gear["type"] != "armor": | ||
138 | mud.send_message(id, 'That cannot be worn.') | ||
139 | else: | ||
140 | players[id]["equipment"][gear['loc']] = tokens[0] | ||
141 | mud.send_message(id, 'You wear the {} on your {}.'.format(tokens[0], gear['loc'])) | ||
142 | players[id]["inventory"][tokens[0]].pop() | ||
143 | if len(players[id]["inventory"][tokens[0]]) == 0: | ||
144 | del players[id]["inventory"][tokens[0]] | ||
145 | |||
146 | utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"])) | ||
147 | |||
148 | def get(self, id, params, players, mud, tokens, command): | ||
149 | room_name = players[id]["room"] | ||
150 | if len(tokens) == 0: | ||
151 | mud.send_message(id, 'What do you want to get?') | ||
152 | return True | ||
153 | |||
154 | room_data = utils.load_object_from_file('rooms/' + room_name + '.json') | ||
155 | |||
156 | container = None | ||
157 | if any(x in params for x in ['from', 'out of']): | ||
158 | if 'out of' in params: | ||
159 | container = params.split('out of')[1].strip() | ||
160 | else: | ||
161 | container = params.split('from')[1].strip() | ||
162 | if room_data["inventory"].get(container) is None and players[id]["inventory"].get(container) is None: | ||
163 | mud.send_message(id, 'You do not see the container {} here.'.format(container)) | ||
164 | return True | ||
165 | |||
166 | if container: | ||
167 | found = False | ||
168 | if container in players[id]["inventory"]: | ||
169 | if tokens[0] in players[id]['inventory'][container][0]['inventory']: | ||
170 | found = True | ||
171 | if tokens[0] in players[id]['inventory']: | ||
172 | print(players[id]['inventory'][container][0]['inventory'][tokens[0]]) | ||
173 | players[id]['inventory'][tokens[0]].append(players[id]['inventory'][container][0]['inventory'][tokens[0]].pop()) | ||
174 | else: | ||
175 | players[id]['inventory'][tokens[0]] = [players[id]['inventory'][container][0]['inventory'][tokens[0]].pop()] | ||
176 | if len(players[id]['inventory'][container][0]['inventory'][tokens[0]]) <= 0: | ||
177 | del players[id]['inventory'][container][0]['inventory'][tokens[0]] | ||
178 | elif container in room_data["inventory"]: | ||
179 | if tokens[0] in room_data['inventory'][container][0]['inventory']: | ||
180 | found = True | ||
181 | if tokens[0] in players[id]['inventory']: | ||
182 | players[id]['inventory'][tokens[0]].append(room_data['inventory'][container][0]['inventory'][tokens[0]].pop()) | ||
183 | else: | ||
184 | players[id]['inventory'][tokens[0]] = [room_data['inventory'][container][0]['inventory'][tokens[0]].pop()] | ||
185 | if len(room_data['inventory'][container][0]['inventory'][tokens[0]]) <= 0: | ||
186 | del room_data['inventory'][container][0]['inventory'][tokens[0]] | ||
187 | if not found: | ||
188 | mud.send_message(id, 'You do not see a {} in the {}.'.format(tokens[0], container)) | ||
189 | else: | ||
190 | for pid, pl in players.items(): | ||
191 | # if they're in the same room as the player | ||
192 | if players[pid]["room"] == players[id]["room"]: | ||
193 | # send them a message telling them what the player said | ||
194 | mud.send_message(pid, "{} picked up a {} from a {}.".format(players[id]["name"], tokens[0], container)) | ||
195 | utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"])) | ||
196 | utils.save_object_to_file(room_data, 'rooms/' + room_name + '.json') | ||
197 | return True | ||
198 | else: | ||
199 | if tokens[0] in room_data.get('inventory'): | ||
200 | if tokens[0] in players[id]['inventory']: | ||
201 | players[id]['inventory'][tokens[0]].append(room_data['inventory'][tokens[0]].pop()) | ||
202 | else: | ||
203 | players[id]['inventory'][tokens[0]] = [room_data['inventory'][tokens[0]].pop()] | ||
204 | |||
205 | if len(room_data['inventory'][tokens[0]]) <= 0: | ||
206 | del room_data['inventory'][tokens[0]] | ||
207 | for pid, pl in players.items(): | ||
208 | # if they're in the same room as the player | ||
209 | if players[pid]["room"] == players[id]["room"]: | ||
210 | # send them a message telling them what the player said | ||
211 | mud.send_message(pid, "{} picked up a {}.".format( | ||
212 | players[id]["name"], tokens[0])) | ||
213 | utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"])) | ||
214 | utils.save_object_to_file(room_data, 'rooms/' + room_name + '.json') | ||
215 | else: | ||
216 | mud.send_message(id, 'There is no {} here to get.'.format(tokens[0])) | ||
217 | |||
218 | |||
219 | def go(self, id, params, players, mud, tokens, command): | ||
220 | # store the exit name | ||
221 | if params == '': | ||
222 | params = command.strip().lower() | ||
223 | else: | ||
224 | params = params.strip().lower() | ||
225 | |||
226 | room_data = utils.load_object_from_file('rooms/' + players[id]["room"] + '.json') | ||
227 | |||
228 | # if the specified exit is found in the room's exits list | ||
229 | exits = room_data['exits'] | ||
230 | |||
231 | if params in exits: | ||
232 | # go through all the players in the game | ||
233 | for pid, pl in players.items(): | ||
234 | # if player is in the same room and isn't the player | ||
235 | # sending the command | ||
236 | if players[pid]["room"] == players[id]["room"] \ | ||
237 | and pid != id: | ||
238 | # send them a message telling them that the player | ||
239 | # left the room | ||
240 | mud.send_message(pid, "{} left via exit '{}'".format( | ||
241 | players[id]["name"], params)) | ||
242 | |||
243 | # update the player's current room to the one the exit leads to | ||
244 | |||
245 | if exits[params] == None: | ||
246 | mud.send_message(id, "An invisible force prevents you from going in that direction.") | ||
247 | return None | ||
248 | else: | ||
249 | new_room = utils.load_object_from_file('rooms/' + exits[params][0] + '.json') | ||
250 | if not new_room: | ||
251 | mud.send_message(id, "An invisible force prevents you from going in that direction.") | ||
252 | return None | ||
253 | else: | ||
254 | players[id]["room"] = exits[params][0] | ||
255 | utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"])) | ||
256 | mud.send_message(id, "You arrive at '{}'".format(new_room['title'])) | ||
257 | |||
258 | # go through all the players in the game | ||
259 | for pid, pl in players.items(): | ||
260 | # if player is in the same (new) room and isn't the player | ||
261 | # sending the command | ||
262 | if players[pid]["room"] == players[id]["room"] \ | ||
263 | and pid != id: | ||
264 | # send them a message telling them that the player | ||
265 | # entered the room | ||
266 | mud.send_message(pid, | ||
267 | "{} arrived via exit '{}'".format( | ||
268 | players[id]["name"], params)) | ||
269 | |||
270 | # send the player a message telling them where they are now | ||
271 | tokens = [] | ||
272 | return self.look(id, params, players, mud, tokens, command) | ||
273 | # the specified exit wasn't found in the current room | ||
274 | else: | ||
275 | # send back an 'unknown exit' message | ||
276 | mud.send_message(id, "Unknown exit '{}'".format(params)) | ||
277 | |||
278 | |||
279 | def help(self, id, params, players, mud, tokens, command): | ||
280 | if len(tokens) > 0: | ||
281 | filename = 'help/' + tokens[0] + '.txt' | ||
282 | else: | ||
283 | filename = 'help/help.txt' | ||
284 | try: | ||
285 | with open(filename, 'r', encoding='utf-8') as f: | ||
286 | for line in f: | ||
287 | mud.send_message(id, line, '\r') | ||
288 | mud.send_message(id, '') | ||
289 | except: | ||
290 | mud.send_message(id, 'No help topics available for \"{}\". A list\r\n of all commands is available at: help index'.format(tokens[0])) | ||
291 | |||
292 | |||
293 | def inventory(self, id, params, players, mud, tokens, command): | ||
294 | mud.send_message(id, " %green+-Item---------------------=Inventory=--------------------Qty--+", nowrap=True) | ||
295 | for item, item_list in players[id]['inventory'].items(): | ||
296 | mud.send_message(id, ' %green|%reset {} {:^4} %green|'.format("%-55s" % item, str(len(item_list)))) | ||
297 | mud.send_message(id, " %green+--------------------------------------------------------------+", nowrap=True) | ||
298 | |||
299 | def kill(self, id, params, players, mud, tokens, command): | ||
300 | if len(params) == 0: | ||
301 | mud.send_message(id, 'What did you want to attack?') | ||
302 | return True | ||
303 | room_monsters = utils.load_object_from_file('rooms/{}_monsters.json'.format(players[id]['room'])) | ||
304 | for mon_name, monster in room_monsters.items(): | ||
305 | if mon_name in params.lower(): | ||
306 | if len(monster['active']) > 0: | ||
307 | if monster['active'][0]['target'] == players[id]['name']: | ||
308 | mud.send_message(id, 'You are already engaged in combat with that target.') | ||
309 | return True | ||
310 | else: | ||
311 | room_monsters[mon_name]['active'][0]['target'] = players[id]['name'] | ||
312 | mud.send_message(id, 'You attack the {}.'.format(mon_name), color=['red', 'bold']) | ||
313 | utils.save_object_to_file(room_monsters, 'rooms/{}_monsters.json'.format(players[id]['room'])) | ||
314 | return True | ||
315 | if params[0] in 'aeiou': | ||
316 | mud.send_message(id, 'You do not see an {} here.'.format(params)) | ||
317 | else: | ||
318 | mud.send_message(id, 'You do not see a {} here.'.format(params)) | ||
319 | |||
320 | |||
321 | def look(self, id, params, players, mud, tokens, command): | ||
322 | room_name = players[id]["room"] | ||
323 | room_data = utils.load_object_from_file('rooms/' + room_name + '.json') | ||
324 | room_monsters = utils.load_object_from_file('rooms/' + room_name + '_monsters.json') | ||
325 | mud.send_message(id, "") | ||
326 | if len(tokens) > 0 and tokens[0] == 'at': | ||
327 | del tokens[0] | ||
328 | container = False | ||
329 | if len(tokens) > 0 and tokens[0] == 'in': | ||
330 | del tokens[0] | ||
331 | container = True | ||
332 | if len(tokens) == 0: | ||
333 | exits = {} | ||
334 | for exit_name, exit in room_data.get('exits').items(): | ||
335 | exits[exit_name] = exit[1] | ||
336 | print(room_data) | ||
337 | # clid, name, zone, terrain, description, exits, coords | ||
338 | mud.send_room(id, room_data.get('num'), room_data.get('title'), room_data.get('zone'), | ||
339 | 'City', '', exits, room_data.get('coords')) | ||
340 | mud.send_message(id, room_data.get('title'), color=['bold', 'green']) | ||
341 | mud.send_message(id, room_data.get('description'), line_ending='\r\n\r\n', color='green') | ||
342 | else: | ||
343 | subject = tokens[0] | ||
344 | items = room_data.get('look_items') | ||
345 | for item in items: | ||
346 | if subject in item: | ||
347 | mud.send_message(id, items[item]) | ||
348 | return True | ||
349 | if subject in room_data['inventory']: | ||
350 | if container and room_data["inventory"][subject][0].get("inventory") is not None: | ||
351 | items = room_data["inventory"][subject][0]["inventory"] | ||
352 | if len(items) > 0: | ||
353 | mud.send_message(id, 'You look in the {} and see:\r\n'.format(subject)) | ||
354 | inv_list = [] | ||
355 | for name, i in items.items(): | ||
356 | if len(i) > 1: | ||
357 | inv_list.append(str(len(i)) + " " + name + "s") | ||
358 | else: | ||
359 | inv_list.append(name) | ||
360 | mud.send_list(id, inv_list, "look") | ||
361 | |||
362 | else: | ||
363 | mud.send_message(id, 'You look in the {} and see nothing.'.format(subject)) | ||
364 | else: | ||
365 | item = utils.load_object_from_file('inventory/' + subject + '.json') | ||
366 | mud.send_message(id, 'You see {}'.format(item.get('description'))) | ||
367 | return True | ||
368 | if subject in players[id]['inventory']: | ||
369 | if container and players[id]["inventory"][subject][0].get("inventory") is not None: | ||
370 | items = players[id]["inventory"][subject][0]["inventory"] | ||
371 | if len(items) > 0: | ||
372 | mud.send_message(id, 'You look in your {} and see:\r\n'.format(subject)) | ||
373 | inv_list = [] | ||
374 | print(items) | ||
375 | for name, i in items.items(): | ||
376 | if len(i) > 1: | ||
377 | inv_list.append(str(len(i)) + " " + name + "s") | ||
378 | else: | ||
379 | inv_list.append(name) | ||
380 | mud.send_list(id, inv_list, "look") | ||
381 | else: | ||
382 | mud.send_message(id, 'You look in your {} and see nothing.'.format(subject)) | ||
383 | else: | ||
384 | item = utils.load_object_from_file('inventory/' + subject + '.json') | ||
385 | mud.send_message(id, 'You check your inventory and see {}'.format(item.get('description'))) | ||
386 | return True | ||
387 | if subject in room_monsters: | ||
388 | if len(room_monsters[subject]['active']) > 0: | ||
389 | monster_template = utils.load_object_from_file('mobs/{}.json'.format(subject)) | ||
390 | if monster_template: | ||
391 | mud.send_message(id, 'You see {}'.format(monster_template.get('desc').lower())) | ||
392 | return True | ||
393 | mud.send_message(id, "That doesn't seem to be here.") | ||
394 | return | ||
395 | |||
396 | playershere = [] | ||
397 | # go through every player in the game | ||
398 | for pid, pl in players.items(): | ||
399 | # if they're in the same room as the player | ||
400 | if players[pid]["room"] == players[id]["room"]: | ||
401 | # ... and they have a name to be shown | ||
402 | if players[pid]["name"] is not None and players[id]["name"] != players[pid]["name"]: | ||
403 | # add their name to the list | ||
404 | playershere.append(players[pid]["name"]) | ||
405 | |||
406 | # send player a message containing the list of players in the room | ||
407 | if len(playershere) > 0: | ||
408 | mud.send_message(id, "%boldPlayers here:%reset {}".format(", ".join(playershere))) | ||
409 | |||
410 | mud.send_message(id, "%boldObvious Exits:%reset ", line_ending='') | ||
411 | mud.send_list(id, room_data.get('exits'), "go") | ||
412 | |||
413 | # send player a message containing the list of exits from this room | ||
414 | if len(room_data.get('inventory')) > 0: | ||
415 | mud.send_message(id, "%boldItems here:%reset ", line_ending='') | ||
416 | inv_list = [] | ||
417 | for name, i in room_data.get('inventory').items(): | ||
418 | if len(i) > 1: | ||
419 | inv_list.append(str(len(i)) + " " + name + "s") | ||
420 | else: | ||
421 | inv_list.append(name) | ||
422 | mud.send_list(id, inv_list, "look") | ||
423 | |||
424 | # send player a message containing the list of players in the room | ||
425 | for mon_name, monster in room_monsters.items(): | ||
426 | count = len(monster['active']) | ||
427 | if count > 1: | ||
428 | mud.send_message(id, "{} {} are here.".format(count, mon_name)) | ||
429 | elif count > 0: | ||
430 | mud.send_message(id, "a {} is here.".format(mon_name)) | ||
431 | |||
432 | |||
433 | |||
434 | # for now actions can only be cast on the thing you are fighting since I don't have a good lexer to pull | ||
435 | # out targets. This also means that actions are offensive only since you cant cast on 'me' | ||
436 | # TODO: Add proper parsing so you can do: cast fireball on turkey or even better, cast fireball on the first turkey | ||
437 | def perform(self, id, params, players, mud, tokens, command): | ||
438 | if params == '': | ||
439 | params = command.strip() | ||
440 | else: | ||
441 | params = params.strip() | ||
442 | if len(params) == 0: | ||
443 | mud.send_message(id, 'What action do you want to perform?') | ||
444 | return True | ||
445 | action = players[id]['at'].get(params) | ||
446 | if not action: | ||
447 | mud.send_message(id, 'You do not appear to know the action %s.' % (params,)) | ||
448 | return True | ||
449 | sta = players[id]['sta'] | ||
450 | if sta > 0 and sta > action['cost']: | ||
451 | room_monsters = utils.load_object_from_file('rooms/{}_monsters.json'.format(players[id]['room'])) | ||
452 | if not room_monsters: | ||
453 | mud.send_message(id, 'There is nothing here to perform that action on.') | ||
454 | for mon_name, monster in room_monsters.items(): | ||
455 | monster_template = utils.load_object_from_file('mobs/{}.json'.format(mon_name)) | ||
456 | if not monster_template: | ||
457 | continue | ||
458 | fighting = False | ||
459 | for active_monster_idx, active_monster in enumerate(monster['active']): | ||
460 | if active_monster['action'] == "attack" and active_monster['target'] == players[id]['name']: | ||
461 | fighting = True | ||
462 | att, sta = utils.calc_att(mud, id, [], sta, action) | ||
463 | |||
464 | players[id]['sta'] = sta | ||
465 | active_monster['hp'] -= att | ||
466 | # don't let them off without saving cheating sons of bees | ||
467 | utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"])) | ||
468 | room_monsters[mon_name]['active'][active_monster_idx] = active_monster | ||
469 | if not fighting: | ||
470 | mud.send_message(id, 'You are not currently in combat') | ||
471 | return True | ||
472 | |||
473 | utils.save_object_to_file(room_monsters, 'rooms/{}_monsters.json'.format(players[id]['room'])) | ||
474 | else: | ||
475 | mud.send_message(id, 'You do not have enough stamina to perform that action.') | ||
476 | |||
477 | |||
478 | def prompt(self, id, params, players, mud, tokens, command): | ||
479 | if len(tokens) == 0: | ||
480 | mud.send_message(id, 'No prompt provided, no changes will be made.\r\nEx: prompt %hp>') | ||
481 | |||
482 | players[id]['prompt'] = params + ' ' | ||
483 | utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"])) | ||
484 | |||
485 | def put(self, id, params, players, mud, tokens, command): | ||
486 | if len(tokens) == 0: | ||
487 | mud.send_message(id, 'What do you want to put and where do you want to put it?') | ||
488 | return True | ||
489 | subject = tokens[0] | ||
490 | if 'in' == tokens[1]: | ||
491 | del tokens[1] | ||
492 | dest = tokens[1] | ||
493 | |||
494 | room_name = players[id]["room"] | ||
495 | room_data = utils.load_object_from_file('rooms/' + room_name + '.json') | ||
496 | |||
497 | if subject in players[id]['inventory']: | ||
498 | if dest in players[id]['inventory'] or dest in room_data['inventory']: | ||
499 | |||
500 | if dest in room_data['inventory']: | ||
501 | if len(room_data['inventory'][dest][0]["inventory"]) == 0 and not room_data['inventory'][dest][0]["inventory"].get(subject): | ||
502 | room_data['inventory'][dest][0]["inventory"][subject] = [players[id]['inventory'][subject].pop()] | ||
503 | else: | ||
504 | room_data['inventory'][dest][0]["inventory"][subject].append(players[id]['inventory'][subject].pop()) | ||
505 | elif dest in players[id]['inventory']: | ||
506 | #print(players[id]['inventory'][dest][0]["inventory"]) | ||
507 | print(players[id]['inventory'][dest][0]["inventory"].get(subject)) | ||
508 | if len(players[id]['inventory'][dest][0]["inventory"]) == 0 and not players[id]['inventory'][dest][0]["inventory"].get(subject): | ||
509 | players[id]['inventory'][dest][0]["inventory"][subject] = [players[id]['inventory'][subject].pop()] | ||
510 | else: | ||
511 | players[id]['inventory'][dest][0]["inventory"][subject].append(players[id]['inventory'][subject].pop()) | ||
512 | if len(players[id]['inventory'][tokens[0]]) <= 0: | ||
513 | del players[id]['inventory'][tokens[0]] | ||
514 | |||
515 | utils.save_object_to_file(room_data, 'rooms/' + room_name + '.json') | ||
516 | for pid, pl in players.items(): | ||
517 | # if they're in the same room as the player | ||
518 | if players[pid]["room"] == players[id]["room"]: | ||
519 | # send them a message telling them what the player said | ||
520 | mud.send_message(pid, "{} put a {} in a {}.".format(players[id]["name"], subject, dest)) | ||
521 | utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"])) | ||
522 | else: | ||
523 | mud.send_message(id, 'You cannot put {} in {} since it is not here.'.format(subject, dest)) | ||
524 | else: | ||
525 | mud.send_message(id, 'You do not have {} in your inventory.'.format(subject)) | ||
526 | |||
527 | |||
528 | def quit(self, id, params, players, mud, tokens, command): | ||
529 | # send the player back the list of possible commands | ||
530 | mud.send_message(id, "Saving...") | ||
531 | utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"])) | ||
532 | mud.disconnect_player(id) | ||
533 | |||
534 | |||
535 | def remove(self, id, params, players, mud, tokens, command): | ||
536 | if len(tokens) == 0: | ||
537 | mud.send_message(id, 'What do you want to stop wearing?') | ||
538 | else: | ||
539 | for item, item_list in players[id]['equipment'].items(): | ||
540 | if isinstance(item_list, list): | ||
541 | for idx, li in enumerate(item_list): | ||
542 | print(li) | ||
543 | if li == tokens[0]: | ||
544 | item_list[idx] = None | ||
545 | if tokens[0] in players[id]['inventory']: | ||
546 | players[id]['inventory'][tokens[0]].append({"expries": 0}) | ||
547 | else: | ||
548 | players[id]['inventory'][tokens[0]] = [{"expries": 0}] | ||
549 | mud.send_message(id, 'You remove the {}.'.format(tokens[0])) | ||
550 | utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"])) | ||
551 | return | ||
552 | elif item_list == tokens[0]: | ||
553 | players[id]['equipment'][item] = None | ||
554 | if tokens[0] in players[id]['inventory']: | ||
555 | players[id]['inventory'][tokens[0]].append({"expries": 0}) | ||
556 | else: | ||
557 | players[id]['inventory'][tokens[0]] = [{"expries": 0}] | ||
558 | mud.send_message(id, 'You remove the {}.'.format(tokens[0])) | ||
559 | utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"])) | ||
560 | return | ||
561 | |||
562 | if tokens[0] == players[id]['weapon']: | ||
563 | if tokens[0] in players[id]['inventory']: | ||
564 | players[id]['inventory'][tokens[0]].append({"expries": 0}) | ||
565 | else: | ||
566 | players[id]['inventory'][tokens[0]] = [{"expries": 0}] | ||
567 | mud.send_message(id, 'You unwield the {}.'.format(tokens[0])) | ||
568 | utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"])) | ||
569 | return | ||
570 | |||
571 | mud.send_message(id, 'You are not wearing a {}.'.format(tokens[0])) | ||
572 | # else: | ||
573 | # gear = utils.load_object_from_file('inventory/' + tokens[0] + '.json') | ||
574 | # if gear["type"] == "weapon": | ||
575 | # mud.send_message(id, 'That is a weapon and must be "wield".'.format(tokens[0])) | ||
576 | # elif gear["type"] != "armor": | ||
577 | # mud.send_message(id, 'That cannot be worn.'.format(tokens[0])) | ||
578 | # else: | ||
579 | # players[id]["equipment"][gear['loc']] = tokens[0] | ||
580 | # mud.send_message(id, 'You wear the {} on your {}.'.format(tokens[0], gear['loc'])) | ||
581 | # if len(players[id]["inventory"][tokens[0]]) == 0: | ||
582 | # del players[id]["inventory"][tokens[0]] | ||
583 | # else: | ||
584 | # players[id]["inventory"][tokens[0]].pop() | ||
585 | # utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"])) | ||
586 | |||
587 | |||
588 | def save(self, id, params, players, mud, tokens, command): | ||
589 | # send the player back the list of possible commands | ||
590 | mud.send_message(id, "Saving...") | ||
591 | utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"])) | ||
592 | mud.send_message(id, "Save complete") | ||
593 | return True | ||
594 | |||
595 | |||
596 | def say(self, id, params, players, mud, tokens, command): | ||
597 | # go through every player in the game | ||
598 | for pid, pl in players.items(): | ||
599 | # if they're in the same room as the player | ||
600 | if players[pid]["room"] == players[id]["room"]: | ||
601 | # send them a message telling them what the player said | ||
602 | mud.send_message(pid, "{} says: {}".format( | ||
603 | players[id]["name"], params)) | ||
604 | |||
605 | |||
606 | def score(self, id, params, players, mud, tokens, command): | ||
607 | from math import floor | ||
608 | |||
609 | mud.send_message(id, " %green+----------------------------=Score=---------------------------+", nowrap=True) | ||
610 | hp = "{:^12}".format(str(floor(players[id]['hp'])) + str(floor(players[id]['maxhp']))) | ||
611 | mp = "{:^12}".format(str(floor(players[id]['mp'])) + str(floor(players[id]['maxmp']))) | ||
612 | sta = "{:^12}".format(str(floor(players[id]['sta'])) + str(floor(players[id]['maxsta']))) | ||
613 | # hp = str("%d/%s" % (floor(players[id]['hp']), '{:^12}'.format(floor(players[id]['maxhp'])))) | ||
614 | # mp = str("%d/%s" % (floor(players[id]['mp']), '{:^12}'.format(floor(players[id]['maxmp'])))) | ||
615 | # sta = str("%d/%s" % (floor(players[id]['sta']), '{:^12}'.format(floor(players[id]['maxsta'])))) | ||
616 | |||
617 | mud.send_message(id, " %%green|%%reset%%bold%%white%s%%reset%%green|" % ('{:^62}'.format(players[id]["name"]),), nowrap=True) | ||
618 | mud.send_message(id, " %green+--------------------------------------------------------------+", nowrap=True) | ||
619 | mud.send_message(id, " %%green|%%reset %%cyanHP:%%reset %%white[%s]%%reset %%green|%%reset %%cyanMP:%%reset %%white[%s]%%reset %%green|%%reset %%cyanST:%%reset %%white[%s]%%reset %%green|%%reset" % (hp, mp, sta), nowrap=True) | ||
620 | |||
621 | |||
622 | # output = """ | ||
623 | # -------------------------------------------- | ||
624 | # HP: {hp} Max HP: {maxhp} | ||
625 | # MP: {mp} Max MP: {maxmp} | ||
626 | # Sta: {sta} Max Sta: {maxsta} | ||
627 | # Experience: {exp} | ||
628 | # Skills:""".format(hp=floor(players[id]['hp']), | ||
629 | # mp=floor(players[id]['mp']), | ||
630 | # maxhp=floor(players[id]['maxhp']), | ||
631 | # maxmp=floor(players[id]['maxmp']), | ||
632 | # sta=floor(players[id]['sta']), | ||
633 | # maxsta=floor(players[id]['maxsta']), | ||
634 | # exp=0) | ||
635 | # mud.send_message(id, output) | ||
636 | |||
637 | mud.send_message(id, " %green+---------------------------=Skills=---------------------------+", nowrap=True) | ||
638 | skills = ["skillasdfasdfasdfasdf", "skill 2 sdfg sdfg", "Skill 3 asdf ewrewwr"] | ||
639 | for skill in skills: | ||
640 | mud.send_message(id, " %green|%reset {0: <61}%green|%reset".format(skill), nowrap=True) | ||
641 | |||
642 | mud.send_message(id, " %green+--------------------------------------------------------------+", nowrap=True) | ||
643 | |||
644 | |||
645 | def spells(self, id, params, players, mud, tokens, command): | ||
646 | mud.send_message(id, '\r\n-Spell-----------=Spells=-----------Cost-\r\n') | ||
647 | for name, spell in players[id]['sp'].items(): | ||
648 | mud.send_message(id, '{} {}'.format("%-37s" % name, spell['cost'])) | ||
649 | mud.send_message(id, '\r\n-----------------------------------------\r\n') | ||
650 | mud.send_message(id, 'For more detail on a specific spell use "help <spell>"') | ||
651 | |||
652 | |||
653 | def whisper(self, id, params, players, mud, tokens, command): | ||
654 | # go through every player in the game | ||
655 | for pid, pl in players.items(): | ||
656 | # if they're in the same room as the player | ||
657 | if players[pid]["name"] == tokens[0]: | ||
658 | # send them a message telling them what the player said | ||
659 | mud.send_message(pid, "{} whispers: {}".format( | ||
660 | players[id]["name"], ' '.join(tokens[1:]))) | ||
661 | |||
662 | |||
663 | def who(self, id, params, players, mud, tokens, command): | ||
664 | mud.send_message(id, "") | ||
665 | mud.send_message(id, "-------- {} Players Currently Online --------".format(len(players))) | ||
666 | for pid, player in players.items(): | ||
667 | if player["name"] is None: | ||
668 | continue | ||
669 | mud.send_message(id, " " + player["name"]) | ||
670 | mud.send_message(id, "---------------------------------------------".format(len(players))) | ||
671 | mud.send_message(id, "") | ||
672 | |||
673 | |||
674 | def wield(self, id, params, players, mud, tokens, command): | ||
675 | if len(tokens) == 0: | ||
676 | mud.send_message(id, " %greenYou are currently wielding: %reset%bold%white{}".format(players[id]['weapon'])) | ||
677 | else: | ||
678 | if tokens[0] not in players[id]["inventory"]: | ||
679 | mud.send_message(id, 'You do not have {} in your inventory.'.format(tokens[0])) | ||
680 | else: | ||
681 | gear = utils.load_object_from_file('inventory/' + tokens[0] + '.json') | ||
682 | if gear["type"] == "armor": | ||
683 | mud.send_message(id, 'That is armor and must be "equip".') | ||
684 | elif gear["type"] != "weapon": | ||
685 | mud.send_message(id, 'That cannot be wielded.') | ||
686 | else: | ||
687 | players[id]["weapon"] = tokens[0] | ||
688 | mud.send_message(id, 'You wield the {}!'.format(tokens[0])) | ||
689 | players[id]["inventory"][tokens[0]].pop() | ||
690 | if len(players[id]["inventory"][tokens[0]]) == 0: | ||
691 | del players[id]["inventory"][tokens[0]] | ||
692 | |||
693 | utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"])) | ||
694 | |||
695 | |||
25 | class CommandHandler(object): | 696 | class CommandHandler(object): |
26 | 697 | ||
27 | def parse(self, id, cmd, params, mud, players): | 698 | def parse(self, id, cmd, params, mud, players): |
... | @@ -38,9 +709,7 @@ class CommandHandler(object): | ... | @@ -38,9 +709,7 @@ class CommandHandler(object): |
38 | token = token.strip() | 709 | token = token.strip() |
39 | if len(token) > 0: | 710 | if len(token) > 0: |
40 | tokens.append(token) | 711 | tokens.append(token) |
41 | locals()['tokens'] = tokens | ||
42 | 712 | ||
43 | locals()['next_command'] = None | ||
44 | try: | 713 | try: |
45 | if cmd in (exit.lower() for exit in utils.load_object_from_file('rooms/' + players[id]["room"] + '.json').get('exits')): | 714 | if cmd in (exit.lower() for exit in utils.load_object_from_file('rooms/' + players[id]["room"] + '.json').get('exits')): |
46 | params = cmd + " " + params.lower().strip() | 715 | params = cmd + " " + params.lower().strip() |
... | @@ -53,25 +722,32 @@ class CommandHandler(object): | ... | @@ -53,25 +722,32 @@ class CommandHandler(object): |
53 | cmd = "perform" | 722 | cmd = "perform" |
54 | if cmd == '': | 723 | if cmd == '': |
55 | return True | 724 | return True |
56 | command = cmd | 725 | commands = Commands() |
57 | ldict = locals() | 726 | command_method = getattr(commands, cmd, None) |
58 | with open('commands/{}.txt'.format(cmd), 'r', encoding='utf-8') as f: | 727 | if callable(command_method): |
59 | command_text = f.read() | 728 | params = params.lower().strip() |
60 | exec(command_text, globals(), ldict) | 729 | return command_method(id, params, players, mud, tokens, cmd) |
61 | del command_text | 730 | # else: |
62 | if ldict['next_command'] is not None: | 731 | # ldict = locals() |
63 | locals()['tokens'] = [] | 732 | |
64 | tokens = [] | 733 | # with open('commands/{}.txt'.format(cmd), 'r', encoding='utf-8') as f: |
65 | with open('commands/{}.txt'.format(ldict['next_command']), 'r', encoding='utf-8') as f: | 734 | # command_text = f.read() |
66 | exec(f.read()) | 735 | # exec(command_text, globals(), ldict) |
67 | del ldict | 736 | # del command_text |
68 | return True | 737 | # if ldict['next_command'] is not None: |
738 | # locals()['tokens'] = [] | ||
739 | # tokens = [] | ||
740 | # with open('commands/{}.txt'.format(ldict['next_command']), 'r', encoding='utf-8') as f: | ||
741 | # exec(f.read()) | ||
742 | # del ldict | ||
743 | #raise Exception("Missing command: {}".format(cmd)) | ||
69 | except Exception as e: | 744 | except Exception as e: |
70 | print('Command handler exception:') | 745 | print('Command handler exception:') |
71 | if 'esp' not in sys.platform: | 746 | if 'esp' not in sys.platform: |
72 | import traceback | 747 | import traceback |
73 | traceback.print_exc() | 748 | traceback.print_exc() |
74 | else: | 749 | else: |
75 | print(e) | 750 | print(repr(e)) |
751 | #raise | ||
76 | mud.send_message(id, "Unknown command '{}'".format(cmd)) | 752 | mud.send_message(id, "Unknown command '{}'".format(cmd)) |
77 | return False | 753 | return False | ... | ... |
commands/actions.txt
deleted
100644 → 0
1 | def actions(id, players, mud): | ||
2 | mud.send_message(id, '\r\n-Action----------=Actions=-----------Cost-\r\n') | ||
3 | for name, action in players[id]['at'].items(): | ||
4 | mud.send_message(id, '{} {}'.format("%-37s" % name, action['cost'])) | ||
5 | mud.send_message(id, '\r\n------------------------------------------\r\n') | ||
6 | mud.send_message(id, 'For more detail on a specific action use "help <action>"') | ||
7 | |||
8 | |||
9 | actions(id, players, mud) | ||
10 | del actions | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
commands/cast.txt
deleted
100644 → 0
1 | import utils | ||
2 | |||
3 | # for now spells can only be cast on the thing you are fighting since I don't have a good lexer to pull | ||
4 | # out targets. This also means that spells are offensive only since you cant cast on 'me' | ||
5 | # TODO: Add proper parsing so you can do: cast fireball on turkey or even better, cast fireball on the first turkey | ||
6 | def cast(id, params, players, mud, command): | ||
7 | if params == '': | ||
8 | params = command.strip() | ||
9 | else: | ||
10 | params = params.strip() | ||
11 | if len(params) == 0: | ||
12 | mud.send_message(id, 'What spell do you want to cast?') | ||
13 | return True | ||
14 | spell = players[id]['sp'].get(params) | ||
15 | if not spell: | ||
16 | mud.send_message(id, 'You do not appear to know how to cast %s.' % (params,)) | ||
17 | return True | ||
18 | mp = players[id]['mp'] | ||
19 | if mp > 0 and mp > spell['cost']: | ||
20 | room_monsters = utils.load_object_from_file('rooms/{}_monsters.json'.format(players[id]['room'])) | ||
21 | if not room_monsters: | ||
22 | mud.send_message(id, 'There is nothing here to cast that spell on.') | ||
23 | for mon_name, monster in room_monsters.items(): | ||
24 | monster_template = utils.load_object_from_file('mobs/{}.json'.format(mon_name)) | ||
25 | if not monster_template: | ||
26 | continue | ||
27 | fighting = False | ||
28 | for active_monster_idx, active_monster in enumerate(monster['active']): | ||
29 | if active_monster['action'] == "attack" and active_monster['target'] == players[id]['name']: | ||
30 | fighting = True | ||
31 | att, mp = utils.calc_att(mud, id, [], mp, spell) | ||
32 | |||
33 | players[id]['mp'] = mp | ||
34 | active_monster['hp'] -= att | ||
35 | # don't let them off without saving cheating sons of bees | ||
36 | utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"])) | ||
37 | room_monsters[mon_name]['active'][active_monster_idx] = active_monster | ||
38 | if not fighting: | ||
39 | mud.send_message(id, 'You are not currently in combat') | ||
40 | return True | ||
41 | |||
42 | utils.save_object_to_file(room_monsters, 'rooms/{}_monsters.json'.format(players[id]['room'])) | ||
43 | else: | ||
44 | mud.send_message(id, 'You do not have enough mana to cast that spell.') | ||
45 | |||
46 | if command is None and cmd is not None: | ||
47 | command = cmd | ||
48 | cast(id, params.strip(), players, mud, command) | ||
49 | del cast | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
commands/drop.txt
deleted
100644 → 0
1 | def drop(id, tokens, players, mud): | ||
2 | room_name = players[id]["room"] | ||
3 | if len(tokens) == 0: | ||
4 | mud.send_message(id, 'What do you want to drop?') | ||
5 | return True | ||
6 | room_data = utils.load_object_from_file('rooms/' + room_name + '.json') | ||
7 | if tokens[0] in players[id]['inventory']: | ||
8 | if tokens[0] in room_data['inventory']: | ||
9 | room_data['inventory'][tokens[0]].append(players[id]['inventory'][tokens[0]].pop()) | ||
10 | else: | ||
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') | ||
16 | for pid, pl in players.items(): | ||
17 | # if they're in the same room as the player | ||
18 | if players[pid]["room"] == players[id]["room"]: | ||
19 | # send them a message telling them what the player said | ||
20 | mud.send_message(pid, "{} dropped a {}.".format( | ||
21 | players[id]["name"], tokens[0])) | ||
22 | utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"])) | ||
23 | else: | ||
24 | mud.send_message(id, 'You do not have {} in your inventory.'.format(tokens[0])) | ||
25 | |||
26 | drop(id, tokens, players, mud) | ||
27 | del drop | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
commands/emote.txt
deleted
100644 → 0
1 | def emote(id, params, players, mud): | ||
2 | # go through every player in the game | ||
3 | for pid, pl in players.items(): | ||
4 | # if they're in the same room as the player | ||
5 | if players[pid]["room"] == players[id]["room"]: | ||
6 | # send them a message telling them what the player said | ||
7 | mud.send_message(pid, "{} {}".format(players[id]["name"], params)) | ||
8 | |||
9 | emote(id, params, players, mud) | ||
10 | del emote | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
commands/equip.txt
deleted
100644 → 0
1 | def equip(id, players, tokens, mud): | ||
2 | if len(tokens) == 0: | ||
3 | mud.send_message(id, " %green+-Item---------------------=Equipment=------------------Loc----+", nowrap=True) | ||
4 | if players[id].get('equipment'): | ||
5 | for item, item_list in players[id]['equipment'].items(): | ||
6 | if isinstance(item_list, list): | ||
7 | vals = [val for val in item_list if val] | ||
8 | if len(vals) > 0: | ||
9 | mud.send_message(id, ' %green|%reset {} {} %green|'.format("%-51s" % ', '.join(vals), item.rjust(8, ' '))) | ||
10 | else: | ||
11 | mud.send_message(id, ' %green|%reset {} {} %green|'.format("%-51s" % 'None', item.rjust(8, ' '))) | ||
12 | else: | ||
13 | mud.send_message(id, ' %green|%reset {} {} %green|'.format("%-51s" % item_list or "None", item.rjust(8, ' '))) | ||
14 | mud.send_message(id, ' %green|%reset {} {} %green|'.format("%-51s" % players[id]['weapon'] or "None", 'weapon'.rjust(8, ' '))) | ||
15 | mud.send_message(id, " %green+--------------------------------------------------------------+", nowrap=True) | ||
16 | else: | ||
17 | if tokens[0] not in players[id]["inventory"]: | ||
18 | mud.send_message(id, 'You do not have {} in your inventory.'.format(tokens[0])) | ||
19 | else: | ||
20 | gear = utils.load_object_from_file('inventory/' + tokens[0] + '.json') | ||
21 | if gear["type"] == "weapon": | ||
22 | mud.send_message(id, 'That is a weapon and must be "wield".') | ||
23 | elif gear["type"] != "armor": | ||
24 | mud.send_message(id, 'That cannot be worn.') | ||
25 | else: | ||
26 | players[id]["equipment"][gear['loc']] = tokens[0] | ||
27 | mud.send_message(id, 'You wear the {} on your {}.'.format(tokens[0], gear['loc'])) | ||
28 | players[id]["inventory"][tokens[0]].pop() | ||
29 | if len(players[id]["inventory"][tokens[0]]) == 0: | ||
30 | del players[id]["inventory"][tokens[0]] | ||
31 | |||
32 | utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"])) | ||
33 | |||
34 | |||
35 | equip(id, players, tokens, mud) | ||
36 | del equip | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
commands/get.txt
deleted
100644 → 0
1 | def get(id, params, tokens, players, mud): | ||
2 | room_name = players[id]["room"] | ||
3 | if len(tokens) == 0: | ||
4 | mud.send_message(id, 'What do you want to get?') | ||
5 | return True | ||
6 | |||
7 | room_data = utils.load_object_from_file('rooms/' + room_name + '.json') | ||
8 | |||
9 | container = None | ||
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 {}.'.format(tokens[0], container)) | ||
42 | else: | ||
43 | for pid, pl in players.items(): | ||
44 | # if they're in the same room as the player | ||
45 | if players[pid]["room"] == players[id]["room"]: | ||
46 | # send them a message telling them what the player said | ||
47 | mud.send_message(pid, "{} picked up a {} from a {}.".format(players[id]["name"], tokens[0], container)) | ||
48 | utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"])) | ||
49 | utils.save_object_to_file(room_data, 'rooms/' + room_name + '.json') | ||
50 | return True | ||
51 | else: | ||
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])) | ||
70 | |||
71 | get(id, params.lower().strip(), tokens, players, mud) | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
commands/go.txt
deleted
100644 → 0
1 | def go(id, params, players, mud, tokens, command): | ||
2 | # store the exit name | ||
3 | if params == '': | ||
4 | params = command.strip().lower() | ||
5 | else: | ||
6 | params = params.strip().lower() | ||
7 | |||
8 | room_data = utils.load_object_from_file('rooms/' + players[id]["room"] + '.json') | ||
9 | |||
10 | # if the specified exit is found in the room's exits list | ||
11 | exits = room_data['exits'] | ||
12 | |||
13 | if params in exits: | ||
14 | # go through all the players in the game | ||
15 | for pid, pl in players.items(): | ||
16 | # if player is in the same room and isn't the player | ||
17 | # sending the command | ||
18 | if players[pid]["room"] == players[id]["room"] \ | ||
19 | and pid != id: | ||
20 | # send them a message telling them that the player | ||
21 | # left the room | ||
22 | mud.send_message(pid, "{} left via exit '{}'".format( | ||
23 | players[id]["name"], params)) | ||
24 | |||
25 | # update the player's current room to the one the exit leads to | ||
26 | |||
27 | if exits[params] == None: | ||
28 | mud.send_message(id, "An invisible force prevents you from going in that direction.") | ||
29 | return None | ||
30 | else: | ||
31 | new_room = utils.load_object_from_file('rooms/' + exits[params][0] + '.json') | ||
32 | if not new_room: | ||
33 | mud.send_message(id, "An invisible force prevents you from going in that direction.") | ||
34 | return None | ||
35 | else: | ||
36 | players[id]["room"] = exits[params][0] | ||
37 | utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"])) | ||
38 | mud.send_message(id, "You arrive at '{}'".format(new_room['title'])) | ||
39 | |||
40 | # go through all the players in the game | ||
41 | for pid, pl in players.items(): | ||
42 | # if player is in the same (new) room and isn't the player | ||
43 | # sending the command | ||
44 | if players[pid]["room"] == players[id]["room"] \ | ||
45 | and pid != id: | ||
46 | # send them a message telling them that the player | ||
47 | # entered the room | ||
48 | mud.send_message(pid, | ||
49 | "{} arrived via exit '{}'".format( | ||
50 | players[id]["name"], params)) | ||
51 | |||
52 | # send the player a message telling them where they are now | ||
53 | tokens = [] | ||
54 | return 'look' | ||
55 | # the specified exit wasn't found in the current room | ||
56 | else: | ||
57 | # send back an 'unknown exit' message | ||
58 | mud.send_message(id, "Unknown exit '{}'".format(params)) | ||
59 | if command is None and cmd is not None: | ||
60 | command = cmd | ||
61 | next_command = go(id, params, players, mud, tokens, command) | ||
62 | del go | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
commands/help.txt
deleted
100644 → 0
1 | def help(id, tokens, mud): | ||
2 | if len(tokens) > 0: | ||
3 | filename = 'help/' + tokens[0] + '.txt' | ||
4 | else: | ||
5 | filename = 'help/help.txt' | ||
6 | try: | ||
7 | with open(filename, 'r', encoding='utf-8') as f: | ||
8 | for line in f: | ||
9 | mud.send_message(id, line, '\r') | ||
10 | mud.send_message(id, '') | ||
11 | except: | ||
12 | mud.send_message(id, 'No help topics available for \"{}\". A list\r\n of all commands is available at: help index'.format(tokens[0])) | ||
13 | |||
14 | help(id, tokens, mud) | ||
15 | del help | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
commands/inventory.txt
deleted
100644 → 0
1 | def inventory(id, players, mud): | ||
2 | mud.send_message(id, " %green+-Item---------------------=Inventory=--------------------Qty--+", nowrap=True) | ||
3 | for item, item_list in players[id]['inventory'].items(): | ||
4 | mud.send_message(id, ' %green|%reset {} {} %green|'.format("%-55s" % item, str(len(item_list)).center(4, ' '))) | ||
5 | mud.send_message(id, " %green+--------------------------------------------------------------+", nowrap=True) | ||
6 | |||
7 | inventory(id, players, mud) | ||
8 | del inventory | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
commands/kill.txt
deleted
100644 → 0
1 | |||
2 | def kill(id, params, players, mud): | ||
3 | if len(params) == 0: | ||
4 | mud.send_message(id, 'What did you want to attack?') | ||
5 | return True | ||
6 | room_monsters = utils.load_object_from_file('rooms/{}_monsters.json'.format(players[id]['room'])) | ||
7 | for mon_name, monster in room_monsters.items(): | ||
8 | if mon_name in params.lower(): | ||
9 | if len(monster['active']) > 0: | ||
10 | if monster['active'][0]['target'] == players[id]['name']: | ||
11 | mud.send_message(id, 'You are already engaged in combat with that target.') | ||
12 | return True | ||
13 | else: | ||
14 | room_monsters[mon_name]['active'][0]['target'] = players[id]['name'] | ||
15 | mud.send_message(id, 'You attack the {}.'.format(mon_name), color=['red', 'bold']) | ||
16 | utils.save_object_to_file(room_monsters, 'rooms/{}_monsters.json'.format(players[id]['room'])) | ||
17 | return True | ||
18 | if params[0] in 'aeiou': | ||
19 | mud.send_message(id, 'You do not see an {} here.'.format(params)) | ||
20 | else: | ||
21 | mud.send_message(id, 'You do not see a {} here.'.format(params)) | ||
22 | |||
23 | kill(id, params, players, mud) | ||
24 | del kill | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
commands/look.txt
deleted
100644 → 0
1 | def look(id, mud, players, tokens): | ||
2 | room_name = players[id]["room"] | ||
3 | room_data = utils.load_object_from_file('rooms/' + room_name + '.json') | ||
4 | room_monsters = utils.load_object_from_file('rooms/' + room_name + '_monsters.json') | ||
5 | mud.send_message(id, "") | ||
6 | if len(tokens) > 0 and tokens[0] == 'at': | ||
7 | del tokens[0] | ||
8 | container = False | ||
9 | if len(tokens) > 0 and tokens[0] == 'in': | ||
10 | del tokens[0] | ||
11 | container = True | ||
12 | if len(tokens) == 0: | ||
13 | exits = {} | ||
14 | for exit_name, exit in room_data.get('exits').items(): | ||
15 | exits[exit_name] = exit[1] | ||
16 | print(room_data) | ||
17 | # clid, name, zone, terrain, description, exits, coords | ||
18 | mud.send_room(id, room_data.get('num'), room_data.get('title'), room_data.get('zone'), | ||
19 | 'City', '', exits, room_data.get('coords')) | ||
20 | mud.send_message(id, room_data.get('title'), color=['bold', 'green']) | ||
21 | mud.send_message(id, room_data.get('description'), line_ending='\r\n\r\n', color='green') | ||
22 | else: | ||
23 | subject = tokens[0] | ||
24 | items = room_data.get('look_items') | ||
25 | for item in items: | ||
26 | if subject in item: | ||
27 | mud.send_message(id, items[item]) | ||
28 | return True | ||
29 | if subject in room_data['inventory']: | ||
30 | if container and room_data["inventory"][subject][0].get("inventory") is not None: | ||
31 | items = room_data["inventory"][subject][0]["inventory"] | ||
32 | if len(items) > 0: | ||
33 | mud.send_message(id, 'You look in the {} and see:\r\n'.format(subject)) | ||
34 | inv_list = [] | ||
35 | for name, i in items.items(): | ||
36 | if len(i) > 1: | ||
37 | inv_list.append(str(len(i)) + " " + name + "s") | ||
38 | else: | ||
39 | inv_list.append(name) | ||
40 | mud.send_list(id, inv_list, "look") | ||
41 | |||
42 | else: | ||
43 | mud.send_message(id, 'You look in the {} and see nothing.'.format(subject)) | ||
44 | else: | ||
45 | item = utils.load_object_from_file('inventory/' + subject + '.json') | ||
46 | mud.send_message(id, 'You see {}'.format(item.get('description'))) | ||
47 | return True | ||
48 | if subject in players[id]['inventory']: | ||
49 | if container and players[id]["inventory"][subject][0].get("inventory") is not None: | ||
50 | items = players[id]["inventory"][subject][0]["inventory"] | ||
51 | if len(items) > 0: | ||
52 | mud.send_message(id, 'You look in your {} and see:\r\n'.format(subject)) | ||
53 | inv_list = [] | ||
54 | print(items) | ||
55 | for name, i in items.items(): | ||
56 | if len(i) > 1: | ||
57 | inv_list.append(str(len(i)) + " " + name + "s") | ||
58 | else: | ||
59 | inv_list.append(name) | ||
60 | mud.send_list(id, inv_list, "look") | ||
61 | else: | ||
62 | mud.send_message(id, 'You look in your {} and see nothing.'.format(subject)) | ||
63 | else: | ||
64 | item = utils.load_object_from_file('inventory/' + subject + '.json') | ||
65 | mud.send_message(id, 'You check your inventory and see {}'.format(item.get('description'))) | ||
66 | return True | ||
67 | if subject in room_monsters: | ||
68 | if len(room_monsters[subject]['active']) > 0: | ||
69 | monster_template = utils.load_object_from_file('mobs/{}.json'.format(subject)) | ||
70 | if monster_template: | ||
71 | mud.send_message(id, 'You see {}'.format(monster_template.get('desc').lower())) | ||
72 | return True | ||
73 | mud.send_message(id, "That doesn't seem to be here.") | ||
74 | return | ||
75 | |||
76 | playershere = [] | ||
77 | # go through every player in the game | ||
78 | for pid, pl in players.items(): | ||
79 | # if they're in the same room as the player | ||
80 | if players[pid]["room"] == players[id]["room"]: | ||
81 | # ... and they have a name to be shown | ||
82 | if players[pid]["name"] is not None and players[id]["name"] != players[pid]["name"]: | ||
83 | # add their name to the list | ||
84 | playershere.append(players[pid]["name"]) | ||
85 | |||
86 | # send player a message containing the list of players in the room | ||
87 | if len(playershere) > 0: | ||
88 | mud.send_message(id, "%boldPlayers here:%reset {}".format(", ".join(playershere))) | ||
89 | |||
90 | mud.send_message(id, "%boldObvious Exits:%reset ", line_ending='') | ||
91 | mud.send_list(id, room_data.get('exits'), "go") | ||
92 | |||
93 | # send player a message containing the list of exits from this room | ||
94 | if len(room_data.get('inventory')) > 0: | ||
95 | mud.send_message(id, "%boldItems here:%reset ", line_ending='') | ||
96 | inv_list = [] | ||
97 | for name, i in room_data.get('inventory').items(): | ||
98 | if len(i) > 1: | ||
99 | inv_list.append(str(len(i)) + " " + name + "s") | ||
100 | else: | ||
101 | inv_list.append(name) | ||
102 | mud.send_list(id, inv_list, "look") | ||
103 | |||
104 | # send player a message containing the list of players in the room | ||
105 | for mon_name, monster in room_monsters.items(): | ||
106 | count = len(monster['active']) | ||
107 | if count > 1: | ||
108 | mud.send_message(id, "{} {} are here.".format(count, mon_name)) | ||
109 | elif count > 0: | ||
110 | mud.send_message(id, "a {} is here.".format(mon_name)) | ||
111 | |||
112 | look(id, mud, players, tokens) | ||
113 | del look | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
commands/perform.txt
deleted
100644 → 0
1 | import utils | ||
2 | |||
3 | # for now actions can only be cast on the thing you are fighting since I don't have a good lexer to pull | ||
4 | # out targets. This also means that actions are offensive only since you cant cast on 'me' | ||
5 | # TODO: Add proper parsing so you can do: cast fireball on turkey or even better, cast fireball on the first turkey | ||
6 | def perform(id, params, players, mud, command): | ||
7 | if params == '': | ||
8 | params = command.strip() | ||
9 | else: | ||
10 | params = params.strip() | ||
11 | if len(params) == 0: | ||
12 | mud.send_message(id, 'What action do you want to perform?') | ||
13 | return True | ||
14 | action = players[id]['at'].get(params) | ||
15 | if not action: | ||
16 | mud.send_message(id, 'You do not appear to know the action %s.' % (params,)) | ||
17 | return True | ||
18 | sta = players[id]['sta'] | ||
19 | if sta > 0 and sta > action['cost']: | ||
20 | room_monsters = utils.load_object_from_file('rooms/{}_monsters.json'.format(players[id]['room'])) | ||
21 | if not room_monsters: | ||
22 | mud.send_message(id, 'There is nothing here to perform that action on.') | ||
23 | for mon_name, monster in room_monsters.items(): | ||
24 | monster_template = utils.load_object_from_file('mobs/{}.json'.format(mon_name)) | ||
25 | if not monster_template: | ||
26 | continue | ||
27 | fighting = False | ||
28 | for active_monster_idx, active_monster in enumerate(monster['active']): | ||
29 | if active_monster['action'] == "attack" and active_monster['target'] == players[id]['name']: | ||
30 | fighting = True | ||
31 | att, sta = utils.calc_att(mud, id, [], sta, action) | ||
32 | |||
33 | players[id]['sta'] = sta | ||
34 | active_monster['hp'] -= att | ||
35 | # don't let them off without saving cheating sons of bees | ||
36 | utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"])) | ||
37 | room_monsters[mon_name]['active'][active_monster_idx] = active_monster | ||
38 | if not fighting: | ||
39 | mud.send_message(id, 'You are not currently in combat') | ||
40 | return True | ||
41 | |||
42 | utils.save_object_to_file(room_monsters, 'rooms/{}_monsters.json'.format(players[id]['room'])) | ||
43 | else: | ||
44 | mud.send_message(id, 'You do not have enough stamina to perform that action.') | ||
45 | |||
46 | if command is None and cmd is not None: | ||
47 | command = cmd | ||
48 | perform(id, params.strip(), players, mud, command) | ||
49 | del perform | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
commands/prompt.txt
deleted
100644 → 0
1 | def prompt(id, tokens, params, players, mud): | ||
2 | if len(tokens) == 0: | ||
3 | mud.send_message(id, 'No prompt provided, no changes will be made.\r\nEx: prompt %hp>') | ||
4 | |||
5 | players[id]['prompt'] = params + ' ' | ||
6 | utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"])) | ||
7 | |||
8 | prompt(id, tokens, params, players, mud) | ||
9 | del prompt | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
commands/put.txt
deleted
100644 → 0
1 | def put(id, tokens, players, mud): | ||
2 | if len(tokens) == 0: | ||
3 | mud.send_message(id, 'What do you want to put and where do you want to put it?') | ||
4 | return True | ||
5 | subject = tokens[0] | ||
6 | if 'in' == tokens[1]: | ||
7 | del tokens[1] | ||
8 | dest = tokens[1] | ||
9 | |||
10 | room_name = players[id]["room"] | ||
11 | room_data = utils.load_object_from_file('rooms/' + room_name + '.json') | ||
12 | |||
13 | if subject in players[id]['inventory']: | ||
14 | if dest in players[id]['inventory'] or dest in room_data['inventory']: | ||
15 | |||
16 | if dest in room_data['inventory']: | ||
17 | if len(room_data['inventory'][dest][0]["inventory"]) == 0 and not room_data['inventory'][dest][0]["inventory"].get(subject): | ||
18 | room_data['inventory'][dest][0]["inventory"][subject] = [players[id]['inventory'][subject].pop()] | ||
19 | else: | ||
20 | room_data['inventory'][dest][0]["inventory"][subject].append(players[id]['inventory'][subject].pop()) | ||
21 | elif dest in players[id]['inventory']: | ||
22 | #print(players[id]['inventory'][dest][0]["inventory"]) | ||
23 | print(players[id]['inventory'][dest][0]["inventory"].get(subject)) | ||
24 | if len(players[id]['inventory'][dest][0]["inventory"]) == 0 and not players[id]['inventory'][dest][0]["inventory"].get(subject): | ||
25 | players[id]['inventory'][dest][0]["inventory"][subject] = [players[id]['inventory'][subject].pop()] | ||
26 | else: | ||
27 | players[id]['inventory'][dest][0]["inventory"][subject].append(players[id]['inventory'][subject].pop()) | ||
28 | if len(players[id]['inventory'][tokens[0]]) <= 0: | ||
29 | del players[id]['inventory'][tokens[0]] | ||
30 | |||
31 | utils.save_object_to_file(room_data, 'rooms/' + room_name + '.json') | ||
32 | for pid, pl in players.items(): | ||
33 | # if they're in the same room as the player | ||
34 | if players[pid]["room"] == players[id]["room"]: | ||
35 | # send them a message telling them what the player said | ||
36 | mud.send_message(pid, "{} put a {} in a {}.".format(players[id]["name"], subject, dest)) | ||
37 | utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"])) | ||
38 | else: | ||
39 | mud.send_message(id, 'You cannot put {} in {} since it is not here.'.format(subject, dest)) | ||
40 | else: | ||
41 | mud.send_message(id, 'You do not have {} in your inventory.'.format(subject)) | ||
42 | |||
43 | put(id, tokens, players, mud) | ||
44 | del put | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
commands/quit.txt
deleted
100644 → 0
1 | def quit(id, players, mud): | ||
2 | # send the player back the list of possible commands | ||
3 | mud.send_message(id, "Saving...") | ||
4 | utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"])) | ||
5 | mud.disconnect_player(id) | ||
6 | |||
7 | quit(id, players, mud) | ||
8 | del quit | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
commands/remove.txt
deleted
100644 → 0
1 | def remove(id, players, tokens, mud): | ||
2 | if len(tokens) == 0: | ||
3 | mud.send_message(id, 'What do you want to stop wearing?') | ||
4 | else: | ||
5 | for item, item_list in players[id]['equipment'].items(): | ||
6 | if isinstance(item_list, list): | ||
7 | for idx, li in enumerate(item_list): | ||
8 | print(li) | ||
9 | if li == tokens[0]: | ||
10 | item_list[idx] = None | ||
11 | if tokens[0] in players[id]['inventory']: | ||
12 | players[id]['inventory'][tokens[0]].append({"expries": 0}) | ||
13 | else: | ||
14 | players[id]['inventory'][tokens[0]] = [{"expries": 0}] | ||
15 | mud.send_message(id, 'You remove the {}.'.format(tokens[0])) | ||
16 | utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"])) | ||
17 | return | ||
18 | elif item_list == tokens[0]: | ||
19 | players[id]['equipment'][item] = None | ||
20 | if tokens[0] in players[id]['inventory']: | ||
21 | players[id]['inventory'][tokens[0]].append({"expries": 0}) | ||
22 | else: | ||
23 | players[id]['inventory'][tokens[0]] = [{"expries": 0}] | ||
24 | mud.send_message(id, 'You remove the {}.'.format(tokens[0])) | ||
25 | utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"])) | ||
26 | return | ||
27 | |||
28 | if tokens[0] == players[id]['weapon']: | ||
29 | if tokens[0] in players[id]['inventory']: | ||
30 | players[id]['inventory'][tokens[0]].append({"expries": 0}) | ||
31 | else: | ||
32 | players[id]['inventory'][tokens[0]] = [{"expries": 0}] | ||
33 | mud.send_message(id, 'You unwield the {}.'.format(tokens[0])) | ||
34 | utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"])) | ||
35 | return | ||
36 | |||
37 | mud.send_message(id, 'You are not wearing a {}.'.format(tokens[0])) | ||
38 | # else: | ||
39 | # gear = utils.load_object_from_file('inventory/' + tokens[0] + '.json') | ||
40 | # if gear["type"] == "weapon": | ||
41 | # mud.send_message(id, 'That is a weapon and must be "wield".'.format(tokens[0])) | ||
42 | # elif gear["type"] != "armor": | ||
43 | # mud.send_message(id, 'That cannot be worn.'.format(tokens[0])) | ||
44 | # else: | ||
45 | # players[id]["equipment"][gear['loc']] = tokens[0] | ||
46 | # mud.send_message(id, 'You wear the {} on your {}.'.format(tokens[0], gear['loc'])) | ||
47 | # if len(players[id]["inventory"][tokens[0]]) == 0: | ||
48 | # del players[id]["inventory"][tokens[0]] | ||
49 | # else: | ||
50 | # players[id]["inventory"][tokens[0]].pop() | ||
51 | # utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"])) | ||
52 | |||
53 | |||
54 | remove(id, players, tokens, mud) | ||
55 | del remove | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
commands/save.txt
deleted
100644 → 0
1 | def save(id, players, mud): | ||
2 | # send the player back the list of possible commands | ||
3 | mud.send_message(id, "Saving...") | ||
4 | utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"])) | ||
5 | mud.send_message(id, "Save complete") | ||
6 | return True | ||
7 | |||
8 | save(id, players, mud) | ||
9 | del save | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
commands/say.txt
deleted
100644 → 0
1 | def say(id, params, players, mud): | ||
2 | # go through every player in the game | ||
3 | for pid, pl in players.items(): | ||
4 | # if they're in the same room as the player | ||
5 | if players[pid]["room"] == players[id]["room"]: | ||
6 | # send them a message telling them what the player said | ||
7 | mud.send_message(pid, "{} says: {}".format( | ||
8 | players[id]["name"], params)) | ||
9 | say(id, params, players, mud) | ||
10 | del say | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
commands/score.txt
deleted
100644 → 0
1 | def score(id, players, mud): | ||
2 | from math import floor | ||
3 | |||
4 | mud.send_message(id, " %green+----------------------------=Score=---------------------------+", nowrap=True) | ||
5 | hp = str("%d/%d" % (floor(players[id]['hp']), floor(players[id]['maxhp']))).center(12, ' ') | ||
6 | mp = str("%d/%d" % (floor(players[id]['mp']), floor(players[id]['maxmp']))).center(12, ' ') | ||
7 | sta = str("%d/%d" % (floor(players[id]['sta']), floor(players[id]['maxsta']))).center(12, ' ') | ||
8 | |||
9 | mud.send_message(id, " %%green|%%reset%%bold%%white%s%%reset%%green|" % (players[id]["name"].center(62),), nowrap=True) | ||
10 | mud.send_message(id, " %green+--------------------------------------------------------------+", nowrap=True) | ||
11 | mud.send_message(id, " %%green|%%reset %%cyanHP:%%reset %%white[%s]%%reset %%green|%%reset %%cyanMP:%%reset %%white[%s]%%reset %%green|%%reset %%cyanST:%%reset %%white[%s]%%reset %%green|%%reset" % (hp, mp, sta), nowrap=True) | ||
12 | |||
13 | |||
14 | # output = """ | ||
15 | # -------------------------------------------- | ||
16 | # HP: {hp} Max HP: {maxhp} | ||
17 | # MP: {mp} Max MP: {maxmp} | ||
18 | # Sta: {sta} Max Sta: {maxsta} | ||
19 | # Experience: {exp} | ||
20 | # Skills:""".format(hp=floor(players[id]['hp']), | ||
21 | # mp=floor(players[id]['mp']), | ||
22 | # maxhp=floor(players[id]['maxhp']), | ||
23 | # maxmp=floor(players[id]['maxmp']), | ||
24 | # sta=floor(players[id]['sta']), | ||
25 | # maxsta=floor(players[id]['maxsta']), | ||
26 | # exp=0) | ||
27 | # mud.send_message(id, output) | ||
28 | |||
29 | mud.send_message(id, " %green+---------------------------=Skills=---------------------------+", nowrap=True) | ||
30 | skills = ["skillasdfasdfasdfasdf", "skill 2 sdfg sdfg", "Skill 3 asdf ewrewwr"] | ||
31 | for skill in skills: | ||
32 | mud.send_message(id, " %%green|%%reset %s%%green|%%reset" % (skill.ljust(61),), nowrap=True) | ||
33 | |||
34 | mud.send_message(id, " %green+--------------------------------------------------------------+", nowrap=True) | ||
35 | |||
36 | |||
37 | |||
38 | score(id, players, mud) | ||
39 | del score | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
commands/spells.txt
deleted
100644 → 0
1 | def spells(id, players, mud): | ||
2 | mud.send_message(id, '\r\n-Spell-----------=Spells=-----------Cost-\r\n') | ||
3 | for name, spell in players[id]['sp'].items(): | ||
4 | mud.send_message(id, '{} {}'.format("%-37s" % name, spell['cost'])) | ||
5 | mud.send_message(id, '\r\n-----------------------------------------\r\n') | ||
6 | mud.send_message(id, 'For more detail on a specific spell use "help <spell>"') | ||
7 | |||
8 | |||
9 | spells(id, players, mud) | ||
10 | del spells | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
commands/whisper.txt
deleted
100644 → 0
1 | def whisper(id, tokens, players, mud): | ||
2 | # go through every player in the game | ||
3 | for pid, pl in players.items(): | ||
4 | # if they're in the same room as the player | ||
5 | if players[pid]["name"] == tokens[0]: | ||
6 | # send them a message telling them what the player said | ||
7 | mud.send_message(pid, "{} whispers: {}".format( | ||
8 | players[id]["name"], ' '.join(tokens[1:]))) | ||
9 | |||
10 | whisper(id, tokens, players, mud) | ||
11 | del whisper | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
commands/who.txt
deleted
100644 → 0
1 | def who(id, players, mud): | ||
2 | mud.send_message(id, "") | ||
3 | mud.send_message(id, "-------- {} Players Currently Online --------".format(len(players))) | ||
4 | for pid, player in players.items(): | ||
5 | if player["name"] is None: | ||
6 | continue | ||
7 | mud.send_message(id, " " + player["name"]) | ||
8 | mud.send_message(id, "---------------------------------------------".format(len(players))) | ||
9 | mud.send_message(id, "") | ||
10 | who(id, players, mud) | ||
11 | del who | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
commands/wield.txt
deleted
100644 → 0
1 | def wield(id, players, tokens, mud): | ||
2 | if len(tokens) == 0: | ||
3 | mud.send_message(id, " %greenYou are currently wielding: %reset%bold%white{}".format(players[id]['weapon'])) | ||
4 | else: | ||
5 | if tokens[0] not in players[id]["inventory"]: | ||
6 | mud.send_message(id, 'You do not have {} in your inventory.'.format(tokens[0])) | ||
7 | else: | ||
8 | gear = utils.load_object_from_file('inventory/' + tokens[0] + '.json') | ||
9 | if gear["type"] == "armor": | ||
10 | mud.send_message(id, 'That is armor and must be "equip".') | ||
11 | elif gear["type"] != "weapon": | ||
12 | mud.send_message(id, 'That cannot be wielded.') | ||
13 | else: | ||
14 | players[id]["weapon"] = tokens[0] | ||
15 | mud.send_message(id, 'You wield the {}!'.format(tokens[0])) | ||
16 | players[id]["inventory"][tokens[0]].pop() | ||
17 | if len(players[id]["inventory"][tokens[0]]) == 0: | ||
18 | del players[id]["inventory"][tokens[0]] | ||
19 | |||
20 | utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"])) | ||
21 | |||
22 | |||
23 | wield(id, players, tokens, mud) | ||
24 | del wield | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
... | @@ -299,9 +299,12 @@ class MudServer(object): | ... | @@ -299,9 +299,12 @@ class MudServer(object): |
299 | self.send_message(clid, ', '.join(list_items)) | 299 | self.send_message(clid, ', '.join(list_items)) |
300 | 300 | ||
301 | def gmcp_message(self, clid, message): | 301 | def gmcp_message(self, clid, message): |
302 | byte_data = bytearray([self._TN_IAC, self._TN_SUB_START, self._GMCP]) | 302 | array = [self._TN_IAC, self._TN_SUB_START, self._GMCP] |
303 | byte_data.extend(message.encode()) | 303 | for char in message: |
304 | byte_data.extend([self._TN_IAC, self._TN_SUB_END]) | 304 | array.append(ord(char)) |
305 | array.append(self._TN_IAC) | ||
306 | array.append(self._TN_SUB_END) | ||
307 | byte_data = bytearray(array) | ||
305 | 308 | ||
306 | print("SENDING GMCP") | 309 | print("SENDING GMCP") |
307 | print(byte_data) | 310 | print(byte_data) |
... | @@ -309,7 +312,10 @@ class MudServer(object): | ... | @@ -309,7 +312,10 @@ class MudServer(object): |
309 | client_socket.sendall(byte_data) | 312 | client_socket.sendall(byte_data) |
310 | 313 | ||
311 | def mxp_secure(self, clid, message, mxp_code="1"): | 314 | def mxp_secure(self, clid, message, mxp_code="1"): |
312 | bytes_to_send = bytearray("\x1b[{}z{}\x1b[3z\r\n".format(mxp_code, message), 'utf-8') | 315 | if 'esp' in sys.platform: |
316 | bytes_to_send = bytearray("\x1b[{}z{}\x1b[3z\r\n".format(mxp_code, message)) | ||
317 | else: | ||
318 | bytes_to_send = bytearray("\x1b[{}z{}\x1b[3z\r\n".format(mxp_code, message), 'utf-8') | ||
313 | client_socket = self._clients[clid].socket | 319 | client_socket = self._clients[clid].socket |
314 | client_socket.sendall(bytes_to_send) | 320 | client_socket.sendall(bytes_to_send) |
315 | 321 | ... | ... |
1 | {"name": "test", "password": "6c76899eb15393064b4f4db94805e5862232920b", "room": "town/tavern", "equipment": {"finger": [null, null], "hand": [null, null], "arm": [null, null], "leg": [null, null], "foot": [null, null], "head": null, "neck": null, "back": null, "body": null, "waist": null}, "inventory": {"bag": [{"expires": 0, "inventory": {"shirt": [{"expires": 0}]}}]}, "prompt": "hp %hp mp %mp> ", "aliases": {}, "hp": 100, "mp": 10, "maxhp": 100, "maxmp": 10, "maxsta": 10, "sta": 10, "aa": "1d2", "mpr": 0.25, "star": 0.4, "weapon": null, "sp": {}, "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": "6c76899eb15393064b4f4db94805e5862232920b", "room": "town/room001", "equipment": {"finger": [null, null], "hand": [null, null], "arm": [null, null], "leg": [null, null], "foot": [null, null], "head": null, "neck": null, "back": null, "body": null, "waist": null}, "inventory": {"bag": [{"expires": 0, "inventory": {"shirt": [{"expires": 0}]}}]}, "prompt": "hp %hp mp %mp> ", "aliases": {}, "hp": 94, "mp": 10, "maxhp": 100, "maxmp": 10, "maxsta": 10, "sta": 0.8000000000000004, "aa": "1d2", "mpr": 0.25, "star": 0.4, "weapon": null, "sp": {}, "at": {"kick": {"cost": 5, "dmg": "2d4", "desc": "You unleash a powerful kick"}}} | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -11,7 +11,7 @@ IPADDRESS = '192.168.1.189' | ... | @@ -11,7 +11,7 @@ IPADDRESS = '192.168.1.189' |
11 | 11 | ||
12 | BAUDRATE = 115200 | 12 | BAUDRATE = 115200 |
13 | 13 | ||
14 | folders = ['help', 'rooms', 'rooms/town', 'rooms/wilderness', 'inventory', 'commands', 'mobs'] | 14 | folders = ['help', 'rooms', 'rooms/town', 'rooms/wilderness', 'inventory', 'mobs'] |
15 | 15 | ||
16 | files = [ | 16 | files = [ |
17 | "welcome.txt", | 17 | "welcome.txt", | ... | ... |
... | @@ -2,6 +2,7 @@ import os | ... | @@ -2,6 +2,7 @@ import os |
2 | import io | 2 | import io |
3 | import serial | 3 | import serial |
4 | import time | 4 | import time |
5 | import sys | ||
5 | 6 | ||
6 | ###################################### | 7 | ###################################### |
7 | # EDIT THIS TO MATCH YOUR SETTINGS | 8 | # EDIT THIS TO MATCH YOUR SETTINGS |
... | @@ -21,6 +22,11 @@ baked_files = [ | ... | @@ -21,6 +22,11 @@ baked_files = [ |
21 | "utils.py" | 22 | "utils.py" |
22 | ] | 23 | ] |
23 | 24 | ||
25 | def countdown(t): | ||
26 | for x in reversed(range(t)): | ||
27 | sys.stdout.write('\r{} '.format(x + 1)) | ||
28 | time.sleep(1) | ||
29 | print('\r\n') | ||
24 | 30 | ||
25 | def run_command(sio, command, expected='>>>'): | 31 | def run_command(sio, command, expected='>>>'): |
26 | sio.write("{}\n".format(command)) | 32 | sio.write("{}\n".format(command)) |
... | @@ -47,7 +53,7 @@ os.system('esptool --port {} erase_flash'.format(PORT)) | ... | @@ -47,7 +53,7 @@ os.system('esptool --port {} erase_flash'.format(PORT)) |
47 | os.system('esptool --port {} --baud 460800 write_flash --flash_size=detect 0 image/firmware-combined.bin'.format(PORT)) | 53 | os.system('esptool --port {} --baud 460800 write_flash --flash_size=detect 0 image/firmware-combined.bin'.format(PORT)) |
48 | 54 | ||
49 | print("Sleeping 10 seconds for reboot") | 55 | print("Sleeping 10 seconds for reboot") |
50 | time.sleep(10) | 56 | countdown(10) |
51 | 57 | ||
52 | with open('releasepw.conf', 'r', encoding='utf-8') as f: | 58 | with open('releasepw.conf', 'r', encoding='utf-8') as f: |
53 | WEBREPL_PASS = f.read() | 59 | WEBREPL_PASS = f.read() |
... | @@ -70,6 +76,9 @@ with serial.Serial(PORT, BAUDRATE, timeout=1) as ser: | ... | @@ -70,6 +76,9 @@ with serial.Serial(PORT, BAUDRATE, timeout=1) as ser: |
70 | print('Connecting to {}'.format(ESSID)) | 76 | print('Connecting to {}'.format(ESSID)) |
71 | run_command(sio, "sta_if.connect('{}', '{}')".format(ESSID, WIFI_PASSWORD)) | 77 | run_command(sio, "sta_if.connect('{}', '{}')".format(ESSID, WIFI_PASSWORD)) |
72 | 78 | ||
79 | print('Waiting 15 seconds for network to connect.\r\n') | ||
80 | countdown(15) | ||
81 | |||
73 | waiting_for_ip = True | 82 | waiting_for_ip = True |
74 | while waiting_for_ip: | 83 | while waiting_for_ip: |
75 | try: | 84 | try: |
... | @@ -87,7 +96,8 @@ with serial.Serial(PORT, BAUDRATE, timeout=1) as ser: | ... | @@ -87,7 +96,8 @@ with serial.Serial(PORT, BAUDRATE, timeout=1) as ser: |
87 | 96 | ||
88 | run_command(sio, 'import machine;machine.reset()') | 97 | run_command(sio, 'import machine;machine.reset()') |
89 | 98 | ||
90 | print('Starting the squishy mud release') | 99 | print('Starting the squishy mud release\r\n') |
91 | time.sleep(5) | 100 | countdown(5) |
101 | |||
92 | # Run the rest of the mud setup | 102 | # Run the rest of the mud setup |
93 | import release | 103 | import release |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
1 | { | ||
2 | "num": 1002, | ||
3 | "coords": { "id": 1000, "x": 1, "y": 0, "z": 0 }, | ||
4 | "look_items": { | ||
5 | "wooden,oak,plank": "An old solid oak plank that has a large number of chips and drink marks.", | ||
6 | "barrel,barrels": "The old barrels bands are thick with oxidation and stained with the purple of spilled wine.", | ||
7 | "bar": "The bar is a long wooden plank thrown over roughly hewn barrels." | ||
8 | }, | ||
9 | "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.", | ||
10 | "inventory": { | ||
11 | "candle": [{ | ||
12 | "age": 0 | ||
13 | }] | ||
14 | }, | ||
15 | "exits": { | ||
16 | "tavern": ["town/tavern", 1001] | ||
17 | }, | ||
18 | "title": "Behind the bar", | ||
19 | "zone": "town" | ||
20 | } | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | {"num": 1002, "coords": {"id": 1000, "x": 1, "y": 0, "z": 0}, "look_items": {"wooden,oak,plank": "An old solid oak plank that has a large number of chips and drink marks.", "barrel,barrels": "The old barrels bands are thick with oxidation and stained with the purple of spilled wine.", "bar": "The bar is a long wooden plank thrown over roughly hewn 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.", "inventory": {"candle": [{"age": 0}]}, "exits": {"tavern": ["town/tavern", 1001]}, "title": "Behind the bar", "zone": "town"} | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
1 | {"cricket": {"max": 1, "active": [{"mp": 10, "maxhp": 14, "hp": 14, "sta": 10, "maxmp": 10, "target": "", "action": "attack", "maxsta": 10}]}} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | {"cricket": {"max": 1, "active": []}} | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or sign in to post a comment