Loot changes
This commit is contained in:
@@ -21,9 +21,11 @@ const WORLD_TILE_SIZE := TILE_SIZE * TILE_SCALE # 32 pixels per tile in world
|
||||
@onready var hud = $Hud
|
||||
@onready var inventory_panel = $Inventory
|
||||
@onready var chat_panel = $Chat
|
||||
@onready var char_sheet_ui = $CharSheet
|
||||
|
||||
# Crafting panel (loaded dynamically)
|
||||
var crafting_panel = null
|
||||
var mob_loot_ui = null
|
||||
|
||||
# Visual tile renderer (for V2 dungeons)
|
||||
var visual_renderer: VisualTileMapRenderer = null
|
||||
@@ -74,6 +76,13 @@ func _ready():
|
||||
crafting_panel.visible = false
|
||||
add_child(crafting_panel)
|
||||
|
||||
# Load mob loot UI
|
||||
if ResourceLoader.exists("res://scenes/ui/mob_loot_ui.tscn"):
|
||||
var mob_loot_scene = load("res://scenes/ui/mob_loot_ui.tscn")
|
||||
mob_loot_ui = mob_loot_scene.instantiate()
|
||||
mob_loot_ui.visible = false
|
||||
add_child(mob_loot_ui)
|
||||
|
||||
# Create visual tile renderer
|
||||
visual_renderer = VisualTileMapRenderer.new()
|
||||
visual_renderer.name = "VisualTileRenderer"
|
||||
@@ -276,6 +285,8 @@ func _handle_input():
|
||||
inventory_panel.visible = false
|
||||
elif chat_panel and chat_panel.visible:
|
||||
chat_panel.visible = false
|
||||
elif char_sheet_ui and char_sheet_ui.visible:
|
||||
char_sheet_ui.visible = false
|
||||
else:
|
||||
# Player pressed escape but no UI open - hint about portals
|
||||
print("[Dungeon] To exit, walk into the purple exit portal near spawn")
|
||||
@@ -283,7 +294,11 @@ func _handle_input():
|
||||
# Chat (Enter key)
|
||||
if Input.is_action_just_pressed("chat"):
|
||||
_open_chat()
|
||||
|
||||
|
||||
# Interact with dead mobs (E key)
|
||||
if Input.is_key_pressed(KEY_E) and not ui_open:
|
||||
_try_loot_nearby_mob()
|
||||
|
||||
# Hotbar keys 1-8
|
||||
if not ui_open:
|
||||
for i in range(1, 9):
|
||||
@@ -291,6 +306,11 @@ func _handle_input():
|
||||
_use_hotbar_slot(i - 1)
|
||||
|
||||
func _perform_attack(attack_angle: float):
|
||||
# Don't attack if UI is open
|
||||
var ui_open = (inventory_panel and inventory_panel.visible) or (chat_panel and chat_panel.visible) or (crafting_panel and crafting_panel.visible)
|
||||
if ui_open:
|
||||
return
|
||||
|
||||
# Check attack cooldown
|
||||
var current_time = Time.get_ticks_msec() / 1000.0
|
||||
var time_since_last_attack = current_time - last_attack_time
|
||||
@@ -437,30 +457,45 @@ func _on_state_updated():
|
||||
func _update_entities(container: Node2D, data: Dictionary, scene: PackedScene):
|
||||
if scene == null or container == null:
|
||||
return
|
||||
|
||||
|
||||
var seen_ids = []
|
||||
|
||||
|
||||
for id in data:
|
||||
seen_ids.append(id)
|
||||
var entity_data = data[id]
|
||||
var entity_node = _find_entity_by_id(container, id)
|
||||
|
||||
|
||||
if entity_node == null:
|
||||
entity_node = scene.instantiate()
|
||||
entity_node.set_meta("entity_id", id)
|
||||
container.add_child(entity_node)
|
||||
|
||||
|
||||
var x = entity_data.get("x", entity_data.get("X", 0))
|
||||
var y = entity_data.get("y", entity_data.get("Y", 0))
|
||||
entity_node.position = Vector2(x, y)
|
||||
|
||||
|
||||
# Check if this is a mob that just died
|
||||
if container == mobs_container:
|
||||
var hp = entity_data.get("health", entity_data.get("Health", 100))
|
||||
var was_alive = not entity_node.get_meta("is_dead", false)
|
||||
|
||||
if hp <= 0 and was_alive:
|
||||
# Mark as dead and play death animation
|
||||
entity_node.set_meta("is_dead", true)
|
||||
if entity_node.has_method("play_death_animation"):
|
||||
entity_node.play_death_animation()
|
||||
|
||||
if entity_node.has_method("update_data"):
|
||||
entity_node.update_data(entity_data)
|
||||
|
||||
|
||||
for child in container.get_children():
|
||||
if child.has_meta("entity_id"):
|
||||
var id = child.get_meta("entity_id")
|
||||
if id not in seen_ids:
|
||||
# For mobs, keep dead bodies for looting
|
||||
if container == mobs_container and child.get_meta("is_dead", false):
|
||||
# Don't remove dead mob bodies
|
||||
continue
|
||||
child.queue_free()
|
||||
|
||||
func _find_entity_by_id(container: Node2D, id) -> Node2D:
|
||||
@@ -484,6 +519,10 @@ func _toggle_crafting():
|
||||
else:
|
||||
print("[DungeonManager] Crafting UI not loaded")
|
||||
|
||||
func _toggle_char_sheet():
|
||||
if char_sheet_ui:
|
||||
char_sheet_ui.visible = not char_sheet_ui.visible
|
||||
|
||||
func _open_chat():
|
||||
if chat_panel:
|
||||
chat_panel.visible = true
|
||||
@@ -497,6 +536,31 @@ func _use_hotbar_slot(index: int):
|
||||
if hotbar_entry and hotbar_entry.has("inventory_slot"):
|
||||
GameState.send_use_item(hotbar_entry.inventory_slot)
|
||||
|
||||
func _try_loot_nearby_mob():
|
||||
if not player_scene or not mobs_container:
|
||||
return
|
||||
|
||||
var player_pos = $Player.position
|
||||
var loot_range = 50.0 # Pixels
|
||||
|
||||
# Find nearest dead mob within range
|
||||
var nearest_mob = null
|
||||
var nearest_distance = loot_range
|
||||
|
||||
for child in mobs_container.get_children():
|
||||
if child.get_meta("is_dead", false):
|
||||
var distance = player_pos.distance_to(child.position)
|
||||
if distance < nearest_distance:
|
||||
nearest_distance = distance
|
||||
nearest_mob = child
|
||||
|
||||
if nearest_mob:
|
||||
var mob_id = nearest_mob.get_meta("entity_id", -1)
|
||||
if mob_id >= 0:
|
||||
# Request loot from server
|
||||
GameState.request_mob_loot(mob_id)
|
||||
print("[DungeonManager] Requesting loot from mob ID: %d at distance %.1f" % [mob_id, nearest_distance])
|
||||
|
||||
func _update_loot_chests():
|
||||
if loot_chest_scene == null or loot_chests_container == null:
|
||||
return
|
||||
|
||||
@@ -506,3 +506,55 @@ func play_hurt_effect():
|
||||
await get_tree().create_timer(0.1).timeout
|
||||
if is_instance_valid(sprite_to_flash):
|
||||
sprite_to_flash.modulate = original_color
|
||||
|
||||
func play_death_animation():
|
||||
"""Play death animation and stop on last frame"""
|
||||
_current_state = "dead"
|
||||
|
||||
if _animated_sprite and _animated_sprite.sprite_frames:
|
||||
# Try to play death animation
|
||||
var frames = _animated_sprite.sprite_frames
|
||||
var death_anim_name = ""
|
||||
|
||||
# Try different death animation names
|
||||
var names_to_try = [
|
||||
"dead_%s" % _facing_direction,
|
||||
"dead",
|
||||
"death_%s" % _facing_direction,
|
||||
"death"
|
||||
]
|
||||
|
||||
for anim_name in names_to_try:
|
||||
if frames.has_animation(anim_name):
|
||||
death_anim_name = anim_name
|
||||
break
|
||||
|
||||
if death_anim_name != "":
|
||||
# Play the death animation
|
||||
_animated_sprite.play(death_anim_name)
|
||||
|
||||
# Wait for animation to finish
|
||||
if _animated_sprite.sprite_frames.get_animation_loop(death_anim_name):
|
||||
# If it loops, disable looping temporarily
|
||||
_animated_sprite.sprite_frames.set_animation_loop(death_anim_name, false)
|
||||
|
||||
# Wait for animation to complete
|
||||
await _animated_sprite.animation_finished
|
||||
|
||||
# Stop on last frame
|
||||
var frame_count = _animated_sprite.sprite_frames.get_frame_count(death_anim_name)
|
||||
if frame_count > 0:
|
||||
_animated_sprite.frame = frame_count - 1
|
||||
_animated_sprite.stop()
|
||||
else:
|
||||
# No death animation, just fade out the fallback
|
||||
_update_fallback_state("dead")
|
||||
else:
|
||||
# Using fallback sprite, just update its appearance
|
||||
_update_fallback_state("dead")
|
||||
|
||||
# Hide health bar and name label for dead mobs
|
||||
if health_bar:
|
||||
health_bar.visible = false
|
||||
if name_label:
|
||||
name_label.visible = false
|
||||
|
||||
Reference in New Issue
Block a user