Khaligufzel / Dimensionfall

A survival game inspired by Cataclysm: Dark Days Ahead and Bright Nights.
MIT License
12 stars 5 forks source link

RockyHill: Containers on top of the hill are duplicated #187

Closed snipercup closed 3 months ago

snipercup commented 4 months ago

When re-entering the RockyHill map and climbing to the top, the container that was created after you destroy the furniture has duplicated

Steps to reproduce:

This is probably cause by the container being close to the edge of the chunks and two of them consider the container to be part of it. So when the chunks are re-loaded, they both spawn the same container, duplicating them.

The ContainerItem class is used in several scripts within the repository. Here are the relevant matches:

  1. Definition of ContainerItem Class

    • File: Scripts/container.gd
    • Snippet:
      class_name ContainerItem
      extends Node3D
  2. Usage in FurniturePhysics.gd

    • File: Scripts/FurniturePhysics.gd
    • Snippet:

      # When the furniture is destroyed, it leaves a wreck behind
      func add_corpse(pos: Vector3):
       if can_be_destroyed():
           var newItem: ContainerItem = ContainerItem.new()
      
           var itemgroup = furnitureJSONData.get("destruction", {}).get("group", "")
           if itemgroup:
  3. Usage in FurnitureStatic.gd

    • File: Scripts/FurnitureStatic.gd
    • Snippet:

      var door_state: String = "Closed"  # Default state
      var container: ContainerItem = null # Reference to the container, if this furniture acts as one
      
      if "Function" in furnitureJSONData and "container" in furnitureJSONData["Function"]:
       container = ContainerItem.new()
       container.construct_self(pos)
  4. Usage in Chunk.gd

    • File: Scripts/Chunk.gd
    • Snippet:
      # Called by generate_items function when a save is loaded
      func add_item_to_map(item: Dictionary):
       var newItem: ContainerItem = ContainerItem.new()
       newItem.add_to_group("mapitems")
       var pos: Vector3 = Vector3(item.global_position_x,item.global_position_y,item.global_position_z)
       newItem.construct_self(pos)
  5. Usage in Mob.gd

    • File: Scripts/Mob.gd
    • Snippet:

      func add_corpse(pos: Vector3):
       var newItem: ContainerItem = ContainerItem.new()
      
       # Retrieve mob data from Gamedata
       var mob_data = Gamedata.get_data_by_id(Gamedata.data.mobs, mobJSON.id)

These usages indicate that the ContainerItem class is primarily used in functions that handle the creation and management of container items in different contexts, such as furniture, chunks, and mobs.

The functions add_to_group("mapitems") and get_nodes_in_group("mapitems") are used in the following context within the repository:

  1. Usage in Chunk.gd
    • File: Scripts/Chunk.gd
    • Snippet for add_to_group("mapitems"):
      var newItem: ContainerItem = ContainerItem.new()
      newItem.add_to_group("mapitems")
      var pos: Vector3 = Vector3(item.global_position_x,item.global_position_y,item.global_position_z)
      newItem.construct_self(pos)
    • Snippet for get_nodes_in_group("mapitems"):
      }
      var mapitems = get_tree().get_nodes_in_group("mapitems")
      var newitemData: Dictionary

These functions are used in the Chunk.gd script to manage items within a specific group, mapitems. The add_to_group("mapitems") function is used to add a new ContainerItem instance to the mapitems group. The get_nodes_in_group("mapitems") function is used to retrieve all nodes that belong to the mapitems group from the scene tree.

The functions add_to_group("Containers") and get_nodes_in_group("Containers") are used in the following files:

  1. Usage in ItemDetector.gd

    • File: Scripts/ItemDetector.gd
    • Snippet for get_nodes_in_group("Containers"):
      func _on_area_entered(area):
       if area.get_owner().is_in_group("Containers"):
           # Add area to the dictionary and check initial proximity status
           areas_in_proximity[area] = is_clear_path_to_area(area)
           if areas_in_proximity[area]:
               Helper.signal_broker.container_entered_proximity.emit(area.get_owner())
  2. Usage in container.gd

    • File: Scripts/container.gd
    • Snippet for add_to_group("Containers"):
      func construct_self(containerPos: Vector3):
       containerpos = containerPos
       add_to_group("Containers")
       create_inventory()
       create_sprite()
       create_area3d()
  3. Usage in LevelManager.gd

    • File: LevelManager.gd
    • Snippet for get_nodes_in_group("Containers"):
      func update_visibility(player_y: float):
       # Update container visibility
       for container in get_tree().get_nodes_in_group("Containers"):
           var is_above_player = container.global_position.y > player_y
           container.visible = not is_above_player

These usages indicate that the Containers group is utilized to manage container items within the game, checking their proximity, visibility, and adding them to the scene tree.