- Drei daten-getriebene Lektionen (data/lessons/): Mini-Vorlesung in Professoren-Stimme mit Zwischenrufen des Sitznachbarn und drei Timed Events pro Stunde (7-s-Balken, vier Antworten + Nichts sagen) - lesson_teacher.gd ersetzt die Wissens-Stationen in Rotunde, Aula und Geschichtsklasse: hinsetzen, Steuerung gesperrt, Beats über Sprechblasen, Quiz-Overlay (lesson_quiz.tscn) fokus-navigierbar - Richtig: +1 Verstand + 1 Fachwissen (gleiche Zähler wie Lexicon und Dreschen-Daumen); Deveras Muster-Frage liefert das erste W1-Fragment aufs Muster-Board; falsch: −1 Staffel-Ansehen (Fraktion "staffel") + Spott; schweigen/Zeitablauf: neutral; Szene verbraucht den Tages-Slot - Räume umgebaut: Kapsel-Professoren (Kaori/Devera/Markham) mit Googly Eyes, sitzende Schüler + Nachbar; Sparring bleibt Walk-up - Buchführung: CR 4 vollständig nach CHANGEREQUESTS_DONE, Phasen-Plan auf Phase 10 gestellt Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
142 lines
5.5 KiB
GDScript
142 lines
5.5 KiB
GDScript
extends StaticBody3D
|
||
## Interaktiver Unterricht als Szene (Phase 9, CR 4 — ersetzt für die
|
||
## Wissens-Fächer das Stationsmodell; SPEC §5.1/§6, Inhalte aus WELT.md).
|
||
##
|
||
## Der Professor steht im Raum; interact in Reichweite startet die
|
||
## Unterrichts-Szene aus lesson_path (data/lessons/*.json): Tyrveil wird
|
||
## auf den Sitzplatz (sit_marker_path) gesetzt, die Steuerung ist
|
||
## gesperrt, und die Mini-Vorlesung läuft über die Sprechblasen —
|
||
## Lehrer-Beats, Zwischenrufe des Nachbarn (neighbor_path) und mehrere
|
||
## Timed Events (~7 s, lesson_quiz.tscn): „nichts sagen" + vier
|
||
## Antworten, eine richtig. Richtig = +1 Verstand + 1 Fachwissen
|
||
## (knowledge_flag der Lektion; Fragen können zusätzlich per
|
||
## fragment_flag/fragment_text ein Wahrheit-1-Fragment aufs Muster-Board
|
||
## legen — Gefechtskunde). Falsch = spöttischer Nachbar-Kommentar und
|
||
## −1 Staffel-Ansehen (FactionSystem, Fraktion "staffel"). Schweigen =
|
||
## sicher, kein Gewinn. Das Durchspielen der Szene verbraucht den
|
||
## Tages-Slot; ist der Slot verbraucht, gibt es nur die Absage-Zeile.
|
||
## Reine Körper-Stationen (Sparring/Ausweichen) bleiben Walk-up.
|
||
|
||
const QUIZ_SCENE := preload("res://scenes/ui/lesson_quiz.tscn")
|
||
const STAFFEL_FACTION_ID := "staffel"
|
||
const DEFAULT_SILENT_LINE := "Schweigen. Kein Fehler — aber auch keine Antwort. Weiter."
|
||
|
||
@export_file("*.json") var lesson_path: String
|
||
@export var neighbor_path: NodePath
|
||
@export var sit_marker_path: NodePath
|
||
@export var exhausted_line := "Für heute reicht es — der Unterricht wartet morgen wieder."
|
||
|
||
var _is_player_in_range := false
|
||
var _is_running := false
|
||
var _lesson: Dictionary = {}
|
||
|
||
@onready var _prompt_label: Label3D = $PromptLabel
|
||
@onready var _interaction_area: Area3D = $InteractionArea
|
||
@onready var _bubble: Node3D = $SpeechBubble
|
||
@onready var _neighbor_bubble: Node3D = get_node(neighbor_path).get_node("SpeechBubble")
|
||
@onready var _sit_marker: Node3D = get_node(sit_marker_path)
|
||
|
||
|
||
## Lädt die Lektion und verbindet die Reichweiten-Signale.
|
||
func _ready() -> void:
|
||
_interaction_area.body_entered.connect(_on_body_entered)
|
||
_interaction_area.body_exited.connect(_on_body_exited)
|
||
var file := FileAccess.open(lesson_path, FileAccess.READ)
|
||
if file == null:
|
||
push_error("Lektion nicht lesbar: %s" % lesson_path)
|
||
return
|
||
var parsed: Variant = JSON.parse_string(file.get_as_text())
|
||
file.close()
|
||
if parsed is Dictionary and parsed.get("beats") is Array:
|
||
_lesson = parsed
|
||
else:
|
||
push_error("Lektion ist ungültig: %s" % lesson_path)
|
||
|
||
|
||
## Startet den Unterricht bei interact in Reichweite, außerhalb laufender
|
||
## Dialoge und wenn nicht schon eine Stunde läuft.
|
||
func _unhandled_input(event: InputEvent) -> void:
|
||
if not _is_player_in_range or _is_running:
|
||
return
|
||
if DialogueSystem.is_dialogue_active:
|
||
return
|
||
if not event.is_action_pressed("interact"):
|
||
return
|
||
_run_lesson()
|
||
|
||
|
||
## Spielt die komplette Unterrichts-Szene als Coroutine: hinsetzen,
|
||
## Vorlesungs-Beats, Timed Events, Auswertung, Slot-Verbrauch.
|
||
func _run_lesson() -> void:
|
||
if _lesson.is_empty():
|
||
return
|
||
if TimeSystem.is_current_slot_used:
|
||
_bubble.show_line(exhausted_line)
|
||
return
|
||
var player := get_tree().get_first_node_in_group("player")
|
||
if player == null:
|
||
return
|
||
_is_running = true
|
||
player.set_control_locked(true)
|
||
player.global_position = _sit_marker.global_position
|
||
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
|
||
var quiz: CanvasLayer = QUIZ_SCENE.instantiate()
|
||
add_child(quiz)
|
||
var correct_count := 0
|
||
var knowledge_flag := str(_lesson.get("knowledge_flag", ""))
|
||
for beat in _lesson.get("beats", []):
|
||
if beat.has("question"):
|
||
correct_count += await _run_question(quiz, beat["question"], knowledge_flag)
|
||
elif beat.has("nachbar"):
|
||
await _say(_neighbor_bubble, str(beat["nachbar"]))
|
||
else:
|
||
await _say(_bubble, str(beat.get("teacher", "")))
|
||
TimeSystem.try_spend_slot()
|
||
var end_line := str(_lesson.get("end_line", "Der Unterricht ist beendet."))
|
||
if correct_count > 0:
|
||
end_line += " (Verstand +%d, Fachwissen +%d)" % [correct_count, correct_count]
|
||
await _say(_bubble, end_line)
|
||
quiz.queue_free()
|
||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||
player.set_control_locked(false)
|
||
_is_running = false
|
||
|
||
|
||
## Spielt ein Timed Event und wertet es aus; liefert 1 bei richtiger
|
||
## Antwort, sonst 0.
|
||
func _run_question(quiz: CanvasLayer, question: Dictionary, knowledge_flag: String) -> int:
|
||
var index: int = await quiz.ask(question)
|
||
if index == int(question.get("correct", 0)):
|
||
GameState.increase_stat("intellect", 1)
|
||
if not knowledge_flag.is_empty():
|
||
GameState.set_story_flag(knowledge_flag, int(GameState.get_story_flag(knowledge_flag, 0)) + 1)
|
||
if question.has("fragment_flag"):
|
||
GameState.set_story_flag(str(question["fragment_flag"]), str(question.get("fragment_text", "")))
|
||
await _say(_bubble, str(question.get("correct_line", "Richtig.")))
|
||
return 1
|
||
if index < 0:
|
||
await _say(_bubble, str(question.get("silent_line", DEFAULT_SILENT_LINE)))
|
||
return 0
|
||
FactionSystem.adjust_standing(STAFFEL_FACTION_ID, -1)
|
||
await _say(_neighbor_bubble, str(question.get("mock_line", "Ein Kichern aus der Reihe hinter dir.")))
|
||
return 0
|
||
|
||
|
||
## Zeigt eine Zeile über der Blase und wartet ihr Ende ab.
|
||
func _say(bubble: Node3D, text: String) -> void:
|
||
if text.is_empty():
|
||
return
|
||
bubble.show_line(text)
|
||
await bubble.line_finished
|
||
|
||
|
||
## Blendet den Prompt ein, sobald der Spieler die Reichweite betritt.
|
||
func _on_body_entered(_body: Node3D) -> void:
|
||
_is_player_in_range = true
|
||
_prompt_label.visible = true
|
||
|
||
|
||
## Blendet den Prompt aus, wenn der Spieler die Reichweite verlässt.
|
||
func _on_body_exited(_body: Node3D) -> void:
|
||
_is_player_in_range = false
|
||
_prompt_label.visible = false
|