This commit is contained in:
Marek Lenczewski
2026-04-04 00:00:15 +02:00
parent 3488856b91
commit f1d34ebf1d
104 changed files with 1912 additions and 1789 deletions

View File

@@ -2,8 +2,6 @@ extends Node
const ENEMY_SCENE: PackedScene = preload("res://scenes/enemy/enemy.tscn")
var portal_data: Dictionary = {}
func _ready() -> void:
EventBus.health_changed.connect(_on_health_changed)
EventBus.entity_died.connect(_on_entity_died)
@@ -11,22 +9,18 @@ func _ready() -> void:
func _on_health_changed(entity: Node, current: float, max_val: float) -> void:
if not entity.is_in_group("portals"):
return
if entity not in portal_data:
var base: BaseStats = Stats.get_base(entity)
var thresholds: Array[float] = base.thresholds if base is PortalStats else [0.85, 0.70, 0.55, 0.40, 0.25, 0.10]
var triggered: Array[bool] = []
triggered.resize(thresholds.size())
triggered.fill(false)
portal_data[entity] = { "thresholds": thresholds, "triggered": triggered }
if current <= 0:
return
var data: Dictionary = portal_data[entity]
var data: Dictionary = PortalData.entities.get(entity, {})
if data.is_empty():
return
var ratio: float = current / max_val
var base: BaseStats = Stats.get_base(entity)
var spawn_count: int = base.spawn_count if base is PortalStats else 3
for i in range(data["thresholds"].size()):
if not data["triggered"][i] and ratio <= data["thresholds"][i]:
data["triggered"][i] = true
var thresholds: Array = data["thresholds"]
var triggered: Array = data["triggered"]
var spawn_count: int = data["spawn_count"]
for i in range(thresholds.size()):
if not triggered[i] and ratio <= thresholds[i]:
triggered[i] = true
_spawn_enemies(entity, spawn_count)
func _spawn_enemies(portal: Node, count: int) -> void:
@@ -36,8 +30,6 @@ func _spawn_enemies(portal: Node, count: int) -> void:
var offset := Vector3(randf_range(-2, 2), 0, randf_range(-2, 2))
portal.get_parent().add_child(entity)
entity.global_position = portal.global_position + offset
entity.spawn_position = portal.global_position
entity.portal = portal
spawned.append(entity)
var player: Node = get_tree().get_first_node_in_group("player")
if player:
@@ -49,4 +41,4 @@ func _spawn_enemies(portal: Node, count: int) -> void:
func _on_entity_died(entity: Node) -> void:
if entity.is_in_group("portals"):
portal_data.erase(entity)
PortalData.deregister(entity)