From 85c95e9f6a1a2b79e9869fadf8aac72bba38b4f8 Mon Sep 17 00:00:00 2001 From: dingo Date: Wed, 21 Jan 2026 08:43:18 -0500 Subject: [PATCH] Loot change --- project.godot | 1 - scripts/dungeon/dungeon_manager.gd | 74 ++++++++++++++++++++++++++++++ scripts/dungeon/mob_visual.gd | 24 ++++------ 3 files changed, 83 insertions(+), 16 deletions(-) diff --git a/project.godot b/project.godot index 2e7520f..c61b385 100644 --- a/project.godot +++ b/project.godot @@ -65,7 +65,6 @@ attack={ inventory={ "deadzone": 0.2, "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":73,"key_label":0,"unicode":105,"location":0,"echo":false,"script":null) -, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":69,"key_label":0,"unicode":101,"location":0,"echo":false,"script":null) ] } escape_menu={ diff --git a/scripts/dungeon/dungeon_manager.gd b/scripts/dungeon/dungeon_manager.gd index a06d6bc..049cca5 100644 --- a/scripts/dungeon/dungeon_manager.gd +++ b/scripts/dungeon/dungeon_manager.gd @@ -27,6 +27,10 @@ const WORLD_TILE_SIZE := TILE_SIZE * TILE_SCALE # 32 pixels per tile in world var crafting_panel = null var mob_loot_ui = null +# Loot popup prompt +var loot_popup: Button = null +var nearby_lootable_mob: Node = null + # Visual tile renderer (for V2 dungeons) var visual_renderer: VisualTileMapRenderer = null @@ -83,6 +87,9 @@ func _ready(): mob_loot_ui.visible = false add_child(mob_loot_ui) + # Create loot popup prompt + _create_loot_popup() + # Create visual tile renderer visual_renderer = VisualTileMapRenderer.new() visual_renderer.name = "VisualTileRenderer" @@ -238,6 +245,7 @@ func _process(delta): _handle_input() _update_camera(delta) + _update_loot_popup() func _physics_process(_delta): if not GameState or GameState.current_state != GameState.STATE_PLAYING: @@ -719,3 +727,69 @@ func _on_damage_number(data: Dictionary): color = Color(1.0, 0.5, 0.0) # Orange for weakness dmg_number.initialize(damage, color) + +func _create_loot_popup(): + """Create the loot popup prompt that appears when near corpses""" + # Create a button instead of label so it's clickable + var button = Button.new() + button.text = "[E]" + button.add_theme_font_size_override("font_size", 14) + button.add_theme_color_override("font_color", Color.WHITE) + button.visible = false + button.z_index = 100 + button.custom_minimum_size = Vector2(30, 30) + + # Make it styled + var style_normal = StyleBoxFlat.new() + style_normal.bg_color = Color(0, 0, 0, 0.8) + style_normal.set_border_width_all(2) + style_normal.border_color = Color(0.8, 0.8, 0.3) + style_normal.set_corner_radius_all(4) + button.add_theme_stylebox_override("normal", style_normal) + + var style_hover = StyleBoxFlat.new() + style_hover.bg_color = Color(0.2, 0.2, 0, 0.9) + style_hover.set_border_width_all(2) + style_hover.border_color = Color(1.0, 1.0, 0.5) + style_hover.set_corner_radius_all(4) + button.add_theme_stylebox_override("hover", style_hover) + + button.pressed.connect(_on_loot_popup_clicked) + add_child(button) + loot_popup = button + +func _update_loot_popup(): + """Update loot popup position and visibility based on nearby corpses""" + if not loot_popup or not player_node or not mobs_container: + return + + var player_pos = player_node.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: + # Show popup above the corpse + nearby_lootable_mob = nearest_mob + loot_popup.visible = true + loot_popup.global_position = nearest_mob.global_position + Vector2(-40, -40) + else: + nearby_lootable_mob = null + loot_popup.visible = false + +func _on_loot_popup_clicked(): + """Handle click on loot popup""" + if nearby_lootable_mob: + var mob_id = nearby_lootable_mob.get_meta("entity_id", -1) + if mob_id >= 0: + GameState.request_mob_loot(mob_id) + print("[DungeonManager] Loot popup clicked - requesting loot from mob ID: %d" % mob_id) diff --git a/scripts/dungeon/mob_visual.gd b/scripts/dungeon/mob_visual.gd index 2ca92af..12b52ed 100644 --- a/scripts/dungeon/mob_visual.gd +++ b/scripts/dungeon/mob_visual.gd @@ -114,17 +114,13 @@ func update_data(data: Dictionary): _initialized = true - # Update visual state - #var state = data.get("state", data.get("State", "idle")).to_lower() - #var rotation = data.get("rotation", data.get("Rotation", 0.0)) - # - #_update_animation_state(state, rotation) - - var raw_state = data.get("state", data.get("State", "idle")).to_lower() - var animation_state := _state_to_animation(raw_state) - var rotation = data.get("rotation", data.get("Rotation", 0.0)) + # Update visual state (skip for dead mobs to preserve death animation) + if _current_state != "dead": + var raw_state = data.get("state", data.get("State", "idle")).to_lower() + var animation_state := _state_to_animation(raw_state) + var rotation = data.get("rotation", data.get("Rotation", 0.0)) - _update_animation_state(animation_state, rotation) + _update_animation_state(animation_state, rotation) # Apply scale @@ -536,15 +532,13 @@ func play_death_animation(): break if death_anim_name != "": + # Disable looping for death animation BEFORE playing + _animated_sprite.sprite_frames.set_animation_loop(death_anim_name, false) + # Play the death animation _last_animation = death_anim_name _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