Example #1
0
    def __init__(self,
                 srcnode: ba.Node = None,
                 pos: Sequence[float] = None,
                 velocity: Sequence[float] = None,
                 magnitude: float = 1.0,
                 velocity_magnitude: float = 0.0,
                 radius: float = 1.0,
                 source_player: ba.Player = None,
                 kick_back: float = 1.0,
                 flat_damage: float = None,
                 hit_type: str = 'generic',
                 force_direction: Sequence[float] = None,
                 hit_subtype: str = 'default'):
        """Instantiate a message with given values."""

        self.srcnode = srcnode
        self.pos = pos if pos is not None else _ba.Vec3()
        self.velocity = velocity if velocity is not None else _ba.Vec3()
        self.magnitude = magnitude
        self.velocity_magnitude = velocity_magnitude
        self.radius = radius
        self.source_player = source_player
        self.kick_back = kick_back
        self.flat_damage = flat_damage
        self.hit_type = hit_type
        self.hit_subtype = hit_subtype
        self.force_direction = (force_direction
                                if force_direction is not None else velocity)
Example #2
0
    def position(self) -> ba.Vec3:
        """The position of the player, as defined by its current Actor.

        This value should not be used when the player has no Actor, as
        it is undefined in that case.
        """
        return _ba.Vec3(self.node.position)
Example #3
0
    def get_ffa_start_position(
            self, players: Sequence[ba.Player]) -> Sequence[float]:
        """Return a random starting position in one of the FFA spawn areas.

        If a list of ba.Players is provided; the returned points will be
        as far from these players as possible.
        """

        # Get positions for existing players.
        player_pts = []
        for player in players:
            try:
                if player.node:
                    pnt = _ba.Vec3(player.node.position)
                    player_pts.append(pnt)
            except Exception as exc:
                print('EXC in get_ffa_start_position:', exc)

        def _getpt() -> Sequence[float]:
            point = self.ffa_spawn_points[self._next_ffa_start_index]
            self._next_ffa_start_index = ((self._next_ffa_start_index + 1) %
                                          len(self.ffa_spawn_points))
            x_range = (-0.5, 0.5) if point[3] == 0.0 else (-point[3], point[3])
            z_range = (-0.5, 0.5) if point[5] == 0.0 else (-point[5], point[5])
            point = (point[0] + random.uniform(*x_range), point[1],
                     point[2] + random.uniform(*z_range))
            return point

        if not player_pts:
            return _getpt()

        # Let's calc several start points and then pick whichever is
        # farthest from all existing players.
        farthestpt_dist = -1.0
        farthestpt = None
        for _i in range(10):
            testpt = _ba.Vec3(_getpt())
            closest_player_dist = 9999.0
            for ppt in player_pts:
                dist = (ppt - testpt).length()
                if dist < closest_player_dist:
                    closest_player_dist = dist
            if closest_player_dist > farthestpt_dist:
                farthestpt_dist = closest_player_dist
                farthestpt = testpt
        assert farthestpt is not None
        return tuple(farthestpt)
Example #4
0
    def position(self) -> ba.Vec3:
        """The position of the player, as defined by its current ba.Actor.

        This value is undefined when the player has no Actor.
        """
        assert self._postinited
        assert not self._expired
        assert self.actor is not None
        return _ba.Vec3(self.node.position)
Example #5
0
    def position(self) -> ba.Vec3:
        """The position of the player, as defined by its current ba.Actor.

        If the player currently has no actor, raises a ba.ActorNotFoundError.
        """
        assert self._postinited
        assert not self._expired
        if self.actor is None:
            raise ActorNotFoundError
        return _ba.Vec3(self.node.position)
        def _apply(name2: Lstr, score2: int, showpoints2: bool,
                   color2: tuple[float, float, float, float], scale2: float,
                   sound2: Optional[ba.Sound]) -> None:
            from bastd.actor.popuptext import PopupText

            # Only award this if they're still alive and we can get
            # a current position for them.
            our_pos: Optional[ba.Vec3] = None
            if self._sessionplayer:
                if self._sessionplayer.activityplayer is not None:
                    try:
                        our_pos = self._sessionplayer.activityplayer.position
                    except NotFoundError:
                        pass
            if our_pos is None:
                return

            # Jitter position a bit since these often come in clusters.
            our_pos = _ba.Vec3(our_pos[0] + (random.random() - 0.5) * 2.0,
                               our_pos[1] + (random.random() - 0.5) * 2.0,
                               our_pos[2] + (random.random() - 0.5) * 2.0)
            activity = self.getactivity()
            if activity is not None:
                PopupText(Lstr(
                    value=(('+' + str(score2) + ' ') if showpoints2 else '') +
                    '${N}',
                    subs=[('${N}', name2)]),
                          color=color2,
                          scale=scale2,
                          position=our_pos).autoretain()
            if sound2:
                _ba.playsound(sound2)

            self.score += score2
            self.accumscore += score2

            # Inform a running game of the score.
            if score2 != 0 and activity is not None:
                activity.handlemessage(PlayerScoredMessage(score=score2))
 def position(self) -> ba.Vec3:
     """The position of the current collision."""
     return _ba.Vec3(_ba.get_collision_info('position'))