diff options
Diffstat (limited to 'godot/scripts/GameBase.gd')
| -rw-r--r-- | godot/scripts/GameBase.gd | 58 |
1 files changed, 38 insertions, 20 deletions
diff --git a/godot/scripts/GameBase.gd b/godot/scripts/GameBase.gd index e77d070..477e44e 100644 --- a/godot/scripts/GameBase.gd +++ b/godot/scripts/GameBase.gd @@ -2,16 +2,18 @@ extends Spatial var client var client_id: int -var is_local = false +var is_local: bool = false +var is_host: bool = false var local_server_tree = null -var player_name : String -var player_team : String +var player_name : String = "Player" +var player_team : int = -1 #-1 = spec var player_char = null onready var cam: ClippedCamera = $PLAYERCAM onready var hud = $HUD var players_info = {} #dictionary of id : name, team, ping, etc. +var teams_info = {-1: "SPEC"} #dictionary of teams for given server var is_chatting: bool = false @@ -21,6 +23,14 @@ signal screen_shake(location, strength, time) func _ready(): connect("screen_shake", self, "shake_cam") + if !is_local and !is_host: #if connecting to external server + NavigationServer.set_active(false) + elif !is_local and is_host: #dedicated server + remove_child($HUD) + remove_child($PLAYERCAM) + else: #local server + players_info[1] = ["Player", "SPEC"] + cam.attach($DEFAULTCAM, "STATIC", NodePath(".")) func shake_cam(loc, strength, time): var dist: float = (cam.global_transform.origin - loc).length() @@ -29,20 +39,17 @@ func shake_cam(loc, strength, time): cam.shake(strength, time) func _process(delta): - $HUD/Health.text = str(player_char.health) if player_char != null else "" - if is_local: - local_server_tree.call("idle",delta) + if is_local or !is_host: + $HUD/Health.text = str(player_char.health) if player_char != null else "" func _physics_process(delta): - if is_local: - local_server_tree.call("iteration", delta) + pass remote func set_up_server_info(info): $HUD/ServerJoinMenu/MOTD.text = info["MOTD"] $HUD/ServerJoinMenu/ServerName.text = info["server_name"] $DEFAULTCAM.transform = info["cam_pos"] cam.attach($DEFAULTCAM, "STATIC", NodePath(".")) - rpc_id(1, "_call_on_server", "_client_connection_confirmed", {"id" : client_id, "username" : player_name}) @@ -62,31 +69,41 @@ remote func load_entities(entity_info): #machines, players, and projectiles ent.transform = entity["transform"] ent.mp_init(entity["init_info"]) -remote func update_players_info(info): +remotesync func _call_on_server(function, arguments): + if get_network_master() != 1: return + print('Remote server call: ' + function) + $Server.call(function, arguments) + +remotesync func update_players_info(info): + players_info = info + if is_host and !is_local: return $HUD/ServerJoinMenu/Team1Players.text = "" $HUD/ServerJoinMenu/Team2Players.text = "" $HUD/ServerJoinMenu/Spectators.text = "" - players_info = info for player in players_info.keys(): var p_team = players_info[player][1] var p_name = players_info[player][0] - if p_team == "RED": + if p_team == 0: $HUD/ServerJoinMenu/Team1Players.text += p_name + ", " - elif p_team == "BLUE": + elif p_team == 1: $HUD/ServerJoinMenu/Team2Players.text += p_name + ", " - elif p_team == "SPEC": + elif p_team == -1: $HUD/ServerJoinMenu/Spectators.text += p_name + ", " -remote func game_update_chars(): +remotesync func game_update_chars(): + if is_host and !is_local: return $HUD.update_characters() -remote func game_chat_msg(msg): +remotesync func game_chat_msg(msg): + if is_host and !is_local: return $HUD.ui_chat_msg(msg) remotesync func game_hitsound(): + if is_host and !is_local: return $HUD.ui_play_hitsound() remotesync func game_killsound(): + if is_host and !is_local: return $HUD.ui_play_killsound() func request_select_character(dest): @@ -96,12 +113,13 @@ func request_select_character(dest): rpc_id(1, "_call_on_server", "_client_request_change_character", {"id" : client_id, "current_char_name" : player_char.name, "char_name" : dest}) func client_disconnect(): - if player_char != null: + if player_char != null: player_char.deselect_character() - client.close_connection() if is_local: - local_server_tree.get_root().get_node("GAMEWORLD/Server").stop_server() - local_server_tree.free() + $Server.stop_server() + else: + client.close_connection() + back_to_main() func _connection_lost(): |
