Merge pull request #648 from 3alTemp/ctf_fix

CTF Ghost capturing fix 🚩
This commit is contained in:
Eric Froemling 2024-03-01 20:04:29 -08:00 committed by GitHub
commit abac38a542
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 32 additions and 0 deletions

View File

@ -29,6 +29,8 @@
brostos!).
- Fixes a bug where Meteor Shower could make the game-end bell sound twice
(Thanks 3alTemp!).
- Leaving the game or dying while touching your team's flag will no longer recover
& return it indefinitely in a teams game of Capture the Flag. (Thanks 3alTemp!)
### 1.7.32 (build 21741, api 8, 2023-12-20)
- Fixed a screen message that no one will ever see (Thanks vishal332008?...)

View File

@ -529,6 +529,30 @@ 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 theflag (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',
@ -591,6 +615,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):
@ -617,3 +642,8 @@ class CaptureTheFlagGame(bs.TeamGameActivity[Player, Team]):
else:
super().handlemessage(msg)
@override
def on_player_leave(self, player: Player) -> None:
"""Prevents leaving players from capturing their flag."""
self._handle_death_flag_capture(player)