Team switch on half rounds

This commit is contained in:
Rendo 2025-12-07 15:41:25 +05:00
commit 72bfd798da
2 changed files with 47 additions and 0 deletions

View file

@ -78,6 +78,20 @@ func set_teams(attack: Array[int],defence: Array[int],spectators: Array[int]):
func switch_team(team: int) -> void:
team_switch_notification.rpc(multiplayer.get_unique_id(),team)
func swap_teams() -> void:
if not multiplayer.is_server():
return
var temp_defenders = defence_team.duplicate()
for attacker in attack_team:
server_team_switch.rpc(attacker,Session.TEAMS.DEFENCE)
for defender in temp_defenders:
server_team_switch.rpc(defender,Session.TEAMS.ATTACK)
update_peers.rpc()
@rpc("any_peer","call_local","reliable")
func team_switch_notification(id: int, team: int) -> void:
if (team == Session.TEAMS.DEFENCE and len(defence_team) > 4) or (team == Session.TEAMS.ATTACK and len(attack_team) > 4):
@ -105,6 +119,32 @@ func team_switch_notification(id: int, team: int) -> void:
update_teams_state.emit()
@rpc("authority","call_local","reliable")
func server_team_switch(id: int, team: int) -> void:
if multiplayer.get_remote_sender_id() != 1 and not multiplayer.is_server():
return
if team == Session.TEAMS.DEFENCE:
if attack_team.has(id):
attack_team.erase(id)
if specators_team.has(id):
specators_team.erase(id)
defence_team.append(id)
if team == Session.TEAMS.ATTACK:
if defence_team.has(id):
defence_team.erase(id)
if specators_team.has(id):
specators_team.erase(id)
attack_team.append(id)
if team == Session.TEAMS.SPECTATE:
if attack_team.has(id):
attack_team.erase(id)
elif defence_team.has(id):
defence_team.erase(id)
specators_team.append(id)
@rpc("authority","call_local","reliable")
func start_game() -> void:
get_tree().change_scene_to_file("res://levels/prototype_scene.tscn")
@ -121,3 +161,7 @@ func get_team() -> Session.TEAMS:
if specators_team.has(id):
return Session.TEAMS.SPECTATE
return Session.TEAMS.UNASSIGNED
@rpc("authority","call_local","reliable")
func update_peers():
update_teams_state.emit()

View file

@ -141,12 +141,15 @@ func end_round(win_team: int) -> void:
if multiplayer.is_server():
get_tree().create_timer(5).timeout.connect(start_round)
end_round.rpc(win_team)
if current_round == Lobby.half_rounds:
Lobby.swap_teams()
if win_team == TEAMS.DEFENCE:
defender_score += 1
elif win_team == TEAMS.ATTACK:
attacker_score += 1
round_state = ROUND_STATES.AFTER_ROUND
round_state_changed.emit(round_state)