Begehbarkeit stand als Präfixliste in stadt.gd, die Position als Konstante, und das Gespräch schrieb direkt in Widgets. Jetzt: - Die Karte trägt die Begehbarkeit selbst: legend.<zeichen>.boden, start, exits in data/maps/garana.json; _schema.json und validate_data.py prüfen Start auf Boden und Ausgänge als Durchgang. - scripts/core/karte.gd beantwortet Start, Boden, Ausgang und NSC in Rufweite — ohne Knoten, Textur oder Dateinamen. - Game (game_state.gd) hält Position, Belegung und Gespräch und entscheidet den Schritt; platz_geaendert, dialog_geaendert und ausgang_erreicht sind die einzigen Wege zur Szene. stadt.gd zeichnet und sendet Absichten. - Selbstprüfung: neun Punkte für die Regeln ohne Szene (23 statt 12); Probes fragen Game.position statt Szenenfelder. docs/engine.md §6.1 hält die drei Grenzen fest und nennt, was noch offen ist (MapView-Schnitt, Kampf erbt keine Regel aus der Stadt).
207 lines
7.2 KiB
GDScript
207 lines
7.2 KiB
GDScript
extends Node
|
|
## Game (Autoload) — der Spielzustand: Party, Ort, Zeit, Flaggen **und die
|
|
## Regel, wo die Figur stehen darf**.
|
|
##
|
|
## Gespeichert werden **Eingaben**, keine abgeleiteten Werte (docs/engine.md §7):
|
|
## TP ja, RK nein. Wird eine Klasse nachbalanciert, korrigiert der nächste
|
|
## Ladevorgang die Ableitung automatisch.
|
|
##
|
|
## Die Szene zeigt, dieses Skript entscheidet (docs/engine.md §6.1): Bewegung,
|
|
## Begehbarkeit und Gesprächspartner stehen hier, gezeichnet wird dort. Die
|
|
## Szene sendet Absichten (`gehe`, `sprechen`) und hört auf die Signale unten —
|
|
## sie setzt keine Position und kein Dialogfeld selbst.
|
|
|
|
const START = "garana"
|
|
const KARTE := preload("res://scripts/core/karte.gd")
|
|
|
|
## Die Figur hat das Feld gewechselt. `nach` ist die neue Position im Raster.
|
|
signal platz_geaendert(von: Vector2i, nach: Vector2i)
|
|
## Ein Gespräch hat begonnen oder geendet — leeres Dictionary heißt „zu".
|
|
signal dialog_geaendert(nsc: Dictionary)
|
|
## Die Figur steht auf einem Ausgang; `ziel` ist sein `to` aus den Kartendaten.
|
|
signal ausgang_erreicht(ziel: String)
|
|
|
|
var party: Array = [] ## Array von Dictionaries (ids + Werte)
|
|
var place: Dictionary = {"id": START, "x": 0, "y": 0}
|
|
var time: Dictionary = {"day": 1, "slot": 0}
|
|
var flags: Dictionary = {}
|
|
var log_lines: Array[String] = []
|
|
|
|
var belegt: Dictionary = {} ## Requisiten und NSCs als Vector2i -> true
|
|
var dialog: Dictionary = {} ## NSC des offenen Gesprächs, {} = zu
|
|
var _karte: Dictionary = {}
|
|
|
|
func _ready() -> void:
|
|
if party.is_empty():
|
|
_neue_party()
|
|
|
|
## Vier Figuren, wie in docs/systeme.md §11 durchgerechnet.
|
|
func _neue_party() -> void:
|
|
var vorgabe := [
|
|
{"name": "Aldric", "race": "human", "class": "fighter",
|
|
"attributes": {"str": 16, "dex": 12, "con": 14, "int": 10, "wis": 9, "cha": 11}},
|
|
{"name": "Bruna", "race": "dwarf", "class": "cleric",
|
|
"attributes": {"str": 12, "dex": 9, "con": 15, "int": 10, "wis": 16, "cha": 11}},
|
|
{"name": "Cael", "race": "elf", "class": "magier",
|
|
"attributes": {"str": 8, "dex": 15, "con": 11, "int": 17, "wis": 12, "cha": 10}},
|
|
{"name": "Dorn", "race": "halfling", "class": "thief",
|
|
"attributes": {"str": 11, "dex": 17, "con": 12, "int": 12, "wis": 10, "cha": 13}},
|
|
]
|
|
party = []
|
|
for i in vorgabe.size():
|
|
party.append(neue_figur("pc_%d" % (i + 1), vorgabe[i]))
|
|
|
|
func neue_figur(id: String, vorgabe: Dictionary) -> Dictionary:
|
|
var klasse: Dictionary = Content.class_def(str(vorgabe["class"]))
|
|
var volk: Dictionary = Content.entry("races", str(vorgabe["race"]))
|
|
var attrs: Dictionary = vorgabe["attributes"].duplicate()
|
|
for attribut in volk.get("attribute_mods", {}):
|
|
attrs[attribut] = int(attrs.get(attribut, 10)) + int(volk["attribute_mods"][attribut])
|
|
var hp_max := _hp_stufe1(klasse, attrs)
|
|
return {
|
|
"id": id, "name": vorgabe["name"],
|
|
"race": vorgabe["race"], "class": vorgabe["class"],
|
|
"level": 1, "xp": 0,
|
|
"attributes": attrs,
|
|
"hp": {"current": hp_max, "max": hp_max},
|
|
"skills": _startfertigkeiten(klasse),
|
|
"spells": {"known": [], "prepared": [], "slots": {}},
|
|
"inventory": [], "equipment": {},
|
|
"conditions": [],
|
|
}
|
|
|
|
func _hp_stufe1(klasse: Dictionary, attrs: Dictionary) -> int:
|
|
var kon := Dice.modifier(int(attrs.get("con", 10)))
|
|
return maxi(1, int(klasse.get("hit_die", 6)) + kon)
|
|
|
|
func _startfertigkeiten(klasse: Dictionary) -> Dictionary:
|
|
var out := {}
|
|
for id in klasse.get("trained_skills", []):
|
|
var fertigkeit: Dictionary = Content.skill(str(id))
|
|
out[str(id)] = int(fertigkeit.get("trained_bonus", 3))
|
|
return out
|
|
|
|
## Abgeleitete Werte werden gerechnet, nie gespeichert.
|
|
func rk(figur: Dictionary) -> int:
|
|
var ac := 10 + Dice.modifier(int(figur["attributes"].get("dex", 10)))
|
|
var ruestung: Dictionary = Content.entry("items", str(figur.get("equipment", {}).get("armor", "")))
|
|
ac += int(ruestung.get("ac_bonus", 0))
|
|
if figur.get("equipment", {}).get("shield", false):
|
|
var schild: Dictionary = Content.entry("items", "schild")
|
|
ac += int(schild.get("ac_bonus", 1))
|
|
return ac
|
|
|
|
func angriffsbonus(figur: Dictionary) -> int:
|
|
var klasse: Dictionary = Content.class_def(str(figur["class"]))
|
|
var stufe := int(figur.get("level", 1))
|
|
var leiter: Array = klasse.get("attack_per_level", [])
|
|
if stufe - 1 < leiter.size():
|
|
return int(leiter[stufe - 1])
|
|
return int(leiter[leiter.size() - 1]) if not leiter.is_empty() else 0
|
|
|
|
func notiz(text: String) -> void:
|
|
log_lines.append(text)
|
|
if log_lines.size() > 200:
|
|
log_lines.pop_front()
|
|
|
|
# ---------------------------------------------------------------- Ort & Wege --
|
|
|
|
## Ort wechseln: Karte laden, Figur auf ihr Startfeld, Requisiten belegen.
|
|
## Gibt die Kartendaten zurück, damit die Szene sie zeichnen kann.
|
|
func betreten(id: String) -> Dictionary:
|
|
_karte = Content.entry("maps", id)
|
|
if _karte.is_empty():
|
|
push_error("Karte fehlt: " + id)
|
|
return {}
|
|
var s := KARTE.start(_karte)
|
|
place = {"id": id, "x": s.x, "y": s.y}
|
|
belegt = KARTE.belegung(_karte)
|
|
if not dialog.is_empty():
|
|
dialog = {}
|
|
dialog_geaendert.emit({})
|
|
return _karte
|
|
|
|
## Die geladene Karte (leer, solange kein Ort betreten ist).
|
|
func karte() -> Dictionary:
|
|
return _karte
|
|
|
|
## Figur versetzen — nur für Laden und Prüfungen, nicht für Eingaben.
|
|
func setzen(x: int, y: int) -> bool:
|
|
if not KARTE.begehbar(_karte, x, y, belegt):
|
|
return false
|
|
var von := Vector2i(int(place.get("x", 0)), int(place.get("y", 0)))
|
|
place["x"] = x
|
|
place["y"] = y
|
|
var nach := Vector2i(x, y)
|
|
if von != nach:
|
|
platz_geaendert.emit(von, nach)
|
|
return true
|
|
|
|
## Die Figur steht auf diesem Feld?
|
|
func position() -> Vector2i:
|
|
return Vector2i(int(place.get("x", 0)), int(place.get("y", 0)))
|
|
|
|
## Darf auf (x,y) gestanden werden? Regel, nicht Darstellung.
|
|
func begehbar(x: int, y: int) -> bool:
|
|
return KARTE.begehbar(_karte, x, y, belegt)
|
|
|
|
## Einen Schritt gehen. `false` heißt: das Feld ist nicht begehbar.
|
|
## Ein offenes Gespräch endet dabei, wie ein Gast, der den Raum verlässt.
|
|
func gehe(richtung: Vector2i) -> bool:
|
|
if _karte.is_empty():
|
|
return false
|
|
if not dialog.is_empty():
|
|
dialog_schliessen()
|
|
var von := position()
|
|
var ziel := von + richtung
|
|
if not KARTE.begehbar(_karte, ziel.x, ziel.y, belegt):
|
|
return false
|
|
place["x"] = ziel.x
|
|
place["y"] = ziel.y
|
|
platz_geaendert.emit(von, ziel)
|
|
var aus := KARTE.ausgang(_karte, ziel.x, ziel.y)
|
|
if not aus.is_empty():
|
|
ausgang_erreicht.emit(String(aus.get("to", "")))
|
|
return true
|
|
|
|
## Mit dem nächsten NSC sprechen. Ein offenes Gespräch wird dabei geschlossen.
|
|
func sprechen() -> bool:
|
|
if not dialog.is_empty():
|
|
dialog_schliessen()
|
|
return true
|
|
var eintrag := KARTE.nsc_in_rufweite(_karte, position())
|
|
if eintrag.is_empty():
|
|
return false
|
|
var nsc: Dictionary = Content.entry("npcs", String(eintrag.get("id", "")))
|
|
if nsc.is_empty():
|
|
return false
|
|
dialog = nsc
|
|
dialog_geaendert.emit(dialog)
|
|
return true
|
|
|
|
func dialog_schliessen() -> void:
|
|
if dialog.is_empty():
|
|
return
|
|
dialog = {}
|
|
dialog_geaendert.emit({})
|
|
|
|
# ------------------------------------------------------------- speichern ----
|
|
|
|
func to_dict() -> Dictionary:
|
|
return {
|
|
"save_version": Saves.VERSION,
|
|
"place": place,
|
|
"time": time,
|
|
"party": party,
|
|
"flags": flags,
|
|
"log": log_lines,
|
|
}
|
|
|
|
func from_dict(d: Dictionary) -> void:
|
|
place = d.get("place", place)
|
|
time = d.get("time", time)
|
|
party = d.get("party", party)
|
|
flags = d.get("flags", {})
|
|
log_lines = []
|
|
for zeile in d.get("log", []):
|
|
log_lines.append(str(zeile))
|