feat: Implement core game managers, player movement logic, and initial UI scenes.

This commit is contained in:
2025-12-27 05:45:57 +08:00
parent 6870016ba6
commit c5e9d073fa
23 changed files with 1456 additions and 97 deletions
+22 -4
View File
@@ -54,6 +54,10 @@ func grab_item(grid_position: Vector2i) -> bool:
if not player.is_multiplayer_authority():
return false
# Play pickup animation
if player.has_method("play_pickup_animation"):
player.play_pickup_animation()
# === Optimistic Local Update (immediate visual feedback) ===
# Apply changes locally first, server will validate/sync
enhanced_gridmap.set_cell_item(cell, -1) # Remove item visually immediately
@@ -82,7 +86,9 @@ func grab_item(grid_position: Vector2i) -> bool:
if multiplayer.is_server():
# HOST/SERVER: Broadcast to all clients
main.rpc("sync_grid_item", cell.x, cell.y, cell.z, -1)
player.rpc("sync_playerboard", player.playerboard)
# Use main's RPC which properly looks up player by ID on each client
var peer_id = player.get_multiplayer_authority()
main.rpc("sync_playerboard", peer_id, player.playerboard)
player.has_performed_action = true
player.consume_action_points(1)
player.rpc("force_action_state_none")
@@ -138,13 +144,17 @@ func _execute_grab(grid_pos: Vector2i, cell: Vector3i, item_id: int):
player.playerboard[target_slot] = item_id
# 3c. Broadcast the new playerboard state to all clients
player.rpc("sync_playerboard", player.playerboard)
var peer_id = player.get_multiplayer_authority()
main.rpc("sync_playerboard", peer_id, player.playerboard)
# 3d. Consume action points
# 3d. Check if goal is completed (SERVER-SIDE - this triggers goal regeneration for clients!)
_check_goal_completion()
# 3e. Consume action points
player.has_performed_action = true
player.consume_action_points(1)
# 3e. Reset the UI for the player who acted
# 3f. Reset the UI for the player who acted
player.rpc("force_action_state_none")
return true
@@ -306,6 +316,10 @@ func auto_put_item() -> bool:
var cell = Vector3i(target_pos.x, 1, target_pos.y)
if player.is_multiplayer_authority():
# Play put animation
if player.has_method("play_put_animation"):
player.play_put_animation()
# === Optimistic Local Update (immediate visual feedback) ===
enhanced_gridmap.set_cell_item(cell, item) # Add item to grid visually immediately
player.playerboard[put_slot] = -1 # Remove from playerboard immediately
@@ -627,6 +641,10 @@ func _check_goal_completion():
if powerup_manager:
powerup_manager.add_goal_completion_reward()
# Trigger screen shake for goal completion
if player.is_multiplayer_authority() and player.has_method("trigger_screen_shake"):
player.trigger_screen_shake("goal")
# Notify GoalsCycleManager for scoring
var main = player.get_tree().get_root().get_node_or_null("Main")
if main: