diff --git a/assets/src/ba_data/python/ba/_activity.py b/assets/src/ba_data/python/ba/_activity.py index d06e3dc2..b19a2e40 100644 --- a/assets/src/ba_data/python/ba/_activity.py +++ b/assets/src/ba_data/python/ba/_activity.py @@ -113,7 +113,7 @@ class Activity(DependencyComponent, Generic[PlayerType, TeamType]): inherits_tint = False # Whether players should be allowed to join in the middle of - # activities. + # activity. allow_mid_activity_joins: bool = True # If the activity fades or transitions in, it should set the length of diff --git a/assets/src/ba_data/python/ba/_coopgame.py b/assets/src/ba_data/python/ba/_coopgame.py index f7c3dc07..1811bb05 100644 --- a/assets/src/ba_data/python/ba/_coopgame.py +++ b/assets/src/ba_data/python/ba/_coopgame.py @@ -27,8 +27,6 @@ class CoopGameActivity(GameActivity[PlayerType, TeamType]): # We can assume our session is a CoopSession. session: ba.CoopSession - allow_mid_activity_joins = False - @classmethod def supports_session_type(cls, sessiontype: Type[ba.Session]) -> bool: from ba._coopsession import CoopSession diff --git a/assets/src/ba_data/python/ba/_coopsession.py b/assets/src/ba_data/python/ba/_coopsession.py index c6674c61..fed532e9 100644 --- a/assets/src/ba_data/python/ba/_coopsession.py +++ b/assets/src/ba_data/python/ba/_coopsession.py @@ -90,6 +90,16 @@ class CoopSession(Session): """Get the game instance currently being played.""" return self._current_game_instance + def should_allow_mid_activity_joins(self, activity: Activity) -> bool: + # pylint: disable=cyclic-import + from ba._gameactivity import GameActivity + + # Disallow any joins in the middle of the game. + if isinstance(activity, GameActivity): + return False + + return True + def _update_on_deck_game_instances(self) -> None: # pylint: disable=cyclic-import from ba._gameactivity import GameActivity diff --git a/assets/src/ba_data/python/ba/_session.py b/assets/src/ba_data/python/ba/_session.py index 6ff90754..2c7e6520 100644 --- a/assets/src/ba_data/python/ba/_session.py +++ b/assets/src/ba_data/python/ba/_session.py @@ -205,6 +205,14 @@ class Session: raise NodeNotFoundError() return node + def should_allow_mid_activity_joins(self, activity: Activity) -> bool: + """Returned value is used by the Session to determine + whether to allow players to join in the middle of activity. + + Activity.allow_mid_activity_joins is also required to allow these + joins.""" + return True + def on_player_request(self, player: ba.SessionPlayer) -> bool: """Called when a new ba.Player wants to join the Session. @@ -651,7 +659,8 @@ class Session: # However, if we're not allowing mid-game joins, don't actually pass; # just announce the arrival and say they'll partake next round. if pass_to_activity: - if not activity.allow_mid_activity_joins: + if not (activity.allow_mid_activity_joins + and self.should_allow_mid_activity_joins(activity)): pass_to_activity = False with _ba.Context(self): _ba.screenmessage( diff --git a/assets/src/ba_data/python/bastd/game/meteorshower.py b/assets/src/ba_data/python/bastd/game/meteorshower.py index 9be79902..32c62c0d 100644 --- a/assets/src/ba_data/python/bastd/game/meteorshower.py +++ b/assets/src/ba_data/python/bastd/game/meteorshower.py @@ -44,7 +44,11 @@ class MeteorShowerGame(ba.TeamGameActivity[Player, Team]): # Print messages when players die (since its meaningful in this game). announce_player_deaths = True - # we're currently hard-coded for one map.. + # Don't allow joining after we start + # (would enable leave/rejoin tomfoolery). + allow_mid_activity_joins = False + + # We're currently hard-coded for one map. @classmethod def get_supported_maps(cls, sessiontype: Type[ba.Session]) -> List[str]: return ['Rampage'] @@ -93,22 +97,6 @@ class MeteorShowerGame(ba.TeamGameActivity[Player, Team]): # Check for immediate end (if we've only got 1 player, etc). ba.timer(5.0, self._check_end_game) - def on_player_join(self, player: Player) -> None: - # Don't allow joining after we start - # (would enable leave/rejoin tomfoolery). - if self.has_begun(): - ba.screenmessage( - ba.Lstr(resource='playerDelayedJoinText', - subs=[('${PLAYER}', player.getname(full=True))]), - color=(0, 1, 0), - ) - # For score purposes, mark them as having died right as the - # game started. - assert self._timer is not None - player.death_time = self._timer.getstarttime() - return - self.spawn_player(player) - def on_player_leave(self, player: Player) -> None: # Augment default behavior. super().on_player_leave(player)