Stacking effects
This commit is contained in:
@@ -27,7 +27,7 @@ func on_area2d_body_entered(body: Node2D) -> void:
|
|||||||
if invulnerability_component and invulnerability_component.is_invulnerable():
|
if invulnerability_component and invulnerability_component.is_invulnerable():
|
||||||
return
|
return
|
||||||
|
|
||||||
if status_effect_data.effect_type != StatusEffectComponent.EffectType.NONE:
|
if status_effect_data and status_effect_data.effect_type != StatusEffectComponent.EffectType.NONE:
|
||||||
effect_inflicted.emit(body, status_effect_data)
|
effect_inflicted.emit(body, status_effect_data)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
class_name EffectInflictorComponent
|
class_name EffectInflictorComponent
|
||||||
extends Node
|
extends Node
|
||||||
|
|
||||||
@export var damage: DamageComponent
|
@export var damage: DamageComponent
|
||||||
@@ -18,5 +18,3 @@ func on_effect_inflicted(target: Node2D, effect: StatusEffectDataResource) -> vo
|
|||||||
return
|
return
|
||||||
|
|
||||||
status_effect_component.apply_effect(effect)
|
status_effect_component.apply_effect(effect)
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
class_name FireEffectComponent
|
class_name FireEffectComponent
|
||||||
extends Node
|
extends Node
|
||||||
|
|
||||||
@export var health_component: HealthComponent
|
@export var health_component: HealthComponent
|
||||||
|
@@ -5,6 +5,7 @@ extends Node
|
|||||||
@export var status_effect_component: StatusEffectComponent
|
@export var status_effect_component: StatusEffectComponent
|
||||||
|
|
||||||
var data: StatusEffectDataResource = null
|
var data: StatusEffectDataResource = null
|
||||||
|
var ice_effects_applied: int = 0
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
@@ -22,19 +23,21 @@ func _ready() -> void:
|
|||||||
func on_effect_applied(effect_data: StatusEffectDataResource) -> void:
|
func on_effect_applied(effect_data: StatusEffectDataResource) -> void:
|
||||||
if effect_data.effect_type == StatusEffectComponent.EffectType.ICE:
|
if effect_data.effect_type == StatusEffectComponent.EffectType.ICE:
|
||||||
data = effect_data
|
data = effect_data
|
||||||
|
ice_effects_applied += 1
|
||||||
apply_freeze()
|
apply_freeze()
|
||||||
|
|
||||||
|
|
||||||
func on_effect_removed(effect_type: StatusEffectComponent.EffectType) -> void:
|
func on_effect_removed(effect_type: StatusEffectComponent.EffectType) -> void:
|
||||||
if effect_type == StatusEffectComponent.EffectType.ICE:
|
if effect_type == StatusEffectComponent.EffectType.ICE:
|
||||||
data = null
|
data = null
|
||||||
|
ice_effects_applied -= 1
|
||||||
remove_freeze()
|
remove_freeze()
|
||||||
|
|
||||||
|
|
||||||
func apply_freeze() -> void:
|
func apply_freeze() -> void:
|
||||||
for component_path in components_to_disable:
|
for component_path in components_to_disable:
|
||||||
var component: Node = get_node_or_null(component_path)
|
var component: Node = get_node_or_null(component_path)
|
||||||
if not component:
|
if not component or ice_effects_applied == 0:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
component.process_mode = PROCESS_MODE_DISABLED
|
component.process_mode = PROCESS_MODE_DISABLED
|
||||||
@@ -43,7 +46,7 @@ func apply_freeze() -> void:
|
|||||||
func remove_freeze() -> void:
|
func remove_freeze() -> void:
|
||||||
for component_path in components_to_disable:
|
for component_path in components_to_disable:
|
||||||
var component: Node = get_node_or_null(component_path)
|
var component: Node = get_node_or_null(component_path)
|
||||||
if not component:
|
if not component or ice_effects_applied > 0:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
component.process_mode = PROCESS_MODE_ALWAYS
|
component.process_mode = PROCESS_MODE_ALWAYS
|
@@ -6,41 +6,40 @@ enum EffectType {
|
|||||||
FIRE,
|
FIRE,
|
||||||
ICE
|
ICE
|
||||||
}
|
}
|
||||||
var active_effect: StatusEffectDataResource = null
|
var active_effects: Array = []
|
||||||
var timer: Timer
|
|
||||||
var is_active: bool = false
|
|
||||||
var time_elapsed: float = 0.0
|
|
||||||
signal effect_applied(effect_data: StatusEffectDataResource)
|
signal effect_applied(effect_data: StatusEffectDataResource)
|
||||||
signal effect_removed(effect_type: EffectType)
|
signal effect_removed(effect_type: EffectType)
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
|
||||||
timer = Timer.new()
|
|
||||||
timer.timeout.connect(on_timer_timeout)
|
|
||||||
add_child(timer)
|
|
||||||
|
|
||||||
|
|
||||||
func apply_effect(effect_data: StatusEffectDataResource) -> void:
|
func apply_effect(effect_data: StatusEffectDataResource) -> void:
|
||||||
if is_active:
|
var data: StatusEffectDataResource = effect_data.duplicate()
|
||||||
|
|
||||||
|
var timer: Timer = create_timer(effect_data.duration, data)
|
||||||
|
|
||||||
|
var new_effect: Dictionary = {
|
||||||
|
"data": data,
|
||||||
|
"elapsed_time": 0.0,
|
||||||
|
"timer": timer
|
||||||
|
}
|
||||||
|
|
||||||
|
active_effects.append(new_effect)
|
||||||
|
effect_applied.emit(effect_data)
|
||||||
|
|
||||||
|
|
||||||
|
func remove_effect(effect_data: StatusEffectDataResource) -> void:
|
||||||
|
for i in range(active_effects.size()):
|
||||||
|
if active_effects[i].data == effect_data:
|
||||||
|
active_effects[i].timer.queue_free()
|
||||||
|
active_effects.remove_at(i)
|
||||||
|
effect_removed.emit(effect_data.effect_type)
|
||||||
return
|
return
|
||||||
|
|
||||||
is_active = true
|
|
||||||
active_effect = effect_data
|
|
||||||
prepare_timer()
|
|
||||||
effect_applied.emit(active_effect)
|
|
||||||
timer.start()
|
|
||||||
|
|
||||||
|
func create_timer(duration: float, effect_data: StatusEffectDataResource) -> Timer:
|
||||||
func remove_effect() -> void:
|
var timer = Timer.new()
|
||||||
is_active = false
|
timer.wait_time = duration
|
||||||
effect_removed.emit(active_effect.effect_type)
|
timer.one_shot = true
|
||||||
|
timer.autostart = true
|
||||||
|
timer.timeout.connect(func(): remove_effect(effect_data))
|
||||||
func on_timer_timeout() -> void:
|
add_child(timer)
|
||||||
remove_effect()
|
return timer
|
||||||
|
|
||||||
|
|
||||||
func prepare_timer() -> void:
|
|
||||||
timer.set_wait_time(active_effect.duration)
|
|
||||||
timer.set_one_shot(true)
|
|
||||||
timer.stop()
|
|
Reference in New Issue
Block a user