From d1defe0558f3d48e00a50493077e2f86d4534be0 Mon Sep 17 00:00:00 2001 From: TrialTemp Date: Fri, 5 Jan 2024 21:53:29 -0600 Subject: [PATCH] ctf fix implementation --- .../bascenev1lib/game/capturetheflag.py | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/assets/ba_data/python/bascenev1lib/game/capturetheflag.py b/src/assets/ba_data/python/bascenev1lib/game/capturetheflag.py index 4e5da2d6..4e615e23 100644 --- a/src/assets/ba_data/python/bascenev1lib/game/capturetheflag.py +++ b/src/assets/ba_data/python/bascenev1lib/game/capturetheflag.py @@ -519,6 +519,26 @@ class CaptureTheFlagGame(bs.TeamGameActivity[Player, Team]): if team.flag_return_touches < 0: logging.exception('CTF flag_return_touches < 0') + def _handle_death_flag_capture(self, player: Player) -> None: + """Handles flag values when a player dies or leaves the game.""" + # Don't do anything if the player hasn't touched the flag at all. + if not player.touching_own_flag: return + + team = player.team + # For each "point" our player has touched the flag (Could be multiple), + # deduct one from both our player and the flag's return touches variable. + for _ in range(player.touching_own_flag): + # Deduct + player.touching_own_flag -= 1 + team.flag_return_touches -= 1 + # Update our flag's timer accordingly (Prevents immediate resets in case there might be more people touching it). + if team.flag_return_touches == 0: + team.touch_return_timer = None + team.touch_return_timer_ticking = None + # Safety check, just to be sure! + if team.flag_return_touches < 0: + logging.exception('CTF flag_return_touches < 0') + def _flash_base(self, team: Team, length: float = 2.0) -> None: light = bs.newnode( 'light', @@ -579,6 +599,7 @@ class CaptureTheFlagGame(bs.TeamGameActivity[Player, Team]): def handlemessage(self, msg: Any) -> Any: if isinstance(msg, bs.PlayerDiedMessage): super().handlemessage(msg) # Augment standard behavior. + self._handle_death_flag_capture(msg.getplayer(Player)) self.respawn_player(msg.getplayer(Player)) elif isinstance(msg, FlagDiedMessage): @@ -605,3 +626,7 @@ class CaptureTheFlagGame(bs.TeamGameActivity[Player, Team]): else: super().handlemessage(msg) + + def on_player_leave(self, player: Player) -> None: + """Prevents leaving players from capturing their flag.""" + self._handle_death_flag_capture(player)