game: Zauber und Fernkampf — Zauberliste, Plätze, Reichweiten, Waffen mit range

This commit is contained in:
torsten 2026-11-17 22:03:18 +01:00
parent 5204280eb3
commit 145931d133
13 changed files with 518 additions and 22 deletions

View file

@ -119,11 +119,68 @@ func neue_figur(id: String, vorgabe: Dictionary) -> Dictionary:
"attributes": attrs,
"hp": {"current": hp_max, "max": hp_max},
"skills": _startfertigkeiten(klasse),
"spells": {"known": [], "prepared": [], "slots": {}},
"spells": _zaubersatz(klasse),
"inventory": inventar, "equipment": equipment,
"conditions": [],
}
## Zauber einer Klasse: bekannte Sprüche und Plätze der Stufe 1.
## Magier lernen arkan, Kleriker göttlich; Kämpfer und Diebe bekommen nichts.
func _zaubersatz(klasse: Dictionary) -> Dictionary:
var schule := ""
match str(klasse.get("name", "")):
"Magier": schule = "arcane"
"Kleriker": schule = "divine"
var bekannt: Array[String] = []
if not schule.is_empty():
for id in Content.ids("spells"):
var spruch: Dictionary = Content.entry("spells", id)
if str(spruch.get("school", "")) == schule:
bekannt.append(str(id))
return {"known": bekannt, "prepared": [], "slots": _slots_fuer(klasse, 1)}
## Zauberplätze der Stufe `stufe` aus der Klassenleiter (`spell_slots`).
func _slots_fuer(klasse: Dictionary, stufe: int) -> Dictionary:
var slots := {}
# Kämpfer und Diebe haben `"spell_slots": null` in den Daten.
var leiter: Dictionary = klasse.get("spell_slots") if klasse.get("spell_slots") is Dictionary else {}
for grad in leiter:
var werte: Array = leiter[grad]
if stufe - 1 < werte.size() and int(werte[stufe - 1]) > 0:
slots[str(grad)] = int(werte[stufe - 1])
return slots
## Höchster Zaubergrad, für den die Figur Plätze hat.
func hoechster_grad(figur: Dictionary) -> int:
var grad := 0
for g in figur.get("spells", {}).get("slots", {}):
if int(figur["spells"]["slots"][g]) > 0:
grad = maxi(grad, int(g))
return grad
func zauberplatz(figur: Dictionary, grad: int) -> int:
return int(figur.get("spells", {}).get("slots", {}).get(str(grad), 0))
## Verbraucht einen Platz. Gibt false zurück, wenn keiner übrig ist.
func zauber_verbrauchen(figur: Dictionary, grad: int) -> bool:
var slots: Dictionary = figur.get("spells", {}).get("slots", {})
var key := str(grad)
if int(slots.get(key, 0)) <= 0:
return false
slots[key] = int(slots[key]) - 1
return true
## Plätze für einen neuen Tag/Encounter auffüllen (bis ein Rastsystem existiert).
func zauberplaetze_auffrischen(figur: Dictionary) -> void:
var klasse: Dictionary = Content.class_def(str(figur.get("class", "")))
figur["spells"]["slots"] = _slots_fuer(klasse, int(figur.get("level", 1)))
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)
@ -176,6 +233,7 @@ func _stufe_auf(figur: Dictionary) -> void:
tp["max"] = int(tp.get("max", 1)) + zuwachs
tp["current"] = int(tp.get("current", 0)) + zuwachs
figur["hp"] = tp
zauberplaetze_auffrischen(figur)
func _startfertigkeiten(klasse: Dictionary) -> Dictionary:
var out := {}
@ -185,6 +243,19 @@ func _startfertigkeiten(klasse: Dictionary) -> Dictionary:
return out
## Abgeleitete Werte werden gerechnet, nie gespeichert.
## Reichweite der ausgerüsteten Waffe in Feldern (0 = nur Nahkampf).
func waffe_reichweite(figur: Dictionary) -> int:
var id := str(figur.get("equipment", {}).get("weapon", ""))
return int(Content.entry("items", id).get("range", 0))
## Rettungswürfe der Klasse (für Zauber, die einen Wurf verlangen).
func rettungsbonus(figur: Dictionary) -> Dictionary:
var klasse: Dictionary = Content.class_def(str(figur.get("class", "")))
var b: Dictionary = klasse.get("save_bonus", {})
return b
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", "")))