FINISHED DAMN DROP SYSTEM
This commit is contained in:
parent
3302fcfc96
commit
100afe5e51
17 changed files with 151 additions and 25 deletions
|
|
@ -1,5 +0,0 @@
|
|||
extends Node3D
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
Session.dynamic_objects_container = self
|
||||
|
|
@ -1 +0,0 @@
|
|||
uid://be7l33prlm8gh
|
||||
|
|
@ -7,4 +7,29 @@ enum TEAMS {
|
|||
UNASSIGNED
|
||||
}
|
||||
|
||||
var dynamic_objects_container: Node3D
|
||||
var dynamic_objects_spawner: MultiplayerSpawner
|
||||
|
||||
func spawn(data: Dictionary) -> void:
|
||||
spawn_internal.rpc_id(1,data)
|
||||
|
||||
@rpc("any_peer","call_local","reliable")
|
||||
func spawn_internal(data: Dictionary) -> void:
|
||||
if multiplayer.is_server() == false:
|
||||
printerr(str(multiplayer.get_remote_sender_id())+" tried to spawn internally on "+str(multiplayer.get_unique_id()))
|
||||
return
|
||||
|
||||
var object = dynamic_objects_spawner.spawn(data)
|
||||
|
||||
if data.has("position"):
|
||||
object.global_position = data.position
|
||||
|
||||
func despawn(path: NodePath):
|
||||
despawn_internal.rpc_id(1,path)
|
||||
|
||||
@rpc("any_peer","call_local","reliable")
|
||||
func despawn_internal(path: NodePath) -> void:
|
||||
if multiplayer.is_server() == false:
|
||||
printerr(str(multiplayer.get_remote_sender_id())+" tried to despawn internally on "+str(multiplayer.get_unique_id()))
|
||||
return
|
||||
|
||||
get_node(path).queue_free()
|
||||
|
|
|
|||
17
scripts/multiplayer/spawn_system/dyn_objects_spawner.gd
Normal file
17
scripts/multiplayer/spawn_system/dyn_objects_spawner.gd
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
extends MultiplayerSpawner
|
||||
|
||||
func _ready() -> void:
|
||||
spawn_function = request_spawn
|
||||
Session.dynamic_objects_spawner = self
|
||||
|
||||
func request_spawn(data: Variant) -> Node:
|
||||
if data.has_all(["scene","impulse"]):
|
||||
var projectile: RigidBody3D = load(data.scene).instantiate()
|
||||
if data.has_all(["ammo","remaining_ammo","slot"]):
|
||||
projectile.weapon.ammo = data.ammo
|
||||
projectile.weapon.remaining_ammo = data.remaining_ammo
|
||||
projectile.slot = data.slot
|
||||
|
||||
projectile.apply_impulse(data.impulse)
|
||||
return projectile
|
||||
return Node.new()
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://bqjv6l7hh0lix
|
||||
|
|
@ -19,4 +19,16 @@ func on_body_entered(body: Node3D):
|
|||
"slot": body.slot
|
||||
})
|
||||
weapon_system.on_weapon_added(weapon)
|
||||
body.queue_free()
|
||||
|
||||
Session.despawn(body.get_path())
|
||||
|
||||
func start_temp_ignore():
|
||||
if is_multiplayer_authority() == false:
|
||||
return
|
||||
monitoring = false
|
||||
get_tree().create_timer(0.5).timeout.connect(stop_temp_ignore)
|
||||
|
||||
func stop_temp_ignore():
|
||||
if is_multiplayer_authority() == false:
|
||||
return
|
||||
monitoring = true
|
||||
|
|
|
|||
|
|
@ -2,6 +2,14 @@ extends RigidBody3D
|
|||
|
||||
class_name DroppableWeapon
|
||||
|
||||
const IMPULSE = 10
|
||||
|
||||
@export var slot: StringName
|
||||
@export var weapon: WeaponSubStateMachine
|
||||
@export var team: Session.TEAMS
|
||||
|
||||
@rpc("any_peer","call_local","reliable")
|
||||
func drop(direction: Vector3,new_position: Vector3):
|
||||
apply_impulse(direction * IMPULSE)
|
||||
global_position = new_position
|
||||
|
||||
|
|
|
|||
|
|
@ -15,11 +15,12 @@ func state_input(event: InputEvent) -> void:
|
|||
init_reload.rpc()
|
||||
|
||||
func use_begin() -> void:
|
||||
transition.emit("Shoot")
|
||||
if machine.ammo > 0:
|
||||
transition.emit("Shoot")
|
||||
|
||||
@rpc("authority","call_local","reliable")
|
||||
func init_reload():
|
||||
if machine.ammo == machine.max_ammo:
|
||||
if machine.ammo == machine.max_ammo or machine.remaining_ammo <= 0:
|
||||
return
|
||||
transition.emit("Reload")
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,12 @@ func exit() -> void:
|
|||
|
||||
func on_animation_finished(animation):
|
||||
if animation == with_morphems("reload"):
|
||||
machine.ammo = machine.max_ammo
|
||||
if machine.remaining_ammo > machine.max_ammo:
|
||||
machine.ammo = machine.max_ammo
|
||||
machine.remaining_ammo -= machine.max_ammo
|
||||
else:
|
||||
machine.ammo = machine.remaining_ammo
|
||||
machine.remaining_ammo = 0
|
||||
transition.emit("Idle")
|
||||
|
||||
func with_morphems(animation):
|
||||
|
|
|
|||
|
|
@ -3,8 +3,7 @@ extends SubStateMachine
|
|||
class_name WeaponSubStateMachine
|
||||
|
||||
@export var animation_prefix: StringName
|
||||
@export var droppable: PackedScene
|
||||
@export var self_scene: PackedScene
|
||||
@export var droppable: StringName
|
||||
@export var visibility_target: StringName
|
||||
|
||||
@export var max_ammo: int
|
||||
|
|
@ -12,6 +11,7 @@ class_name WeaponSubStateMachine
|
|||
@onready var remaining_ammo: int = max_ammo * 3
|
||||
|
||||
@export var can_be_previous: bool = true
|
||||
@export var destroy_when_empty: bool = false
|
||||
|
||||
var slot: StringName
|
||||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ 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)
|
||||
|
|
@ -55,7 +56,7 @@ func add(state: WeaponSubStateMachine, slot: StringName) -> void:
|
|||
state.request_return.connect(return_to_previous)
|
||||
|
||||
func switch(to: StringName):
|
||||
if slots.has(to) == false or slots[to] == null or slots[to] == current_state:
|
||||
if slots.has(to) == false or slots[to] == null or slots[to] == current_state or is_multiplayer_authority() == false:
|
||||
return
|
||||
current_state.exit()
|
||||
if current_state.can_be_previous:
|
||||
|
|
@ -69,7 +70,23 @@ func switch(to: StringName):
|
|||
|
||||
update_remotes.rpc(to)
|
||||
|
||||
func drop(): pass
|
||||
func drop():
|
||||
if slots.find_key(current_state) == "knife":
|
||||
return
|
||||
var drop_data: Dictionary = {}
|
||||
drop_data.scene = current_state.droppable
|
||||
drop_data.ammo = current_state.ammo
|
||||
drop_data.remaining_ammo = current_state.remaining_ammo
|
||||
drop_data.slot = current_state.slot
|
||||
drop_data.position = camera.global_position
|
||||
drop_data.impulse = -camera.global_basis.z * 10
|
||||
|
||||
Session.spawn(drop_data)
|
||||
|
||||
$"../PickupRange".start_temp_ignore()
|
||||
|
||||
Session.despawn(current_state.get_path())
|
||||
return_to_previous()
|
||||
|
||||
# Spawn function
|
||||
# Data should be a dictionary with these keys:
|
||||
|
|
@ -91,6 +108,8 @@ func on_weapon_added(weapon: Node):
|
|||
func return_to_previous():
|
||||
if last_slot != "":
|
||||
switch(last_slot)
|
||||
else:
|
||||
switch("knife")
|
||||
|
||||
@rpc("authority","call_remote","reliable")
|
||||
func update_remotes(to: StringName):
|
||||
|
|
@ -143,4 +162,7 @@ func _input(event: InputEvent) -> void:
|
|||
current_state.alternate_state()
|
||||
if event.is_action_pressed("plr_firemode"):
|
||||
current_state.switch_mode()
|
||||
|
||||
if event.is_action_pressed("plr_drop"):
|
||||
drop()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue