2024-02-07 23:25:08 +03:00
|
|
|
extends CharacterBody3D
|
|
|
|
|
|
|
|
const SENSETIVITY = 0.009;
|
|
|
|
|
2024-02-08 21:16:31 +03:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2024-02-12 00:11:50 +03:00
|
|
|
var speed = 0
|
|
|
|
var walk = 0
|
|
|
|
var run = 0
|
|
|
|
var jump = 0
|
|
|
|
var gravity = 0
|
|
|
|
var game_settings
|
|
|
|
var client_settings
|
|
|
|
|
2024-02-07 23:25:08 +03:00
|
|
|
@onready var head = $Head
|
|
|
|
@onready var camera = $Head/Camera
|
|
|
|
@onready var playerCharacterBody = $"."
|
2024-02-08 21:16:31 +03:00
|
|
|
|
|
|
|
|
|
|
|
func set_player_name (n):
|
|
|
|
$"..".name = n
|
2024-02-07 23:25:08 +03:00
|
|
|
|
|
|
|
func set_internal_id(id):
|
2024-02-08 21:16:31 +03:00
|
|
|
print("Setting internal_id to " + str(id))
|
|
|
|
properties["internal_id"] = id
|
2024-02-07 23:25:08 +03:00
|
|
|
|
|
|
|
func set_is_playable(value):
|
2024-02-08 21:16:31 +03:00
|
|
|
properties["is_playable"] = value
|
2024-02-07 23:25:08 +03:00
|
|
|
|
|
|
|
func _ready():
|
2024-02-08 21:16:31 +03:00
|
|
|
if (!properties["is_playable"]): return
|
2024-02-07 23:25:08 +03:00
|
|
|
camera.make_current()
|
|
|
|
playerCharacterBody.up_direction = Vector3.UP;
|
|
|
|
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
|
|
|
|
|
|
|
func _unhandled_input(event):
|
2024-02-08 21:16:31 +03:00
|
|
|
if (!properties["is_playable"]): return
|
2024-02-07 23:25:08 +03:00
|
|
|
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))
|
2024-02-14 22:18:05 +03:00
|
|
|
Networking.rotate_camera_client.rpc_id(1, multiplayer.get_unique_id(), head.rotation.y, camera.rotation.x)
|
|
|
|
|
2024-02-07 23:25:08 +03:00
|
|
|
func _physics_process(delta):
|
2024-02-12 00:11:50 +03:00
|
|
|
if (!properties["is_playable"]): return
|
|
|
|
if (game_settings == null): return
|
2024-02-14 22:18:05 +03:00
|
|
|
if (multiplayer.multiplayer_peer == null):
|
|
|
|
properties["is_playable"] = false
|
2024-02-07 23:25:08 +03:00
|
|
|
if not is_on_floor():
|
|
|
|
velocity.y -= 4 * gravity * delta
|
|
|
|
|
|
|
|
var input_dir = Input.get_vector("left", "right", "forward", "backward")
|
|
|
|
var direction = (head.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
|
|
|
|
|
|
|
|
if is_on_floor():
|
|
|
|
if Input.is_action_just_pressed("jump"):
|
2024-02-12 00:11:50 +03:00
|
|
|
velocity.y = jump
|
2024-02-07 23:25:08 +03:00
|
|
|
if Input.is_action_pressed("run"):
|
2024-02-12 00:11:50 +03:00
|
|
|
speed = run
|
2024-02-07 23:25:08 +03:00
|
|
|
else:
|
2024-02-12 00:11:50 +03:00
|
|
|
speed = walk
|
2024-02-07 23:25:08 +03:00
|
|
|
if direction:
|
|
|
|
velocity.x = direction.x * speed
|
|
|
|
velocity.z = direction.z * speed
|
|
|
|
else:
|
2024-02-14 22:18:05 +03:00
|
|
|
velocity.x = lerp(velocity.x, direction.x * speed, delta * 4)
|
|
|
|
velocity.z = lerp(velocity.z, direction.z * speed, delta * 4)
|
2024-02-07 23:25:08 +03:00
|
|
|
else:
|
|
|
|
velocity.x = lerp(velocity.x, direction.x * speed, delta)
|
|
|
|
velocity.z = lerp(velocity.z, direction.z * speed, delta)
|
|
|
|
move_and_slide()
|
|
|
|
if (!multiplayer.is_server()):
|
|
|
|
Networking.move_client.rpc_id(1, multiplayer.get_unique_id(), $".".position)
|
2024-02-08 21:20:49 +03:00
|
|
|
#print("I am " + $"..".name +", belonging of " + str(multiplayer.get_unique_id()) + ", with internal ID: " + str(properties["internal_id"]))
|
2024-02-07 23:25:08 +03:00
|
|
|
|
2024-02-08 21:20:49 +03:00
|
|
|
@rpc ("authority", "call_remote", "unreliable")
|
2024-02-07 23:25:08 +03:00
|
|
|
func move_puppet(p: Vector3, i_id):
|
2024-02-08 21:16:31 +03:00
|
|
|
if (i_id == properties["internal_id"]):
|
2024-02-07 23:25:08 +03:00
|
|
|
playerCharacterBody.position = p
|
2024-02-12 00:11:50 +03:00
|
|
|
|
|
|
|
@rpc ("authority", "call_remote", "reliable")
|
|
|
|
func set_game_settings(s):
|
|
|
|
if(!properties["is_playable"]): return
|
|
|
|
print("Got settings from server: " + str(s))
|
|
|
|
game_settings = s
|
|
|
|
gravity = game_settings["moving"]["gravity"]
|
|
|
|
walk = game_settings["moving"]["walk"]
|
|
|
|
run = game_settings["moving"]["run"]
|
|
|
|
jump = game_settings["moving"]["jump"]
|
2024-02-14 22:18:05 +03:00
|
|
|
|
|
|
|
@rpc("authority", "call_remote", "unreliable")
|
|
|
|
func rotate_camera_puppet(rot, i_id):
|
|
|
|
if (i_id == properties["internal_id"]):
|
|
|
|
head.rotation.y = rot.y
|
|
|
|
camera.rotation.x = rot.x
|