DungeonCrawler/inventory.gd
Andre e682ed65e4 Consumable-System, Klassen-Ressourcen, Hauptmenü und Item-Icons
- Consumable-System: Tränke (HP/Mana) mit Stacking, Rechtsklick-Benutzung, Aktionsleisten-Zuweisung
- Klassen-Ressourcen: ResourceType (NONE/MANA/RAGE/ENERGY) pro Klasse statt universelles Mana
- Hauptmenü: Einstellungen für Auflösung, Fenstermodus, VSync, MSAA
- Item-Icons: SVG-Icons für alle Equipment-Items und Tränke
- Character Panel: Icon-Grid mit Hover-Tooltips statt Textanzeige
- HUD: Ressourcen-Leiste mit klassenabhängiger Farbe
- Loot: Consumable-Support in LootTable/LootWindow
- Dokumentation vollständig aktualisiert

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-15 20:45:57 +01:00

95 lines
2.3 KiB
GDScript

# Inventory.gd
# Verwaltet das Spieler-Inventar mit Items (Equipment + Consumables) und Gold
extends Resource
class_name Inventory
signal inventory_changed
signal gold_changed(new_amount: int)
const MAX_SLOTS = 20 # Maximale Inventarplätze
var items: Array = [] # Equipment oder Consumable
var gold: int = 0
func _init():
items = []
gold = 0
# Item hinzufügen - gibt true zurück wenn erfolgreich
# Consumables werden gestackt wenn möglich
func add_item(item) -> bool:
# Consumable stacking
if item is Consumable:
for existing in items:
if existing is Consumable and existing.item_name == item.item_name:
var space = existing.max_stack - existing.stack_size
if space > 0:
var transfer = mini(item.stack_size, space)
existing.stack_size += transfer
item.stack_size -= transfer
if item.stack_size <= 0:
inventory_changed.emit()
print("Item gestackt: ", existing.item_name, " x", existing.stack_size)
return true
if items.size() >= MAX_SLOTS:
print("Inventar voll!")
return false
items.append(item)
inventory_changed.emit()
if item is Consumable:
print("Item erhalten: ", item.item_name, " x", item.stack_size)
else:
print("Item erhalten: ", item.item_name)
return true
# Item an Index entfernen
func remove_item_at(index: int):
if index < 0 or index >= items.size():
return null
var item = items[index]
items.remove_at(index)
inventory_changed.emit()
return item
# Item direkt entfernen
func remove_item(item) -> bool:
var index = items.find(item)
if index == -1:
return false
items.remove_at(index)
inventory_changed.emit()
return true
# Gold hinzufügen
func add_gold(amount: int):
gold += amount
gold_changed.emit(gold)
print("+", amount, " Gold (Gesamt: ", gold, ")")
# Gold ausgeben - gibt true zurück wenn genug vorhanden
func spend_gold(amount: int) -> bool:
if gold < amount:
print("Nicht genug Gold!")
return false
gold -= amount
gold_changed.emit(gold)
return true
# Prüfen ob Inventar voll ist
func is_full() -> bool:
return items.size() >= MAX_SLOTS
# Anzahl freier Slots
func free_slots() -> int:
return MAX_SLOTS - items.size()
# Item an Index holen
func get_item(index: int):
if index < 0 or index >= items.size():
return null
return items[index]
# Anzahl Items
func item_count() -> int:
return items.size()