oh man i fixed that status effect bug
This commit is contained in:
@ -1,12 +1,12 @@
|
||||
class_name StatusEffector extends Node3D
|
||||
class_name StatusEffector extends Node
|
||||
|
||||
@export var hbox: HBoxContainer
|
||||
@export var enemy: EnemyController
|
||||
@export var sprite_container: Container ## Container that effect icons should be instantiated under
|
||||
|
||||
var enemy: EnemyController ## Enemy Controller that this node should affect
|
||||
var icon_scene: PackedScene = preload("res://Scenes/status_icon.tscn")
|
||||
var immune: Array[StatusEffect] = []
|
||||
var effects: Dictionary = {}
|
||||
var icons: Dictionary = {}
|
||||
var immunities: Array[StatusEffect] = [] ## The set of status effects that this effector shouldn't apply
|
||||
var effects: Dictionary[StatusEffect, int] = {}
|
||||
var icons: Dictionary[StatusEffect, TextureRect] = {}
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
@ -20,7 +20,7 @@ func _process(delta: float) -> void:
|
||||
effects[effect] -= 1
|
||||
effect.on_removed(enemy, effects)
|
||||
if effects[effect] == 0:
|
||||
icons[effect].set_visible(false)
|
||||
icons[effect].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
|
||||
@ -33,27 +33,25 @@ func force_proc(effect_to_proc: StatusEffect) -> void:
|
||||
|
||||
|
||||
func add_effect(new_effect: StatusEffect) -> void:
|
||||
for effect: StatusEffect in immune:
|
||||
# Return early if this node immune to the new effect
|
||||
for effect: StatusEffect in immunities:
|
||||
if effect.stats == new_effect.stats:
|
||||
return
|
||||
|
||||
var existing_effect: StatusEffect
|
||||
|
||||
var existing_effect: StatusEffect = null
|
||||
for effect: StatusEffect in effects:
|
||||
if effect.stats == new_effect.stats:
|
||||
existing_effect = effect
|
||||
if !existing_effect:
|
||||
existing_effect = new_effect
|
||||
effects[new_effect] = 0
|
||||
existing_effect = new_effect.duplicate()
|
||||
effects[existing_effect] = 0
|
||||
var icon: TextureRect = icon_scene.instantiate()
|
||||
icon.texture = new_effect.stats.icon
|
||||
icon.set_visible(false)
|
||||
icons[new_effect] = icon
|
||||
hbox.add_child(icon)
|
||||
icon.texture = existing_effect.stats.icon
|
||||
icons[existing_effect] = icon
|
||||
sprite_container.add_child(icon)
|
||||
|
||||
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)
|
||||
icons[existing_effect].visible = true
|
||||
effects[existing_effect] += 1
|
||||
existing_effect.time_existed = 0.0
|
||||
if existing_effect.stats.max_stacks != 0 and effects[existing_effect] > existing_effect.stats.max_stacks:
|
||||
effects[existing_effect] = existing_effect.stats.max_stacks
|
||||
|
Reference in New Issue
Block a user