game: Inventar und fünf Vollbilder in 1920 — Titel scharf, Startgepäck
This commit is contained in:
parent
5b11e770b8
commit
3fae74b1e8
56 changed files with 795 additions and 84 deletions
|
|
@ -96,6 +96,9 @@ func neue_figur(id: String, vorgabe: Dictionary) -> Dictionary:
|
|||
equipment[feld] = str(start[feld])
|
||||
if bool(start.get("shield", false)):
|
||||
equipment["shield"] = true
|
||||
var inventar := []
|
||||
for item_id in start.get("items", []):
|
||||
inventar.append({"id": str(item_id), "count": 1})
|
||||
return {
|
||||
"id": id, "name": vorgabe["name"],
|
||||
"race": vorgabe["race"], "class": vorgabe["class"],
|
||||
|
|
@ -105,7 +108,7 @@ func neue_figur(id: String, vorgabe: Dictionary) -> Dictionary:
|
|||
"hp": {"current": hp_max, "max": hp_max},
|
||||
"skills": _startfertigkeiten(klasse),
|
||||
"spells": {"known": [], "prepared": [], "slots": {}},
|
||||
"inventory": [], "equipment": equipment,
|
||||
"inventory": inventar, "equipment": equipment,
|
||||
"conditions": [],
|
||||
}
|
||||
|
||||
|
|
@ -138,6 +141,93 @@ func angriffsbonus(figur: Dictionary) -> int:
|
|||
return int(leiter[stufe - 1])
|
||||
return int(leiter[leiter.size() - 1]) if not leiter.is_empty() else 0
|
||||
|
||||
# ------------------------------------------------------------- Inventar ----
|
||||
# Ein Gegenstand ist `{"id": ..., "count": n}`; Ausrüstung referenziert ids.
|
||||
# Ausrüsten nimmt ein Stück aus dem Rucksack, Ablegen legt es zurück.
|
||||
|
||||
func inventar_hat(figur: Dictionary, id: String) -> int:
|
||||
for eintrag in figur.get("inventory", []):
|
||||
if typeof(eintrag) == TYPE_DICTIONARY:
|
||||
if str(eintrag.get("id", "")) == id:
|
||||
return int(eintrag.get("count", 0))
|
||||
elif str(eintrag) == id:
|
||||
return 1
|
||||
return 0
|
||||
|
||||
|
||||
func inventar_hinzufuegen(figur: Dictionary, id: String, anzahl: int = 1) -> void:
|
||||
if id.is_empty() or anzahl <= 0:
|
||||
return
|
||||
var inventar: Array = figur.get("inventory", [])
|
||||
for eintrag in inventar:
|
||||
if typeof(eintrag) == TYPE_DICTIONARY and str(eintrag.get("id", "")) == id:
|
||||
eintrag["count"] = int(eintrag.get("count", 0)) + anzahl
|
||||
return
|
||||
inventar.append({"id": id, "count": anzahl})
|
||||
figur["inventory"] = inventar
|
||||
|
||||
|
||||
func inventar_entfernen(figur: Dictionary, id: String, anzahl: int = 1) -> bool:
|
||||
var inventar: Array = figur.get("inventory", [])
|
||||
for i in inventar.size():
|
||||
var eintrag = inventar[i]
|
||||
var treffer := false
|
||||
var zahl := 1
|
||||
if typeof(eintrag) == TYPE_DICTIONARY:
|
||||
treffer = str(eintrag.get("id", "")) == id
|
||||
zahl = int(eintrag.get("count", 1))
|
||||
else:
|
||||
treffer = str(eintrag) == id
|
||||
if not treffer:
|
||||
continue
|
||||
if zahl <= anzahl:
|
||||
inventar.remove_at(i)
|
||||
else:
|
||||
eintrag["count"] = zahl - anzahl
|
||||
return true
|
||||
return false
|
||||
|
||||
|
||||
func ausruesten(figur: Dictionary, id: String) -> bool:
|
||||
var item: Dictionary = Content.entry("items", id)
|
||||
if item.is_empty():
|
||||
return false
|
||||
var typ := str(item.get("type", ""))
|
||||
if typ not in ["weapon", "armor", "shield"]:
|
||||
return false
|
||||
if inventar_hat(figur, id) <= 0:
|
||||
return false
|
||||
var equipment: Dictionary = figur.get("equipment", {})
|
||||
if typ == "shield":
|
||||
if bool(equipment.get("shield", false)):
|
||||
inventar_hinzufuegen(figur, "schild")
|
||||
equipment["shield"] = true
|
||||
else:
|
||||
var alt := str(equipment.get(typ, ""))
|
||||
if not alt.is_empty():
|
||||
inventar_hinzufuegen(figur, alt)
|
||||
equipment[typ] = id
|
||||
figur["equipment"] = equipment
|
||||
inventar_entfernen(figur, id)
|
||||
return true
|
||||
|
||||
|
||||
func ablegen(figur: Dictionary, slot: String) -> bool:
|
||||
var equipment: Dictionary = figur.get("equipment", {})
|
||||
if slot == "shield":
|
||||
if not bool(equipment.get("shield", false)):
|
||||
return false
|
||||
equipment["shield"] = false
|
||||
inventar_hinzufuegen(figur, "schild")
|
||||
else:
|
||||
var id := str(equipment.get(slot, ""))
|
||||
if id.is_empty():
|
||||
return false
|
||||
equipment.erase(slot)
|
||||
inventar_hinzufuegen(figur, id)
|
||||
figur["equipment"] = equipment
|
||||
return true
|
||||
|
||||
func notiz(text: String) -> void:
|
||||
log_lines.append(text)
|
||||
if log_lines.size() > 200:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue