2024-02-22 06:22:22 +11:00
|
|
|
class_name StatusEffector extends Node3D
|
2023-11-08 14:28:55 +11:00
|
|
|
|
2024-02-22 06:22:22 +11:00
|
|
|
@export var hbox: HBoxContainer
|
|
|
|
@export var enemy: EnemyController
|
2023-11-08 14:28:55 +11:00
|
|
|
|
2024-02-22 06:22:22 +11:00
|
|
|
var icon_scene: PackedScene = preload("res://Scenes/status_icon.tscn")
|
|
|
|
var immune: Array[StatusEffect] = []
|
|
|
|
var effects: Dictionary = {}
|
|
|
|
var icons: Dictionary = {}
|
2023-11-11 19:03:01 +11:00
|
|
|
|
|
|
|
|
|
|
|
func _process(delta: float) -> void:
|
2024-02-22 06:22:22 +11:00
|
|
|
for effect: StatusEffect in effects:
|
2023-11-11 19:03:01 +11:00
|
|
|
if effects[effect] == 0:
|
|
|
|
continue
|
|
|
|
effect.time_since_proc += delta
|
|
|
|
effect.time_existed += delta
|
|
|
|
if effect.stats.duration > 0.0 and effect.time_existed >= effect.stats.duration:
|
|
|
|
effect.time_existed -= effect.stats.duration
|
|
|
|
effects[effect] -= 1
|
|
|
|
effect.on_removed(enemy, effects)
|
|
|
|
if effects[effect] == 0:
|
|
|
|
icons[effect].set_visible(false)
|
|
|
|
if effect.time_since_proc >= effect.stats.proc_cd:
|
|
|
|
effect.proc(enemy, effects[effect], effects)
|
|
|
|
effect.time_since_proc -= effect.stats.proc_cd
|
|
|
|
|
|
|
|
|
2024-02-22 06:22:22 +11:00
|
|
|
func force_proc(effect_to_proc: StatusEffect) -> void:
|
|
|
|
for effect: StatusEffect in effects:
|
2023-11-11 19:03:01 +11:00
|
|
|
if effect.stats == effect_to_proc.stats:
|
|
|
|
effect.proc(enemy, effects[effect], effects)
|
2023-11-08 14:28:55 +11:00
|
|
|
|
|
|
|
|
2024-02-22 06:22:22 +11:00
|
|
|
func add_effect(new_effect: StatusEffect) -> void:
|
|
|
|
for effect: StatusEffect in immune:
|
2023-11-11 19:03:01 +11:00
|
|
|
if effect.stats == new_effect.stats:
|
|
|
|
return
|
|
|
|
|
2024-02-22 06:22:22 +11:00
|
|
|
var existing_effect: StatusEffect
|
|
|
|
for effect: StatusEffect in effects:
|
2023-11-08 14:28:55 +11:00
|
|
|
if effect.stats == new_effect.stats:
|
2023-11-11 19:03:01 +11:00
|
|
|
existing_effect = effect
|
|
|
|
if !existing_effect:
|
|
|
|
existing_effect = new_effect
|
|
|
|
effects[new_effect] = 0
|
2024-02-22 06:22:22 +11:00
|
|
|
var icon: TextureRect = icon_scene.instantiate()
|
2023-11-08 14:28:55 +11:00
|
|
|
icon.texture = new_effect.stats.icon
|
2023-11-11 19:03:01 +11:00
|
|
|
icon.set_visible(false)
|
|
|
|
icons[new_effect] = icon
|
2023-11-08 14:28:55 +11:00
|
|
|
hbox.add_child(icon)
|
2023-11-11 19:03:01 +11:00
|
|
|
|
|
|
|
if existing_effect.stats.max_stacks == 0 or effects[existing_effect] < existing_effect.stats.max_stacks:
|
|
|
|
existing_effect.on_attached(enemy, effects)
|
|
|
|
icons[existing_effect].set_visible(true)
|
|
|
|
effects[existing_effect] += 1
|
2023-11-16 00:07:41 +11:00
|
|
|
existing_effect.time_existed = 0.0
|
2023-11-11 19:03:01 +11:00
|
|
|
if existing_effect.stats.max_stacks != 0 and effects[existing_effect] > existing_effect.stats.max_stacks:
|
|
|
|
effects[existing_effect] = existing_effect.stats.max_stacks
|