From 0072a5e2e34f273b235f71efd4755612a20ed211 Mon Sep 17 00:00:00 2001 From: RealMelwei Date: Tue, 14 Oct 2025 15:57:23 +0200 Subject: [PATCH] Documented status code --- statusses/status.gd | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/statusses/status.gd b/statusses/status.gd index 19dbe85..5697352 100644 --- a/statusses/status.gd +++ b/statusses/status.gd @@ -1,12 +1,23 @@ +# Status inherits from Timer: The time until the status expires. class_name Status extends Timer var params = {} const default_parameters = { + # Vulnerable: Player Status. Increases Damage taken by 1 per Hit "Vulnerable": {}, + # Slow: Player Status. Decreases movement speed by speed_factor. + # Can theoretically also be used to increase speed. "Slow": { "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 = {}): if not target.has_node(status_name): 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) child.reapply(duration) +# Checks whether the target is affected by the given status. static func affects(status_name : String, target : Node) -> bool: 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: if affects(status_name, target): return target.get_node(status_name) else: return null -func _enter_tree() -> void: - timeout.connect(expire) - +# By default, reapplying a status resets the duration and merges the new parameters into the given ones. func reapply(duration_new : float, params_new : Dictionary = {}): self.start(max(duration_new, time_left)) merge_params(params_new) +# Controls the override behavior of each status func merge_params(params_new): 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)