# Datenflows

## 1. Kampf-Flow (Schaden)

```
Spieler drückt 1-4          Gegner im ATTACK-State
        │                           │
   combat.gd                  enemy_ai_system.gd
        │                           │
        ▼                           ▼
ability_use_requested ──►  AbilitySystem  ◄── _process (Auto-Attack)
                                │
                    damage_requested(attacker, target, amount)
                                │
                                ▼
                          HealthSystem
                          ├── ShieldSystem.absorb() → Schild reduzieren
                          │       └── shield_changed / shield_broken
                          ├── damage_dealt ──► AggroSystem (Aggro aufbauen)
                          ├── health_changed ──► Healthbar, HUD, SpawnSystem
                          └── falls HP=0: entity_died
                                    │
                        ┌───────────┼───────────┐
                        ▼           ▼           ▼
                  AggroSystem  RespawnSystem  SpawnSystem
                  (Tabelle     (Spieler:      (Portal:
                   aufräumen)   3s → Taverne)  Daten löschen)
```

## 2. Kampf-Flow (Heilung)

```
Heiler drückt 1/2/4 (is_heal) oder Auto-Attack (aa_is_heal)
        │
   AbilitySystem
        │
   heal_requested(healer, target, amount)
        │
        ├──► HealthSystem → HP erhöhen → health_changed → HUD
        └──► AggroSystem  → 0.5x Aggro auf ALLE Gegner die Heiler kennen
```

## 3. Aggro-Flow

```
damage_dealt ──► AggroSystem._on_damage_dealt()
                   │  Tank-Rolle → 2x Multiplikator
                   ▼
              aggro_tables[enemy][player] += amount

heal_requested ──► AggroSystem._on_heal_requested()
                     │  0.5x auf ALLE Gegner mit Heiler in Tabelle
                     ▼
                aggro_tables[enemy][healer] += amount * 0.5

enemy_detected ──► AggroSystem._on_enemy_detected()
                     │  +1 Aggro, State → CHASE
                     └──► _alert_nearby() → Nachbarn im alert_radius auch aktivieren

_process(delta):
  ├── Aggro decay: -aggro_decay/s
  ├── Außerhalb Portal-Radius: exponentieller Decay (+1%·2^sekunden)
  ├── Innerhalb Portal-Radius: Minimum 1.0 Aggro
  └── _update_target(): Höchster Aggro-Wert → enemy.target + State
```

## 4. Portal → Dungeon Flow

```
Portal wird angegriffen
        │
   health_changed ──► SpawnSystem
        │               └── HP-Schwellen (85/70/55/40/25/10%) → Gegner spawnen
        │                         └── portal_spawn Signal
        ▼
   Portal HP = 0 → entity_died
        │
   portal.gd: _on_entity_died()
        ├── Mesh → grün (Gate-Look)
        ├── Gegner mit Portal löschen
        └── Gate instanzieren an Portal-Position
              └── portal_defeated Signal

Spieler betritt Gate
        │
   gate.gd: _on_gate_area_body_entered()
        ├── GameState.save_player() → Rolle speichern
        ├── Stats.deregister() → player_cache befüllen
        └── change_scene → dungeon.tscn
                              │
                        dungeon_manager.gd _ready()
                              ├── Stats.register() → player_cache wiederherstellen
                              └── GameState.restore_player() → Rolle setzen
```

## 5. Dungeon → Welt Flow

```
Boss stirbt → entity_died
        │
   dungeon_manager.gd: _on_entity_died()
        ├── 2s warten
        ├── GameState.dungeon_cleared = true
        ├── GameState.clear() → Stats.clear_player_cache()
        ├── dungeon_cleared Signal
        └── change_scene → world.tscn
                              │
                        Spieler spawnt bei Taverne (0, 1, -5)
                        volle HP + Schild (durch clear_player_cache)

Exit-Gate (zurück zur Welt ohne Boss-Kill):
        ├── GameState.returning_from_dungeon = true
        └── change_scene → world.tscn
              └── Spieler bei portal_position, Stats aus Cache
```

## 6. Rollen-Flow

```
Spieler drückt ALT+1/2/3
        │
   role.gd: set_role()
        │
   role_changed(player, role_type)
        │
        ├──► BuffSystem: Passive-Buffs berechnen
        │      ├── buff_damage/buff_heal/buff_shield in Stats setzen
        │      ├── max_shield anpassen (Tank-Passive)
        │      └── buff_changed + shield_changed Signals
        │
        └──► CooldownSystem: Alle Cooldowns zurücksetzen
```

## 7. Cooldown-Flow

```
AbilitySystem führt Ability aus
        │
   CooldownSystem.set_cooldown(player, index, cd, gcd)
        │
   _process(delta): Alle Timer runterzählen
        │
   cooldown_tick(cds, max_cds, gcd_timer) ──► HUD (Ability-Icons updaten)
        │
   AbilitySystem fragt vor Ausführung:
        ├── is_ready(player, index) — Ability-CD abgelaufen?
        ├── is_gcd_ready(player) — GCD abgelaufen?
        └── is_aa_ready(player) — Auto-Attack bereit?
```

## 8. Respawn-Flow

```
entity_died (Spieler)
        │
   RespawnSystem._on_entity_died()
        ├── Mesh/Collision/Input deaktivieren
        └── dead_players[player] = 3.0s

_process(delta):
        ├── Timer runterzählen
        ├── respawn_tick → HUD (Countdown anzeigen)
        └── Timer ≤ 0: _respawn()
              ├── Position → Taverne (0, 1, -5)
              ├── HP/Schild auf Max
              ├── Mesh/Collision/Input reaktivieren
              ├── health_changed + shield_changed
              └── player_respawned
```

## Signalübersicht

| Signal | Sender | Empfänger |
|---|---|---|
| `ability_use_requested` | Combat | AbilitySystem |
| `damage_requested` | AbilitySystem, EnemyAI | HealthSystem |
| `heal_requested` | AbilitySystem | HealthSystem, AggroSystem |
| `damage_dealt` | HealthSystem | AggroSystem, Targeting |
| `health_changed` | HealthSystem, RespawnSystem | SpawnSystem, Healthbar, HUD |
| `shield_changed` | ShieldSystem, AbilitySystem, BuffSystem, RespawnSystem | Healthbar, HUD |
| `entity_died` | HealthSystem | AggroSystem, RespawnSystem, SpawnSystem, Targeting, DungeonManager, Portal |
| `role_changed` | Role | BuffSystem, CooldownSystem |
| `enemy_detected` | Enemy (DetectionArea) | AggroSystem |
| `enemy_engaged` | AggroSystem | Targeting |
| `cooldown_tick` | CooldownSystem | HUD |
| `respawn_tick` | RespawnSystem | HUD |
| `dungeon_cleared` | DungeonManager | Gate |
| `portal_defeated` | Portal | — |
| `player_respawned` | RespawnSystem | — |
