29 lines
1.0 KiB
GDScript
29 lines
1.0 KiB
GDScript
extends CharacterBody3D
|
|
|
|
@export var stats: BaseStats
|
|
|
|
func _ready() -> void:
|
|
add_to_group("player")
|
|
Stats.register(self, stats)
|
|
var cooldown_system: Node = get_tree().get_first_node_in_group("cooldown_system")
|
|
if cooldown_system:
|
|
cooldown_system.register(self, 5)
|
|
if GameState.returning_from_dungeon:
|
|
GameState.restore_player(self)
|
|
global_position = GameState.portal_position + Vector3(0, 1, -5)
|
|
GameState.returning_from_dungeon = false
|
|
elif GameState.dungeon_cleared:
|
|
GameState.clear()
|
|
var health: float = Stats.get_stat(self, "health")
|
|
var max_health: float = Stats.get_stat(self, "max_health")
|
|
var shield: float = Stats.get_stat(self, "shield")
|
|
var max_shield: float = Stats.get_stat(self, "max_shield")
|
|
EventBus.health_changed.emit(self, health, max_health)
|
|
EventBus.shield_changed.emit(self, shield, max_shield)
|
|
|
|
func _exit_tree() -> void:
|
|
Stats.deregister(self)
|
|
var cooldown_system: Node = get_tree().get_first_node_in_group("cooldown_system")
|
|
if cooldown_system:
|
|
cooldown_system.deregister(self)
|