mirror of
https://github.com/RYDE-WORK/ballistica.git
synced 2026-02-03 22:14:45 +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).
|
# transitions).
|
||||||
inherits_tint = False
|
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
|
# 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
|
# time here so that previous activities will be kept alive for that
|
||||||
# long (avoiding 'holes' in the screen)
|
# long (avoiding 'holes' in the screen)
|
||||||
|
|||||||
@ -27,6 +27,8 @@ class CoopGameActivity(GameActivity[PlayerType, TeamType]):
|
|||||||
# We can assume our session is a CoopSession.
|
# We can assume our session is a CoopSession.
|
||||||
session: ba.CoopSession
|
session: ba.CoopSession
|
||||||
|
|
||||||
|
allow_mid_activity_joins = False
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def supports_session_type(cls, sessiontype: Type[ba.Session]) -> bool:
|
def supports_session_type(cls, sessiontype: Type[ba.Session]) -> bool:
|
||||||
from ba._coopsession import CoopSession
|
from ba._coopsession import CoopSession
|
||||||
|
|||||||
@ -158,13 +158,13 @@ class CoopSession(Session):
|
|||||||
|
|
||||||
if _ba.app.server is not None:
|
if _ba.app.server is not None:
|
||||||
# If we're in server mode, end game and show results.
|
# 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:
|
else:
|
||||||
# Otherwise, if all our players leave
|
# Otherwise, if all our players leave
|
||||||
# we wanna quit out of the session.
|
# we wanna quit out of the session.
|
||||||
_ba.timer(2.0, WeakCall(self._end_session_if_empty))
|
_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()
|
activity = self.getactivity()
|
||||||
if activity is None:
|
if activity is None:
|
||||||
return # Probably everything is already broken, why do something?
|
return # Probably everything is already broken, why do something?
|
||||||
@ -175,9 +175,8 @@ class CoopSession(Session):
|
|||||||
with _ba.Context(activity):
|
with _ba.Context(activity):
|
||||||
from ba._gameactivity import GameActivity
|
from ba._gameactivity import GameActivity
|
||||||
|
|
||||||
# FIXME: rewrite this, doesn't cover all cases
|
if isinstance(activity, GameActivity):
|
||||||
assert isinstance(activity, GameActivity)
|
activity.end_game()
|
||||||
activity.end_game()
|
|
||||||
|
|
||||||
def _end_session_if_empty(self) -> None:
|
def _end_session_if_empty(self) -> None:
|
||||||
activity = self.getactivity()
|
activity = self.getactivity()
|
||||||
|
|||||||
@ -63,10 +63,6 @@ class Session:
|
|||||||
team instead of their own profile colors. This only applies if
|
team instead of their own profile colors. This only applies if
|
||||||
use_teams is enabled.
|
use_teams is enabled.
|
||||||
|
|
||||||
allow_mid_activity_joins
|
|
||||||
Whether players should be allowed to join in the middle of
|
|
||||||
activities.
|
|
||||||
|
|
||||||
customdata
|
customdata
|
||||||
A shared dictionary for objects to use as storage on this session.
|
A shared dictionary for objects to use as storage on this session.
|
||||||
Ensure that keys here are unique to avoid collisions.
|
Ensure that keys here are unique to avoid collisions.
|
||||||
@ -74,7 +70,6 @@ class Session:
|
|||||||
"""
|
"""
|
||||||
use_teams: bool = False
|
use_teams: bool = False
|
||||||
use_team_colors: bool = True
|
use_team_colors: bool = True
|
||||||
allow_mid_activity_joins: bool = True
|
|
||||||
|
|
||||||
# Note: even though these are instance vars, we annotate them at the
|
# Note: even though these are instance vars, we annotate them at the
|
||||||
# class level so that docs generation can access their types.
|
# 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 _ba.app.stress_test_reset_timer is None:
|
||||||
|
|
||||||
if len(self.sessionplayers) >= self.max_players:
|
if len(self.sessionplayers) >= self.max_players:
|
||||||
|
|
||||||
# Print a rejection message *only* to the client trying to
|
# Print a rejection message *only* to the client trying to
|
||||||
# join (prevents spamming everyone else in the game).
|
# join (prevents spamming everyone else in the game).
|
||||||
_ba.playsound(_ba.getsound('error'))
|
_ba.playsound(_ba.getsound('error'))
|
||||||
@ -657,7 +651,7 @@ class Session:
|
|||||||
# However, if we're not allowing mid-game joins, don't actually pass;
|
# However, if we're not allowing mid-game joins, don't actually pass;
|
||||||
# just announce the arrival and say they'll partake next round.
|
# just announce the arrival and say they'll partake next round.
|
||||||
if pass_to_activity:
|
if pass_to_activity:
|
||||||
if not self.allow_mid_activity_joins:
|
if not activity.allow_mid_activity_joins:
|
||||||
pass_to_activity = False
|
pass_to_activity = False
|
||||||
with _ba.Context(self):
|
with _ba.Context(self):
|
||||||
_ba.screenmessage(
|
_ba.screenmessage(
|
||||||
|
|||||||
@ -179,6 +179,8 @@ class EliminationGame(ba.TeamGameActivity[Player, Team]):
|
|||||||
# Show messages when players die since it's meaningful here.
|
# Show messages when players die since it's meaningful here.
|
||||||
announce_player_deaths = True
|
announce_player_deaths = True
|
||||||
|
|
||||||
|
allow_mid_activity_joins = False
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_available_settings(
|
def get_available_settings(
|
||||||
cls, sessiontype: Type[ba.Session]) -> List[ba.Setting]:
|
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'
|
self.session, ba.DualTeamSession) else 'last one standing wins'
|
||||||
|
|
||||||
def on_player_join(self, player: Player) -> None:
|
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
|
player.lives = self._lives_per_player
|
||||||
|
|
||||||
if self._solo_mode:
|
if self._solo_mode:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user