예제 #1
0
파일: player.py 프로젝트: Remboooo/LoBotomy
	def handle_scan(self, radius):
		# check state
		if self.state is not PlayerState.ACTING:
			raise LoBotomyException(202)

		# check action validity
		if game.scan_cost(radius) > config.player.max_energy:
			raise LoBotomyException(103)

		self.scan_action = (radius,)
예제 #2
0
    def handle_scan(self, radius):
        # check state
        if self.state is not PlayerState.ACTING:
            raise LoBotomyException(202)

        # check action validity
        if game.scan_cost(radius) > config.player.max_energy:
            raise LoBotomyException(103)

        self.scan_action = (radius, )
예제 #3
0
파일: server.py 프로젝트: akaIDIOT/LoBotomy
    def execute_scans(self, players):
        result_signals = []
        for player in players:
            (radius, ) = player.scan_action
            logging.info('player {} at {} scanned with radius {}'.format(
                player.name, player.location, radius))

            # subtract energy cost
            cost = game.scan_cost(radius)
            prev_energy = player.energy
            player.energy -= cost

            self.emit_event(type='player_scan',
                            player=player.name,
                            location=player.location,
                            radius=radius,
                            cost=cost,
                            energy=(prev_energy, player.energy))
            if player.energy <= 0.0:
                # signal player is dead
                result_signals.append(self.player_death(player))
                self.emit_event(type='player_suicide',
                                action='scan',
                                cost=cost,
                                energy=(prev_energy, player.energy))
                logging.info('player {} died from exhaustion (scan)'.format(
                    player.name))
            else:
                x, y = player.location
                # calculate the bounding box for the scan
                bounds = (x - radius, y - radius, x + radius, y + radius)
                # collect all players in the bounding box for the blast
                subjects = set()
                for region in util.generate_wrapped_bounds(
                    (0, 0, self.width, self.height), bounds):
                    subjects = subjects.union(self.find_players(region))

                radius = util.WrappedRadius(player.location, radius,
                                            (self.width, self.height))
                # check if subject in scan radius (bounding box possibly selects too many players)
                for subject in subjects:
                    # calculate distance to all subjects, signal detect if within scan
                    # TODO: using radius twice runs the expensive operation twice
                    (distance,
                     wrapped_location) = radius.distance(subject.location)
                    if subject is not player and subject.location in radius:
                        result_signals.append(
                            (player.signal_detect, subject.name,
                             util.angle(player.location, wrapped_location),
                             util.distance(player.location,
                                           wrapped_location), subject.energy))
                        self.emit_event(type='player_detect',
                                        player=player.name,
                                        energy=player.energy,
                                        location=player.location,
                                        radius=radius,
                                        detected=subject.name,
                                        detected_location=subject.location,
                                        detected_energy=subject.energy)
                        logging.info('player {} detected {}'.format(
                            player.name, subject.name))
        return result_signals
예제 #4
0
파일: server.py 프로젝트: Sakartu/LoBotomy
	def execute_scans(self, players):
		result_signals = []
		for player in players:
			(radius,) = player.scan_action
			logging.info('player {} at {} scanned with radius {}'.format(
				player.name,
				player.location,
				radius
			))

			# subtract energy cost
			cost = game.scan_cost(radius)
			prev_energy = player.energy
			player.energy -= cost

			self.emit_event(
				type = 'player_scan',
				player = player.name,
				location = player.location,
				radius = radius,
				cost = cost,
				energy = (prev_energy, player.energy)
			)
			if player.energy <= 0.0:
				# signal player is dead
				result_signals.append(self.player_death(player))
				self.emit_event(
					type = 'player_suicide',
					action = 'scan',
					cost = cost,
					energy = (prev_energy, player.energy)
				)
				logging.info('player {} died from exhaustion (scan)'.format(player.name))
			else:
				x, y = player.location
				# calculate the bounding box for the scan
				bounds = (
					x - radius, y - radius,
					x + radius, y + radius
				)
				# collect all players in the bounding box for the blast
				subjects = set()
				for region in util.generate_wrapped_bounds((0, 0, self.width, self.height), bounds):
					subjects = subjects.union(self.find_players(region))

				radius = util.WrappedRadius(player.location, radius, (self.width, self.height))
				# check if subject in scan radius (bounding box possibly selects too many players)
				for subject in subjects:
					# calculate distance to all subjects, signal detect if within scan
					# TODO: using radius twice runs the expensive operation twice
					(distance, wrapped_location) = radius.distance(subject.location)
					if subject is not player and subject.location in radius:
						result_signals.append((player.signal_detect, subject.name,
							util.angle(player.location, wrapped_location),
							util.distance(player.location, wrapped_location),
							subject.energy
						))
						self.emit_event(
							type = 'player_detect',
							player = player.name,
							energy = player.energy,
							location = player.location,
							radius = radius,
							detected = subject.name,
							detected_location = subject.location,
							detected_energy = subject.energy
						)
						logging.info('player {} detected {}'.format(player.name, subject.name))
		return result_signals