84 lines
2.3 KiB
GDScript
84 lines
2.3 KiB
GDScript
class_name BurstComponent
|
|
extends Node
|
|
|
|
signal burst_changed(burst_ready: bool, active: bool, cooldown: int)
|
|
|
|
const BURST_EFFECT_PATH := "res://resources/effects/effect_burst_power.tres"
|
|
|
|
@export var active_beats := 16
|
|
@export var cooldown_beats := 4
|
|
|
|
var burst_ready := false
|
|
var active := false
|
|
var cooldown := 0
|
|
var _beats_left := 0
|
|
@onready var effect_container: Node = get_node_or_null("../EffectContainer")
|
|
|
|
|
|
func _ready() -> void:
|
|
var rhythm := get_tree().root.get_node_or_null("RhythmManager")
|
|
if rhythm != null and not rhythm.is_connected("beat_ticked", _on_beat_ticked):
|
|
rhythm.connect("beat_ticked", _on_beat_ticked)
|
|
|
|
|
|
func set_ready(value: bool) -> void:
|
|
if active or cooldown > 0:
|
|
burst_ready = false
|
|
else:
|
|
burst_ready = value
|
|
burst_changed.emit(burst_ready, active, cooldown)
|
|
|
|
|
|
func activate() -> bool:
|
|
if not burst_ready or active or cooldown > 0:
|
|
return false
|
|
burst_ready = false
|
|
active = true
|
|
_beats_left = active_beats
|
|
_apply_burst_effect()
|
|
burst_changed.emit(burst_ready, active, cooldown)
|
|
return true
|
|
|
|
|
|
func damage_mult(_action: Resource = null) -> float:
|
|
return _effect_stat_multiplier(&"damage_mult")
|
|
|
|
|
|
func cost_mult(_action: Resource = null) -> float:
|
|
return _effect_stat_multiplier(&"cost_mult")
|
|
|
|
|
|
func move_mult(_action: Resource = null) -> float:
|
|
return 1.0
|
|
|
|
|
|
func _on_beat_ticked(_beat_index: int) -> void:
|
|
if active:
|
|
_beats_left -= 1
|
|
if _beats_left <= 0:
|
|
active = false
|
|
cooldown = cooldown_beats
|
|
burst_changed.emit(burst_ready, active, cooldown)
|
|
elif cooldown > 0:
|
|
cooldown -= 1
|
|
burst_changed.emit(burst_ready, active, cooldown)
|
|
|
|
|
|
func _apply_burst_effect() -> void:
|
|
if effect_container == null:
|
|
effect_container = get_node_or_null("../EffectContainer")
|
|
if effect_container != null and effect_container.has_method("add_effect"):
|
|
var burst_effect: Resource = load(BURST_EFFECT_PATH) if ResourceLoader.exists(BURST_EFFECT_PATH) else null
|
|
if burst_effect != null:
|
|
effect_container.call("add_effect", burst_effect, &"burst")
|
|
|
|
|
|
func _effect_stat_multiplier(stat: StringName) -> float:
|
|
if not active:
|
|
return 1.0
|
|
if effect_container == null:
|
|
effect_container = get_node_or_null("../EffectContainer")
|
|
if effect_container != null and effect_container.has_method("stat_multiplier"):
|
|
return float(effect_container.call("stat_multiplier", stat, null))
|
|
return 1.0
|