106 lines
3.6 KiB
GDScript3
106 lines
3.6 KiB
GDScript3
|
|
extends Node
|
||
|
|
## Rules (Autoload) — die Effekt-Vokabel aus docs/engine.md §5.
|
||
|
|
##
|
||
|
|
## Ein Effekt ist ein Wörterbuch mit `op` und Parametern; `apply()` löst ihn
|
||
|
|
## gegen einen Kontext auf und liefert das Ergebnis zurück. Die Vokabel wird
|
||
|
|
## hier EINMAL implementiert — neue Zauber, Klassen und Fähigkeiten sind neue
|
||
|
|
## Kombinationen in game/data/, kein neuer Code.
|
||
|
|
##
|
||
|
|
## `ctx` (alles optional):
|
||
|
|
## "target" : Dictionary einer Figur (saves, hp, tags …)
|
||
|
|
## "targets" : Array solcher Dictionaries bei Flächeneffekten
|
||
|
|
## "source" : Dictionary des Wirkenden (level, attributes …)
|
||
|
|
## "dc" : Rettungswurf-SG, wenn der Effekt keinen eigenen mitbringt
|
||
|
|
|
||
|
|
## Ergebnis eines Effekts, z. B. {"op": "damage", "amount": 3, "saved": false}
|
||
|
|
func apply(effects: Array, ctx: Dictionary = {}) -> Array:
|
||
|
|
var out: Array = []
|
||
|
|
for e in effects:
|
||
|
|
var r := _run(e, ctx)
|
||
|
|
if not r.is_empty():
|
||
|
|
out.append(r)
|
||
|
|
return out
|
||
|
|
|
||
|
|
func _run(e: Dictionary, ctx: Dictionary) -> Dictionary:
|
||
|
|
match str(e.get("op", "")):
|
||
|
|
"damage":
|
||
|
|
var amount := Dice.roll(str(e.get("amount", "1d4")))
|
||
|
|
var saved := _save(e, ctx)
|
||
|
|
if saved and str(e.get("save_effect", "")) == "half":
|
||
|
|
amount = int(amount / 2.0)
|
||
|
|
return {"op": "damage", "amount": amount,
|
||
|
|
"type": e.get("type", "wucht"), "saved": saved}
|
||
|
|
|
||
|
|
"heal":
|
||
|
|
return {"op": "heal", "amount": Dice.roll(str(e.get("amount", "1d6"))),
|
||
|
|
"affects": e.get("affects", "single")}
|
||
|
|
|
||
|
|
"condition":
|
||
|
|
if e.has("add"):
|
||
|
|
return {"op": "condition", "add": e["add"],
|
||
|
|
"duration": e.get("duration", {}),
|
||
|
|
"saved": _save(e, ctx)}
|
||
|
|
return {"op": "condition", "remove": e["remove"]}
|
||
|
|
|
||
|
|
"bonus":
|
||
|
|
var r := {"op": "bonus", "target": e.get("target"), "duration": {}}
|
||
|
|
if e.has("value"):
|
||
|
|
r["value"] = int(e["value"])
|
||
|
|
if e.has("multiplier"):
|
||
|
|
r["multiplier"] = int(e["multiplier"])
|
||
|
|
for feld in ["save", "skill", "when", "per", "max", "affects"]:
|
||
|
|
if e.has(feld):
|
||
|
|
r[feld] = e[feld]
|
||
|
|
return r
|
||
|
|
|
||
|
|
"move":
|
||
|
|
return {"op": "move", "mode": e.get("mode", "walk"),
|
||
|
|
"tiles": int(e.get("tiles", 0))}
|
||
|
|
|
||
|
|
"summon":
|
||
|
|
var mon := Content.monster(str(e.get("monster", "")))
|
||
|
|
return {"op": "summon", "monster": e.get("monster"),
|
||
|
|
"count": int(e.get("count", 1)), "def": mon}
|
||
|
|
|
||
|
|
"light":
|
||
|
|
return {"op": "light", "radius": int(e.get("radius", 0)),
|
||
|
|
"duration": e.get("duration", {})}
|
||
|
|
|
||
|
|
"grant_spells":
|
||
|
|
return {"op": "grant_spells", "school": e.get("school", "any")}
|
||
|
|
|
||
|
|
"extra_attack":
|
||
|
|
return {"op": "extra_attack", "count": int(e.get("count", 1))}
|
||
|
|
|
||
|
|
"resource":
|
||
|
|
return {"op": "resource", "pool": e.get("pool"),
|
||
|
|
"delta": int(e.get("delta", 0))}
|
||
|
|
|
||
|
|
"message":
|
||
|
|
return {"op": "message", "text_id": e.get("text_id", "")}
|
||
|
|
|
||
|
|
"turn_undead":
|
||
|
|
return {"op": "turn_undead", "wurf": Dice.roll("2d6"),
|
||
|
|
"duration": int(e.get("duration", 3)),
|
||
|
|
"only": e.get("only", {})}
|
||
|
|
|
||
|
|
"immunity":
|
||
|
|
return {"op": "immunity", "against": e.get("against", [])}
|
||
|
|
|
||
|
|
_:
|
||
|
|
# Kein assert: ContentDB lehnt unbekannte ops schon beim Laden ab.
|
||
|
|
# Hier ist es das Sicherheitsnetz für Effekte, die im Code entstehen.
|
||
|
|
push_error("Rules: unbekanntes op '%s' — Vokabel in game/data/_schema.json "
|
||
|
|
% str(e.get("op", "")) + "und effect_runner.gd ergänzen")
|
||
|
|
return {}
|
||
|
|
|
||
|
|
## Rettungswurf: d20 + Bonus des Ziels gegen den SG des Effekts.
|
||
|
|
func _save(e: Dictionary, ctx: Dictionary) -> bool:
|
||
|
|
if not e.has("save"):
|
||
|
|
return false
|
||
|
|
var target: Dictionary = ctx.get("target", {})
|
||
|
|
var bonuses: Dictionary = target.get("save_bonus", {})
|
||
|
|
var bonus := int(bonuses.get(str(e["save"]), 0))
|
||
|
|
var dc := int(e.get("dc", ctx.get("dc", 10)))
|
||
|
|
return Dice.roll("1d20") + bonus >= dc
|