extends Node ## Game (Autoload) — der Spielzustand: Party, Ort, Zeit, Flaggen. ## ## 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. const START = "garana" var party: Array = [] ## Array von Dictionaries (ids + Werte) var place: Dictionary = {"id": START, "x": 9, "y": 9} var time: Dictionary = {"day": 1, "slot": 0} var flags: Dictionary = {} var log_lines: Array[String] = [] 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() # ------------------------------------------------------------- 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))