mirror of
https://github.com/RYDE-WORK/ballistica.git
synced 2026-01-24 07:53:30 +08:00
some cleanups; fixed trouble from PR message
This commit is contained in:
parent
5c3b707710
commit
2d39ad7121
@ -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)
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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()
|
||||
|
||||
@ -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(
|
||||
|
||||
@ -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:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user