- data/combat/armor.json: Lederkluft (0 % Schutz, volles Tempo, längere i-Frames), Gehärtetes Leder (18 % / −8 % Tempo), Schuppenpanzer (35 % / −20 % Tempo, kürzere i-Frames, teurere Ausdauer) — jede Stufe kauft Schutz mit Tempo, kein „mehr ist besser" - PlayerCombat: equip_armor/get_armor; die Rüstung greift an vier Stellen (Schadensreduktion über überschriebenes take_hit, Tempo, i-Frame-Länge, Ausdauerkosten); getragene Rüstung liegt im GameState und reist im Spielstand mit - Gemessen: Schuppenpanzer 26 statt 40 Schaden, dafür 32 > 25 Frames pro Schwung, 11 < 21 i-Frame-Frames und 15,3 > 12,0 Ausdauer - Buchführung: 8e nach CHANGEREQUESTS_DONE; Welle 2 und CR 8 in der ROADMAP als abgeschlossen markiert Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
571 lines
20 KiB
GDScript
571 lines
20 KiB
GDScript
extends CombatActor
|
||
## Tyrveils Kampf-Kern (CR 8a) — Node am Spieler, ersetzt kein Movement.
|
||
##
|
||
## Die Bewegung bleibt frei: player.gd läuft weiter, dieses Skript legt
|
||
## nur die Kampf-Grammatik darüber (SPEC §1, CHANGEREQUESTS §8). Aktiv
|
||
## ist es ausschließlich in Encounter-Zonen (set_encounter_active) —
|
||
## außerhalb schluckt es keine Eingaben, damit Sprung, Slide und
|
||
## Klettern unberührt bleiben (Option B: kein Welt-Sandbox).
|
||
##
|
||
## Grammatik:
|
||
## - **Leichter Angriff** (attack): schnell, günstig.
|
||
## - **Schwerer Angriff** (heavy_attack): langer Windup, hoher Schaden,
|
||
## **bricht Blocks** und kann nicht pariert werden.
|
||
## - **Seitenschritt** (dodge + Bewegungsrichtung quer): kurzer Schritt
|
||
## OHNE Unverwundbarkeit — reine Positionierung, billig.
|
||
## - **Dodge-Rolle** (dodge ohne Richtung bzw. vorwärts): Rolle MIT
|
||
## Unverwundbarkeits-Fenster, teurer.
|
||
## - **Block/Parry** (block halten): stark reduzierter Schaden; in den
|
||
## ersten Sekundenbruchteilen ein **Parry**, das den Angreifer
|
||
## staggert.
|
||
##
|
||
## Stats-Kopplung (SPEC §6): Kraft hebt den Schaden, Schnelligkeit
|
||
## verkürzt Windup/Recovery und verlängert die i-Frames, Verstand weitet
|
||
## das Parry-Fenster. Alle Zahlen aus data/combat/combat_tuning.json.
|
||
##
|
||
## Rüstungen (CR 8e, data/combat/armor.json): Leder, Gehärtetes Leder
|
||
## und Schuppenpanzer bilden einen echten **Trade-off Schutz ↔ Tempo** —
|
||
## mehr Schadensreduktion bedeutet langsamere Aktionen, kürzere i-Frames
|
||
## und höhere Ausdauerkosten. Es gibt kein „mehr ist besser". Die
|
||
## getragene Rüstung liegt im GameState und reist im Spielstand mit.
|
||
##
|
||
## Waffen (CR 8b, data/combat/weapons.json): Dolch, Schwert und Axt sind
|
||
## **jederzeit wechselbar** (weapon_switch; mitten in einer Aktion wird
|
||
## der Wechsel gemerkt und beim Zurückfallen auf READY ausgeführt — kein
|
||
## Bruch im Zustand). Jede Waffe hat ein cycle_scale, das Zeiten,
|
||
## Schaden UND Ausdauerkosten gemeinsam skaliert: Wer langsamer schlägt,
|
||
## trifft proportional härter → **gleiche DPR bei gleichem Skill**, die
|
||
## Wahl ist Stil. Echte Unterschiede sind Reichweite und Haltungsschaden.
|
||
|
||
## Kombos & Waffenskill (CR 8c): Ein Treffer öffnet ein kurzes
|
||
## Eingabefenster — wer rechtzeitig nachschlägt, hängt das nächste
|
||
## Kettenglied an (Eröffnung → Folge → Abschluss). Die Kette ist für
|
||
## alle drei Klassen gleich aufgebaut und skaliert wie alles andere mit
|
||
## cycle_scale, damit die **DPR-Parität aus 8b erhalten bleibt**. Der
|
||
## **Waffenskill wächst pro Waffenklasse getrennt** (GameState,
|
||
## save-persistent): Er schaltet die späteren Kettenglieder frei und
|
||
## senkt die Ausdauerkosten — er hebt **NICHT** den Rohschaden. Nach
|
||
## einem Parry öffnet sich ein **Konter-Fenster**, das Verstand weitet;
|
||
## ein Schlag darin trifft deutlich härter.
|
||
|
||
signal attack_landed(result: String, damage: int)
|
||
signal attack_started(kind: String)
|
||
signal dodge_started(has_iframes: bool)
|
||
signal weapon_changed(weapon_id: String, weapon_name: String)
|
||
signal combo_advanced(link_id: String, link_index: int)
|
||
signal counter_window_opened
|
||
signal counter_landed(damage: int)
|
||
|
||
enum ActionState { READY, WINDUP, ACTIVE, RECOVERY, DODGING }
|
||
|
||
const WEAPONS_PATH := "res://data/combat/weapons.json"
|
||
const ARMOR_PATH := "res://data/combat/armor.json"
|
||
const HITBOX_RADIUS := 1.1
|
||
|
||
var is_encounter_active := false
|
||
|
||
var _weapons: Array = []
|
||
var _armor_sets: Array = []
|
||
var _weapon_index := 0
|
||
var _pending_weapon_index := -1
|
||
var _action := ActionState.READY
|
||
var _action_kind := ""
|
||
var _action_timer := 0.0
|
||
var _dodge_timer := 0.0
|
||
var _dodge_has_iframes := false
|
||
var _dodge_direction := Vector3.ZERO
|
||
var _block_timer := 0.0
|
||
var _is_block_held := false
|
||
var _has_hit_this_swing := false
|
||
var _combo_index := 0
|
||
var _combo_window := 0.0
|
||
var _is_combo_queued := false
|
||
var _counter_window := 0.0
|
||
|
||
@onready var _player: CharacterBody3D = get_parent() as CharacterBody3D
|
||
@onready var _mesh: Node3D = _player.get_node("MeshInstance3D") as Node3D
|
||
@onready var _camera_pivot: Node3D = _player.get_node("CameraPivot") as Node3D
|
||
|
||
|
||
## Übernimmt die Kampfwerte aus dem Tuning, lädt die Waffen und startet
|
||
## inaktiv.
|
||
func _ready() -> void:
|
||
var player_data := tuning_section("player")
|
||
max_health = int(player_data.get("max_health", 100))
|
||
max_stamina = float(player_data.get("max_stamina", 100.0))
|
||
_load_weapons()
|
||
_load_armor()
|
||
reset_combat_values()
|
||
parried.connect(_on_parried)
|
||
set_physics_process(false)
|
||
|
||
|
||
## Ein gelungener Parry öffnet das Konter-Fenster (Verstand weitet es).
|
||
func _on_parried(_attacker: CombatActor) -> void:
|
||
var skill_data := tuning_section("skill")
|
||
var stats := tuning_section("stats")
|
||
var window := float(skill_data.get("counter_window_seconds", 0.6))
|
||
window += minf(GameState.intellect * float(stats.get("intellect_counter_per_point", 0.006)), float(stats.get("intellect_counter_max_bonus", 0.4)))
|
||
_counter_window = window
|
||
counter_window_opened.emit()
|
||
|
||
|
||
## Liefert die verbleibende Zeit des Konter-Fensters in Sekunden.
|
||
func get_counter_window() -> float:
|
||
return _counter_window
|
||
|
||
|
||
## Liefert den Skill der aktiven Waffenklasse (0–100).
|
||
func get_weapon_skill() -> int:
|
||
return GameState.get_weapon_skill(str(get_weapon().get("id", "")))
|
||
|
||
|
||
## Liefert den Index des nächsten Kettenglieds (0 = frischer Angriff).
|
||
func get_combo_index() -> int:
|
||
return _combo_index
|
||
|
||
|
||
## Liefert die Kettenglieder aus dem Tuning.
|
||
func get_combo_links() -> Array:
|
||
return tuning_section("combo").get("links", [])
|
||
|
||
|
||
## Gibt zurück, wie viele Kettenglieder der aktuelle Waffenskill
|
||
## freigeschaltet hat (mindestens eines).
|
||
func get_unlocked_combo_links() -> int:
|
||
var skill := get_weapon_skill()
|
||
var unlocked := 0
|
||
for link in get_combo_links():
|
||
if skill >= int(link.get("min_skill", 0)):
|
||
unlocked += 1
|
||
return maxi(unlocked, 1)
|
||
|
||
|
||
## Lädt die Waffentabelle und rüstet die Standardwaffe aus.
|
||
func _load_weapons() -> void:
|
||
var file := FileAccess.open(WEAPONS_PATH, FileAccess.READ)
|
||
if file == null:
|
||
push_error("Waffentabelle nicht lesbar: %s" % WEAPONS_PATH)
|
||
return
|
||
var parsed: Variant = JSON.parse_string(file.get_as_text())
|
||
file.close()
|
||
if not (parsed is Dictionary) or not (parsed.get("weapons") is Array):
|
||
push_error("Waffentabelle ist ungültig: %s" % WEAPONS_PATH)
|
||
return
|
||
_weapons = parsed["weapons"]
|
||
equip_weapon(str(parsed.get("default_weapon", "")))
|
||
|
||
|
||
## Lädt die Rüstungstabelle und rüstet die gespeicherte bzw. die
|
||
## Standard-Rüstung aus (CR 8e).
|
||
func _load_armor() -> void:
|
||
var file := FileAccess.open(ARMOR_PATH, FileAccess.READ)
|
||
if file == null:
|
||
push_error("Rüstungstabelle nicht lesbar: %s" % ARMOR_PATH)
|
||
return
|
||
var parsed: Variant = JSON.parse_string(file.get_as_text())
|
||
file.close()
|
||
if not (parsed is Dictionary) or not (parsed.get("sets") is Array):
|
||
push_error("Rüstungstabelle ist ungültig: %s" % ARMOR_PATH)
|
||
return
|
||
_armor_sets = parsed["sets"]
|
||
if GameState.equipped_armor.is_empty():
|
||
GameState.equipped_armor = str(parsed.get("default_armor", ""))
|
||
|
||
|
||
## Rüstet eine Rüstung über ihre ID aus; liefert false bei unbekannter ID.
|
||
func equip_armor(armor_id: String) -> bool:
|
||
for armor_set in _armor_sets:
|
||
if str(armor_set.get("id", "")) == armor_id:
|
||
GameState.equipped_armor = armor_id
|
||
return true
|
||
return false
|
||
|
||
|
||
## Liefert die aktuell getragene Rüstung (leer, wenn keine geladen).
|
||
func get_armor() -> Dictionary:
|
||
for armor_set in _armor_sets:
|
||
if str(armor_set.get("id", "")) == GameState.equipped_armor:
|
||
return armor_set
|
||
return {}
|
||
|
||
|
||
## Liefert alle Rüstungs-IDs (für UI und Tests).
|
||
func get_armor_ids() -> Array:
|
||
var ids: Array = []
|
||
for armor_set in _armor_sets:
|
||
ids.append(str(armor_set.get("id", "")))
|
||
return ids
|
||
|
||
|
||
## Rüstet eine Waffe über ihre ID aus; liefert false bei unbekannter ID.
|
||
func equip_weapon(weapon_id: String) -> bool:
|
||
for i in _weapons.size():
|
||
if str(_weapons[i].get("id", "")) == weapon_id:
|
||
_set_weapon_index(i)
|
||
return true
|
||
return false
|
||
|
||
|
||
## Schaltet auf die nächste Waffenklasse weiter (weapon_switch).
|
||
func cycle_weapon() -> void:
|
||
if _weapons.size() < 2:
|
||
return
|
||
_set_weapon_index((_weapon_index + 1) % _weapons.size())
|
||
|
||
|
||
## Liefert die aktuell ausgerüstete Waffe (leer, wenn keine geladen).
|
||
func get_weapon() -> Dictionary:
|
||
if _weapons.is_empty():
|
||
return {}
|
||
return _weapons[_weapon_index]
|
||
|
||
|
||
## Liefert die Zykluszeit-Skala der aktiven Waffe (1.0 = Schwert).
|
||
func get_weapon_cycle_scale() -> float:
|
||
return float(get_weapon().get("cycle_scale", 1.0))
|
||
|
||
|
||
## Setzt die Waffe sofort, wenn keine Aktion läuft — sonst wird der
|
||
## Wechsel gemerkt und beim Zurückfallen auf READY nachgezogen, damit
|
||
## ein laufender Schwung nicht bricht.
|
||
func _set_weapon_index(index: int) -> void:
|
||
if index < 0 or index >= _weapons.size():
|
||
return
|
||
if _action != ActionState.READY:
|
||
_pending_weapon_index = index
|
||
return
|
||
_weapon_index = index
|
||
_pending_weapon_index = -1
|
||
var weapon := get_weapon()
|
||
weapon_changed.emit(str(weapon.get("id", "")), str(weapon.get("name", "")))
|
||
|
||
|
||
## Zieht einen während einer Aktion angeforderten Waffenwechsel nach.
|
||
func _apply_pending_weapon() -> void:
|
||
if _pending_weapon_index < 0:
|
||
return
|
||
var index := _pending_weapon_index
|
||
_pending_weapon_index = -1
|
||
_set_weapon_index(index)
|
||
|
||
|
||
## Schaltet den Kampf-Modus einer Encounter-Zone scharf oder ab.
|
||
func set_encounter_active(is_active: bool) -> void:
|
||
is_encounter_active = is_active
|
||
set_physics_process(is_active)
|
||
if is_active:
|
||
reset_combat_values()
|
||
return
|
||
_action = ActionState.READY
|
||
_is_block_held = false
|
||
_block_timer = 0.0
|
||
|
||
|
||
## Liest im Encounter die Kampf-Eingaben und treibt Aktions- und
|
||
## Dodge-Timer voran; ohne Encounter passiert nichts.
|
||
func _physics_process(delta: float) -> void:
|
||
tick_combat(delta)
|
||
if not is_alive() or _player == null:
|
||
return
|
||
if _player.is_control_locked() or DialogueSystem.is_dialogue_active:
|
||
return
|
||
_tick_action(delta)
|
||
_tick_block(delta)
|
||
_tick_windows(delta)
|
||
if is_staggered():
|
||
return
|
||
if Input.is_action_just_pressed("weapon_switch"):
|
||
cycle_weapon()
|
||
if Input.is_action_just_pressed("attack"):
|
||
if _action != ActionState.READY and _combo_window > 0.0:
|
||
_is_combo_queued = true
|
||
else:
|
||
try_light_attack()
|
||
elif Input.is_action_just_pressed("heavy_attack"):
|
||
try_heavy_attack()
|
||
elif Input.is_action_just_pressed("dodge"):
|
||
try_dodge(Input.get_vector("move_left", "move_right", "move_forward", "move_back"))
|
||
if Input.is_action_just_pressed("block"):
|
||
start_block()
|
||
elif Input.is_action_just_released("block"):
|
||
end_block()
|
||
|
||
|
||
## Startet einen leichten Angriff; liefert false, wenn blockiert,
|
||
## gestaggert, in einer anderen Aktion oder ohne Ausdauer.
|
||
func try_light_attack() -> bool:
|
||
return _start_attack("light_attack")
|
||
|
||
|
||
## Startet einen schweren Angriff (langer Windup, bricht Blocks).
|
||
func try_heavy_attack() -> bool:
|
||
return _start_attack("heavy_attack")
|
||
|
||
|
||
## Startet Seitenschritt oder Rolle: Eine überwiegend seitliche
|
||
## Eingaberichtung ergibt den billigen Seitenschritt OHNE i-Frames,
|
||
## alles andere die teurere Rolle MIT Unverwundbarkeits-Fenster.
|
||
func try_dodge(input_dir := Vector2.ZERO) -> bool:
|
||
if _action == ActionState.DODGING or is_staggered():
|
||
return false
|
||
var is_sidestep: bool = input_dir.length() > 0.4 and absf(input_dir.x) > absf(input_dir.y)
|
||
var section := "sidestep" if is_sidestep else "dodge_roll"
|
||
var data := tuning_section(section)
|
||
if not spend_stamina(float(data.get("stamina_cost", 15.0))):
|
||
return false
|
||
_action = ActionState.DODGING
|
||
_action_kind = section
|
||
_dodge_timer = 0.0
|
||
_dodge_has_iframes = not is_sidestep
|
||
_dodge_direction = _direction_from_input(input_dir)
|
||
_is_block_held = false
|
||
_block_timer = 0.0
|
||
dodge_started.emit(_dodge_has_iframes)
|
||
return true
|
||
|
||
|
||
## Beginnt zu blocken und öffnet das Parry-Fenster.
|
||
func start_block() -> void:
|
||
if _action != ActionState.READY or is_staggered():
|
||
return
|
||
_is_block_held = true
|
||
_block_timer = 0.0
|
||
|
||
|
||
## Beendet den Block.
|
||
func end_block() -> void:
|
||
_is_block_held = false
|
||
_block_timer = 0.0
|
||
|
||
|
||
## Unverwundbar während des i-Fensters der Rolle (Schnelligkeit
|
||
## verlängert es leicht).
|
||
func is_invulnerable() -> bool:
|
||
if _action != ActionState.DODGING or not _dodge_has_iframes:
|
||
return false
|
||
var data := tuning_section("dodge_roll")
|
||
var scale := _agility_scale() * float(get_armor().get("iframe_scale", 1.0))
|
||
return _dodge_timer >= float(data.get("iframe_start", 0.05)) and _dodge_timer <= float(data.get("iframe_end", 0.3)) * scale
|
||
|
||
|
||
## Block zählt, solange die Taste gehalten wird und keine Aktion läuft.
|
||
func is_blocking() -> bool:
|
||
return _is_block_held and _action == ActionState.READY
|
||
|
||
|
||
## Parry-Fenster: die ersten Augenblicke des Blocks (Verstand weitet es).
|
||
func is_parrying() -> bool:
|
||
if not is_blocking():
|
||
return false
|
||
var data := tuning_section("block")
|
||
var stats := tuning_section("stats")
|
||
var window := float(data.get("parry_window_seconds", 0.2))
|
||
window += minf(GameState.intellect * float(stats.get("intellect_parry_per_point", 0.004)), float(stats.get("intellect_parry_max_bonus", 0.12)))
|
||
return _block_timer <= window
|
||
|
||
|
||
## Liefert den Namen der laufenden Aktion (für Tests und Debug).
|
||
func get_action_name() -> String:
|
||
return ActionState.keys()[_action]
|
||
|
||
|
||
## Startet einen Angriff aus dem Tuning-Abschnitt; Schnelligkeit
|
||
## verkürzt Windup und Recovery.
|
||
func _start_attack(section: String) -> bool:
|
||
if _action != ActionState.READY or is_staggered():
|
||
return false
|
||
var data := tuning_section(section)
|
||
if not spend_stamina(_stamina_cost(float(data.get("stamina_cost", 10.0)))):
|
||
return false
|
||
_action = ActionState.WINDUP
|
||
_action_kind = section
|
||
_action_timer = 0.0
|
||
_has_hit_this_swing = false
|
||
_is_block_held = false
|
||
_combo_index = 0
|
||
attack_started.emit(section)
|
||
return true
|
||
|
||
|
||
## Ausdauerkosten einer Aktion: Waffen-Zykluszeit mal Skill-Rabatt
|
||
## (Skill senkt die Kosten, NICHT den Rohschaden — CR 8c).
|
||
func _stamina_cost(base_cost: float) -> float:
|
||
var skill_data := tuning_section("skill")
|
||
var maximum := maxf(float(skill_data.get("max", 100)), 1.0)
|
||
var discount := float(skill_data.get("stamina_discount_max", 0.3)) * (float(get_weapon_skill()) / maximum)
|
||
return base_cost * get_weapon_cycle_scale() * (1.0 - discount) * float(get_armor().get("stamina_scale", 1.0))
|
||
|
||
|
||
## Nimmt einen Treffer entgegen und zieht vorher die Schutzwirkung der
|
||
## Rüstung ab (CR 8e — Schutz ist die eine Hälfte des Trade-offs).
|
||
func take_hit(damage: int, is_heavy := false, attacker: CombatActor = null) -> String:
|
||
var reduction := float(get_armor().get("damage_reduction", 0.0))
|
||
var reduced := maxi(int(round(float(damage) * (1.0 - reduction))), 1 if damage > 0 else 0)
|
||
return super(reduced, is_heavy, attacker)
|
||
|
||
|
||
## Hängt das nächste Kettenglied an, wenn der Skill es freigeschaltet
|
||
## hat und noch eines übrig ist; sonst endet die Kette.
|
||
func _try_advance_combo() -> bool:
|
||
var links := get_combo_links()
|
||
if _combo_index >= links.size() or _combo_index >= get_unlocked_combo_links():
|
||
return false
|
||
var data := tuning_section("light_attack")
|
||
if not spend_stamina(_stamina_cost(float(data.get("stamina_cost", 10.0)))):
|
||
return false
|
||
_action = ActionState.WINDUP
|
||
_action_kind = "light_attack"
|
||
_action_timer = 0.0
|
||
_has_hit_this_swing = false
|
||
_is_block_held = false
|
||
combo_advanced.emit(str(links[_combo_index].get("id", "")), _combo_index)
|
||
attack_started.emit("light_attack")
|
||
return true
|
||
|
||
|
||
## Treibt Windup → Active → Recovery voran und schlägt in der aktiven
|
||
## Phase genau einmal zu.
|
||
func _tick_action(delta: float) -> void:
|
||
if _action == ActionState.READY:
|
||
return
|
||
if _action == ActionState.DODGING:
|
||
_tick_dodge(delta)
|
||
return
|
||
var data := tuning_section(_action_kind)
|
||
var scale := get_weapon_cycle_scale() / _agility_scale()
|
||
var link := _current_combo_link()
|
||
_action_timer += delta
|
||
match _action:
|
||
ActionState.WINDUP:
|
||
if _action_timer >= float(data.get("windup_seconds", 0.15)) * scale * float(link.get("windup_scale", 1.0)):
|
||
_action = ActionState.ACTIVE
|
||
_action_timer = 0.0
|
||
ActionState.ACTIVE:
|
||
if not _has_hit_this_swing:
|
||
_resolve_swing(data, link)
|
||
if _action_timer >= float(data.get("active_seconds", 0.15)) * scale:
|
||
_action = ActionState.RECOVERY
|
||
_action_timer = 0.0
|
||
ActionState.RECOVERY:
|
||
if _action_timer >= float(data.get("recovery_seconds", 0.25)) * scale:
|
||
_action = ActionState.READY
|
||
_action_timer = 0.0
|
||
if _is_combo_queued:
|
||
_is_combo_queued = false
|
||
if _try_advance_combo():
|
||
return
|
||
_apply_pending_weapon()
|
||
|
||
|
||
## Liefert die Werte des gerade laufenden Kettenglieds (leer außerhalb
|
||
## einer Kombo — dann gelten die Basiswerte).
|
||
func _current_combo_link() -> Dictionary:
|
||
var links := get_combo_links()
|
||
if _action_kind != "light_attack" or _combo_index >= links.size():
|
||
return {}
|
||
return links[_combo_index]
|
||
|
||
|
||
## Sucht Ziele vor dem Spieler und teilt den Treffer aus. Der Schaden
|
||
## ist Basiswert × Waffen-cycle_scale × Kraft-Faktor — die Skalierung
|
||
## mit derselben Zahl wie die Zeiten hält die DPR über alle
|
||
## Waffenklassen gleich (CR 8b). Die Reichweite kommt aus der Waffe.
|
||
func _resolve_swing(data: Dictionary, link: Dictionary = {}) -> void:
|
||
_has_hit_this_swing = true
|
||
var stats := tuning_section("stats")
|
||
var weapon := get_weapon()
|
||
var base_damage := float(data.get("base_damage", 10)) * get_weapon_cycle_scale() * float(link.get("damage_scale", 1.0))
|
||
var is_counter := _counter_window > 0.0
|
||
if is_counter:
|
||
base_damage *= float(tuning_section("skill").get("counter_damage_scale", 1.8))
|
||
_counter_window = 0.0
|
||
var damage := int(round(base_damage * (1.0 + GameState.strength * float(stats.get("strength_damage_per_point", 0.1)))))
|
||
var is_heavy: bool = bool(data.get("breaks_block", false))
|
||
var origin: Vector3 = _player.global_position + Vector3(0, 1.0, 0)
|
||
var forward: Vector3 = -_mesh.global_transform.basis.z
|
||
forward.y = 0.0
|
||
var center: Vector3 = origin + forward.normalized() * float(weapon.get("reach", 1.9))
|
||
for target in get_tree().get_nodes_in_group("combat_actor"):
|
||
if target == self or not (target is CombatActor):
|
||
continue
|
||
var body := target.get_parent() as Node3D
|
||
if body == null or body == _player:
|
||
continue
|
||
if body.global_position.distance_to(center) > HITBOX_RADIUS + 0.6:
|
||
continue
|
||
var result: String = target.take_hit(damage, is_heavy, self)
|
||
_on_swing_connected(result, damage, is_counter)
|
||
attack_landed.emit(result, damage)
|
||
return
|
||
_combo_window = 0.0
|
||
_combo_index = 0
|
||
attack_landed.emit("miss", damage)
|
||
|
||
|
||
## Wertet einen verbundenen Schlag aus: Skill der geführten Waffe
|
||
## wächst, die Kombo-Kette rückt vor und ihr Eingabefenster öffnet sich.
|
||
## Ein Fehlschlag (miss) bricht die Kette — Kombos sind kein Freifahrtschein.
|
||
func _on_swing_connected(result: String, damage: int, is_counter: bool) -> void:
|
||
if is_counter:
|
||
counter_landed.emit(damage)
|
||
var skill_data := tuning_section("skill")
|
||
GameState.add_weapon_skill(str(get_weapon().get("id", "")), int(skill_data.get("gain_per_hit", 1)), int(skill_data.get("max", 100)))
|
||
if result == "parried" or _action_kind != "light_attack":
|
||
return
|
||
_combo_index += 1
|
||
_combo_window = float(tuning_section("combo").get("window_seconds", 0.45))
|
||
|
||
|
||
## Bewegt den Spieler während Seitenschritt/Rolle und beendet sie.
|
||
func _tick_dodge(delta: float) -> void:
|
||
var data := tuning_section(_action_kind)
|
||
_dodge_timer += delta
|
||
var duration := float(data.get("duration_seconds", 0.4)) / _agility_scale()
|
||
_player.velocity.x = _dodge_direction.x * float(data.get("speed", 8.0))
|
||
_player.velocity.z = _dodge_direction.z * float(data.get("speed", 8.0))
|
||
if _dodge_timer >= duration:
|
||
_action = ActionState.READY
|
||
_dodge_timer = 0.0
|
||
_apply_pending_weapon()
|
||
|
||
|
||
## Zählt die Blockdauer für das Parry-Fenster hoch.
|
||
func _tick_block(delta: float) -> void:
|
||
if _is_block_held:
|
||
_block_timer += delta
|
||
|
||
|
||
## Lässt Kombo- und Konter-Fenster ablaufen; ein verstrichenes
|
||
## Kombo-Fenster setzt die Kette zurück.
|
||
func _tick_windows(delta: float) -> void:
|
||
if _counter_window > 0.0:
|
||
_counter_window = maxf(_counter_window - delta, 0.0)
|
||
if _combo_window <= 0.0:
|
||
return
|
||
_combo_window = maxf(_combo_window - delta, 0.0)
|
||
if _combo_window == 0.0 and _action == ActionState.READY:
|
||
_combo_index = 0
|
||
_is_combo_queued = false
|
||
|
||
|
||
## Wandelt die Eingaberichtung in eine Weltrichtung; ohne Eingabe rollt
|
||
## Tyrveil nach vorn.
|
||
func _direction_from_input(input_dir: Vector2) -> Vector3:
|
||
if input_dir.length() < 0.2:
|
||
var forward: Vector3 = -_mesh.global_transform.basis.z
|
||
forward.y = 0.0
|
||
return forward.normalized()
|
||
var direction: Vector3 = _camera_pivot.global_transform.basis * Vector3(input_dir.x, 0.0, input_dir.y)
|
||
direction.y = 0.0
|
||
return direction.normalized()
|
||
|
||
|
||
## Tempo-Faktor aus Schnelligkeit (>1 = schneller, gedeckelt).
|
||
## Tempo-Faktor aus Schnelligkeit UND Rüstung (>1 = schneller): Die
|
||
## Rüstung ist die andere Hälfte des Trade-offs — Schutz kostet Tempo
|
||
## (CR 8e).
|
||
func _agility_scale() -> float:
|
||
var stats := tuning_section("stats")
|
||
var scale := 1.0 + minf(GameState.agility * float(stats.get("agility_speed_per_point", 0.006)), float(stats.get("agility_speed_max_bonus", 0.4)))
|
||
return scale * float(get_armor().get("speed_scale", 1.0))
|