Starting system
This commit is contained in:
parent
aa1c1c8d64
commit
57c178716e
10 changed files with 63 additions and 49 deletions
|
|
@ -11,10 +11,10 @@ Current plans:
|
|||
Bomb:
|
||||
^ Animation
|
||||
^ In-game animation
|
||||
Droppable
|
||||
^ Droppable
|
||||
Explosion after time
|
||||
Bomb site
|
||||
Weapon system's drop
|
||||
^ Weapon system's drop
|
||||
Molikman's abilities:
|
||||
Molik
|
||||
Flashbang
|
||||
|
|
|
|||
|
|
@ -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://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="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://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"]
|
||||
|
|
@ -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://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://doevvmbvhlig8" path="res://scripts/weapon_system/starting_weapon_spawner.gd" id="17_ownlk"]
|
||||
|
||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_u8vuu"]
|
||||
resource_local_to_scene = true
|
||||
|
|
@ -206,6 +206,9 @@ layout_mode = 2
|
|||
[node name="Properties" type="VBoxContainer" parent="HUD/PanelContainer/VBoxContainer2"]
|
||||
layout_mode = 2
|
||||
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")]
|
||||
layout_mode = 2
|
||||
|
|
@ -260,27 +263,21 @@ script = ExtResource("12_fulsm")
|
|||
player = NodePath("../..")
|
||||
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")
|
||||
default_pistol = NodePath("StartingPistol")
|
||||
default_knife = NodePath("KnifePlaceholder")
|
||||
animation_player = NodePath("../Camera3D/molikman_hands/AnimationPlayer")
|
||||
camera = NodePath("../Camera3D")
|
||||
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"]
|
||||
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="."]
|
||||
libraries = {
|
||||
&"": SubResource("AnimationLibrary_a8ls1")
|
||||
|
|
@ -307,5 +304,3 @@ shape = SubResource("CapsuleShape3D_3xmak")
|
|||
[connection signal="spawned" from="." to="TeamUpdater" method="on_spawned"]
|
||||
|
||||
[editable path="Camera3D/molikman_hands"]
|
||||
[editable path="WeaponSystem/StartingPistol"]
|
||||
[editable path="WeaponSystem/KnifePlaceholder"]
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ collision_mask = 9
|
|||
script = ExtResource("1_hsebh")
|
||||
slot = &"bomb"
|
||||
weapon = NodePath("BombWeapon")
|
||||
team = 1
|
||||
|
||||
[node name="BombWeapon" parent="." instance=ExtResource("2_ucc3u")]
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
[ext_resource type="PackedScene" uid="uid://d3sjs6efbshpk" path="res://models/weapons/starting_pistol.glb" id="3_jym52"]
|
||||
|
||||
[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"]
|
||||
properties/0/path = NodePath(".:position")
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ animation_prefix = &"baked_sp_"
|
|||
droppable = &"uid://dgfqppi21c2u0"
|
||||
visibility_target = &"sp"
|
||||
max_ammo = 20
|
||||
slot = &"secondary"
|
||||
enter_state = NodePath("Intro")
|
||||
metadata/_custom_type_script = "uid://e6lqknfl4ngt"
|
||||
|
||||
|
|
|
|||
|
|
@ -12,13 +12,12 @@ func on_body_entered(body: Node3D):
|
|||
if body is DroppableWeapon:
|
||||
if weapon_system.can_add(body.slot) == false:
|
||||
return
|
||||
var weapon = weapon_spawner.spawn({
|
||||
weapon_spawner.spawn({
|
||||
"ammo": body.weapon.ammo,
|
||||
"remaining_ammo": body.weapon.remaining_ammo,
|
||||
"scene_file_path": body.weapon.scene_file_path,
|
||||
"slot": body.slot
|
||||
})
|
||||
weapon_system.on_weapon_added(weapon)
|
||||
|
||||
Session.despawn(body.get_path())
|
||||
|
||||
|
|
|
|||
14
scripts/weapon_system/starting_weapon_spawner.gd
Normal file
14
scripts/weapon_system/starting_weapon_spawner.gd
Normal 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()
|
||||
1
scripts/weapon_system/starting_weapon_spawner.gd.uid
Normal file
1
scripts/weapon_system/starting_weapon_spawner.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://doevvmbvhlig8
|
||||
|
|
@ -13,7 +13,7 @@ class_name WeaponSubStateMachine
|
|||
@export var can_be_previous: bool = true
|
||||
@export var destroy_when_empty: bool = false
|
||||
|
||||
var slot: StringName
|
||||
@export var slot: StringName
|
||||
|
||||
signal request_return
|
||||
|
||||
|
|
|
|||
|
|
@ -2,9 +2,6 @@ extends Node
|
|||
|
||||
class_name WeaponSystem
|
||||
|
||||
@export var default_pistol: WeaponSubStateMachine
|
||||
@export var default_knife: WeaponSubStateMachine
|
||||
|
||||
@export var animation_player: AnimationPlayer
|
||||
@export var camera: PlayerCamera
|
||||
@export var player: Player
|
||||
|
|
@ -26,27 +23,23 @@ var slots: Dictionary[StringName,WeaponSubStateMachine] = {
|
|||
signal switched_to(state: WeaponSubStateMachine)
|
||||
|
||||
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.spawned.connect(on_weapon_added)
|
||||
|
||||
func can_add(slot: StringName) -> bool:
|
||||
return slots.has(slot) and slots[slot] == null
|
||||
|
||||
@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:
|
||||
return
|
||||
|
||||
if state.get_parent() == null:
|
||||
add_child(state, true)
|
||||
if state.get_parent() != self:
|
||||
state.get_parent().remove_child(state)
|
||||
add_child(state,true)
|
||||
state.ready.emit()
|
||||
if ignore_parent == false:
|
||||
if state.get_parent() == null:
|
||||
add_child(state, true)
|
||||
if state.get_parent() != self:
|
||||
state.get_parent().remove_child(state)
|
||||
add_child(state,true)
|
||||
state.ready.emit()
|
||||
|
||||
slots[slot] = state
|
||||
state.system = self
|
||||
|
|
@ -55,6 +48,10 @@ func add(state: WeaponSubStateMachine, slot: StringName) -> void:
|
|||
state.player = player
|
||||
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):
|
||||
if slots.has(to) == false or slots[to] == null or slots[to] == current_state or is_multiplayer_authority() == false:
|
||||
return
|
||||
|
|
@ -86,6 +83,7 @@ func drop():
|
|||
|
||||
$"../PickupRange".start_temp_ignore()
|
||||
|
||||
slots[slots.find_key(current_state)] = null
|
||||
current_state.queue_free()
|
||||
return_to_previous(false)
|
||||
|
||||
|
|
@ -95,16 +93,23 @@ func drop():
|
|||
# remaining_ammo
|
||||
# scene_file_path
|
||||
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:
|
||||
return null
|
||||
var scene: WeaponSubStateMachine = load(data["scene_file_path"]).instantiate()
|
||||
scene.ammo = data["ammo"]
|
||||
scene.remaining_ammo = data["remaining_ammo"]
|
||||
scene.slot = data["slot"]
|
||||
return scene
|
||||
if data.has("scene_file_path") == false:
|
||||
return Node.new()
|
||||
if data.has_all(["ammo","remaining_ammo"]):
|
||||
var scene: WeaponSubStateMachine = load(data["scene_file_path"]).instantiate()
|
||||
scene.ammo = data["ammo"]
|
||||
scene.remaining_ammo = data["remaining_ammo"]
|
||||
scene.slot = data["slot"]
|
||||
|
||||
func on_weapon_added(weapon: Node):
|
||||
add(weapon,weapon.slot)
|
||||
add(scene,scene.slot,true)
|
||||
|
||||
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):
|
||||
if last_slot != "":
|
||||
|
|
@ -123,13 +128,11 @@ func update_remotes(to: StringName):
|
|||
|
||||
func _process(delta: float) -> void:
|
||||
if current_state == null:
|
||||
push_error("State is not set")
|
||||
return
|
||||
current_state.update(delta)
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if current_state == null:
|
||||
push_error("State is not set")
|
||||
return
|
||||
current_state.physics_update(delta)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue