CR 8b: Waffen-Framework — Dolch, Schwert, Axt bei gleicher DPR
- data/combat/weapons.json: drei Klassen mit cycle_scale, Reichweite und Haltungsschaden; gleiche DPR konstruktiv garantiert, weil Schaden und Ausdauer mit demselben cycle_scale skalieren wie die Zeiten - PlayerCombat lädt den Katalog, equip_weapon/cycle_weapon + weapon_changed; Wechsel jederzeit erlaubt und mitten in Schwung oder Rolle sauber nachgezogen statt den Zustand zu brechen - Zeiten, Schaden, Ausdauerkosten und Trefferreichweite kommen jetzt aus der aktiven Waffe - Neue Input-Action weapon_switch (Q / Steuerkreuz hoch) - Testarena: kleines Waffen-Overlay (Klasse, Reichweite, Tempo) - Verifikation: gemessene DPR Dolch 32,7 / Schwert 33,5 / Axt 31,5 (6,5 % Spanne aus der Ganzzahl-Rundung) - Buchführung: 8b nach CHANGEREQUESTS_DONE, ROADMAP nachgezogen Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
32f75a732b
commit
999c1f7bab
9 changed files with 228 additions and 15 deletions
|
|
@ -22,18 +22,30 @@ extends CombatActor
|
|||
## 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.
|
||||
##
|
||||
## 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.
|
||||
|
||||
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)
|
||||
|
||||
enum ActionState { READY, WINDUP, ACTIVE, RECOVERY, DODGING }
|
||||
|
||||
const HITBOX_RANGE := 1.9
|
||||
const WEAPONS_PATH := "res://data/combat/weapons.json"
|
||||
const HITBOX_RADIUS := 1.1
|
||||
|
||||
var is_encounter_active := false
|
||||
|
||||
var _weapons: Array = []
|
||||
var _weapon_index := 0
|
||||
var _pending_weapon_index := -1
|
||||
var _action := ActionState.READY
|
||||
var _action_kind := ""
|
||||
var _action_timer := 0.0
|
||||
|
|
@ -49,15 +61,84 @@ var _has_hit_this_swing := false
|
|||
@onready var _camera_pivot: Node3D = _player.get_node("CameraPivot") as Node3D
|
||||
|
||||
|
||||
## Übernimmt die Kampfwerte aus dem Tuning und startet inaktiv.
|
||||
## Ü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()
|
||||
reset_combat_values()
|
||||
set_physics_process(false)
|
||||
|
||||
|
||||
## 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", "")))
|
||||
|
||||
|
||||
## 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
|
||||
|
|
@ -82,6 +163,8 @@ func _physics_process(delta: float) -> void:
|
|||
_tick_block(delta)
|
||||
if is_staggered():
|
||||
return
|
||||
if Input.is_action_just_pressed("weapon_switch"):
|
||||
cycle_weapon()
|
||||
if Input.is_action_just_pressed("attack"):
|
||||
try_light_attack()
|
||||
elif Input.is_action_just_pressed("heavy_attack"):
|
||||
|
|
@ -178,7 +261,7 @@ func _start_attack(section: String) -> bool:
|
|||
if _action != ActionState.READY or is_staggered():
|
||||
return false
|
||||
var data := tuning_section(section)
|
||||
if not spend_stamina(float(data.get("stamina_cost", 10.0))):
|
||||
if not spend_stamina(float(data.get("stamina_cost", 10.0)) * get_weapon_cycle_scale()):
|
||||
return false
|
||||
_action = ActionState.WINDUP
|
||||
_action_kind = section
|
||||
|
|
@ -198,7 +281,7 @@ func _tick_action(delta: float) -> void:
|
|||
_tick_dodge(delta)
|
||||
return
|
||||
var data := tuning_section(_action_kind)
|
||||
var scale := 1.0 / _agility_scale()
|
||||
var scale := get_weapon_cycle_scale() / _agility_scale()
|
||||
_action_timer += delta
|
||||
match _action:
|
||||
ActionState.WINDUP:
|
||||
|
|
@ -208,26 +291,31 @@ func _tick_action(delta: float) -> void:
|
|||
ActionState.ACTIVE:
|
||||
if not _has_hit_this_swing:
|
||||
_resolve_swing(data)
|
||||
if _action_timer >= float(data.get("active_seconds", 0.15)):
|
||||
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
|
||||
_apply_pending_weapon()
|
||||
|
||||
|
||||
## Sucht Ziele vor dem Spieler und teilt den Treffer aus; Kraft hebt den
|
||||
## Schaden.
|
||||
## 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) -> void:
|
||||
_has_hit_this_swing = true
|
||||
var stats := tuning_section("stats")
|
||||
var damage := int(round(float(data.get("base_damage", 10)) * (1.0 + GameState.strength * float(stats.get("strength_damage_per_point", 0.1)))))
|
||||
var weapon := get_weapon()
|
||||
var base_damage := float(data.get("base_damage", 10)) * get_weapon_cycle_scale()
|
||||
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() * HITBOX_RANGE
|
||||
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
|
||||
|
|
@ -252,6 +340,7 @@ func _tick_dodge(delta: float) -> void:
|
|||
if _dodge_timer >= duration:
|
||||
_action = ActionState.READY
|
||||
_dodge_timer = 0.0
|
||||
_apply_pending_weapon()
|
||||
|
||||
|
||||
## Zählt die Blockdauer für das Parry-Fenster hoch.
|
||||
|
|
|
|||
1
scripts/ui/pause_menu.gd.uid
Normal file
1
scripts/ui/pause_menu.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://tdq8feymqu0p
|
||||
34
scripts/ui/weapon_hud.gd
Normal file
34
scripts/ui/weapon_hud.gd
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
extends CanvasLayer
|
||||
## Waffen-Anzeige der Kampf-Testarena (CR 8b).
|
||||
##
|
||||
## Zeigt die aktive Waffenklasse samt Reichweite und Zykluszeit-Skala,
|
||||
## damit sich der Wechsel (weapon_switch) beim Spielen nachvollziehen
|
||||
## lässt. Bewusst nur ein Debug-/Greybox-Overlay für die Testarena —
|
||||
## die echte Kampf-HUD kommt mit dem Encounter-Umbau (8d).
|
||||
|
||||
@onready var _label: Label = $Label
|
||||
|
||||
|
||||
## Hängt sich an den Waffenwechsel des Spielers und zeigt den Startwert.
|
||||
func _ready() -> void:
|
||||
var player := get_tree().get_first_node_in_group("player")
|
||||
if player == null:
|
||||
return
|
||||
var combat := player.get_node_or_null("PlayerCombat")
|
||||
if combat == null:
|
||||
return
|
||||
combat.weapon_changed.connect(func(_id: String, _name: String) -> void: _refresh(combat))
|
||||
_refresh(combat)
|
||||
|
||||
|
||||
## Schreibt Name, Reichweite und Tempo der aktiven Waffe ins Label.
|
||||
func _refresh(combat: Node) -> void:
|
||||
var weapon: Dictionary = combat.get_weapon()
|
||||
if weapon.is_empty():
|
||||
_label.text = "Waffe: —"
|
||||
return
|
||||
_label.text = "Waffe: %s Reichweite %.1f m Tempo ×%.2f [Q]" % [
|
||||
str(weapon.get("name", "?")),
|
||||
float(weapon.get("reach", 0.0)),
|
||||
1.0 / maxf(float(weapon.get("cycle_scale", 1.0)), 0.01),
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue