update bot

This commit is contained in:
2026-01-06 08:55:14 +08:00
parent cbbe95e108
commit 059f152374
12 changed files with 353 additions and 148 deletions
+12 -3
View File
@@ -91,10 +91,14 @@ func _on_match_end():
"""Called when global match timer reaches zero - game over!"""
is_match_active = false
is_cycle_active = false
emit_signal("match_ended")
if multiplayer.is_server():
rpc("sync_match_end")
# FINAL SCORING: Process any points remaining on board
_process_cycle_end_for_all_players()
# Sync final scores THEN end match on clients
rpc("sync_final_scores")
else:
emit_signal("match_ended")
@rpc("authority", "call_local", "reliable")
func sync_match_start(duration_seconds: float):
@@ -105,9 +109,14 @@ func sync_match_start(duration_seconds: float):
emit_signal("match_started")
@rpc("authority", "call_local", "reliable")
func sync_match_end():
func sync_final_scores():
"""Called by server at match end. Signals clients to stop."""
is_match_active = false
is_cycle_active = false
# Request final leaderboard refresh
_update_leaderboard()
emit_signal("match_ended")
@rpc("authority", "call_local", "unreliable")
+1 -1
View File
@@ -63,7 +63,7 @@ func after_action_completed():
if player.is_multiplayer_authority():
var main = player.get_tree().get_root().get_node_or_null("Main")
if main:
main.rpc("sync_playerboard", player.get_multiplayer_authority(), player.playerboard)
main.rpc("sync_playerboard", player.name.to_int(), player.playerboard)
player._is_processing_action = false
+13 -11
View File
@@ -76,7 +76,7 @@ func grab_item(grid_position: Vector2i) -> bool:
# Update UI immediately for responsiveness
var main = player.get_tree().get_root().get_node_or_null("Main")
if main and main.ui_manager:
if main and main.ui_manager and not (player.is_bot or player.is_in_group("Bots")):
main.ui_manager.update_playerboard_ui()
# Check if goal is completed after grabbing
@@ -87,7 +87,7 @@ func grab_item(grid_position: Vector2i) -> bool:
# HOST/SERVER: Broadcast to all clients
main.rpc("sync_grid_item", cell.x, cell.y, cell.z, -1)
# Use main's RPC which properly looks up player by ID on each client
var peer_id = player.get_multiplayer_authority()
var peer_id = player.name.to_int()
main.rpc("sync_playerboard", peer_id, player.playerboard)
player.has_performed_action = true
player.consume_action_points(1)
@@ -144,7 +144,7 @@ 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
var peer_id = player.get_multiplayer_authority()
var peer_id = player.name.to_int()
main.rpc("sync_playerboard", peer_id, player.playerboard)
# 3d. Check if goal is completed (SERVER-SIDE - this triggers goal regeneration for clients!)
@@ -326,7 +326,7 @@ func auto_put_item() -> bool:
# Update UI immediately for responsiveness
var main = player.get_tree().get_root().get_node_or_null("Main")
if main and main.ui_manager:
if main and main.ui_manager and not (player.is_bot or player.is_in_group("Bots")):
main.ui_manager.update_playerboard_ui()
main.ui_manager.current_action_state = main.ui_manager.ActionState.NONE
@@ -364,9 +364,10 @@ func arrange_playerboard_item(slot_index: int):
# Highlight valid adjacent slots
for adj_slot in adjacent_slots:
if player.playerboard[adj_slot] == -1: # Only highlight empty adjacent slots
var adj_slot_ui = main.ui_manager.playerboard_ui.get_child(adj_slot)
if adj_slot_ui.get_child_count() > 2:
adj_slot_ui.get_child(2).show()
if not (player.is_bot or player.is_in_group("Bots")):
var adj_slot_ui = main.ui_manager.playerboard_ui.get_child(adj_slot)
if adj_slot_ui.get_child_count() > 2:
adj_slot_ui.get_child(2).show()
player.action_manager.highlighted_cells.append(adj_slot)
# Connect to slot click signals
@@ -403,8 +404,9 @@ func handle_slot_clicked(slot_index: int):
selected_playerboard_slot = -1
# Update the visual representation
main.ui_manager.update_playerboard_ui()
main.ui_manager.current_action_state = main.ui_manager.ActionState.NONE
if not (player.is_bot or player.is_in_group("Bots")):
main.ui_manager.update_playerboard_ui()
main.ui_manager.current_action_state = main.ui_manager.ActionState.NONE
# =============================================================================
# Helper Functions
@@ -594,7 +596,7 @@ func can_move_to_target_playerboard_slot() -> bool:
func _update_playerboard_slot_visual(slot_index: int):
var main = player.get_tree().get_root().get_node_or_null("Main")
if not main or not main.playerboard_ui:
if not main or not main.playerboard_ui or (player.is_bot or player.is_in_group("Bots")):
return
var slot = main.playerboard_ui.get_child(slot_index)
@@ -608,7 +610,7 @@ func _update_playerboard_slot_visual(slot_index: int):
func _highlight_adjacent_playerboard_slots():
var main = player.get_tree().get_root().get_node_or_null("Main")
if not main or not main.playerboard_ui:
if not main or not main.playerboard_ui or (player.is_bot or player.is_in_group("Bots")):
return
for i in range(25):
+2 -2
View File
@@ -73,8 +73,8 @@ func add_goal_completion_reward():
# =============================================================================
func can_use_special() -> bool:
"""Returns true if player has at least 1 bar (4 points)."""
return current_points >= POINTS_PER_BAR
"""Returns true if player has at least 1 bar (4 points) AND IS NOT ON COOLDOWN."""
return current_points >= POINTS_PER_BAR and special_cooldown_timer <= 0
func get_bars() -> int:
"""Returns current number of full bars."""
@@ -194,7 +194,11 @@ func _execute_freeze_player():
opponent.rpc("display_message", "You are frozen!")
func _create_unfreeze_timer(target_player: Node3D, duration: float):
if not is_instance_valid(player) or not is_instance_valid(target_player):
return
await player.get_tree().create_timer(duration).timeout
if is_instance_valid(target_player):
target_player.set("is_frozen", false)
target_player.rpc("display_message", "Unfrozen!")
@@ -250,7 +254,11 @@ func _execute_invisible_mode():
player.rpc("display_message", "Invisible mode activated!")
func _create_invisibility_timer(duration: float):
if not is_instance_valid(player):
return
await player.get_tree().create_timer(duration).timeout
if is_instance_valid(player):
player.set("is_invisible", false)
if player.get("original_movement_range"):