FINISHED DAMN DROP SYSTEM
This commit is contained in:
parent
3302fcfc96
commit
100afe5e51
17 changed files with 151 additions and 25 deletions
|
|
@ -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