forked from interstellar_development/freeftf
Milestone 7 Beta 1
Redid the entire serverside and clientside, matchmaking is finally out, bugfixes.
This commit is contained in:
parent
9de67986dd
commit
699320353a
16 changed files with 324 additions and 266 deletions
File diff suppressed because one or more lines are too long
|
@ -33,14 +33,6 @@ theme_override_font_sizes/font_size = 96
|
||||||
text = "FreeFTF"
|
text = "FreeFTF"
|
||||||
horizontal_alignment = 1
|
horizontal_alignment = 1
|
||||||
|
|
||||||
[node name="create" type="Button" parent="main_content"]
|
|
||||||
visible = false
|
|
||||||
layout_mode = 2
|
|
||||||
size_flags_vertical = 0
|
|
||||||
theme_override_font_sizes/font_size = 32
|
|
||||||
disabled = true
|
|
||||||
text = "Create Lobby"
|
|
||||||
|
|
||||||
[node name="join" type="Button" parent="main_content"]
|
[node name="join" type="Button" parent="main_content"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
size_flags_vertical = 8
|
size_flags_vertical = 8
|
||||||
|
@ -74,10 +66,9 @@ grow_vertical = 0
|
||||||
[node name="Label" type="Label" parent="ver_string"]
|
[node name="Label" type="Label" parent="ver_string"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
theme_override_font_sizes/font_size = 32
|
theme_override_font_sizes/font_size = 32
|
||||||
text = "M6 B2"
|
text = "M7 B1"
|
||||||
horizontal_alignment = 2
|
horizontal_alignment = 2
|
||||||
|
|
||||||
[connection signal="pressed" from="main_content/create" to="." method="_on_create_pressed"]
|
|
||||||
[connection signal="pressed" from="main_content/join" to="." method="_on_join_pressed"]
|
[connection signal="pressed" from="main_content/join" to="." method="_on_join_pressed"]
|
||||||
[connection signal="pressed" from="main_content/settings" to="." method="_on_settings_pressed"]
|
[connection signal="pressed" from="main_content/settings" to="." method="_on_settings_pressed"]
|
||||||
[connection signal="pressed" from="main_content/matchmaking" to="." method="_on_matchmaking_pressed"]
|
[connection signal="pressed" from="main_content/matchmaking" to="." method="_on_matchmaking_pressed"]
|
||||||
|
|
|
@ -16,8 +16,10 @@ config/features=PackedStringArray("4.2", "Forward Plus")
|
||||||
|
|
||||||
[autoload]
|
[autoload]
|
||||||
|
|
||||||
Game="*res://scripts/game.gd"
|
Matchmaking="*res://scripts/matchmaking.gd"
|
||||||
Server="*res://scripts/server.gd"
|
Server="*res://scripts/server.gd"
|
||||||
|
Client="*res://scripts/client.gd"
|
||||||
|
Game="*res://scripts/game.gd"
|
||||||
Save="*res://scripts/save.gd"
|
Save="*res://scripts/save.gd"
|
||||||
Load="*res://scripts/load.gd"
|
Load="*res://scripts/load.gd"
|
||||||
|
|
||||||
|
|
101
scripts/client.gd
Normal file
101
scripts/client.gd
Normal file
|
@ -0,0 +1,101 @@
|
||||||
|
## freeftf
|
||||||
|
## Copyright (C) 2024 Patrick_Pluto
|
||||||
|
##
|
||||||
|
## This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
|
##
|
||||||
|
## This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
##
|
||||||
|
## You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
extends Node
|
||||||
|
|
||||||
|
var offline
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
offline = multiplayer.multiplayer_peer
|
||||||
|
multiplayer.server_disconnected.connect(_on_server_disconnected)
|
||||||
|
|
||||||
|
func join_game():
|
||||||
|
var peer = ENetMultiplayerPeer.new()
|
||||||
|
peer.create_client(Game.ip, Game.port)
|
||||||
|
multiplayer.multiplayer_peer = peer
|
||||||
|
|
||||||
|
func is_valid(sender_id, must_be_from_owner):
|
||||||
|
if must_be_from_owner:
|
||||||
|
if sender_id == Game.player_list.keys()[0] or Game.is_server:
|
||||||
|
return true
|
||||||
|
for id in Game.player_list:
|
||||||
|
if sender_id == id:
|
||||||
|
return true
|
||||||
|
if sender_id == 0 or sender_id == 1:
|
||||||
|
return true
|
||||||
|
return false
|
||||||
|
|
||||||
|
func _on_server_disconnected():
|
||||||
|
Game.reset()
|
||||||
|
get_tree().change_scene_to_file("res://menus/main_menu.tscn")
|
||||||
|
|
||||||
|
@rpc("authority","call_remote","reliable")
|
||||||
|
func _on_player_disconnected(id):
|
||||||
|
var x = 0
|
||||||
|
for i in Game.player_list:
|
||||||
|
if i == id:
|
||||||
|
var current_character = get_tree().root.get_node("./"+Game.map_name+"/player"+str(x))
|
||||||
|
if current_character.hp == 0:
|
||||||
|
Game.dead -= 1
|
||||||
|
elif current_character.is_frozen:
|
||||||
|
Game.frozen -= 1
|
||||||
|
elif current_character.beast:
|
||||||
|
Game.player_escaped = true
|
||||||
|
Game.players = 0
|
||||||
|
else:
|
||||||
|
Game.players -= 1
|
||||||
|
print("found")
|
||||||
|
await get_tree().create_timer(0.5).timeout
|
||||||
|
current_character.free()
|
||||||
|
print("freed")
|
||||||
|
x += 1
|
||||||
|
Game.player_list.erase(id)
|
||||||
|
|
||||||
|
@rpc("authority","call_remote","reliable")
|
||||||
|
func room_closed():
|
||||||
|
_on_server_disconnected()
|
||||||
|
|
||||||
|
@rpc("authority","call_remote","reliable")
|
||||||
|
func send_playerinfo():
|
||||||
|
Matchmaking.rpc_id(1,"recieve_playerinfo",Game.player_name,Game.room_name)
|
||||||
|
|
||||||
|
@rpc("authority","call_remote","reliable")
|
||||||
|
func get_player_list(server_player_list):
|
||||||
|
Game.player_list = server_player_list
|
||||||
|
|
||||||
|
@rpc("any_peer", "call_local", "reliable")
|
||||||
|
func start_game():
|
||||||
|
if is_valid(multiplayer.get_remote_sender_id(), true):
|
||||||
|
Game.start_game()
|
||||||
|
|
||||||
|
@rpc("any_peer", "call_local", "reliable")
|
||||||
|
func player_hit(target, beast):
|
||||||
|
if is_valid(multiplayer.get_remote_sender_id(), false):
|
||||||
|
Game.player_hit(target, beast)
|
||||||
|
|
||||||
|
@rpc("any_peer", "call_local", "unreliable")
|
||||||
|
func sync_player(node_name, position, rotation):
|
||||||
|
if is_valid(multiplayer.get_remote_sender_id(), false):
|
||||||
|
Game.sync_player(node_name, position, rotation)
|
||||||
|
|
||||||
|
@rpc("any_peer", "call_local", "unreliable")
|
||||||
|
func sync_hammer(node_name, rotation):
|
||||||
|
if is_valid(multiplayer.get_remote_sender_id(), false):
|
||||||
|
Game.sync_hammer(node_name, rotation)
|
||||||
|
|
||||||
|
@rpc("any_peer", "call_local", "reliable")
|
||||||
|
func sync_computers(node_name, current):
|
||||||
|
if is_valid(multiplayer.get_remote_sender_id(), true):
|
||||||
|
Game.sync_computers(node_name, current)
|
||||||
|
|
||||||
|
@rpc("any_peer", "call_local", "reliable")
|
||||||
|
func sync_beast(player):
|
||||||
|
if is_valid(multiplayer.get_remote_sender_id(), true):
|
||||||
|
Game.sync_beast(player)
|
||||||
|
|
|
@ -20,9 +20,10 @@ func _ready():
|
||||||
Game.computers += 1
|
Game.computers += 1
|
||||||
|
|
||||||
func _on_computer_tick_timeout():
|
func _on_computer_tick_timeout():
|
||||||
if Server.is_server:
|
if Game.is_server:
|
||||||
current += (pc_occupied[0] + pc_occupied[1] + pc_occupied[2])
|
current += (pc_occupied[0] + pc_occupied[1] + pc_occupied[2])
|
||||||
Server.sync_computers.rpc(name, current)
|
for id in Game.player_list:
|
||||||
|
Client.rpc_id(id,"sync_computers",name, current)
|
||||||
if current >= TARGET:
|
if current >= TARGET:
|
||||||
current = "Complete"
|
current = "Complete"
|
||||||
$computer_tick.stop()
|
$computer_tick.stop()
|
||||||
|
|
|
@ -10,45 +10,49 @@
|
||||||
extends Control
|
extends Control
|
||||||
|
|
||||||
var elevated = false
|
var elevated = false
|
||||||
|
var done
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
multiplayer.connected_to_server.connect(_on_connected_ok)
|
multiplayer.connected_to_server.connect(_on_connected_ok)
|
||||||
if Server.is_server:
|
|
||||||
|
func server_prepare():
|
||||||
|
if Game.is_server:
|
||||||
$player_customization/ip.hide()
|
$player_customization/ip.hide()
|
||||||
$player_customization/ip.text = "localhost"
|
$player_customization/ip.text = "localhost"
|
||||||
$player_customization/ip.editable = false
|
$player_customization/ip.editable = false
|
||||||
$start/start.show()
|
$start/start.show()
|
||||||
$start/start.disabled = false
|
$start/start.disabled = false
|
||||||
$player_list/list.text = " "
|
$player_list/list.text = " "
|
||||||
|
|
||||||
func _process(delta):
|
|
||||||
if Server.is_server:
|
|
||||||
Server.sync_playerlist.rpc($player_list/list.text, multiplayer.get_unique_id())
|
|
||||||
if Server.is_server and !elevated:
|
|
||||||
_ready()
|
|
||||||
Server.send_playerinfo($player_customization/name.text, multiplayer.get_unique_id())
|
|
||||||
elevated = true
|
|
||||||
|
|
||||||
func _on_start_pressed():
|
|
||||||
Server.start_game.rpc(Server.players)
|
|
||||||
|
|
||||||
func _input(event):
|
func _process(_delta):
|
||||||
|
server_prepare()
|
||||||
|
done = 0
|
||||||
|
for id in Game.player_list:
|
||||||
|
if done == 1:
|
||||||
|
$player_list/list.text = str($player_list/list.text +"\n" + Game.player_list[id])
|
||||||
|
else:
|
||||||
|
$player_list/list.text = Game.player_list[id]
|
||||||
|
done = 1
|
||||||
|
|
||||||
|
|
||||||
|
func _on_start_pressed():
|
||||||
|
for id in Game.player_list:
|
||||||
|
Client.rpc_id(id,"start_game")
|
||||||
|
|
||||||
|
func _input(_event):
|
||||||
if Input.is_action_just_pressed("escape"):
|
if Input.is_action_just_pressed("escape"):
|
||||||
Game.reset()
|
|
||||||
Server.reset()
|
|
||||||
get_tree().change_scene_to_file("res://menus/main_menu.tscn")
|
get_tree().change_scene_to_file("res://menus/main_menu.tscn")
|
||||||
|
|
||||||
|
|
||||||
func _on_join_pressed():
|
func _on_join_pressed():
|
||||||
if $player_customization/name.text != "" and $player_customization/name.text.length() <= 20 and $player_customization/ip.text != "":
|
if $player_customization/name.text != "" and $player_customization/name.text.length() <= 20 and $player_customization/ip.text != "":
|
||||||
if !Server.is_server:
|
Game.room_name = $player_customization/ip.text
|
||||||
Server.join_game($player_customization/ip.text)
|
Game.player_name = $player_customization/name.text
|
||||||
|
Client.join_game()
|
||||||
|
|
||||||
func _on_connected_ok():
|
func _on_connected_ok():
|
||||||
$player_customization/join.hide()
|
$player_customization/join.hide()
|
||||||
$player_customization/join.disabled = true
|
$player_customization/join.disabled = true
|
||||||
$player_customization/name.editable = false
|
$player_customization/name.editable = false
|
||||||
$player_customization/ip.editable = false
|
$player_customization/ip.editable = false
|
||||||
await get_tree().create_timer(1).timeout
|
|
||||||
Server.send_playerinfo.rpc($player_customization/name.text, multiplayer.get_unique_id())
|
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ var trapped_body
|
||||||
var occupied = false
|
var occupied = false
|
||||||
var living = true
|
var living = true
|
||||||
|
|
||||||
func _process(delta):
|
func _process(_delta):
|
||||||
if occupied:
|
if occupied:
|
||||||
trapped_body.position = global_position
|
trapped_body.position = global_position
|
||||||
if occupied and trapped_body.hp == 0 and living:
|
if occupied and trapped_body.hp == 0 and living:
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
extends Node
|
extends Node
|
||||||
|
|
||||||
var settings = {"save_version" = 2, "fps_counter" = 1}
|
var settings = {"save_version" = 2, "fps_counter" = 1, "port" = 35000, "ip" = "127.0.0.1"}
|
||||||
var computers = 0
|
var computers = 0
|
||||||
var players = 0
|
var players = 0
|
||||||
var map_name = "mansion"
|
var map_name = "mansion"
|
||||||
|
@ -19,6 +19,14 @@ var dead = 0
|
||||||
var escaped = 0
|
var escaped = 0
|
||||||
var player_escaped = false
|
var player_escaped = false
|
||||||
var is_beast = false
|
var is_beast = false
|
||||||
|
var character = preload("res://objects/player.tscn")
|
||||||
|
# Server Variables
|
||||||
|
var port = 35000
|
||||||
|
var ip = "127.0.0.1"
|
||||||
|
var player_name
|
||||||
|
var room_name
|
||||||
|
var is_server = false
|
||||||
|
var player_list = {}
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
if FileAccess.file_exists("user://settings.json"):
|
if FileAccess.file_exists("user://settings.json"):
|
||||||
|
@ -48,7 +56,7 @@ func has_escaped():
|
||||||
players -= 1
|
players -= 1
|
||||||
escaped += 1
|
escaped += 1
|
||||||
|
|
||||||
func _process(delta):
|
func _process(_delta):
|
||||||
if is_running and players <= 0:
|
if is_running and players <= 0:
|
||||||
get_tree().change_scene_to_file("res://menus/result.tscn")
|
get_tree().change_scene_to_file("res://menus/result.tscn")
|
||||||
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
|
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
|
||||||
|
@ -63,12 +71,62 @@ func reset():
|
||||||
escaped = 0
|
escaped = 0
|
||||||
player_escaped = false
|
player_escaped = false
|
||||||
is_beast = false
|
is_beast = false
|
||||||
|
player_name = null
|
||||||
|
player_list = {}
|
||||||
|
room_name = null
|
||||||
|
is_server = false
|
||||||
|
multiplayer.multiplayer_peer = Client.offline
|
||||||
|
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
|
||||||
|
|
||||||
func save_setting(setting_name, value):
|
func save_setting(setting_name, value):
|
||||||
settings[setting_name] = value
|
settings[setting_name] = value
|
||||||
Save.saveJSON("user://settings.json", settings)
|
Save.saveJSON("user://settings.json", settings)
|
||||||
|
|
||||||
func apply_settings():
|
func apply_settings():
|
||||||
players = Server.players_numbered.size() - 1
|
players = player_list.size() - 1
|
||||||
is_running = true
|
is_running = true
|
||||||
|
|
||||||
|
func start_game():
|
||||||
|
get_tree().change_scene_to_file("res://maps/"+map_name+".tscn")
|
||||||
|
while !get_tree().root.has_node("./"+map_name+"/"):
|
||||||
|
await get_tree().create_timer(0.001).timeout
|
||||||
|
var map = get_tree().root.get_node("./"+map_name+"/")
|
||||||
|
var i = 0
|
||||||
|
for w in player_list:
|
||||||
|
var player = character.instantiate()
|
||||||
|
player.name = "player" + str(i)
|
||||||
|
i += 1
|
||||||
|
player.position.z = -i*2.5
|
||||||
|
player.position.y = 1
|
||||||
|
map.add_child(player)
|
||||||
|
if is_server:
|
||||||
|
var random = randi() % player_list.size()
|
||||||
|
for id in player_list:
|
||||||
|
Client.rpc_id(id,"sync_beast",random)
|
||||||
|
apply_settings()
|
||||||
|
|
||||||
|
func player_hit(target, beast):
|
||||||
|
target = get_tree().root.get_node("./"+map_name+"/"+target)
|
||||||
|
beast = get_tree().root.get_node("./"+map_name+"/"+beast)
|
||||||
|
if !target.is_frozen:
|
||||||
|
target.captured(beast)
|
||||||
|
beast.got_one(target)
|
||||||
|
|
||||||
|
func sync_player(node_name, position, rotation):
|
||||||
|
var current_character = get_tree().root.get_node("./"+map_name+"/"+node_name)
|
||||||
|
current_character.position = position
|
||||||
|
current_character.rotation = rotation
|
||||||
|
|
||||||
|
func sync_hammer(node_name, rotation):
|
||||||
|
var current_character = get_tree().root.get_node("./"+map_name+"/"+node_name+"/hammer")
|
||||||
|
current_character.rotation = rotation
|
||||||
|
|
||||||
|
func sync_computers(node_name, current):
|
||||||
|
var current_character = get_tree().root.get_node("./"+map_name+"/computers/"+node_name)
|
||||||
|
current_character.current = current
|
||||||
|
|
||||||
|
func sync_beast(player):
|
||||||
|
while !get_tree().root.has_node("./"+map_name+"/player"+str(player)):
|
||||||
|
await get_tree().create_timer(0.001).timeout
|
||||||
|
var current_character = get_tree().root.get_node("./"+map_name+"/player"+str(player))
|
||||||
|
current_character.beast_init()
|
||||||
|
|
|
@ -13,7 +13,6 @@ extends Control
|
||||||
|
|
||||||
func _on_button_pressed():
|
func _on_button_pressed():
|
||||||
Game.reset()
|
Game.reset()
|
||||||
Server.reset()
|
|
||||||
get_tree().change_scene_to_file("res://menus/main_menu.tscn")
|
get_tree().change_scene_to_file("res://menus/main_menu.tscn")
|
||||||
queue_free()
|
queue_free()
|
||||||
|
|
||||||
|
|
|
@ -14,17 +14,12 @@ func matchmaking():
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
Game.reset()
|
Game.reset()
|
||||||
Server.reset()
|
|
||||||
if !OS.is_debug_build():
|
if !OS.is_debug_build():
|
||||||
$main_content/matchmaking.hide()
|
$main_content/matchmaking.hide()
|
||||||
$main_content/matchmaking.disabled = true
|
$main_content/matchmaking.disabled = true
|
||||||
if DisplayServer.get_name() == "headless":
|
if DisplayServer.get_name() == "headless":
|
||||||
_on_matchmaking_pressed()
|
_on_matchmaking_pressed()
|
||||||
|
|
||||||
func _on_create_pressed():
|
|
||||||
get_tree().change_scene_to_file("res://menus/create.tscn")
|
|
||||||
|
|
||||||
|
|
||||||
func _on_join_pressed():
|
func _on_join_pressed():
|
||||||
get_tree().change_scene_to_file("res://menus/create.tscn")
|
get_tree().change_scene_to_file("res://menus/create.tscn")
|
||||||
|
|
||||||
|
@ -35,6 +30,6 @@ func _on_settings_pressed():
|
||||||
|
|
||||||
|
|
||||||
func _on_matchmaking_pressed():
|
func _on_matchmaking_pressed():
|
||||||
Server.create_game()
|
Matchmaking.create_game()
|
||||||
matchmaking()
|
matchmaking()
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,6 @@
|
||||||
extends Control
|
extends Control
|
||||||
|
|
||||||
|
|
||||||
func _process(delta):
|
func _process(_delta):
|
||||||
if Input.is_action_just_pressed("escape"):
|
if Input.is_action_just_pressed("escape"):
|
||||||
get_tree().change_scene_to_file("res://menus/main_menu.tscn")
|
get_tree().change_scene_to_file("res://menus/main_menu.tscn")
|
||||||
|
|
70
scripts/matchmaking.gd
Normal file
70
scripts/matchmaking.gd
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
## freeftf
|
||||||
|
## Copyright (C) 2024 Patrick_Pluto
|
||||||
|
##
|
||||||
|
## This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
|
##
|
||||||
|
## This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
##
|
||||||
|
## You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
extends Node
|
||||||
|
|
||||||
|
const PORT = 35000
|
||||||
|
const MAX_CONNECTIONS = 256
|
||||||
|
|
||||||
|
var game_rooms = {}
|
||||||
|
var player_associations = {}
|
||||||
|
var name_associations = {}
|
||||||
|
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
multiplayer.peer_disconnected.connect(_on_player_disconnected)
|
||||||
|
multiplayer.peer_connected.connect(_on_player_connected)
|
||||||
|
|
||||||
|
func create_game():
|
||||||
|
var peer = ENetMultiplayerPeer.new()
|
||||||
|
var error = peer.create_server(PORT, MAX_CONNECTIONS)
|
||||||
|
if error:
|
||||||
|
return error
|
||||||
|
multiplayer.multiplayer_peer = peer
|
||||||
|
|
||||||
|
func _on_player_disconnected(id):
|
||||||
|
if multiplayer.is_server():
|
||||||
|
var room_name = player_associations[id]
|
||||||
|
var player_list = create_player_list(room_name)
|
||||||
|
if game_rooms.has(room_name) and game_rooms[room_name] == id:
|
||||||
|
for p in player_list:
|
||||||
|
Client.rpc_id(p,"room_closed")
|
||||||
|
game_rooms.erase(room_name)
|
||||||
|
else:
|
||||||
|
for p in player_list:
|
||||||
|
Client.rpc_id(p,"_on_player_disconnected",id)
|
||||||
|
player_associations.erase(id)
|
||||||
|
name_associations.erase(id)
|
||||||
|
|
||||||
|
func _on_player_connected(id):
|
||||||
|
if multiplayer.is_server():
|
||||||
|
Client.rpc_id(id,"send_playerinfo")
|
||||||
|
|
||||||
|
func create_player_list(room_name):
|
||||||
|
var player_list = {}
|
||||||
|
for player in player_associations:
|
||||||
|
if player_associations[player] == room_name:
|
||||||
|
player_list[player] = name_associations[player]
|
||||||
|
return player_list
|
||||||
|
|
||||||
|
@rpc("any_peer","call_remote","reliable")
|
||||||
|
func recieve_playerinfo(player_name, room_name):
|
||||||
|
var exists = false
|
||||||
|
var id = multiplayer.get_remote_sender_id()
|
||||||
|
for game_room in game_rooms:
|
||||||
|
if game_room == room_name:
|
||||||
|
exists = true
|
||||||
|
player_associations[id] = room_name
|
||||||
|
name_associations[id] = player_name
|
||||||
|
if !exists:
|
||||||
|
game_rooms[room_name] = id
|
||||||
|
Server.rpc_id(id,"elevate")
|
||||||
|
var player_list = create_player_list(room_name)
|
||||||
|
for p in player_list:
|
||||||
|
Client.rpc_id(p,"get_player_list",player_list)
|
|
@ -10,7 +10,7 @@
|
||||||
extends CharacterBody3D
|
extends CharacterBody3D
|
||||||
|
|
||||||
|
|
||||||
var jump_velocity = 6
|
var jump_velocity = 12
|
||||||
var speed = 7
|
var speed = 7
|
||||||
var zoom = 0
|
var zoom = 0
|
||||||
var player_no
|
var player_no
|
||||||
|
@ -32,9 +32,9 @@ var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
player_no = Game.players
|
player_no = Game.players
|
||||||
$nametag.text = Server.players[Server.players_numbered[player_no]]
|
$nametag.text = Game.player_list[Game.player_list.keys()[player_no]]
|
||||||
Game.players += 1
|
Game.players += 1
|
||||||
if Server.players_numbered[player_no] == multiplayer.get_unique_id():
|
if Game.player_list.keys()[player_no] == multiplayer.get_unique_id():
|
||||||
if Game.settings["fps_counter"] == 1:
|
if Game.settings["fps_counter"] == 1:
|
||||||
$fps_counter.show()
|
$fps_counter.show()
|
||||||
$health.show()
|
$health.show()
|
||||||
|
@ -49,12 +49,7 @@ func _physics_process(delta):
|
||||||
|
|
||||||
if not is_on_floor():
|
if not is_on_floor():
|
||||||
velocity.y -= gravity * delta
|
velocity.y -= gravity * delta
|
||||||
|
|
||||||
if Input.is_action_just_pressed("jump") and is_on_floor() and $jump_timeout.is_stopped():
|
|
||||||
if beast:
|
|
||||||
speed -= 5
|
|
||||||
$jump_timeout.start()
|
|
||||||
velocity.y = jump_velocity
|
|
||||||
|
|
||||||
if Input.is_action_just_pressed("crouch") and !beast:
|
if Input.is_action_just_pressed("crouch") and !beast:
|
||||||
if $collision.rotation.x == 0:
|
if $collision.rotation.x == 0:
|
||||||
|
@ -69,10 +64,12 @@ func _physics_process(delta):
|
||||||
|
|
||||||
if Input.is_action_pressed("click") and $hammer.rotation_degrees.x > -90:
|
if Input.is_action_pressed("click") and $hammer.rotation_degrees.x > -90:
|
||||||
$hammer.rotation_degrees.x -= 5
|
$hammer.rotation_degrees.x -= 5
|
||||||
Server.sync_hammer.rpc(name, $hammer.rotation)
|
for id in Game.player_list:
|
||||||
|
Client.rpc_id(id,"sync_hammer",name, $hammer.rotation)
|
||||||
elif $hammer.rotation_degrees.x < 0 and !Input.is_action_pressed("click"):
|
elif $hammer.rotation_degrees.x < 0 and !Input.is_action_pressed("click"):
|
||||||
$hammer.rotation_degrees.x += 5
|
$hammer.rotation_degrees.x += 5
|
||||||
Server.sync_hammer.rpc(name, $hammer.rotation)
|
for id in Game.player_list:
|
||||||
|
Client.rpc_id(id,"sync_hammer",name, $hammer.rotation)
|
||||||
|
|
||||||
var input_dir = Input.get_vector("left", "right", "forwards", "backwards")
|
var input_dir = Input.get_vector("left", "right", "forwards", "backwards")
|
||||||
var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
|
var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
|
||||||
|
@ -83,10 +80,20 @@ func _physics_process(delta):
|
||||||
velocity.x = move_toward(velocity.x, 0, speed)
|
velocity.x = move_toward(velocity.x, 0, speed)
|
||||||
velocity.z = move_toward(velocity.z, 0, speed)
|
velocity.z = move_toward(velocity.z, 0, speed)
|
||||||
|
|
||||||
|
if Input.is_action_just_pressed("jump") and is_on_floor() and $jump_timeout.is_stopped():
|
||||||
|
if beast:
|
||||||
|
speed -= 5
|
||||||
|
$jump_timeout.start()
|
||||||
|
if velocity.x == 0 or velocity.y == 0:
|
||||||
|
velocity.y = jump_velocity
|
||||||
|
else:
|
||||||
|
velocity.y = jump_velocity/2
|
||||||
|
|
||||||
move_and_slide()
|
move_and_slide()
|
||||||
|
|
||||||
if !npc:
|
if !npc:
|
||||||
Server.sync_player.rpc(name, position, rotation)
|
for id in Game.player_list:
|
||||||
|
Client.rpc_id(id,"sync_player",name, position, rotation)
|
||||||
if mouse_locked and !has_node("./game_menu"):
|
if mouse_locked and !has_node("./game_menu"):
|
||||||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||||
else:
|
else:
|
||||||
|
@ -133,7 +140,8 @@ func beast_init():
|
||||||
|
|
||||||
func _on_detect_hit_body_entered(body):
|
func _on_detect_hit_body_entered(body):
|
||||||
if enabled and body is CharacterBody3D and !got_person:
|
if enabled and body is CharacterBody3D and !got_person:
|
||||||
Server.player_hit.rpc(body.name, name)
|
for id in Game.player_list:
|
||||||
|
Client.rpc_id(id,"player_hit",body.name, name)
|
||||||
|
|
||||||
func captured(beast2):
|
func captured(beast2):
|
||||||
if !npc:
|
if !npc:
|
||||||
|
|
|
@ -16,6 +16,6 @@ func _ready():
|
||||||
$VBoxContainer/Label.text = "You Lose"
|
$VBoxContainer/Label.text = "You Lose"
|
||||||
|
|
||||||
|
|
||||||
func _process(delta):
|
func _process(_delta):
|
||||||
if Input.is_action_just_pressed("escape"):
|
if Input.is_action_just_pressed("escape"):
|
||||||
get_tree().change_scene_to_file("res://menus/main_menu.tscn")
|
get_tree().change_scene_to_file("res://menus/main_menu.tscn")
|
||||||
|
|
|
@ -9,177 +9,6 @@
|
||||||
|
|
||||||
extends Node
|
extends Node
|
||||||
|
|
||||||
const DEFAULT_SERVER_IP = "127.0.0.1"
|
|
||||||
const PORT = 36969
|
|
||||||
const MAX_CONNECTIONS = 16
|
|
||||||
|
|
||||||
var players = {}
|
|
||||||
var players_numbered = []
|
|
||||||
var label
|
|
||||||
var map
|
|
||||||
var character = preload("res://objects/player.tscn")
|
|
||||||
var is_server = false
|
|
||||||
var first_joined = true
|
|
||||||
var game_master = "debug"
|
|
||||||
var map_name = "mansion"
|
|
||||||
var offline
|
|
||||||
|
|
||||||
func _ready():
|
|
||||||
offline = multiplayer.multiplayer_peer
|
|
||||||
multiplayer.peer_disconnected.connect(_on_player_disconnected)
|
|
||||||
multiplayer.server_disconnected.connect(_on_server_disconnected)
|
|
||||||
|
|
||||||
func _on_player_disconnected(id):
|
|
||||||
players.erase(id)
|
|
||||||
if (players.is_empty() or id == game_master) and multiplayer.is_server():
|
|
||||||
get_tree().quit()
|
|
||||||
var x = 0
|
|
||||||
if !multiplayer.is_server():
|
|
||||||
for i in players_numbered:
|
|
||||||
if i == id:
|
|
||||||
var current_character = get_tree().root.get_node("./"+map_name+"/player"+str(x))
|
|
||||||
if current_character.hp == 0:
|
|
||||||
Game.dead -= 1
|
|
||||||
elif current_character.is_frozen:
|
|
||||||
Game.frozen -= 1
|
|
||||||
elif current_character.beast:
|
|
||||||
Game.player_escaped = true
|
|
||||||
Game.players = 0
|
|
||||||
else:
|
|
||||||
Game.players -= 1
|
|
||||||
current_character.free()
|
|
||||||
x += 1
|
|
||||||
|
|
||||||
func _on_server_disconnected():
|
|
||||||
Server.reset()
|
|
||||||
Game.reset()
|
|
||||||
get_tree().change_scene_to_file("res://menus/main_menu.tscn")
|
|
||||||
|
|
||||||
func reset():
|
|
||||||
players = {}
|
|
||||||
players_numbered = []
|
|
||||||
label = null
|
|
||||||
map = null
|
|
||||||
is_server = false
|
|
||||||
first_joined = true
|
|
||||||
game_master = "debug"
|
|
||||||
character = preload("res://objects/player.tscn")
|
|
||||||
if multiplayer != null:
|
|
||||||
multiplayer.multiplayer_peer = offline
|
|
||||||
|
|
||||||
func join_game(ip):
|
|
||||||
var peer = ENetMultiplayerPeer.new()
|
|
||||||
var error = peer.create_client(ip, PORT)
|
|
||||||
if error:
|
|
||||||
return error
|
|
||||||
multiplayer.multiplayer_peer = peer
|
|
||||||
|
|
||||||
|
|
||||||
func create_game():
|
|
||||||
var peer = ENetMultiplayerPeer.new()
|
|
||||||
var error = peer.create_server(PORT, MAX_CONNECTIONS)
|
|
||||||
if error:
|
|
||||||
return error
|
|
||||||
multiplayer.multiplayer_peer = peer
|
|
||||||
|
|
||||||
func _process(delta):
|
|
||||||
if multiplayer.is_server():
|
|
||||||
make_host.rpc(game_master)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@rpc("authority","call_remote","reliable")
|
@rpc("authority","call_remote","reliable")
|
||||||
func make_host(id):
|
func elevate():
|
||||||
first_joined = false
|
Game.is_server = true
|
||||||
game_master = id
|
|
||||||
if str(multiplayer.get_unique_id()) == str(game_master):
|
|
||||||
is_server = true
|
|
||||||
else:
|
|
||||||
is_server = false
|
|
||||||
|
|
||||||
@rpc("any_peer", "call_remote", "reliable")
|
|
||||||
func sync_playerlist(text, host):
|
|
||||||
if !multiplayer.is_server() and (multiplayer.get_remote_sender_id() == game_master or multiplayer.get_remote_sender_id() == 0):
|
|
||||||
get_tree().root.get_node("create/player_list/list").text = text
|
|
||||||
|
|
||||||
@rpc("any_peer", "call_local", "reliable")
|
|
||||||
func send_playerinfo(player_name, id):
|
|
||||||
if !multiplayer.is_server():
|
|
||||||
if is_server:
|
|
||||||
var done = 0
|
|
||||||
players[id] = player_name
|
|
||||||
label = get_tree().root.get_node("create/player_list/list")
|
|
||||||
label.text = ""
|
|
||||||
for w in players:
|
|
||||||
if done == 1:
|
|
||||||
label.text = str(label.text +"\n" + players[w])
|
|
||||||
else:
|
|
||||||
label.text = players[w]
|
|
||||||
done = 1
|
|
||||||
else:
|
|
||||||
players[id] = player_name
|
|
||||||
if first_joined:
|
|
||||||
first_joined = false
|
|
||||||
game_master = id
|
|
||||||
is_server = true
|
|
||||||
|
|
||||||
|
|
||||||
@rpc("any_peer", "call_local", "reliable")
|
|
||||||
func start_game(server_players):
|
|
||||||
if !multiplayer.is_server() and (multiplayer.get_remote_sender_id() == game_master or multiplayer.get_remote_sender_id() == 0):
|
|
||||||
players = server_players
|
|
||||||
players_numbered = players.keys()
|
|
||||||
var success = get_tree().change_scene_to_file("res://maps/"+map_name+".tscn")
|
|
||||||
while !get_tree().root.has_node("./"+map_name+"/"):
|
|
||||||
await get_tree().create_timer(0.001).timeout
|
|
||||||
map = get_tree().root.get_node("./"+map_name+"/")
|
|
||||||
var i = 0
|
|
||||||
for w in players:
|
|
||||||
var player = character.instantiate()
|
|
||||||
player.name = "player" + str(i)
|
|
||||||
i += 1
|
|
||||||
player.position.z = -i*2.5
|
|
||||||
player.position.y = 1
|
|
||||||
map.add_child(player)
|
|
||||||
if Server.is_server:
|
|
||||||
var random = randi() % Server.players.size()
|
|
||||||
sync_beast.rpc(random)
|
|
||||||
Game.apply_settings()
|
|
||||||
|
|
||||||
@rpc("any_peer", "call_remote", "unreliable")
|
|
||||||
func sync_player(node_name, position, rotation):
|
|
||||||
if !multiplayer.is_server():
|
|
||||||
var current_character = get_tree().root.get_node("./"+map_name+"/"+node_name)
|
|
||||||
current_character.position = position
|
|
||||||
current_character.rotation = rotation
|
|
||||||
|
|
||||||
@rpc("any_peer", "call_remote", "unreliable")
|
|
||||||
func sync_hammer(node_name, rotation):
|
|
||||||
if !multiplayer.is_server():
|
|
||||||
var current_character = get_tree().root.get_node("./"+map_name+"/"+node_name+"/hammer")
|
|
||||||
current_character.rotation = rotation
|
|
||||||
|
|
||||||
@rpc("any_peer", "call_local", "reliable")
|
|
||||||
func sync_computers(node_name, current):
|
|
||||||
if !multiplayer.is_server() and (multiplayer.get_remote_sender_id() == game_master or multiplayer.get_remote_sender_id() == 0):
|
|
||||||
var current_character = get_tree().root.get_node("./"+map_name+"/computers/"+node_name)
|
|
||||||
current_character.current = current
|
|
||||||
|
|
||||||
@rpc("any_peer", "call_local", "reliable")
|
|
||||||
func sync_beast(player):
|
|
||||||
if !multiplayer.is_server() and (multiplayer.get_remote_sender_id() == game_master or multiplayer.get_remote_sender_id() == 0):
|
|
||||||
while !get_tree().root.has_node("./"+map_name+"/player"+str(player)):
|
|
||||||
await get_tree().create_timer(0.001).timeout
|
|
||||||
var current_character = get_tree().root.get_node("./"+map_name+"/player"+str(player))
|
|
||||||
current_character.beast_init()
|
|
||||||
|
|
||||||
@rpc("any_peer", "call_local", "reliable")
|
|
||||||
func player_hit(target, beast):
|
|
||||||
if !multiplayer.is_server():
|
|
||||||
target = get_tree().root.get_node("./"+map_name+"/"+target)
|
|
||||||
beast = get_tree().root.get_node("./"+map_name+"/"+beast)
|
|
||||||
if !target.is_frozen:
|
|
||||||
target.captured(beast)
|
|
||||||
beast.got_one(target)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ func _on_body_entered(body):
|
||||||
$mapcam.active
|
$mapcam.active
|
||||||
Game.has_escaped()
|
Game.has_escaped()
|
||||||
|
|
||||||
func _process(delta):
|
func _process(_delta):
|
||||||
if Game.computers == 0:
|
if Game.computers == 0:
|
||||||
$CSGBox3D.show()
|
$CSGBox3D.show()
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue