def handle_close(self): """ Handles closing of the socktet. """ client_logger.debug('Connection closed') if self.player: world.get_room(self.player.room).contents.remove_player(self) for c in self._cycles: c.cancel()
def do_say(client, args, msg): if not args: client.send("say <text you want to say>") else: room = world.get_room(client.player.room) for c in room.contents.get_players(): c.send("misc", "%s says, \"%s\"" % (client.player.name, msg[4:]) )
def do_recall(client, args, msg): if client.player.room == 'limbo1@limbo': messages.warning(client, "You are already at the recall point!") else: current = world.get_room(client.player.room) recall = get_room_id('limbo1@limbo') move_to_room(client, current, recall, 'the heavens', 'the heavens')
def do_exits(cmap, x, y, loc, zl = False): room = world.get_room(loc) if not room: return 0 if zl: cmap[y][x] = 20 return 0 elif room.exits.has_exit(UP): cmap[y][x] = 4 elif room.exits.has_exit(DOWN): cmap[y][x] = 5 else: cmap[y][x] = 3 if room.exits.has_exit(NORTH): cmap[y-1][x] = 1 if room.exits.has_exit(SOUTH): cmap[y+1][x] = 1 if room.exits.has_exit(EAST): cmap[y][x+1] = 2 if room.exits.has_exit(WEST): cmap[y][x-1] = 2 if room.exits.has_exit(NORTH_EAST): cmap[y-1][x+1] = 8 if room.exits.has_exit(NORTH_WEST): cmap[y-1][x-1] = 9 if room.exits.has_exit(SOUTH_EAST): cmap[y+1][x+1] = 10 if room.exits.has_exit(SOUTH_WEST): cmap[y+1][x-1] = 11
def do_look(client, args, msg): room = world.get_room(client.player.room) #client.send('misc', "%s" % room.name) #client.send('misc', "Loc %d, %d, %d" % room.get_loc()) client.send('room_contents', room.contents.get_players_names(), room.contents.get_mob_names()) do_map(client, None, None)
def do_move(client, args, msg): if args: room = client.player.room room, zone = room.split('@') current = world.get_room(client.player.room) abr_dir = ['n', 's', 'e', 'w', 'ne', 'nw', 'se', 'sw', 'u', 'd', ] for e in EXIT_NAMES.keys(): if args[0] == abr_dir[e] or args[0] == EXIT_NAMES[e].lower(): if current.exits.has_exit(e): next_room = world.get_room(current.exits.get_exit(e).room + '@' + zone) if next_room: move_to_room(client, current, next_room) else: client.send("error", 'You can\'t go that way!') else: client.send("error", 'You can\'t go that way!') else: client.send("error", 'You must specify a direction!')
def add_player_to_game(client): if not client.player: lobby_logger.error( 'Client could not be moved to the game, there was no player obj.') client.send('misc', db.get_msg('lobby.login_error')) client.close() else: lobby_logger.info("Adding player:%s to the game" % client.player.name) client.send('state', 'game') client.send('misc', db.get_msg('lobby.enter_game')) client.add_cycle(engine.cycle(client.send, 6, "player_hms", client.player)) client.add_cycle(engine.cycle(heal_tick, 6, [client])) room = world.get_room(client.player.room) room.contents.add_player(client) do_look(client, None, None) do_pi(client, None, None)
def do_dig(client, args, msg): if len(args) == 1: current_room = world.get_room(client.player.room) zone = world.get_zone(current_room.zone) dir = args[0] if current_room.exits.has_exit_by_string(dir): client.send("error", db.get_msg('building.error_dig_overlap')) return for e in EXIT_NAMES.keys(): if dir == EXIT_NAMES[e].lower(): md = MAP_DIR[e] cl = current_room.get_loc() new_room = Room(db.new_room(zone, (cl[0]+md[0], cl[1]+md[1], cl[2]+md[2]))) out_exit = db.new_exit(dir, new_room.short_name) in_exit = db.new_exit(OPPOSITE_EXIT[dir], current_room.short_name) current_room.exits.add_exit(out_exit) new_room.exits.add_exit(in_exit) else: client.send("error", 'Usage: dig <dir>')
def make_map(ch): # 1 = ns path 2 = ew path # 3 = room 4 = room with up # 5 = room with down 6 = room with player # 7 = room with shop # 8 = ne path 9 nw path # 10= se path 11 sw path ch = ch.player room = world.get_room(ch.room) zone = ch.room.split('@')[1] if room._map_cache: return room._map_cache cmap = [ # 0 1 2 3 4 5 6 7 8 91011121314 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],# 0 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],# 1 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],# 2 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],# 3 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],# 4 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],# 5 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],# 6 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],# 7 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],# 8 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],# 9 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],# 10 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],# 11 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],# 12 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],# 13 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],# 14 ] CENTER = 7 #set the center square to a room with the player do_exits(cmap, CENTER, CENTER, ch.room) for e in EXIT_NAMES.keys(): if room.exits.has_exit(e): r_id = room.exits.get_exit(e).room dir = GRID_DIR[e] if e == 8: break if e == 9: break if r_id.find('@') >= 0: do_exits(cmap, CENTER+dir[1], CENTER+dir[0], r_id, True) continue else: do_exits(cmap, CENTER+dir[1], CENTER+dir[0], r_id + '@' + zone) room2 = world.get_room(r_id + '@' + zone) if room2: pass else: break for e in EXIT_NAMES.keys(): if room2.exits.has_exit(e): #print "room has exit ", e, EXIT_NAMES[e] r_id = room2.exits.get_exit(e).room dir2 = GRID_DIR[e] if e == 8: break if e == 9: break if r_id.find('@') >= 0: do_exits(cmap, CENTER+dir[1]+dir2[1], CENTER+dir[0]+dir2[0], r_id, True) continue else: do_exits(cmap, CENTER+dir[1]+dir2[1], CENTER+dir[0]+dir2[0], r_id + '@' + zone) room3 = world.get_room(r_id + '@' + zone) if room3: pass else: break for e in EXIT_NAMES.keys(): if room3.exits.has_exit(e): r_id = room3.exits.get_exit(e).room dir3 = GRID_DIR[e] if e == 8: break if e == 9: break if r_id.find('@') >= 0: do_exits(cmap, CENTER+dir[1]+dir2[1]+dir3[1], CENTER+dir[0]+dir2[0]+dir3[0], r_id, True) continue else: do_exits(cmap, CENTER+dir[1]+dir2[1]+dir3[1], CENTER+dir[0]+dir2[0]+dir3[0], r_id + '@' + zone) #check the directions and add paths if needed cmap[CENTER][CENTER] = 6 #the finished map dmap = [] #append an enclosing line #dmap.append('\n\r@y-----------------------------@d\n\r') #loop through and build the map TODO: add color codes #dmap.append('@y-----------------------------@d\n\r') room._map_cache = cmap #for l in dmap: # print l return cmap
def do_target(client, args, msg): room = world.get_room(client.player.room) e = room.contents.find_entity(args[0]) if e: client.send("target", e.player.name, 22, 233)
def do_spawn(client, args, msg): m = Mob() m.name = "Test Mob" room = world.get_room(client.player.room) room.contents.add_mob(m)
def do_zr(client, args, msg): room = world.get_room(client.player.room) zone = world.get_zone(room.zone) zone.reset()