From a1dbbb72a99f57acc4fc95d400e8b0b36137ba97 Mon Sep 17 00:00:00 2001 From: leca Date: Thu, 7 Mar 2024 14:46:59 +0300 Subject: [PATCH] moved properties to GameData singleton --- scripts/GameData.gd | 17 +++++++++++++++++ scripts/Networking.gd | 7 ++++--- scripts/Player.gd | 26 ++++++-------------------- scripts/SpectatorControls.gd | 2 -- settings/server-settings.json | 7 +++++++ 5 files changed, 34 insertions(+), 25 deletions(-) diff --git a/scripts/GameData.gd b/scripts/GameData.gd index 46b9aad..f267a18 100644 --- a/scripts/GameData.gd +++ b/scripts/GameData.gd @@ -1,5 +1,6 @@ extends Node + var Weapons = { "knife" = { "number": 0, @@ -18,6 +19,22 @@ var Weapons = { } } +var properties_example = { + HP = 100, + AP = 100, + HACK = 1.0, + class_type = 0, + is_playable = false, + internal_id = 0, + nickname = "Unnamed", + ready = false, + current_weapon = Weapons["knife"].duplicate(), + current_weapon_number = 0, + last_shot = 0, + reloading = false, + position = Vector3(0, 5, 0) +} + var client_settings var server_settings diff --git a/scripts/Networking.gd b/scripts/Networking.gd index 1d9e8a6..b548467 100644 --- a/scripts/Networking.gd +++ b/scripts/Networking.gd @@ -1,6 +1,6 @@ extends Node -var player_script := load("res://scripts/Player.gd") +var player_script = load("res://scripts/Player.gd") var player_model = load("res://scenes/models/player.tscn") var peer = ENetMultiplayerPeer.new() var clients:Dictionary = {} @@ -26,7 +26,7 @@ func _Peer_Connected(client_id): var internal_id = last_client_id + 1 last_client_id += 1 - clients[client_id] = player_script.new().properties.duplicate() + clients[client_id] = GameData.properties_example.duplicate() var client = clients[client_id] client["position"] = Vector3(0, 10, 0) client["internal_id"] = internal_id @@ -234,6 +234,7 @@ func get_map(client_id): func choose_class(client_id, class_id): var client = clients[client_id] client["class_type"] = class_id + #client["HP"] = GameData.settings["game"]["classes"][class_id]["HP"] #here are must be checks if the teams are balanced. WIP. if class_id > 0: ServerUtils.team_OS["members"].push_back(client) @@ -303,7 +304,7 @@ func spawn_player(): print(str(player_model)) playermodel = player_model.instantiate() print(str(playermodel)) - var properties = player_script.new().properties.duplicate() + var properties = GameData.properties_example.duplicate() properties = player properties["is_playable"] = false diff --git a/scripts/Player.gd b/scripts/Player.gd index 67bc736..e8c8f67 100644 --- a/scripts/Player.gd +++ b/scripts/Player.gd @@ -18,22 +18,7 @@ enum Class_type { var Weapons = GameData.Weapons -var properties = { - HP = 100, - AP = 100, - HACK = 1.0, - class_type = 0, - is_playable = false, - internal_id = 0, - nickname = "Unnamed", - ready = false, - current_weapon = null, - current_weapon_number = 0, - last_shot = 0, - reloading = false, - offline_mode = false, - position = Vector3(0, 5, 0) -} +var properties var speed = 12 var walk = 12 @@ -61,6 +46,7 @@ var round_status = { @onready var camera: Camera3D = $Head/Camera @onready var playerCharacterBody = $"." @onready var collision_shapes = find_children("collision*","",false) + var HUD var healthLabel var armorLabel @@ -77,6 +63,7 @@ var winnerLabel var killLogList func set_properties(props): + print("Got props from server: " + str(props)) properties = props $"Head/Nickname".text = properties["nickname"] name = "player" + str(properties["internal_id"]) @@ -183,12 +170,11 @@ func try_shoot(): return if Input.is_action_pressed("shoot") and current_weapon_settings["fireRate"] >= 0.5 and not Input.is_action_just_pressed("shoot"): return - time_since_last_shot = (Time.get_ticks_msec() - properties["last_shot"]) / 1000. + time_since_last_shot = (Time.get_ticks_msec() - properties["last_shot"]) / 1000. if (time_since_last_shot > current_weapon_settings["fireRate"]): - if (!properties["offline_mode"]): Networking.shot.rpc_id(1, multiplayer.get_unique_id()) - if (properties["current_weapon"]["magazine"] > 0): - properties["current_weapon"]["magazine"] -= 1 + Networking.shot.rpc_id(1, multiplayer.get_unique_id()) + properties["current_weapon"]["magazine"] -= 1 properties["last_shot"] = Time.get_ticks_msec() func reload(): diff --git a/scripts/SpectatorControls.gd b/scripts/SpectatorControls.gd index d51887e..118760b 100644 --- a/scripts/SpectatorControls.gd +++ b/scripts/SpectatorControls.gd @@ -12,10 +12,8 @@ func _ready(): func _unhandled_input(event): if Input.is_action_pressed("MWU"): walk += walk / 5. - print("UP " + str(walk)) if Input.is_action_pressed("MWD"): walk -= walk / 5. - print("DOWN " + str(walk)) walk = clamp(walk, 0.01, 15) if event is InputEventMouseMotion: head.rotate_y(-event.relative.x * SENSETIVITY) diff --git a/settings/server-settings.json b/settings/server-settings.json index ced342b..c309087 100644 --- a/settings/server-settings.json +++ b/settings/server-settings.json @@ -7,6 +7,13 @@ "gamemode": "TDM" }, "game": { + "classes":{ + "class_1":{ + "HP": 1100000, + "AP": 10000, + "damage_mul": 0.0001 + } + }, "gamemodes":{ "TDM": { "duration": 15,