mirror of
https://github.com/RYDE-WORK/ballistica.git
synced 2026-02-01 20:33:46 +08:00
ctf fix implementation
This commit is contained in:
parent
8f8a32d24d
commit
d1defe0558
@ -519,6 +519,26 @@ class CaptureTheFlagGame(bs.TeamGameActivity[Player, Team]):
|
|||||||
if team.flag_return_touches < 0:
|
if team.flag_return_touches < 0:
|
||||||
logging.exception('CTF 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:
|
def _flash_base(self, team: Team, length: float = 2.0) -> None:
|
||||||
light = bs.newnode(
|
light = bs.newnode(
|
||||||
'light',
|
'light',
|
||||||
@ -579,6 +599,7 @@ class CaptureTheFlagGame(bs.TeamGameActivity[Player, Team]):
|
|||||||
def handlemessage(self, msg: Any) -> Any:
|
def handlemessage(self, msg: Any) -> Any:
|
||||||
if isinstance(msg, bs.PlayerDiedMessage):
|
if isinstance(msg, bs.PlayerDiedMessage):
|
||||||
super().handlemessage(msg) # Augment standard behavior.
|
super().handlemessage(msg) # Augment standard behavior.
|
||||||
|
self._handle_death_flag_capture(msg.getplayer(Player))
|
||||||
self.respawn_player(msg.getplayer(Player))
|
self.respawn_player(msg.getplayer(Player))
|
||||||
|
|
||||||
elif isinstance(msg, FlagDiedMessage):
|
elif isinstance(msg, FlagDiedMessage):
|
||||||
@ -605,3 +626,7 @@ class CaptureTheFlagGame(bs.TeamGameActivity[Player, Team]):
|
|||||||
|
|
||||||
else:
|
else:
|
||||||
super().handlemessage(msg)
|
super().handlemessage(msg)
|
||||||
|
|
||||||
|
def on_player_leave(self, player: Player) -> None:
|
||||||
|
"""Prevents leaving players from capturing their flag."""
|
||||||
|
self._handle_death_flag_capture(player)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user