34 lines
911 B
GDScript
34 lines
911 B
GDScript
extends StaticBody3D
|
|
|
|
@export var stats: BaseStats
|
|
|
|
const GATE_SCENE: PackedScene = preload("res://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
|
|
if not is_inside_tree():
|
|
return
|
|
var pos: Vector3 = global_position
|
|
var gate: Node3D = GATE_SCENE.instantiate()
|
|
gate.global_position = pos
|
|
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)
|