shuffle and team control
This commit is contained in:
parent
faa7745257
commit
13cfa692ce
4 changed files with 59 additions and 10 deletions
|
|
@ -7,6 +7,7 @@ func _ready() -> void:
|
||||||
%TeamSwitchBox.set_value_no_signal(LobbySettings.half_rounds)
|
%TeamSwitchBox.set_value_no_signal(LobbySettings.half_rounds)
|
||||||
%RoundBox.set_value_no_signal(LobbySettings.win_score)
|
%RoundBox.set_value_no_signal(LobbySettings.win_score)
|
||||||
%AllowMultipleAbilityButton.set_pressed_no_signal(LobbySettings.allow_multiple_abilities)
|
%AllowMultipleAbilityButton.set_pressed_no_signal(LobbySettings.allow_multiple_abilities)
|
||||||
|
%AllowTeamSwitch.set_pressed_no_signal(LobbySettings.allow_team_switch)
|
||||||
|
|
||||||
func _on_round_time_box_value_changed(value: float) -> void:
|
func _on_round_time_box_value_changed(value: float) -> void:
|
||||||
LobbySettings.round_time = value
|
LobbySettings.round_time = value
|
||||||
|
|
@ -31,3 +32,11 @@ func _on_team_switch_box_value_changed(value: float) -> void:
|
||||||
|
|
||||||
func _on_allow_multiple_ability_button_toggled(toggled_on: bool) -> void:
|
func _on_allow_multiple_ability_button_toggled(toggled_on: bool) -> void:
|
||||||
LobbySettings.allow_multiple_abilities = toggled_on
|
LobbySettings.allow_multiple_abilities = toggled_on
|
||||||
|
|
||||||
|
|
||||||
|
func _on_shuffle_pressed() -> void:
|
||||||
|
Lobby.shuffle_teams()
|
||||||
|
|
||||||
|
|
||||||
|
func _on_allow_team_switch_toggled(toggled_on: bool) -> void:
|
||||||
|
LobbySettings.allow_team_switch = toggled_on
|
||||||
|
|
|
||||||
|
|
@ -143,7 +143,16 @@ script = ExtResource("3_f5ibf")
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
title = "Команды"
|
title = "Команды"
|
||||||
|
|
||||||
[node name="Shuffle" type="Button" parent="Teams"]
|
[node name="VBoxContainer" type="VBoxContainer" parent="Teams"]
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="AllowTeamSwitch" type="CheckButton" parent="Teams/VBoxContainer"]
|
||||||
|
unique_name_in_owner = true
|
||||||
|
layout_mode = 2
|
||||||
|
text = "Разрешить смену команд"
|
||||||
|
autowrap_mode = 2
|
||||||
|
|
||||||
|
[node name="Shuffle" type="Button" parent="Teams/VBoxContainer"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
text = "Перемешать"
|
text = "Перемешать"
|
||||||
|
|
||||||
|
|
@ -154,3 +163,5 @@ text = "Перемешать"
|
||||||
[connection signal="value_changed" from="Round/VBoxContainer/TeamSwitchAmount/TeamSwitchBox" to="." method="_on_team_switch_box_value_changed"]
|
[connection signal="value_changed" from="Round/VBoxContainer/TeamSwitchAmount/TeamSwitchBox" to="." method="_on_team_switch_box_value_changed"]
|
||||||
[connection signal="toggled" from="Gameplay/AllowMultipleAbilityButton" to="." method="_on_allow_multiple_ability_button_toggled"]
|
[connection signal="toggled" from="Gameplay/AllowMultipleAbilityButton" to="." method="_on_allow_multiple_ability_button_toggled"]
|
||||||
[connection signal="update_ip" from="PortForward/PortForwardContainer/ForwardPortButton" to="PortForward/PortForwardContainer/PublicIP" method="on_update_ip"]
|
[connection signal="update_ip" from="PortForward/PortForwardContainer/ForwardPortButton" to="PortForward/PortForwardContainer/PublicIP" method="on_update_ip"]
|
||||||
|
[connection signal="toggled" from="Teams/VBoxContainer/AllowTeamSwitch" to="." method="_on_allow_team_switch_toggled"]
|
||||||
|
[connection signal="pressed" from="Teams/VBoxContainer/Shuffle" to="." method="_on_shuffle_pressed"]
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,7 @@ func set_teams(attack: Array[int],defence: Array[int],spectators: Array[int]):
|
||||||
set_teams.rpc(attack,defence,spectators)
|
set_teams.rpc(attack,defence,spectators)
|
||||||
|
|
||||||
func switch_team(team: int) -> void:
|
func switch_team(team: int) -> void:
|
||||||
team_switch_notification.rpc(multiplayer.get_unique_id(),team)
|
team_switch_notification.rpc_id(1,team)
|
||||||
|
|
||||||
func swap_teams() -> void:
|
func swap_teams() -> void:
|
||||||
if not is_multiplayer_authority():
|
if not is_multiplayer_authority():
|
||||||
|
|
@ -86,10 +86,41 @@ func swap_teams() -> void:
|
||||||
|
|
||||||
set_teams(defence_team,attack_team,specators_team)
|
set_teams(defence_team,attack_team,specators_team)
|
||||||
|
|
||||||
@rpc("any_peer","call_local","reliable")
|
func shuffle_teams() -> void:
|
||||||
func team_switch_notification(id: int, team: int) -> void:
|
if not is_multiplayer_authority():
|
||||||
if (team == Session.TEAMS.DEFENCE and len(defence_team) > 4) or (team == Session.TEAMS.ATTACK and len(attack_team) > 4):
|
|
||||||
return
|
return
|
||||||
|
var peers: Array = Array(multiplayer.get_peers())
|
||||||
|
peers.append(1)
|
||||||
|
|
||||||
|
var new_attack_team: Array[int] = []
|
||||||
|
var new_defence_team: Array[int] = []
|
||||||
|
var new_spectator_team: Array[int] = []
|
||||||
|
|
||||||
|
while len(new_attack_team) < 5 and len(new_defence_team) < 5:
|
||||||
|
if len(peers) == 0:
|
||||||
|
break
|
||||||
|
var picked_peer = peers.pop_at(randi_range(0,len(peers)-1))
|
||||||
|
var picked_team = randi_range(0,1)
|
||||||
|
match picked_team:
|
||||||
|
Session.TEAMS.DEFENCE:
|
||||||
|
if len(new_defence_team) < 5:
|
||||||
|
new_defence_team.append(picked_peer)
|
||||||
|
else:
|
||||||
|
new_attack_team.append(picked_peer)
|
||||||
|
Session.TEAMS.ATTACK:
|
||||||
|
if len(new_attack_team) < 5:
|
||||||
|
new_attack_team.append(picked_peer)
|
||||||
|
else:
|
||||||
|
new_defence_team.append(picked_peer)
|
||||||
|
|
||||||
|
new_spectator_team.append_array(peers)
|
||||||
|
set_teams(new_attack_team,new_defence_team,new_spectator_team)
|
||||||
|
|
||||||
|
@rpc("any_peer","call_local","reliable")
|
||||||
|
func team_switch_notification(team: int) -> void:
|
||||||
|
if not is_multiplayer_authority() or (team == Session.TEAMS.DEFENCE and len(defence_team) > 4) or (team == Session.TEAMS.ATTACK and len(attack_team) > 4) or not LobbySettings.allow_team_switch:
|
||||||
|
return
|
||||||
|
var id: int = multiplayer.get_remote_sender_id()
|
||||||
if team == Session.TEAMS.DEFENCE:
|
if team == Session.TEAMS.DEFENCE:
|
||||||
if attack_team.has(id):
|
if attack_team.has(id):
|
||||||
attack_team.erase(id)
|
attack_team.erase(id)
|
||||||
|
|
@ -112,6 +143,7 @@ func team_switch_notification(id: int, team: int) -> void:
|
||||||
specators_team.append(id)
|
specators_team.append(id)
|
||||||
|
|
||||||
update_teams_state.emit()
|
update_teams_state.emit()
|
||||||
|
set_teams.rpc(attack_team,defence_team,specators_team)
|
||||||
|
|
||||||
func start_game() -> void:
|
func start_game() -> void:
|
||||||
if not multiplayer.is_server():
|
if not multiplayer.is_server():
|
||||||
|
|
@ -129,7 +161,3 @@ func get_team() -> Session.TEAMS:
|
||||||
if specators_team.has(id):
|
if specators_team.has(id):
|
||||||
return Session.TEAMS.SPECTATE
|
return Session.TEAMS.SPECTATE
|
||||||
return Session.TEAMS.UNASSIGNED
|
return Session.TEAMS.UNASSIGNED
|
||||||
|
|
||||||
@rpc("authority","call_local","reliable")
|
|
||||||
func update_peers():
|
|
||||||
update_teams_state.emit()
|
|
||||||
|
|
|
||||||
|
|
@ -6,3 +6,4 @@ var bomb_time: float = 45.0
|
||||||
var buy_time: float = 15.0
|
var buy_time: float = 15.0
|
||||||
var round_time: float = 150.0
|
var round_time: float = 150.0
|
||||||
var allow_multiple_abilities: bool = false
|
var allow_multiple_abilities: bool = false
|
||||||
|
var allow_team_switch: bool = true
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue