41 lines
1.1 KiB
GDScript
41 lines
1.1 KiB
GDScript
class_name Status extends Timer
|
|
var params = {}
|
|
const default_parameters = {
|
|
"Vulnerable": {},
|
|
"Slow": {
|
|
"slow_factor": 0.6
|
|
}
|
|
}
|
|
|
|
static func apply(status_name : String, target : Node, duration : float, params_in : Dictionary = {}):
|
|
if not target.has_node(status_name):
|
|
var child = Status.new()
|
|
child.name = status_name
|
|
child.params = params_in
|
|
child.params.merge(get_default_parameters(status_name))
|
|
target.add_child(child)
|
|
child.start(duration)
|
|
else:
|
|
var child : Status = target.get_node(status_name)
|
|
child.reapply(duration)
|
|
|
|
static func affects(status_name : String, target : Node) -> bool:
|
|
return target.has_node(status_name)
|
|
|
|
static func get_status(status_name : String, target : Node) -> Status:
|
|
if affects(status_name, target):
|
|
return target.get_node(status_name)
|
|
else:
|
|
return null
|
|
|
|
func _enter_tree() -> void:
|
|
timeout.connect(expire)
|
|
|
|
func reapply(duration_new : float):
|
|
self.start(max(duration_new, time_left))
|
|
|
|
func expire():
|
|
queue_free()
|
|
|
|
static func get_default_parameters(status_name : String) -> Dictionary:
|
|
return default_parameters.get(status_name) if default_parameters.has(status_name) else {}
|