40 lines
982 B
GDScript
40 lines
982 B
GDScript
extends WeaponState
|
|
|
|
@export var raycast: RayCast3D
|
|
@export var emptyable: bool
|
|
@export var damage: int
|
|
|
|
@export var fire_timer: Timer
|
|
|
|
func enter() -> void:
|
|
fire()
|
|
machine.animation_player.animation_finished.connect(on_animation_finished)
|
|
|
|
func exit() -> void:
|
|
machine.animation_player.animation_finished.disconnect(on_animation_finished)
|
|
|
|
func on_animation_finished(animation):
|
|
if animation == with_morphems("shoot"):
|
|
transition.emit("Idle")
|
|
|
|
func use_begin() -> void:
|
|
if fire_timer.time_left > 0:
|
|
return
|
|
fire()
|
|
|
|
func fire() -> void:
|
|
if machine.ammo == 0 or fire_timer.time_left > 0:
|
|
return
|
|
machine.ammo -= 1
|
|
|
|
machine.animation_player.stop()
|
|
machine.animation_player.play(with_morphems("shoot"))
|
|
|
|
if raycast.is_colliding():
|
|
raycast.get_collider().hp -= damage
|
|
|
|
fire_timer.start()
|
|
machine.player_camera.recoil(0,0.1)
|
|
|
|
func with_morphems(animation):
|
|
return machine.animation_prefix + ((animation+"_empty") if emptyable and machine.ammo == 0 else animation)
|