Documented status code
This commit is contained in:
parent
c2649a6032
commit
0072a5e2e3
1 changed files with 15 additions and 3 deletions
|
|
@ -1,12 +1,23 @@
|
||||||
|
# Status inherits from Timer: The time until the status expires.
|
||||||
class_name Status extends Timer
|
class_name Status extends Timer
|
||||||
var params = {}
|
var params = {}
|
||||||
const default_parameters = {
|
const default_parameters = {
|
||||||
|
# Vulnerable: Player Status. Increases Damage taken by 1 per Hit
|
||||||
"Vulnerable": {},
|
"Vulnerable": {},
|
||||||
|
# Slow: Player Status. Decreases movement speed by speed_factor.
|
||||||
|
# Can theoretically also be used to increase speed.
|
||||||
"Slow": {
|
"Slow": {
|
||||||
"slow_factor": 0.6
|
"slow_factor": 0.6
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
timeout.connect(expire)
|
||||||
|
one_shot = true
|
||||||
|
|
||||||
|
# Applies the given Status as a child to the target node for the given duration.
|
||||||
|
# Was intended to work through statusses inheriting from Status, but Godot inheritance interacts terribly with static things.
|
||||||
|
# If that status is already present on the node, duration is reset and reapply is called.
|
||||||
static func apply(status_name : String, target : Node, duration : float, params_in : Dictionary = {}):
|
static func apply(status_name : String, target : Node, duration : float, params_in : Dictionary = {}):
|
||||||
if not target.has_node(status_name):
|
if not target.has_node(status_name):
|
||||||
var child = Status.new()
|
var child = Status.new()
|
||||||
|
|
@ -19,22 +30,23 @@ static func apply(status_name : String, target : Node, duration : float, params_
|
||||||
var child : Status = target.get_node(status_name)
|
var child : Status = target.get_node(status_name)
|
||||||
child.reapply(duration)
|
child.reapply(duration)
|
||||||
|
|
||||||
|
# Checks whether the target is affected by the given status.
|
||||||
static func affects(status_name : String, target : Node) -> bool:
|
static func affects(status_name : String, target : Node) -> bool:
|
||||||
return target.has_node(status_name)
|
return target.has_node(status_name)
|
||||||
|
|
||||||
|
# Returns the status on the target, or null if the status is not present.
|
||||||
static func get_status(status_name : String, target : Node) -> Status:
|
static func get_status(status_name : String, target : Node) -> Status:
|
||||||
if affects(status_name, target):
|
if affects(status_name, target):
|
||||||
return target.get_node(status_name)
|
return target.get_node(status_name)
|
||||||
else:
|
else:
|
||||||
return null
|
return null
|
||||||
|
|
||||||
func _enter_tree() -> void:
|
# By default, reapplying a status resets the duration and merges the new parameters into the given ones.
|
||||||
timeout.connect(expire)
|
|
||||||
|
|
||||||
func reapply(duration_new : float, params_new : Dictionary = {}):
|
func reapply(duration_new : float, params_new : Dictionary = {}):
|
||||||
self.start(max(duration_new, time_left))
|
self.start(max(duration_new, time_left))
|
||||||
merge_params(params_new)
|
merge_params(params_new)
|
||||||
|
|
||||||
|
# Controls the override behavior of each status
|
||||||
func merge_params(params_new):
|
func merge_params(params_new):
|
||||||
if name == "Slow" and params.has("slow_factor") and params_new.has("slow_factor"):
|
if name == "Slow" and params.has("slow_factor") and params_new.has("slow_factor"):
|
||||||
params.slow_factor = min(params.slow_factor, params_new.slow_factor)
|
params.slow_factor = min(params.slow_factor, params_new.slow_factor)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue