feat: Add initial main game scene with grid map, player board UI, and manager scripts for game logic and input.
This commit is contained in:
@@ -119,11 +119,13 @@ func _execute_grab(grid_pos: Vector2i, cell: Vector3i, item_id: int):
|
||||
# Check if item is still there
|
||||
if server_item != item_id:
|
||||
print("Server: Item mismatch or already taken. Server has ", server_item)
|
||||
_force_sync_to_client(cell, server_item)
|
||||
return false
|
||||
|
||||
# Check action points
|
||||
if player.action_points <= 0:
|
||||
print("Server: Player has no action points.")
|
||||
_force_sync_to_client(cell, server_item)
|
||||
return false
|
||||
|
||||
# Check adjacency
|
||||
@@ -131,12 +133,14 @@ func _execute_grab(grid_pos: Vector2i, cell: Vector3i, item_id: int):
|
||||
var neighbors = server_gridmap.get_neighbors(player.current_position, 0)
|
||||
if not neighbors.any(func(n): return n.position == grid_pos):
|
||||
print("Server: Player is not adjacent to item.")
|
||||
_force_sync_to_client(cell, server_item)
|
||||
return false
|
||||
|
||||
# 2. Server-side Auto-Arrange
|
||||
var target_slot = find_best_goal_slot_for_item(item_id)
|
||||
if target_slot == -1:
|
||||
print("Server: Player has no valid slot for item.")
|
||||
_force_sync_to_client(cell, server_item)
|
||||
return false
|
||||
|
||||
# 3. Server Executes the Action
|
||||
@@ -197,6 +201,32 @@ func _check_and_refill_grid_if_needed(server_gridmap: Node):
|
||||
var item = server_gridmap.get_cell_item(Vector3i(x, 1, z))
|
||||
main.rpc("sync_grid_item", x, 1, z, item)
|
||||
|
||||
|
||||
|
||||
func _force_sync_to_client(cell: Vector3i, server_item: int):
|
||||
"""Force a sync of the specific cell and playerboard to the client who initiated the failed action."""
|
||||
# Only meaningful if we are server
|
||||
if not multiplayer.is_server():
|
||||
return
|
||||
|
||||
var main = player.get_tree().get_root().get_node_or_null("Main")
|
||||
if not main: return
|
||||
|
||||
# Determine client peer ID from player name (standard convention)
|
||||
# Note: Bots are ID 1, so we don't need to sync special for them (local function calls)
|
||||
# But for Clients...
|
||||
var peer_id = player.name.to_int()
|
||||
if peer_id == 1: # Server/Bot
|
||||
return
|
||||
|
||||
# Sync the Grid Item (which they thought they took)
|
||||
main.rpc_id(peer_id, "sync_grid_item", cell.x, cell.y, cell.z, server_item)
|
||||
|
||||
# Sync their Playerboard (which they thought they updated)
|
||||
main.rpc_id(peer_id, "sync_playerboard", peer_id, player.playerboard)
|
||||
|
||||
print("Server: Forced sync to client %d due to action failure." % peer_id)
|
||||
|
||||
func bot_try_grab_item() -> bool:
|
||||
if not enhanced_gridmap or player.action_points <= 0:
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user