game: Inventar-Raster mit Icons, Klassenregeln, Gold und Verbrauch
This commit is contained in:
parent
3fae74b1e8
commit
a78de0ffec
61 changed files with 1047 additions and 148 deletions
|
|
@ -268,6 +268,23 @@ func _selbstpruefung() -> bool:
|
|||
Game.ausruesten(figur, "dolch")
|
||||
and str(figur["equipment"].get("weapon", "")) == "dolch"
|
||||
and Game.inventar_hat(figur, "schwert") == 1) and ok
|
||||
var magier := Game.neue_figur("pc_magier", {
|
||||
"name": "Probe-Magier", "race": "elf", "class": "magier",
|
||||
"attributes": {"str": 8, "dex": 14, "con": 10, "int": 17,
|
||||
"wis": 12, "cha": 10}})
|
||||
Game.inventar_hinzufuegen(magier, "leder")
|
||||
ok = _pruefe("Klassenbeschränkung: Magier trägt kein Leder",
|
||||
Game.ausruesten(magier, "leder") == false
|
||||
and Game.inventar_hat(magier, "leder") == 1) and ok
|
||||
ok = _pruefe("Klassenbeschränkung: Magier führt den Stab",
|
||||
Game.ausruesten_erlaubt(magier, "stab")
|
||||
and not Game.ausruesten_erlaubt(magier, "schwert")) and ok
|
||||
figur["hp"]["current"] = 1
|
||||
var vorrat_text: String = Game.benutzen(figur, "vorrat")
|
||||
ok = _pruefe("Verbrauch: Vorrat heilt und verschwindet",
|
||||
int(figur["hp"]["current"]) > 1
|
||||
and Game.inventar_hat(figur, "vorrat") == 0
|
||||
and vorrat_text.begins_with("Vorrat")) and ok
|
||||
|
||||
# Roster: 1..6, siebte Figur abgelehnt, Entfernen gibt den Platz frei.
|
||||
var sicherung: Array = Game.party.duplicate(true)
|
||||
|
|
@ -293,12 +310,15 @@ func _selbstpruefung() -> bool:
|
|||
# JSON kennt nur "Zahl", Godot liest sie als float zurück; vor dem Vergleich
|
||||
# werden ganze Zahlen normalisiert (1.0 -> 1), sonst wäre der Test unehrlich
|
||||
# streng an einer Typfrage statt am Inhalt.
|
||||
Game.gold = 37
|
||||
var vorher := JSON.stringify(_normalisiere(Game.to_dict()))
|
||||
ok = _pruefe("Spielstand schreiben", Saves.write(9)) and ok
|
||||
var geladen: Dictionary = Saves.read(9)
|
||||
Game.from_dict(geladen)
|
||||
ok = _pruefe("Gold im Spielstand", Game.gold == 37) and ok
|
||||
var nachher := JSON.stringify(_normalisiere(Game.to_dict()))
|
||||
ok = _pruefe("Spielstand identisch nach Neustart", vorher == nachher) and ok
|
||||
Game.gold = Game.START_GOLD
|
||||
DirAccess.remove_absolute(Saves.pfad(9))
|
||||
|
||||
print("\nSelbstprüfung: %s" % ("bestanden" if ok else "FEHLGESCHLAGEN"))
|
||||
|
|
|
|||
|
|
@ -7,8 +7,10 @@ extends Node
|
|||
|
||||
const START = "garana"
|
||||
const PARTY_MAX := 6
|
||||
const START_GOLD := 20
|
||||
|
||||
var party: Array = [] ## Array von Dictionaries (ids + Werte)
|
||||
var gold := START_GOLD ## Parteigold; Ausgaben kommen später dazu
|
||||
var place: Dictionary = {"id": START, "x": 9, "y": 9}
|
||||
var time: Dictionary = {"day": 1, "slot": 0}
|
||||
var flags: Dictionary = {}
|
||||
|
|
@ -188,6 +190,21 @@ func inventar_entfernen(figur: Dictionary, id: String, anzahl: int = 1) -> bool:
|
|||
return false
|
||||
|
||||
|
||||
## Klassenbeschränkung aus `classes.json` (`weapons`, `armor`).
|
||||
func ausruesten_erlaubt(figur: Dictionary, id: String) -> bool:
|
||||
var item: Dictionary = Content.entry("items", id)
|
||||
var typ := str(item.get("type", ""))
|
||||
var klasse: Dictionary = Content.class_def(str(figur.get("class", "")))
|
||||
match typ:
|
||||
"weapon":
|
||||
return klasse.get("weapons", []).has(id)
|
||||
"armor":
|
||||
return klasse.get("armor", []).has(id)
|
||||
"shield":
|
||||
return klasse.get("armor", []).has("schild")
|
||||
return false
|
||||
|
||||
|
||||
func ausruesten(figur: Dictionary, id: String) -> bool:
|
||||
var item: Dictionary = Content.entry("items", id)
|
||||
if item.is_empty():
|
||||
|
|
@ -195,6 +212,8 @@ func ausruesten(figur: Dictionary, id: String) -> bool:
|
|||
var typ := str(item.get("type", ""))
|
||||
if typ not in ["weapon", "armor", "shield"]:
|
||||
return false
|
||||
if not ausruesten_erlaubt(figur, id):
|
||||
return false
|
||||
if inventar_hat(figur, id) <= 0:
|
||||
return false
|
||||
var equipment: Dictionary = figur.get("equipment", {})
|
||||
|
|
@ -212,6 +231,29 @@ func ausruesten(figur: Dictionary, id: String) -> bool:
|
|||
return true
|
||||
|
||||
|
||||
## Verbrauchsgüter. Gibt eine Meldung für die UI zurück.
|
||||
func benutzen(figur: Dictionary, id: String) -> String:
|
||||
if inventar_hat(figur, id) <= 0:
|
||||
return "Nicht im Rucksack."
|
||||
match id:
|
||||
"vorrat":
|
||||
var tp: Dictionary = figur.get("hp", {})
|
||||
if int(tp.get("current", 0)) >= int(tp.get("max", 0)):
|
||||
return "TP sind voll."
|
||||
var heilung: int = Dice.roll("1d6")
|
||||
tp["current"] = mini(int(tp.get("max", 0)),
|
||||
int(tp.get("current", 0)) + heilung)
|
||||
figur["hp"] = tp
|
||||
inventar_entfernen(figur, id)
|
||||
return "Vorrat: +%d TP." % heilung
|
||||
"laterne":
|
||||
flags["licht"] = not bool(flags.get("licht", false))
|
||||
return "Laterne %s." % ("an" if flags["licht"] else "aus")
|
||||
"seil":
|
||||
return "Seil: noch keine Anwendung."
|
||||
return "Nicht benutzbar."
|
||||
|
||||
|
||||
func ablegen(figur: Dictionary, slot: String) -> bool:
|
||||
var equipment: Dictionary = figur.get("equipment", {})
|
||||
if slot == "shield":
|
||||
|
|
@ -240,6 +282,7 @@ func to_dict() -> Dictionary:
|
|||
"save_version": Saves.VERSION,
|
||||
"place": place,
|
||||
"time": time,
|
||||
"gold": gold,
|
||||
"party": party,
|
||||
"flags": flags,
|
||||
"log": log_lines,
|
||||
|
|
@ -248,6 +291,7 @@ func to_dict() -> Dictionary:
|
|||
func from_dict(d: Dictionary) -> void:
|
||||
place = d.get("place", place)
|
||||
time = d.get("time", time)
|
||||
gold = int(d.get("gold", gold))
|
||||
party = d.get("party", party)
|
||||
flags = d.get("flags", {})
|
||||
log_lines = []
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue