- Enemy droppt Loot bei Tod (Gold + Items basierend auf LootTable) - LootWindow zeigt Beute an mit "Alles aufheben" Button - Gold-Anzeige im HUD unter XP-Leiste - Beispiel LootTables: Goblin (2-8 Gold) und Skeleton (5-15 Gold) - Loot-System in World verdrahtet Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
118 lines
3.2 KiB
GDScript
118 lines
3.2 KiB
GDScript
# LootWindow.gd
|
|
# Zeigt Loot eines besiegten Gegners an und lässt Spieler Items aufheben
|
|
extends CanvasLayer
|
|
|
|
var player = null
|
|
var current_loot: Dictionary = {} # {"gold": int, "items": [Equipment]}
|
|
var loot_world_position: Vector3 = Vector3.ZERO
|
|
var panel_visible = false
|
|
|
|
const LOOT_PICKUP_RANGE = 5.0
|
|
|
|
@onready var panel = $Panel
|
|
@onready var gold_label = $Panel/VBoxContainer/GoldLabel
|
|
@onready var item_list = $Panel/VBoxContainer/ScrollContainer/ItemList
|
|
@onready var loot_all_button = $Panel/VBoxContainer/LootAllButton
|
|
|
|
func _ready():
|
|
panel.visible = false
|
|
loot_all_button.pressed.connect(_on_loot_all)
|
|
|
|
func setup(p):
|
|
player = p
|
|
|
|
# Loot anzeigen
|
|
func show_loot(loot: Dictionary, world_pos: Vector3):
|
|
current_loot = loot
|
|
loot_world_position = world_pos
|
|
_refresh_display()
|
|
panel_visible = true
|
|
panel.visible = true
|
|
|
|
func hide_loot():
|
|
panel_visible = false
|
|
panel.visible = false
|
|
current_loot = {}
|
|
|
|
func _refresh_display():
|
|
# Gold anzeigen
|
|
if current_loot.get("gold", 0) > 0:
|
|
gold_label.text = str(current_loot["gold"]) + " Gold"
|
|
gold_label.visible = true
|
|
else:
|
|
gold_label.visible = false
|
|
|
|
# Items anzeigen
|
|
for child in item_list.get_children():
|
|
child.queue_free()
|
|
|
|
var items = current_loot.get("items", [])
|
|
for i in range(items.size()):
|
|
var item = items[i]
|
|
var button = Button.new()
|
|
button.text = item.item_name + " (" + Equipment.get_slot_name(item.slot) + ")"
|
|
button.modulate = Equipment.get_rarity_color(item.rarity)
|
|
button.pressed.connect(_on_loot_item.bind(i))
|
|
button.tooltip_text = _get_item_tooltip(item)
|
|
item_list.add_child(button)
|
|
|
|
# Wenn kein Loot mehr da, Fenster schließen
|
|
if current_loot.get("gold", 0) <= 0 and items.size() == 0:
|
|
hide_loot()
|
|
|
|
# Einzelnes Item aufheben
|
|
func _on_loot_item(index: int):
|
|
if player == null:
|
|
return
|
|
|
|
var items = current_loot.get("items", [])
|
|
if index >= items.size():
|
|
return
|
|
|
|
var item = items[index]
|
|
if player.inventory.add_item(item):
|
|
items.remove_at(index)
|
|
_refresh_display()
|
|
|
|
# Alles aufheben
|
|
func _on_loot_all():
|
|
if player == null:
|
|
return
|
|
|
|
# Gold aufheben
|
|
var gold = current_loot.get("gold", 0)
|
|
if gold > 0:
|
|
player.inventory.add_gold(gold)
|
|
current_loot["gold"] = 0
|
|
|
|
# Items aufheben
|
|
var items = current_loot.get("items", [])
|
|
var remaining = []
|
|
for item in items:
|
|
if not player.inventory.add_item(item):
|
|
remaining.append(item) # Inventar voll
|
|
current_loot["items"] = remaining
|
|
|
|
_refresh_display()
|
|
|
|
func _get_item_tooltip(item: Equipment) -> String:
|
|
var tooltip = item.item_name + "\n"
|
|
tooltip += Equipment.get_slot_name(item.slot) + "\n"
|
|
|
|
if item.slot == Equipment.Slot.WEAPON:
|
|
tooltip += "Schaden: " + str(item.min_damage) + "-" + str(item.max_damage) + "\n"
|
|
tooltip += "Tempo: " + str(item.attack_speed) + "s\n"
|
|
if item.armor > 0:
|
|
tooltip += "Rüstung: +" + str(item.armor) + "\n"
|
|
if item.strength > 0:
|
|
tooltip += "Stärke: +" + str(item.strength) + "\n"
|
|
if item.agility > 0:
|
|
tooltip += "Beweglichkeit: +" + str(item.agility) + "\n"
|
|
if item.intelligence > 0:
|
|
tooltip += "Intelligenz: +" + str(item.intelligence) + "\n"
|
|
if item.stamina > 0:
|
|
tooltip += "Ausdauer: +" + str(item.stamina) + "\n"
|
|
if item.haste > 0:
|
|
tooltip += "Tempo: +" + str(int(item.haste * 100)) + "%\n"
|
|
|
|
return tooltip
|