def rollmap(connection, mapname=None, value=None): start_x, start_y, end_x, end_y = 0, 0, 512, 512 if value is not None: start_x, start_y = coordinates(value) end_x, end_y = start_x + 64, start_y + 64 return connection.protocol.start_rollback(connection, mapname, start_x, start_y, end_x, end_y)
def move(connection, player, value, silent=False): """ Go to a specified sector /move <player> <sector> """ player = get_player(connection.protocol, player) x, y = coordinates(value) x += 32 y += 32 player.set_location( (x, y, connection.protocol.map.get_height(x, y) - 2)) if connection is player: message = ('%s ' + ('silently ' if silent else '') + 'teleported to ' 'location %s') message = message % (player.name, value.upper()) else: message = ('%s ' + ('silently ' if silent else '') + 'teleported %s ' 'to location %s') message = message % (connection.name, player.name, value.upper()) if silent: connection.protocol.irc_say('* ' + message) else: connection.protocol.send_chat(message, irc=True)
def rollmap(connection, mapname = None, value = None): start_x, start_y, end_x, end_y = 0, 0, 512, 512 if value is not None: start_x, start_y = coordinates(value) end_x, end_y = start_x + 64, start_y + 64 return connection.protocol.start_rollback(connection, mapname, start_x, start_y, end_x, end_y)
def buildpw(connection, password=None, area=None): """ Quick way of giving a player a password for a protected area /buildpw <password> <area> """ if password is None and area is None: pws_str = "" for pw in connection.protocol.password_areas: pws_str += pw + " " if pws_str == "": pws_str = "none" return "Passwords: " + pws_str elif area is None: areas_str = "" for pw_coord in connection.protocol.password_areas.get(password): areas_str += to_coordinates(pw_coord[0], pw_coord[1]) + " " if areas_str == "": areas_str = "none" return "Areas for " + password + ": " + areas_str else: if connection.protocol.password_areas.get(password) is None: connection.protocol.password_areas[password] = set() areas = connection.protocol.password_areas[password] area_coord = coordinates(area) areas.symmetric_difference_update([area_coord]) message = ("%s now %s with %s" % (area.upper(), "allowed" if area_coord in areas else "disallowed", password)) if len(areas) < 1: connection.protocol.password_areas.pop(password, None) return message
def protect_all(self): self.protected = set() for letter in 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h': for num in range(8): grid = letter + str(num + 1) if grid not in DONT_PROTECT: pos = coordinates(grid) self.protected.symmetric_difference_update([pos])
def do_move(connection, args, silent=False): position = None player = None arg_count = len(args) initial_index = 1 if arg_count == 2 or arg_count == 4 else 0 # the target position is a <sector> if arg_count == 1 or arg_count == 2: x, y = coordinates(args[initial_index]) x += 32 y += 32 z = connection.protocol.map.get_height(x, y) - 2 position = args[initial_index].upper() # the target position is <x> <y> <z> elif arg_count == 3 or arg_count == 4: x = min(max(0, int(args[initial_index])), 511) y = min(max(0, int(args[initial_index + 1])), 511) z = min(max(0, int(args[initial_index + 2])), connection.protocol.map.get_height(x, y) - 2) position = '%d %d %d' % (x, y, z) else: raise ValueError('Wrong number of parameters!') # no player specified if arg_count == 1 or arg_count == 3: # must be run by a player in this case because moving self if connection not in connection.protocol.players.values(): raise ValueError("Both player and target player are required") player = connection.name # player specified elif arg_count == 2 or arg_count == 4: if not (connection.rights.admin or connection.rights.move_others): raise PermissionDenied( "moving other players requires the move_others right") player = args[0] player = get_player(connection.protocol, player) silent = connection.invisible or silent player.set_location((x, y, z)) if connection is player: message = ('%s ' + ('silently ' if silent else '') + 'teleported to ' 'location %s') message = message % (player.name, position) else: message = ('%s ' + ('silently ' if silent else '') + 'teleported %s ' 'to location %s') message = message % (connection.name, player.name, position) if silent: connection.protocol.irc_say('* ' + message) else: connection.protocol.send_chat(message, irc=True)
def on_map_change(self, map): info = self.map_info.info if ALWAYS_ENABLED: self.unbreak = True else: ubrk = getattr(info, 'unbreak', True) if ubrk is True or ubrk is False: self.unbreak = ubrk else: self.unbreak = set(coordinates(s) for s in ubrk) self.player_blocks = {} return protocol.on_map_change(self, map)
def protect(connection, value=None): protocol = connection.protocol if value is None: protocol.protected = None protocol.send_chat('All areas unprotected', irc=True) else: if protocol.protected is None: protocol.protected = set() pos = coordinates(value) protocol.protected.symmetric_difference_update([pos]) message = 'The area at %s is now %s' % (value.upper( ), 'protected' if pos in protocol.protected else 'unprotected') protocol.send_chat(message, irc=True)
def protect(connection, value = None): protocol = connection.protocol if value is None: protocol.protected = None protocol.send_chat('All areas unprotected', irc = True) else: if protocol.protected is None: protocol.protected = set() pos = coordinates(value) protocol.protected.symmetric_difference_update([pos]) message = 'The area at %s is now %s' % (value.upper(), 'protected' if pos in protocol.protected else 'unprotected') protocol.send_chat(message, irc = True)
def do_move(connection, args, silent=False): position = None player = None arg_count = len(args) initial_index = 1 if arg_count == 2 or arg_count == 4 else 0 # the target position is a <sector> if arg_count == 1 or arg_count == 2: x, y = coordinates(args[initial_index]) x += 32 y += 32 z = connection.protocol.map.get_height(x, y) - 2 position = args[initial_index].upper() # the target position is <x> <y> <z> elif arg_count == 3 or arg_count == 4: x = min(max(0, int(args[initial_index])), 511) y = min(max(0, int(args[initial_index + 1])), 511) z = min(max(0, int(args[initial_index + 2])), connection.protocol.map.get_height(x, y) - 2) position = '%d %d %d' % (x, y, z) else: raise ValueError('Wrong number of parameters!') # no player specified if arg_count == 1 or arg_count == 3: if connection not in connection.protocol.players: raise ValueError() player = connection.name # player specified elif arg_count == 2 or arg_count == 4: player = args[0] player = get_player(connection.protocol, player) silent = connection.invisible or silent player.set_location((x, y, z)) if connection is player: message = ('%s ' + ('silently ' if silent else '') + 'teleported to ' 'location %s') message = message % (player.name, position) else: message = ('%s ' + ('silently ' if silent else '') + 'teleported %s ' 'to location %s') message = message % (connection.name, player.name, position) if silent: connection.protocol.irc_say('* ' + message) else: connection.protocol.send_chat(message, irc=True)
def move(connection, player, value, silent = False): player = get_player(connection.protocol, player) x, y = coordinates(value) x += 32 y += 32 player.set_location((x, y, connection.protocol.map.get_height(x, y) - 2)) if connection is player: message = ('%s ' + ('silently ' if silent else '') + 'teleported to ' 'location %s') message = message % (player.name, value.upper()) else: message = ('%s ' + ('silently ' if silent else '') + 'teleported %s ' 'to location %s') message = message % (connection.name, player.name, value.upper()) if silent: connection.protocol.irc_say('* ' + message) else: connection.protocol.send_chat(message, irc = True)
def move_helper(connection, player, value, silent=False): player = get_player(connection.protocol, player) x, y = coordinates(value) x += 32 y += 32 player.set_location((x, y, -2)) if connection is player: message = ('%s ' + ('silently ' if silent else '') + 'teleported to ' 'location %s') message = message % (player.name, value.upper()) else: message = ('%s ' + ('silently ' if silent else '') + 'teleported %s ' 'to location %s') message = message % (connection.name, player.name, value.upper()) if silent: connection.protocol.irc_say('* ' + message) else: connection.protocol.send_chat(message, irc=True)
def protect(connection, area=None): """ Protect an area inside the public build region /protect <area> """ if area is None: areas_str = "" for protected_coord in connection.protocol.protected_areas: areas_str += to_coordinates(protected_coord[0], protected_coord[1]) + " " if areas_str == "": areas_str = "none" return "Protected areas: " + areas_str else: area_coord = coordinates(area) connection.protocol.protected_areas.symmetric_difference_update( [area_coord]) message = ("The area at %s is now %s" % (area.upper(), "protected" if area_coord in connection.protocol.protected_areas else "unprotected")) connection.protocol.broadcast_chat(message)
def airstrike(connection, coords = None): protocol = connection.protocol if connection not in protocol.players: raise ValueError() player = connection if not coords and player.airstrike: return S_READY if player.kills < SCORE_REQUIREMENT: return S_NO_SCORE.format(score = SCORE_REQUIREMENT) elif not player.airstrike: kills_left = STREAK_REQUIREMENT - (player.streak % STREAK_REQUIREMENT) return S_NO_STREAK.format(streak = STREAK_REQUIREMENT, remaining = kills_left) try: coord_x, coord_y = coordinates(coords) except (ValueError): return S_BAD_COORDS last_airstrike = getattr(player.team, 'last_airstrike', None) if last_airstrike and seconds() - last_airstrike < TEAM_COOLDOWN: remaining = TEAM_COOLDOWN - (seconds() - last_airstrike) return S_COOLDOWN.format(seconds = int(ceil(remaining))) player.start_airstrike(coord_x, coord_y)
def build(connection, player, area=None): """ Give temporary build permission to a player /build <#id> <area> """ if player is None: raise ValueError() player = get_player(connection.protocol, player) if area is None: if len(player.allowed_areas) < 1: raise ValueError() else: player.allowed_areas.clear() connection.protocol.broadcast_chat( player.name + " can no longer build at protected areas") else: area_coord = coordinates(area) player.allowed_areas.symmetric_difference_update([area_coord]) message = ("%s can %s build at %s" % (player.name, "temporary" if area_coord in player.allowed_areas else "no longer", area.upper())) connection.protocol.broadcast_chat(message)
def on_map_change(self, map): self.protected = set( coordinates(s) for s in getattr(self.map_info.info, 'protected', [])) protocol.on_map_change(self, map)
def test_from_coords(self): self.assertEqual(coordinates("H8"), (448, 448))
def on_map_change(self, map): self.protected = set(coordinates(s) for s in getattr(self.map_info.info, 'protected', [])) protocol.on_map_change(self, map)