Bomb
This commit is contained in:
parent
388fe1ccce
commit
6b939d241c
12 changed files with 128 additions and 68 deletions
|
|
@ -10,6 +10,7 @@ func _ready() -> void:
|
|||
if child is State:
|
||||
states[child.name] = child
|
||||
child.transition.connect(on_transition_required)
|
||||
|
||||
else:
|
||||
push_warning("Child of state machine is not state")
|
||||
|
||||
|
|
|
|||
17
scripts/weapon_system/bomb/bomb_state.gd
Normal file
17
scripts/weapon_system/bomb/bomb_state.gd
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
extends WeaponState
|
||||
|
||||
|
||||
func enter():
|
||||
machine.animation_player.play(machine.animation_prefix+"plant")
|
||||
machine.animation_player.animation_finished.connect(on_animation_finished)
|
||||
|
||||
func exit():
|
||||
machine.animation_player.animation_finished.disconnect(on_animation_finished)
|
||||
|
||||
func on_animation_finished(animation: StringName):
|
||||
if animation == machine.animation_prefix + "plant":
|
||||
return_to_previous.emit()
|
||||
|
||||
func state_input(event: InputEvent) -> void:
|
||||
if event.is_action_released("plr_bomb"):
|
||||
return_to_previous.emit()
|
||||
1
scripts/weapon_system/bomb/bomb_state.gd.uid
Normal file
1
scripts/weapon_system/bomb/bomb_state.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://rx78vdadldm7
|
||||
|
|
@ -3,6 +3,8 @@ extends State
|
|||
|
||||
class_name WeaponState
|
||||
|
||||
signal return_to_previous
|
||||
|
||||
var machine: WeaponSubStateMachine
|
||||
|
||||
func use_begin() -> void:
|
||||
|
|
|
|||
|
|
@ -3,10 +3,15 @@ extends SubStateMachine
|
|||
class_name WeaponSubStateMachine
|
||||
|
||||
@export var animation_prefix: StringName
|
||||
@export var visibility_mesh: Node3D
|
||||
|
||||
@export var max_ammo: int
|
||||
@onready var ammo: int = max_ammo
|
||||
|
||||
@export var can_be_previous: bool = true
|
||||
|
||||
signal request_return
|
||||
|
||||
var system: WeaponSystem
|
||||
var animation_player: AnimationPlayer
|
||||
var player_camera: PlayerCamera
|
||||
|
|
@ -17,6 +22,15 @@ func _ready() -> void:
|
|||
states[child.name] = child
|
||||
child.machine = self
|
||||
child.transition.connect(on_transition_required)
|
||||
child.return_to_previous.connect(request_return.emit)
|
||||
|
||||
func enter() -> void:
|
||||
super()
|
||||
visibility_mesh.visible = true
|
||||
|
||||
func exit() -> void:
|
||||
super()
|
||||
visibility_mesh.visible = false
|
||||
|
||||
@rpc("authority","call_local","reliable")
|
||||
func use_begin() -> void:
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ class_name WeaponSystem
|
|||
@export var camera: PlayerCamera
|
||||
|
||||
var current_state: WeaponSubStateMachine
|
||||
var last_slot: StringName
|
||||
|
||||
var slots: Dictionary[StringName,WeaponSubStateMachine] = {
|
||||
"primary": null,
|
||||
|
|
@ -29,6 +30,7 @@ func _ready() -> void:
|
|||
child.system = self
|
||||
child.animation_player = animation_player
|
||||
child.player_camera = camera
|
||||
child.request_return.connect(return_to_previous)
|
||||
else:
|
||||
push_warning("Child of weapon system is not ability or weapon")
|
||||
|
||||
|
|
@ -56,18 +58,28 @@ func switch(to: StringName):
|
|||
if slots.has(to) == false or slots[to] == null or slots[to] == current_state:
|
||||
return
|
||||
current_state.exit()
|
||||
current_state.in_use = false
|
||||
if current_state.can_be_previous:
|
||||
last_slot = slots.find_key(current_state)
|
||||
else:
|
||||
last_slot = ""
|
||||
current_state = slots[to]
|
||||
current_state.enter()
|
||||
current_state.in_use = true
|
||||
|
||||
switched_to.emit(current_state)
|
||||
|
||||
#update_remotes.rpc(to)
|
||||
update_remotes.rpc(to)
|
||||
|
||||
func return_to_previous():
|
||||
if last_slot != "":
|
||||
switch(last_slot)
|
||||
|
||||
@rpc("authority","call_remote","reliable")
|
||||
func update_remotes(to: StringName):
|
||||
switch(to)
|
||||
current_state.exit()
|
||||
current_state = slots[to]
|
||||
current_state.enter()
|
||||
|
||||
switched_to.emit(current_state)
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if current_state == null:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue