code cleanup & improvements
This commit is contained in:
parent
b81f4cedff
commit
3c066fb99b
|
@ -0,0 +1,2 @@
|
|||
# Normalize EOL for all files that Git considers text files.
|
||||
* text=auto eol=lf
|
|
@ -21,8 +21,9 @@ customized_files={
|
|||
"res://scripts/GameData.gd": "strip",
|
||||
"res://scripts/Networking.gd": "strip",
|
||||
"res://scripts/Player.gd": "strip",
|
||||
"res://scripts/PlayerClass.gd": "strip",
|
||||
"res://settings/": "strip",
|
||||
"res://settings/client-settings.json": "strip",
|
||||
"res://settings/server-settings.json": "strip",
|
||||
"res://textures/": "strip",
|
||||
"res://textures/texture_04_2.png": "strip"
|
||||
}
|
||||
|
|
|
@ -1,34 +1,6 @@
|
|||
extends Node
|
||||
|
||||
enum Class_type {
|
||||
Spectator = 0,
|
||||
Astra = 1,
|
||||
BlackArch = 2,
|
||||
Kali = 3,
|
||||
Debian = 4,
|
||||
Arch = 5,
|
||||
Windows11 = -1,
|
||||
WindowsServer = -2,
|
||||
MacOS = -3,
|
||||
WindowsXP = -4,
|
||||
Windows10 = -5
|
||||
}
|
||||
|
||||
var Distro = {
|
||||
HP = 100,
|
||||
AP = 100,
|
||||
HACK = 1.0,
|
||||
class_type = 0,
|
||||
}
|
||||
var Player = {
|
||||
distro = Distro.duplicate(),
|
||||
speed = 1.0,
|
||||
position = Vector3(0, 10, 0),
|
||||
velocity = Vector3.ZERO,
|
||||
internal_id = 0,
|
||||
}
|
||||
|
||||
const player_class := preload("res://scripts/PlayerClass.gd")
|
||||
const player_script := preload("res://scripts/Player.gd")
|
||||
|
||||
var player_model = preload("res://models/player.tscn")
|
||||
var peer = ENetMultiplayerPeer.new()
|
||||
|
@ -57,28 +29,34 @@ func StartServer():
|
|||
peer.connect("peer_disconnected", _Peer_Disconnected)
|
||||
|
||||
func send_everyone_except(client_id, args):
|
||||
for current_client_id in clients.keys():
|
||||
if (str(current_client_id) == str(client_id)): continue
|
||||
if (args[1] == null): args[0].rpc_id(int(current_client_id))
|
||||
elif (args[2] == null): args[0].rpc_id(int(current_client_id), args[1])
|
||||
else: args[0].rpc_id(int(current_client_id), args[1], args[2])
|
||||
if (typeof(args[0]) == 4): #string
|
||||
for current_client_id in clients.keys():
|
||||
if (str(current_client_id) == str(client_id)): continue
|
||||
if (args.size() == 1): rpc_id(int(current_client_id), args[0])
|
||||
elif (args.size() == 2): rpc_id(int(current_client_id), args[0], args[1])
|
||||
else: rpc_id(int(current_client_id), args[0], args[1], args[2])
|
||||
else:
|
||||
for current_client_id in clients.keys():
|
||||
if (str(current_client_id) == str(client_id)): continue
|
||||
if (args.size() == 1): args[0].rpc_id(int(current_client_id))
|
||||
elif (args.size() == 2): args[0].rpc_id(int(current_client_id), args[1])
|
||||
else: args[0].rpc_id(int(current_client_id), args[1], args[2])
|
||||
|
||||
func _Peer_Connected(client_id):
|
||||
print("User " + str(client_id) + " has conected")
|
||||
var puppet = player_model.instantiate()
|
||||
var internal_id = clients.size() + 2
|
||||
puppet.find_child("CharacterBody3D").set_is_playable(false)
|
||||
puppet.find_child("CharacterBody3D").set_internal_id(internal_id)
|
||||
puppet.name = "player" + str(internal_id)
|
||||
puppet.find_child("CharacterBody3D").set_player_name("player" + str(internal_id))
|
||||
|
||||
clients[str(client_id)] = Player.duplicate()
|
||||
clients[str(client_id)] = player_script.new().properties.duplicate()
|
||||
clients[str(client_id)]["internal_id"] = internal_id
|
||||
|
||||
add_child(puppet)
|
||||
|
||||
for current_client_id in clients.keys():
|
||||
if (int(current_client_id) == int(client_id)): continue
|
||||
rpc_id(int(current_client_id), "spawn_puppet", internal_id)
|
||||
|
||||
send_everyone_except(client_id, ["spawn_puppet", internal_id])
|
||||
|
||||
func _Peer_Disconnected(client_id):
|
||||
clients.erase(str(client_id))
|
||||
|
||||
|
@ -87,13 +65,13 @@ func get_character_properties(client_id):
|
|||
if !clients.has(str(client_id)):
|
||||
return
|
||||
var to_send = clients[str(client_id)]
|
||||
rpc_id(client_id, "set_character_properties", to_send)
|
||||
rpc_id(client_id, "set_character_properties", to_send.duplicate())
|
||||
|
||||
@rpc("any_peer", "call_remote")
|
||||
func move_client(client_id, position):
|
||||
#if(settings["enableAntiCheat"]): if(position > 10): return # нормально допилить надо
|
||||
clients[str(client_id)]["position"] = position
|
||||
var client = clients[str(client_id)]
|
||||
client["position"] = position
|
||||
send_everyone_except(client_id, [get_node("player" + str(client["internal_id"])).find_child("CharacterBody3D").move_puppet, position, client["internal_id"]])
|
||||
|
||||
@rpc ("any_peer", "call_remote", "reliable")
|
||||
|
@ -108,6 +86,7 @@ var player
|
|||
|
||||
@rpc ("reliable", "call_remote")
|
||||
func set_character_properties(p):
|
||||
print("Setting player properties to " + str(p))
|
||||
player = p
|
||||
|
||||
@rpc("authority", "reliable", "call_remote")
|
||||
|
@ -115,6 +94,8 @@ func spawn_puppet(internal_id):
|
|||
var puppet = player_model.instantiate()
|
||||
puppet.find_child("CharacterBody3D").set_is_playable(false)
|
||||
puppet.find_child("CharacterBody3D").set_internal_id(internal_id)
|
||||
puppet.find_child("CharacterBody3D").set_player_name("player" + str(internal_id))
|
||||
|
||||
puppet.name = "player" + str(internal_id)
|
||||
|
||||
add_child(puppet)
|
||||
|
@ -147,6 +128,7 @@ func _Connection_Succseeded():
|
|||
var player_node = player_model.instantiate()
|
||||
player_node.find_child("CharacterBody3D").set_is_playable(true)
|
||||
player_node.find_child("CharacterBody3D").set_internal_id(player["internal_id"])
|
||||
player_node.find_child("CharacterBody3D").set_player_name("player" + str(player["internal_id"]))
|
||||
add_child(player_node)
|
||||
|
||||
func _Server_Disconnected():
|
||||
|
|
|
@ -1,43 +1,65 @@
|
|||
extends CharacterBody3D
|
||||
|
||||
|
||||
const WALK_VELOCITY = 12.0
|
||||
const RUN_VELOCITY = 24.0
|
||||
const JUMP_VELOCITY = 12.0
|
||||
const SENSETIVITY = 0.009;
|
||||
|
||||
var gravity = 9.8
|
||||
enum Class_type {
|
||||
Spectator = 0,
|
||||
Astra = 1,
|
||||
BlackArch = 2,
|
||||
Kali = 3,
|
||||
Debian = 4,
|
||||
Arch = 5,
|
||||
Windows11 = -1,
|
||||
WindowsServer = -2,
|
||||
MacOS = -3,
|
||||
WindowsXP = -4,
|
||||
Windows10 = -5
|
||||
}
|
||||
|
||||
var properties = {
|
||||
HP = 100,
|
||||
AP = 100,
|
||||
HACK = 1.0,
|
||||
class_type = 0,
|
||||
is_playable = false,
|
||||
internal_id = 0
|
||||
}
|
||||
|
||||
var speed = WALK_VELOCITY
|
||||
var gravity = 9.8
|
||||
@onready var head = $Head
|
||||
@onready var camera = $Head/Camera
|
||||
@onready var playerCharacterBody = $"."
|
||||
var is_playable = false
|
||||
var internal_id
|
||||
|
||||
|
||||
func set_player_name (n):
|
||||
$"..".name = n
|
||||
|
||||
func set_internal_id(id):
|
||||
internal_id = id
|
||||
print("Setting internal_id to " + str(id))
|
||||
properties["internal_id"] = id
|
||||
|
||||
func set_is_playable(value):
|
||||
is_playable = value
|
||||
|
||||
func test(text):
|
||||
print(text)
|
||||
properties["is_playable"] = value
|
||||
|
||||
func _ready():
|
||||
if (!is_playable): return
|
||||
if (!properties["is_playable"]): return
|
||||
camera.make_current()
|
||||
playerCharacterBody.up_direction = Vector3.UP;
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||
|
||||
func _unhandled_input(event):
|
||||
if (!is_playable): return
|
||||
if (!properties["is_playable"]): return
|
||||
if event is InputEventMouseMotion:
|
||||
head.rotate_y(-event.relative.x * SENSETIVITY)
|
||||
camera.rotate_x(-event.relative.y * SENSETIVITY)
|
||||
camera.rotation.x = clamp(camera.rotation.x, deg_to_rad(-50), deg_to_rad(60))
|
||||
|
||||
func _physics_process(delta):
|
||||
if (!is_playable): return
|
||||
if (!properties["is_playable"]): return
|
||||
if not is_on_floor():
|
||||
velocity.y -= 4 * gravity * delta
|
||||
|
||||
|
@ -63,9 +85,9 @@ func _physics_process(delta):
|
|||
move_and_slide()
|
||||
if (!multiplayer.is_server()):
|
||||
Networking.move_client.rpc_id(1, multiplayer.get_unique_id(), $".".position)
|
||||
print("I am " + $"..".name +", belonging of " + str(multiplayer.get_unique_id()) + ", with internal ID: " + str(internal_id))
|
||||
print("I am " + $"..".name +", belonging of " + str(multiplayer.get_unique_id()) + ", with internal ID: " + str(properties["internal_id"]))
|
||||
|
||||
@rpc ("authority", "call_remote")
|
||||
func move_puppet(p: Vector3, i_id):
|
||||
if (i_id == internal_id):
|
||||
if (i_id == properties["internal_id"]):
|
||||
playerCharacterBody.position = p
|
||||
|
|
Loading…
Reference in New Issue