Starting system

This commit is contained in:
Rendo 2025-11-28 19:39:31 +05:00
commit 57c178716e
10 changed files with 63 additions and 49 deletions

View file

@ -11,10 +11,10 @@ Current plans:
Bomb: Bomb:
^ Animation ^ Animation
^ In-game animation ^ In-game animation
Droppable ^ Droppable
Explosion after time Explosion after time
Bomb site Bomb site
Weapon system's drop ^ Weapon system's drop
Molikman's abilities: Molikman's abilities:
Molik Molik
Flashbang Flashbang

View file

@ -8,7 +8,6 @@
[ext_resource type="Script" uid="uid://bmecgup3kcua7" path="res://scripts/weapon_system/weapon_system.gd" id="4_qlg0r"] [ext_resource type="Script" uid="uid://bmecgup3kcua7" path="res://scripts/weapon_system/weapon_system.gd" id="4_qlg0r"]
[ext_resource type="Script" uid="uid://dd5mp72dq43v6" path="res://scripts/multiplayer/own_visibility_toggle.gd" id="4_smehm"] [ext_resource type="Script" uid="uid://dd5mp72dq43v6" path="res://scripts/multiplayer/own_visibility_toggle.gd" id="4_smehm"]
[ext_resource type="Script" uid="uid://5gwpjiswnegn" path="res://scripts/player/collision_team_updater.gd" id="7_a8ls1"] [ext_resource type="Script" uid="uid://5gwpjiswnegn" path="res://scripts/player/collision_team_updater.gd" id="7_a8ls1"]
[ext_resource type="PackedScene" uid="uid://djwjl8xll53vn" path="res://scenes/weapons/starting_pistol.tscn" id="7_fjrip"]
[ext_resource type="Script" uid="uid://7gmgcaxfh8sb" path="res://scripts/debug/property_shower.gd" id="7_oprun"] [ext_resource type="Script" uid="uid://7gmgcaxfh8sb" path="res://scripts/debug/property_shower.gd" id="7_oprun"]
[ext_resource type="Script" uid="uid://3777rkbebgjm" path="res://scripts/state_machine/machine.gd" id="8_f1ej7"] [ext_resource type="Script" uid="uid://3777rkbebgjm" path="res://scripts/state_machine/machine.gd" id="8_f1ej7"]
[ext_resource type="PackedScene" uid="uid://c2r8dbudbs7l3" path="res://models/characters/worldmodels/molikman_ingame.glb" id="8_smehm"] [ext_resource type="PackedScene" uid="uid://c2r8dbudbs7l3" path="res://models/characters/worldmodels/molikman_ingame.glb" id="8_smehm"]
@ -18,6 +17,7 @@
[ext_resource type="Script" uid="uid://cwasvwhm5yg0o" path="res://scripts/player/states/walk.gd" id="11_qfm1y"] [ext_resource type="Script" uid="uid://cwasvwhm5yg0o" path="res://scripts/player/states/walk.gd" id="11_qfm1y"]
[ext_resource type="Script" uid="uid://cq4i0afwesdm3" path="res://scripts/player/states/falling.gd" id="12_fulsm"] [ext_resource type="Script" uid="uid://cq4i0afwesdm3" path="res://scripts/player/states/falling.gd" id="12_fulsm"]
[ext_resource type="Script" uid="uid://xsgfbuyje35p" path="res://scripts/player/player_pickup.gd" id="17_fjvrb"] [ext_resource type="Script" uid="uid://xsgfbuyje35p" path="res://scripts/player/player_pickup.gd" id="17_fjvrb"]
[ext_resource type="Script" uid="uid://doevvmbvhlig8" path="res://scripts/weapon_system/starting_weapon_spawner.gd" id="17_ownlk"]
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_u8vuu"] [sub_resource type="CapsuleShape3D" id="CapsuleShape3D_u8vuu"]
resource_local_to_scene = true resource_local_to_scene = true
@ -206,6 +206,9 @@ layout_mode = 2
[node name="Properties" type="VBoxContainer" parent="HUD/PanelContainer/VBoxContainer2"] [node name="Properties" type="VBoxContainer" parent="HUD/PanelContainer/VBoxContainer2"]
layout_mode = 2 layout_mode = 2
script = ExtResource("7_oprun") script = ExtResource("7_oprun")
property_array = Dictionary[NodePath, StringName]({
NodePath("../../../../WeaponSystem"): &"current_state"
})
[node name="InventoryPreview" type="Label" parent="HUD/PanelContainer/VBoxContainer2" node_paths=PackedStringArray("inventory")] [node name="InventoryPreview" type="Label" parent="HUD/PanelContainer/VBoxContainer2" node_paths=PackedStringArray("inventory")]
layout_mode = 2 layout_mode = 2
@ -260,27 +263,21 @@ script = ExtResource("12_fulsm")
player = NodePath("../..") player = NodePath("../..")
SPEED = 5.0 SPEED = 5.0
[node name="WeaponSystem" type="Node" parent="." node_paths=PackedStringArray("default_pistol", "default_knife", "animation_player", "camera", "player")] [node name="WeaponSystem" type="Node" parent="." node_paths=PackedStringArray("animation_player", "camera", "player")]
script = ExtResource("4_qlg0r") script = ExtResource("4_qlg0r")
default_pistol = NodePath("StartingPistol")
default_knife = NodePath("KnifePlaceholder")
animation_player = NodePath("../Camera3D/molikman_hands/AnimationPlayer") animation_player = NodePath("../Camera3D/molikman_hands/AnimationPlayer")
camera = NodePath("../Camera3D") camera = NodePath("../Camera3D")
player = NodePath("..") player = NodePath("..")
[node name="StartingPistol" parent="WeaponSystem" instance=ExtResource("7_fjrip")]
[node name="Shoot" parent="WeaponSystem/StartingPistol" index="1" node_paths=PackedStringArray("raycast")]
raycast = NodePath("../../../Camera3D/RayCast3D")
[node name="KnifePlaceholder" parent="WeaponSystem" instance=ExtResource("7_fjrip")]
[node name="Shoot" parent="WeaponSystem/KnifePlaceholder" index="1" node_paths=PackedStringArray("raycast")]
raycast = NodePath("../../../Camera3D/RayCast3D")
[node name="WeaponSpawner" type="MultiplayerSpawner" parent="WeaponSystem"] [node name="WeaponSpawner" type="MultiplayerSpawner" parent="WeaponSystem"]
spawn_path = NodePath("..") spawn_path = NodePath("..")
[node name="StartingWeaponSpawner" type="Node" parent="WeaponSystem" node_paths=PackedStringArray("weapon_spawner")]
script = ExtResource("17_ownlk")
starting_pistol = &"uid://djwjl8xll53vn"
starting_knife = &"uid://djwjl8xll53vn"
weapon_spawner = NodePath("../WeaponSpawner")
[node name="AnimationPlayer" type="AnimationPlayer" parent="."] [node name="AnimationPlayer" type="AnimationPlayer" parent="."]
libraries = { libraries = {
&"": SubResource("AnimationLibrary_a8ls1") &"": SubResource("AnimationLibrary_a8ls1")
@ -307,5 +304,3 @@ shape = SubResource("CapsuleShape3D_3xmak")
[connection signal="spawned" from="." to="TeamUpdater" method="on_spawned"] [connection signal="spawned" from="." to="TeamUpdater" method="on_spawned"]
[editable path="Camera3D/molikman_hands"] [editable path="Camera3D/molikman_hands"]
[editable path="WeaponSystem/StartingPistol"]
[editable path="WeaponSystem/KnifePlaceholder"]

View file

@ -21,6 +21,7 @@ collision_mask = 9
script = ExtResource("1_hsebh") script = ExtResource("1_hsebh")
slot = &"bomb" slot = &"bomb"
weapon = NodePath("BombWeapon") weapon = NodePath("BombWeapon")
team = 1
[node name="BombWeapon" parent="." instance=ExtResource("2_ucc3u")] [node name="BombWeapon" parent="." instance=ExtResource("2_ucc3u")]

View file

@ -5,7 +5,7 @@
[ext_resource type="PackedScene" uid="uid://d3sjs6efbshpk" path="res://models/weapons/starting_pistol.glb" id="3_jym52"] [ext_resource type="PackedScene" uid="uid://d3sjs6efbshpk" path="res://models/weapons/starting_pistol.glb" id="3_jym52"]
[sub_resource type="BoxShape3D" id="BoxShape3D_hsebh"] [sub_resource type="BoxShape3D" id="BoxShape3D_hsebh"]
size = Vector3(0.07324219, 0.25274658, 0.46972656) size = Vector3(0.24707031, 0.3173828, 0.46972656)
[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_ddvbd"] [sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_ddvbd"]
properties/0/path = NodePath(".:position") properties/0/path = NodePath(".:position")

View file

@ -24,6 +24,7 @@ animation_prefix = &"baked_sp_"
droppable = &"uid://dgfqppi21c2u0" droppable = &"uid://dgfqppi21c2u0"
visibility_target = &"sp" visibility_target = &"sp"
max_ammo = 20 max_ammo = 20
slot = &"secondary"
enter_state = NodePath("Intro") enter_state = NodePath("Intro")
metadata/_custom_type_script = "uid://e6lqknfl4ngt" metadata/_custom_type_script = "uid://e6lqknfl4ngt"

View file

@ -12,13 +12,12 @@ func on_body_entered(body: Node3D):
if body is DroppableWeapon: if body is DroppableWeapon:
if weapon_system.can_add(body.slot) == false: if weapon_system.can_add(body.slot) == false:
return return
var weapon = weapon_spawner.spawn({ weapon_spawner.spawn({
"ammo": body.weapon.ammo, "ammo": body.weapon.ammo,
"remaining_ammo": body.weapon.remaining_ammo, "remaining_ammo": body.weapon.remaining_ammo,
"scene_file_path": body.weapon.scene_file_path, "scene_file_path": body.weapon.scene_file_path,
"slot": body.slot "slot": body.slot
}) })
weapon_system.on_weapon_added(weapon)
Session.despawn(body.get_path()) Session.despawn(body.get_path())

View file

@ -0,0 +1,14 @@
extends Node
@export var starting_pistol: StringName
@export var starting_knife: StringName
@export var weapon_spawner: MultiplayerSpawner
func _ready() -> void:
deferred_ready.call_deferred()
func deferred_ready() -> void:
if is_multiplayer_authority():
weapon_spawner.spawn({"scene_file_path": starting_pistol})
weapon_spawner.spawn({"scene_file_path": starting_knife})
queue_free()

View file

@ -0,0 +1 @@
uid://doevvmbvhlig8

View file

@ -13,7 +13,7 @@ class_name WeaponSubStateMachine
@export var can_be_previous: bool = true @export var can_be_previous: bool = true
@export var destroy_when_empty: bool = false @export var destroy_when_empty: bool = false
var slot: StringName @export var slot: StringName
signal request_return signal request_return

View file

@ -2,9 +2,6 @@ extends Node
class_name WeaponSystem class_name WeaponSystem
@export var default_pistol: WeaponSubStateMachine
@export var default_knife: WeaponSubStateMachine
@export var animation_player: AnimationPlayer @export var animation_player: AnimationPlayer
@export var camera: PlayerCamera @export var camera: PlayerCamera
@export var player: Player @export var player: Player
@ -26,27 +23,23 @@ var slots: Dictionary[StringName,WeaponSubStateMachine] = {
signal switched_to(state: WeaponSubStateMachine) signal switched_to(state: WeaponSubStateMachine)
func _ready() -> void: func _ready() -> void:
current_state = default_pistol
add(default_pistol,"secondary")
add(default_knife,"knife")
current_state.enter()
$WeaponSpawner.spawn_function = pick_up_weapon $WeaponSpawner.spawn_function = pick_up_weapon
$WeaponSpawner.spawned.connect(on_weapon_added)
func can_add(slot: StringName) -> bool: func can_add(slot: StringName) -> bool:
return slots.has(slot) and slots[slot] == null return slots.has(slot) and slots[slot] == null
@rpc("call_local","reliable") @rpc("call_local","reliable")
func add(state: WeaponSubStateMachine, slot: StringName) -> void: func add(state: WeaponSubStateMachine, slot: StringName,ignore_parent: bool = false) -> void:
if can_add(slot) == false: if can_add(slot) == false:
return return
if state.get_parent() == null: if ignore_parent == false:
add_child(state, true) if state.get_parent() == null:
if state.get_parent() != self: add_child(state, true)
state.get_parent().remove_child(state) if state.get_parent() != self:
add_child(state,true) state.get_parent().remove_child(state)
state.ready.emit() add_child(state,true)
state.ready.emit()
slots[slot] = state slots[slot] = state
state.system = self state.system = self
@ -54,6 +47,10 @@ func add(state: WeaponSubStateMachine, slot: StringName) -> void:
state.player_camera = camera state.player_camera = camera
state.player = player state.player = player
state.request_return.connect(return_to_previous) state.request_return.connect(return_to_previous)
if current_state == null:
current_state = state
state.enter.call_deferred()
func switch(to: StringName, exit: bool = true): func switch(to: StringName, exit: bool = true):
if slots.has(to) == false or slots[to] == null or slots[to] == current_state or is_multiplayer_authority() == false: if slots.has(to) == false or slots[to] == null or slots[to] == current_state or is_multiplayer_authority() == false:
@ -86,6 +83,7 @@ func drop():
$"../PickupRange".start_temp_ignore() $"../PickupRange".start_temp_ignore()
slots[slots.find_key(current_state)] = null
current_state.queue_free() current_state.queue_free()
return_to_previous(false) return_to_previous(false)
@ -95,16 +93,23 @@ func drop():
# remaining_ammo # remaining_ammo
# scene_file_path # scene_file_path
func pick_up_weapon(data: Variant) -> Node: func pick_up_weapon(data: Variant) -> Node:
if data.has("ammo") == false or data.has("remaining_ammo") == false or data.has("scene_file_path") == false or data.has("slot") == false: if data.has("scene_file_path") == false:
return null return Node.new()
var scene: WeaponSubStateMachine = load(data["scene_file_path"]).instantiate() if data.has_all(["ammo","remaining_ammo"]):
scene.ammo = data["ammo"] var scene: WeaponSubStateMachine = load(data["scene_file_path"]).instantiate()
scene.remaining_ammo = data["remaining_ammo"] scene.ammo = data["ammo"]
scene.slot = data["slot"] scene.remaining_ammo = data["remaining_ammo"]
return scene scene.slot = data["slot"]
func on_weapon_added(weapon: Node): add(scene,scene.slot,true)
add(weapon,weapon.slot)
return scene
else:
var scene: WeaponSubStateMachine = load(data["scene_file_path"]).instantiate()
add(scene,scene.slot,true)
return scene
func return_to_previous(exit: bool = true): func return_to_previous(exit: bool = true):
if last_slot != "": if last_slot != "":
@ -123,13 +128,11 @@ func update_remotes(to: StringName):
func _process(delta: float) -> void: func _process(delta: float) -> void:
if current_state == null: if current_state == null:
push_error("State is not set")
return return
current_state.update(delta) current_state.update(delta)
func _physics_process(delta: float) -> void: func _physics_process(delta: float) -> void:
if current_state == null: if current_state == null:
push_error("State is not set")
return return
current_state.physics_update(delta) current_state.physics_update(delta)