This commit is contained in:
Marek Le
2026-03-30 09:03:29 +02:00
parent 80a65fa555
commit 4fddc74df1
31 changed files with 295 additions and 153 deletions

View File

@@ -49,7 +49,7 @@ func _try_target_under_mouse(mouse_pos: Vector2) -> void:
set_target(null)
func _cycle_target() -> void:
var targets := get_tree().get_nodes_in_group("targetable")
var targets := get_tree().get_nodes_in_group("enemies") + get_tree().get_nodes_in_group("portals")
if targets.is_empty():
set_target(null)
return
@@ -70,23 +70,26 @@ func _on_enemy_engaged(_enemy: Node, target: Node) -> void:
if not in_combat:
in_combat = true
if current_target == null:
_target_nearest()
_auto_target()
func _on_damage_dealt(_attacker: Node, target: Node, _amount: float) -> void:
func _on_damage_dealt(attacker: Node, target: Node, _amount: float) -> void:
if target == player:
combat_timer = COMBAT_TIMEOUT
if not in_combat:
in_combat = true
if current_target == null:
_target_nearest()
_auto_target()
elif attacker == player and in_combat:
combat_timer = COMBAT_TIMEOUT
func _on_entity_died(entity: Node) -> void:
if entity == current_target:
set_target(null)
if in_combat:
_target_nearest_except(entity)
_auto_target(entity)
func _target_nearest_except(exclude: Node = null) -> void:
func _auto_target(exclude: Node = null) -> void:
# Priorität 1: Nächster Gegner
var enemies := get_tree().get_nodes_in_group("enemies")
var nearest: Node3D = null
var nearest_dist: float = INF
@@ -98,16 +101,14 @@ func _target_nearest_except(exclude: Node = null) -> void:
nearest = enemy
if nearest:
set_target(nearest)
func _target_nearest() -> void:
var enemies := get_tree().get_nodes_in_group("enemies")
var nearest: Node3D = null
var nearest_dist: float = INF
for enemy in enemies:
if is_instance_valid(enemy):
var dist: float = player.global_position.distance_to(enemy.global_position)
return
# Priorität 2: Nächstes Portal
var portals := get_tree().get_nodes_in_group("portals")
for p in portals:
if is_instance_valid(p) and p != exclude:
var dist: float = player.global_position.distance_to(p.global_position)
if dist < nearest_dist:
nearest_dist = dist
nearest = enemy
nearest = p
if nearest:
set_target(nearest)