attempt to make stop n go gamemode

This commit is contained in:
2026-02-19 03:42:59 +08:00
parent 4ce917db0f
commit a7a8106b7e
11 changed files with 516 additions and 28 deletions
+70
View File
@@ -832,6 +832,67 @@ func _find_valid_drop_position() -> Vector2i:
return Vector2i(-1, -1)
@rpc("any_peer", "call_local")
func on_stop_phase_violation():
"""Moving during STOP phase makes you lose and scatter tiles."""
if not multiplayer.is_server(): return
print("[STOP n GO] Violation by player %s! Scattering tiles." % name)
# Stun effect
apply_stagger(2.0)
# Scatter items
var items_to_scatter = []
for i in range(playerboard.size()):
if playerboard[i] != -1:
items_to_scatter.append(playerboard[i])
playerboard[i] = -1
if items_to_scatter.is_empty():
return
rpc("sync_playerboard", playerboard)
# Find multiple valid drop positions around the player
var drop_positions = _find_multiple_drop_positions(items_to_scatter.size())
for i in range(items_to_scatter.size()):
var item_id = items_to_scatter[i]
var pos = drop_positions[i] if i < drop_positions.size() else _find_valid_drop_position()
if pos != Vector2i(-1, -1):
var cell = Vector3i(pos.x, 1, pos.y)
rpc("sync_grid_item", cell.x, cell.y, cell.z, item_id)
NotificationManager.send_message(self, "STOP VIOLATION! Tiles scattered!", NotificationManager.MessageType.WARNING)
func _find_multiple_drop_positions(count: int) -> Array:
var positions = []
var neighbors = enhanced_gridmap.get_neighbors(current_position, 0)
neighbors.shuffle()
# Also consider neighbors of neighbors (radius 2) for more scattering
var candidates = []
for n in neighbors:
candidates.append(n.position)
var n2 = enhanced_gridmap.get_neighbors(n.position, 0)
for nn in n2:
if not nn.position in candidates:
candidates.append(nn.position)
candidates.shuffle()
for pos in candidates:
if positions.size() >= count: break
var item_cell = Vector3i(pos.x, 1, pos.y)
if enhanced_gridmap.get_cell_item(item_cell) == -1:
if not is_position_occupied(pos):
positions.append(pos)
return positions
# =============================================================================
# Targeting Action
# =============================================================================
@@ -1200,6 +1261,15 @@ func start_movement_along_path(path: Array, clear_visual: bool = true):
if is_carrying_tekton and is_instance_valid(carried_tekton):
carried_tekton.current_position = current_position
# Stop n Go Win Check
if LobbyManager.game_mode == "Stop n Go":
var sng_main = get_tree().root.get_node_or_null("Main")
if sng_main:
var sng_manager = sng_main.get_node_or_null("StopNGoManager")
if sng_manager and sng_manager.has_method("check_win_condition"):
if sng_manager.check_win_condition(name.to_int(), current_position):
sng_main.rpc("sync_game_end_stop_n_go", name.to_int())
# FORCE SNAP: Update target visual position to the perfect grid center
# This ensures that when interpolation resumes (in _process), it pulls to the correct spot
target_visual_position = grid_to_world(current_position)