feat: Introduce EnhancedGridMap addon for advanced grid management and procedural generation, and StaticTektonManager for tekton spawning and placement.
This commit is contained in:
+74
-17
@@ -603,6 +603,9 @@ func _assign_random_spawn_positions():
|
||||
# Tekton NPC Management
|
||||
# =============================================================================
|
||||
|
||||
const StaticTektonManager = preload("res://scripts/managers/static_tekton_manager.gd")
|
||||
var static_tekton_manager
|
||||
|
||||
func spawn_tekton_npc():
|
||||
"""Spawn a Tekton NPC at a random location."""
|
||||
if not multiplayer.is_server(): return
|
||||
@@ -611,7 +614,7 @@ func spawn_tekton_npc():
|
||||
var enhanced_gridmap = $EnhancedGridMap
|
||||
if not enhanced_gridmap: return
|
||||
|
||||
# Spawn Static Tektons (Bottom Right, Mid Right)
|
||||
# Spawn Static Tektons (Using Manager)
|
||||
spawn_static_tektons()
|
||||
|
||||
# Spawn 3 Roaming Tektons
|
||||
@@ -629,6 +632,10 @@ func spawn_tekton_npc():
|
||||
|
||||
# Check if walkable and no existing Tekton nearby?
|
||||
if enhanced_gridmap.get_cell_item(cell) == 0: # Walkable floor
|
||||
# Ensure not occupied by static tekton stand (Item 4)
|
||||
var item_id = enhanced_gridmap.get_cell_item(Vector3i(x, 1, y))
|
||||
if item_id == 4: continue # Wall/Stand
|
||||
|
||||
valid_pos = Vector2i(x, y)
|
||||
|
||||
# Generate a consistent ID/Name for sync (add index to ensure uniqueness)
|
||||
@@ -673,31 +680,81 @@ func _create_tekton(pos: Vector2i, tekton_id: int, is_static: bool = false):
|
||||
print("[Main] Spawned Tekton at %s (ID: %d)" % [pos, tekton_id])
|
||||
|
||||
func spawn_static_tektons():
|
||||
"""Spawn fixed static tektons (Bottom Right, Mid Right)."""
|
||||
"""Spawn fixed static tektons using StaticTektonManager."""
|
||||
if not multiplayer.is_server(): return
|
||||
var enhanced_gridmap = $EnhancedGridMap
|
||||
if not enhanced_gridmap: return
|
||||
|
||||
# Bottom Right (Max X, Max Y)
|
||||
if "columns" in enhanced_gridmap and "rows" in enhanced_gridmap:
|
||||
var cols = enhanced_gridmap.columns
|
||||
var rows = enhanced_gridmap.rows
|
||||
print("[Main] Initializing StaticTektonManager...")
|
||||
if not static_tekton_manager:
|
||||
static_tekton_manager = StaticTektonManager.new()
|
||||
# Keeping manager instance in memory
|
||||
|
||||
# Calculate Spawn Points (Server Logic)
|
||||
var spawn_points = static_tekton_manager.calculate_spawn_points(3, enhanced_gridmap)
|
||||
print("[Main] Static Tekton Points: %s" % str(spawn_points))
|
||||
|
||||
for i in range(spawn_points.size()):
|
||||
var pos = spawn_points[i]
|
||||
# ID: 99000 + i (Consistent IDs for Static Tektons)
|
||||
var id = 99000 + i
|
||||
|
||||
# Bottom Right (Corner - 1)
|
||||
var pos_br = Vector2i(cols - 2, rows - 2)
|
||||
var id_br = 99001
|
||||
_create_tekton(pos_br, id_br, true)
|
||||
rpc("sync_spawn_static_tekton", pos_br, id_br)
|
||||
# Spawn on Server
|
||||
_create_static_setup(pos, id)
|
||||
|
||||
# Mid Right
|
||||
var pos_mr = Vector2i(cols - 2, rows / 2)
|
||||
var id_mr = 99002
|
||||
_create_tekton(pos_mr, id_mr, true)
|
||||
rpc("sync_spawn_static_tekton", pos_mr, id_mr)
|
||||
# Sync to Clients
|
||||
rpc("sync_spawn_static_setup", pos, id)
|
||||
|
||||
@rpc("call_remote", "reliable")
|
||||
func sync_spawn_static_tekton(pos: Vector2i, tekton_id: int):
|
||||
func sync_spawn_static_setup(pos: Vector2i, tekton_id: int):
|
||||
_create_static_setup(pos, tekton_id)
|
||||
|
||||
func _create_static_setup(pos: Vector2i, tekton_id: int):
|
||||
"""Creates both the Stand and the Static Tekton at the position."""
|
||||
var enhanced_gridmap = $EnhancedGridMap
|
||||
|
||||
# 1. Create Stand
|
||||
var stand_name = "StaticStand_%d" % tekton_id
|
||||
if not has_node(stand_name):
|
||||
var stand_scene = load("res://scenes/static_tekton_stand.tscn")
|
||||
if stand_scene:
|
||||
var stand = stand_scene.instantiate()
|
||||
stand.name = stand_name
|
||||
add_child(stand)
|
||||
|
||||
# Position Stand
|
||||
if enhanced_gridmap:
|
||||
# Convert grid to world
|
||||
var world_pos = Vector3(pos.x + 0.5, 0, pos.y + 0.5)
|
||||
if "cell_size" in enhanced_gridmap:
|
||||
world_pos = Vector3(
|
||||
pos.x * enhanced_gridmap.cell_size.x + enhanced_gridmap.cell_size.x/2,
|
||||
0,
|
||||
pos.y * enhanced_gridmap.cell_size.z + enhanced_gridmap.cell_size.z/2
|
||||
)
|
||||
stand.global_position = world_pos
|
||||
|
||||
# Update GridMap to block pathfinding (Item 4 = Wall)
|
||||
# Mark entire 3x3 area as immutable obstacles on FLOOR 0 (Ground Level)
|
||||
# This overwrites the ground tile to ensure PlayerMovementManager sees it as blocked.
|
||||
for dx in range(-1, 2):
|
||||
for dy in range(-1, 2):
|
||||
var tile_pos = Vector3i(pos.x + dx, 0, pos.y + dy)
|
||||
enhanced_gridmap.set_cell_item(tile_pos, 4)
|
||||
|
||||
# CRITICAL: Force AStar update so Bots and Pathfinding know about the new walls
|
||||
if enhanced_gridmap.has_method("update_astar_costs"):
|
||||
enhanced_gridmap.update_astar_costs()
|
||||
|
||||
# 2. Create Tekton
|
||||
# Reuse _create_tekton logic but force params
|
||||
_create_tekton(pos, tekton_id, true)
|
||||
|
||||
# Force Tekton height UP to sit on stand
|
||||
var tekton = get_node_or_null("Tekton_%d" % tekton_id)
|
||||
if tekton:
|
||||
tekton.position.y += 0.6 # Stand Height
|
||||
|
||||
|
||||
|
||||
# =============================================================================
|
||||
|
||||
Reference in New Issue
Block a user