From 2d39ad7121bfa2f7ca43e5b9b1c2d1ae6dd4ac03 Mon Sep 17 00:00:00 2001 From: Roman Trapeznikov Date: Tue, 21 Sep 2021 17:12:48 +0300 Subject: [PATCH] some cleanups; fixed trouble from PR message --- assets/src/ba_data/python/ba/_activity.py | 4 ++++ assets/src/ba_data/python/ba/_coopgame.py | 2 ++ assets/src/ba_data/python/ba/_coopsession.py | 9 ++++----- assets/src/ba_data/python/ba/_session.py | 8 +------- .../ba_data/python/bastd/game/elimination.py | 19 ++----------------- 5 files changed, 13 insertions(+), 29 deletions(-) diff --git a/assets/src/ba_data/python/ba/_activity.py b/assets/src/ba_data/python/ba/_activity.py index 0060ab64..d06e3dc2 100644 --- a/assets/src/ba_data/python/ba/_activity.py +++ b/assets/src/ba_data/python/ba/_activity.py @@ -112,6 +112,10 @@ class Activity(DependencyComponent, Generic[PlayerType, TeamType]): # transitions). inherits_tint = False + # Whether players should be allowed to join in the middle of + # activities. + allow_mid_activity_joins: bool = True + # If the activity fades or transitions in, it should set the length of # time here so that previous activities will be kept alive for that # long (avoiding 'holes' in the screen) diff --git a/assets/src/ba_data/python/ba/_coopgame.py b/assets/src/ba_data/python/ba/_coopgame.py index 1811bb05..f7c3dc07 100644 --- a/assets/src/ba_data/python/ba/_coopgame.py +++ b/assets/src/ba_data/python/ba/_coopgame.py @@ -27,6 +27,8 @@ 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 3435569e..7d5b0ff4 100644 --- a/assets/src/ba_data/python/ba/_coopsession.py +++ b/assets/src/ba_data/python/ba/_coopsession.py @@ -158,13 +158,13 @@ class CoopSession(Session): if _ba.app.server is not None: # If we're in server mode, end game and show results. - _ba.timer(2.0, WeakCall(self._end_activity_if_empty)) + _ba.timer(2.0, WeakCall(self._end_game_if_empty)) else: # Otherwise, if all our players leave # we wanna quit out of the session. _ba.timer(2.0, WeakCall(self._end_session_if_empty)) - def _end_activity_if_empty(self) -> None: + def _end_game_if_empty(self) -> None: activity = self.getactivity() if activity is None: return # Probably everything is already broken, why do something? @@ -175,9 +175,8 @@ class CoopSession(Session): with _ba.Context(activity): from ba._gameactivity import GameActivity - # FIXME: rewrite this, doesn't cover all cases - assert isinstance(activity, GameActivity) - activity.end_game() + if isinstance(activity, GameActivity): + activity.end_game() def _end_session_if_empty(self) -> None: activity = self.getactivity() diff --git a/assets/src/ba_data/python/ba/_session.py b/assets/src/ba_data/python/ba/_session.py index 7bb94288..6ff90754 100644 --- a/assets/src/ba_data/python/ba/_session.py +++ b/assets/src/ba_data/python/ba/_session.py @@ -63,10 +63,6 @@ class Session: team instead of their own profile colors. This only applies if use_teams is enabled. - allow_mid_activity_joins - Whether players should be allowed to join in the middle of - activities. - customdata A shared dictionary for objects to use as storage on this session. Ensure that keys here are unique to avoid collisions. @@ -74,7 +70,6 @@ class Session: """ use_teams: bool = False use_team_colors: bool = True - allow_mid_activity_joins: bool = True # Note: even though these are instance vars, we annotate them at the # class level so that docs generation can access their types. @@ -220,7 +215,6 @@ class Session: if _ba.app.stress_test_reset_timer is None: if len(self.sessionplayers) >= self.max_players: - # Print a rejection message *only* to the client trying to # join (prevents spamming everyone else in the game). _ba.playsound(_ba.getsound('error')) @@ -657,7 +651,7 @@ 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 self.allow_mid_activity_joins: + if not activity.allow_mid_activity_joins: pass_to_activity = False with _ba.Context(self): _ba.screenmessage( diff --git a/assets/src/ba_data/python/bastd/game/elimination.py b/assets/src/ba_data/python/bastd/game/elimination.py index aac7d823..dd95a469 100644 --- a/assets/src/ba_data/python/bastd/game/elimination.py +++ b/assets/src/ba_data/python/bastd/game/elimination.py @@ -179,6 +179,8 @@ class EliminationGame(ba.TeamGameActivity[Player, Team]): # Show messages when players die since it's meaningful here. announce_player_deaths = True + allow_mid_activity_joins = False + @classmethod def get_available_settings( cls, sessiontype: Type[ba.Session]) -> List[ba.Setting]: @@ -257,23 +259,6 @@ class EliminationGame(ba.TeamGameActivity[Player, Team]): self.session, ba.DualTeamSession) else 'last one standing wins' def on_player_join(self, player: Player) -> None: - - # No longer allowing mid-game joiners here; too easy to exploit. - if self.has_begun(): - - # Make sure their team has survival seconds set if they're all dead - # (otherwise blocked new ffa players are considered 'still alive' - # in score tallying). - if (self._get_total_team_lives(player.team) == 0 - and player.team.survival_seconds is None): - player.team.survival_seconds = 0 - ba.screenmessage( - ba.Lstr(resource='playerDelayedJoinText', - subs=[('${PLAYER}', player.getname(full=True))]), - color=(0, 1, 0), - ) - return - player.lives = self._lives_per_player if self._solo_mode: