grunk/src/world/mechanics/alarm/gunk_alarm.gd

58 lines
1.7 KiB
GDScript3
Raw Normal View History

2025-03-28 14:16:43 -06:00
@tool
2025-03-15 19:00:37 -06:00
class_name GunkAlarm extends SignalNode
2025-03-13 13:34:35 -06:00
## Raises the grunk alert when triggered.
const ALERT_DELTA := 1
2025-03-28 14:16:43 -06:00
const JITTER_SCALE_FACTOR := 0.15
const JITTER_INFLATION_FACTOR := 1.5
## Time to wait for a pulse signal before triggering.
@export var pulse_timeout := 6.0
2025-03-13 13:34:35 -06:00
var _busy := false
@onready var pulse_listener_timer: Timer = %PulseListenerTimer
2025-03-28 14:16:43 -06:00
@onready var animation_player: AnimationPlayer = $FrameSkipper/AlarmMesh/AnimationPlayer
2025-04-19 17:31:21 -06:00
@onready var effect_animation: AnimationPlayer = %EffectAnimation
2025-03-28 14:16:43 -06:00
@onready var bud: MeshInstance3D = $FrameSkipper/AlarmMesh/Armature/Skeleton3D/Bud
2025-04-02 20:09:09 -06:00
@onready var alarm_sfx: AudioStreamPlayer3D = %AlarmSFX
2025-03-13 13:34:35 -06:00
## Trigger this alarm.
##
## Will not trigger if this alarm is busy (e.g. on cooldown)
func trigger() -> void:
if not _busy:
_busy = true
2025-03-13 14:50:59 -06:00
Game.manager.raise_alert(ALERT_DELTA)
2025-03-13 13:34:35 -06:00
animation_player.play("trigger")
2025-04-19 17:31:21 -06:00
effect_animation.play("trigger")
2025-04-02 20:09:09 -06:00
alarm_sfx.play()
2025-03-13 13:34:35 -06:00
## Pulse this alarm, resetting the pulse countdown until triggering.
##
## Note that alarms will not begin the pulse countdown until receiving the first pulse.
## On networks without a heart, the pulse timeout will be completely ignored.
func pulse() -> void:
pulse_listener_timer.start(pulse_timeout)
2025-03-13 13:34:35 -06:00
func _process(delta: float) -> void:
2025-03-28 14:16:43 -06:00
if Engine.is_editor_hint():
return
2025-03-13 13:34:35 -06:00
super._process(delta)
# TODO actual model & animation
var shader: ShaderMaterial = bud.get_surface_override_material(0)
2025-03-28 14:16:43 -06:00
var damage := pct_damage()
shader.set_shader_parameter("jitter_time_scale", pow(damage * JITTER_SCALE_FACTOR, 1.2))
shader.set_shader_parameter("vertex_inflation", pow(damage * JITTER_INFLATION_FACTOR, 3))
# TODO pulse animation
2025-03-13 13:34:35 -06:00
func _on_animation_finished(anim_name: StringName) -> void:
if anim_name == "trigger":
_busy = false