mirror of
https://gitlab.com/open-fpsz/open-fpsz.git
synced 2026-03-27 08:09:25 +00:00
38 lines
782 B
GDScript
38 lines
782 B
GDScript
extends Area3D
|
|
class_name HealthComponent
|
|
|
|
@export var max_health : float = 100.0
|
|
@export var health : float = 100.0:
|
|
set(value):
|
|
health = value
|
|
health_changed.emit(value)
|
|
|
|
signal health_zeroed
|
|
signal health_changed(value : int)
|
|
|
|
func _ready():
|
|
heal_full()
|
|
area_entered.connect(_on_area_entered)
|
|
|
|
@rpc("call_local")
|
|
func _damage(amount : int) -> void:
|
|
health = clampf(health - amount, 0.0, max_health)
|
|
if health == 0.0:
|
|
health_zeroed.emit()
|
|
|
|
@rpc("call_local")
|
|
func _heal(amount : int):
|
|
health = clampf(health + amount, 0.0, max_health)
|
|
|
|
func heal_full():
|
|
if not is_multiplayer_authority():
|
|
return
|
|
|
|
_heal.rpc(max_health)
|
|
|
|
func _on_area_entered(area : Area3D):
|
|
if not is_multiplayer_authority():
|
|
return
|
|
|
|
if area is AreaDamageComponent:
|
|
_damage.rpc(area.damage)
|