Files
mmo/scripts/portal/portal.gd
Marek Lenczewski e76c66eda6 update
2026-04-01 22:53:28 +02:00

31 lines
855 B
GDScript

extends StaticBody3D
@export var stats: BaseStats
const GATE_SCENE: PackedScene = preload("res://scenes/portal/gate.tscn")
func _ready() -> void:
add_to_group("portals")
Stats.register(self, stats)
EventBus.entity_died.connect(_on_entity_died)
func _exit_tree() -> void:
Stats.deregister(self)
func _on_entity_died(entity: Node) -> void:
if entity != self:
return
var gate: Node3D = GATE_SCENE.instantiate()
gate.global_position = global_position
get_parent().add_child(gate)
var enemies := get_tree().get_nodes_in_group("enemies")
for enemy in enemies:
if is_instance_valid(enemy):
enemy.queue_free()
EventBus.portal_defeated.emit(self)
queue_free()
func _on_detection_area_body_entered(body: Node3D) -> void:
if body is CharacterBody3D and body.name == "Player":
EventBus.enemy_engaged.emit(self, body)