Loot changes

This commit is contained in:
dingo
2026-01-20 16:23:00 -05:00
parent 5bc1c6e0f9
commit a39f4a0a98
20 changed files with 791 additions and 50 deletions
+47 -21
View File
@@ -302,10 +302,22 @@ func _get_item_emoji(item: Dictionary) -> String:
func _on_inventory_gui_input(event: InputEvent, slot_index: int):
if not event is InputEventMouseButton:
return
var item = GameState.inventory[slot_index] if slot_index < GameState.inventory.size() else null
if event.button_index == MOUSE_BUTTON_LEFT:
if event.button_index == MOUSE_BUTTON_LEFT and event.pressed:
if item == null:
return
# Left click: equip/unequip or assign to hotbar
var item_type = item.get("type", item.get("Type", ""))
if item_type == "Consumable":
# Show hotbar menu for consumables
_show_hotbar_menu(slot_index)
elif item_type in ["Weapon", "Armor", "Accessory"]:
# Equip on left click
GameState.send_equip_item(slot_index)
elif event.button_index == MOUSE_BUTTON_RIGHT:
if event.pressed:
# Start drag if has item
if item and not item.is_empty() and DragManager:
@@ -313,25 +325,18 @@ func _on_inventory_gui_input(event: InputEvent, slot_index: int):
else:
# End drag on release (if still dragging)
if DragManager and DragManager.is_dragging:
# Check if we should equip or use
# Check if we're dropping onto another inventory slot
var target_item = GameState.inventory[slot_index] if slot_index < GameState.inventory.size() else null
var drag_item = DragManager.get_drag_item()
var item_type = drag_item.get("type", drag_item.get("Type", ""))
GameState.send_use_item(slot_index)
# If released over same slot or no target, treat as click
# For now, just end the drag
# Try to stack consumables
if target_item and drag_item and _can_stack_items(drag_item, target_item):
var source_slot = DragManager.drag_data.get("source_slot", -1)
if source_slot >= 0 and source_slot != slot_index:
GameState.send_stack_items(source_slot, slot_index)
# Just end the drag - drop handling is done by the drop target
DragManager.end_drag()
elif event.button_index == MOUSE_BUTTON_RIGHT and event.pressed:
if item == null:
return
# Right click: context action
var item_type = item.get("type", item.get("Type", ""))
if item_type == "Consumable":
# Use consumable on right click
_show_hotbar_menu(slot_index)
elif item_type in ["Weapon", "Armor", "Accessory"]:
# Equip on right click
GameState.send_equip_item(slot_index)
func _on_equipment_gui_input(event: InputEvent, slot_name: String):
if event is InputEventMouseButton and event.pressed and event.button_index == MOUSE_BUTTON_LEFT:
@@ -339,6 +344,27 @@ func _on_equipment_gui_input(event: InputEvent, slot_name: String):
if item != null:
GameState.send_unequip_item(slot_name)
func _can_stack_items(item1: Dictionary, item2: Dictionary) -> bool:
# Check if both items are consumables with the same name
var type1 = item1.get("type", item1.get("Type", ""))
var type2 = item2.get("type", item2.get("Type", ""))
if type1 != "Consumable" or type2 != "Consumable":
return false
# Check if same item type
var name1 = item1.get("name", item1.get("Name", ""))
var name2 = item2.get("name", item2.get("Name", ""))
if name1 != name2:
return false
# Check if target has room (not already at max stack)
var max_stack = item2.get("maxStack", item2.get("MaxStack", 99))
var current_quantity = item2.get("quantity", item2.get("Quantity", 1))
return current_quantity < max_stack
func _show_hotbar_menu(inv_slot: int):
# Simple approach: assign to next empty hotbar slot or use slot 0
# For now, find first empty slot or use slot 0
@@ -347,7 +373,7 @@ func _show_hotbar_menu(inv_slot: int):
if GameState.hotbar[i] == null:
target_slot = i
break
GameState.assign_hotbar(target_slot, inv_slot)
print("Assigned inventory slot %d to hotbar slot %d" % [inv_slot, target_slot])