update scarcity
This commit is contained in:
@@ -159,8 +159,46 @@ func _execute_grab(grid_pos: Vector2i, cell: Vector3i, item_id: int):
|
||||
# 3f. Reset the UI for the player who acted
|
||||
player.rpc("force_action_state_none")
|
||||
|
||||
# 4. Check if we need to respawn tiles (Scarcity Logic)
|
||||
# "during no more tiles" -> Refill if floor is empty
|
||||
_check_and_refill_grid_if_needed(server_gridmap)
|
||||
|
||||
return true
|
||||
|
||||
func _check_and_refill_grid_if_needed(server_gridmap: Node):
|
||||
# Check if there are any items left on floor 1
|
||||
var has_items = false
|
||||
var item_list = server_gridmap.mesh_library.get_item_list() if server_gridmap.mesh_library else []
|
||||
|
||||
# We can't efficiently iterate all cells, but we can check usage via get_used_cells_by_item is too specific
|
||||
# Iterating columns/rows is safe for this map size (10x10 usually)
|
||||
for x in range(server_gridmap.columns):
|
||||
for z in range(server_gridmap.rows):
|
||||
var item = server_gridmap.get_cell_item(Vector3i(x, 1, z))
|
||||
if item != -1:
|
||||
has_items = true
|
||||
break
|
||||
if has_items:
|
||||
break
|
||||
|
||||
if not has_items:
|
||||
print("[PlayerboardManager] Floor 1 empty! Respawning tiles with Scarcity...")
|
||||
# Call randomize_floor on floor 1
|
||||
# Since Main owns gridmap, we can sync this or just do it server side (which we are)
|
||||
server_gridmap.randomize_floor(1)
|
||||
|
||||
# We need to sync the ENTIRE floor to clients.
|
||||
# EnhancedGridMap doesn't have a "Sync Floor" RPC built-in to Main, only single cells or array update.
|
||||
# Main.gd has sync_grid_item which handles single cells.
|
||||
# Ideally we'd loop and sync all, or add a method to Main to sync floor.
|
||||
# Loop is okay for 10x10 (100 RPCs is a bit much but acceptable for a rare event).
|
||||
var main = player.get_tree().get_root().get_node_or_null("Main")
|
||||
if main:
|
||||
for x in range(server_gridmap.columns):
|
||||
for z in range(server_gridmap.rows):
|
||||
var item = server_gridmap.get_cell_item(Vector3i(x, 1, z))
|
||||
main.rpc("sync_grid_item", x, 1, z, item)
|
||||
|
||||
func bot_try_grab_item() -> bool:
|
||||
if not enhanced_gridmap or player.action_points <= 0:
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user