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
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)
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue