feat: Introduce player input and movement managers to handle continuous, turn-based, and targeted grid interactions.

This commit is contained in:
Yogi Wiguna
2026-02-23 17:09:33 +08:00
parent 3a5e6ad703
commit 19fdb12c31
4 changed files with 77 additions and 35 deletions
+38 -12
View File
@@ -34,6 +34,7 @@ func can_rpc() -> bool:
# Special effect states
var is_frozen: bool = false
var is_stop_frozen: bool = false # Special freeze for Stop n Go phase
var is_invisible: bool = false
var original_movement_range: int = 1
@@ -718,10 +719,35 @@ func apply_stagger(duration: float = 1.5):
is_frozen = false
# If still immune, show immunity tint (Green?), otherwise White
if immunity_timer > 0:
_apply_tint_recursive(self , Color(0.5, 1.0, 0.5)) # Light Green for immunity
# UNLESS we are still stop-frozen (Cyan)
if is_stop_frozen:
_apply_tint_recursive(self, Color.CYAN)
elif immunity_timer > 0:
_apply_tint_recursive(self, Color(0.5, 1.0, 0.5)) # Light Green for immunity
else:
_apply_tint_recursive(self , Color.WHITE) # Remove tint
_apply_tint_recursive(self, Color.WHITE) # Remove tint
@rpc("any_peer", "call_local", "reliable")
func sync_stop_freeze(enabled: bool):
# Security: Only allow server (peer 1) or local calls (peer 0)
var sender = multiplayer.get_remote_sender_id()
if sender != 1 and sender != 0:
return
is_stop_frozen = enabled
if enabled:
_apply_tint_recursive(self, Color.CYAN)
print("[STOP n GO] Player %s FROZEN until GO phase" % name)
else:
# Restore appropriate tint
if is_frozen:
_apply_tint_recursive(self, Color.BLUE)
elif immunity_timer > 0:
_apply_tint_recursive(self, Color(0.5, 1.0, 0.5))
else:
_apply_tint_recursive(self, Color.WHITE)
print("[STOP n GO] Player %s UNFROZEN" % name)
@rpc("any_peer", "call_local")
func apply_slow_effect(duration: float = 3.0):
@@ -837,11 +863,12 @@ func _find_valid_drop_position() -> Vector2i:
func on_stop_phase_violation():
"""Moving during STOP phase makes you lose and scatter tiles."""
if not multiplayer.is_server(): return
if is_stop_frozen: return # Already penalized for this phase
print("[STOP n GO] Violation by player %s! Scattering tiles." % name)
# Stun effect
apply_stagger(2.0)
# New Indefinite Freeze until phase ends
rpc("sync_stop_freeze", true)
# Scatter items
var items_to_scatter = []
@@ -850,9 +877,6 @@ func on_stop_phase_violation():
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
@@ -1039,7 +1063,7 @@ func _physics_process(delta):
func _unhandled_input(event):
# Handle power-up usage
if event.is_action_pressed("use_powerup") and is_multiplayer_authority():
if is_frozen:
if is_frozen or is_stop_frozen:
return
if powerup_manager and powerup_manager.can_use_special():
powerup_manager.use_special_effect()
@@ -1054,6 +1078,8 @@ func _on_slot_gui_input(event, slot_index, slot_ui) -> int:
return -1
func handle_grid_click(grid_position: Vector2i):
if is_frozen or is_stop_frozen:
return
if input_manager:
input_manager.handle_grid_click(grid_position)
@@ -1921,7 +1947,7 @@ func complete_race(final_position: int):
# =============================================================================
func grab_tekton():
if not is_multiplayer_authority() or is_carrying_tekton or is_frozen:
if not is_multiplayer_authority() or is_carrying_tekton or is_frozen or is_stop_frozen:
return
# Find nearby Tekton
@@ -1940,7 +1966,7 @@ func sync_grab_tekton(tekton_path: NodePath):
print("[Player %s] Grabbed Tekton %s" % [name, tekton.name])
func throw_tekton():
if not is_multiplayer_authority() or not is_carrying_tekton or is_frozen:
if not is_multiplayer_authority() or not is_carrying_tekton or is_frozen or is_stop_frozen:
return
# Determine throw direction (where player is facing)
@@ -2084,7 +2110,7 @@ func update_active_player_indicator():
func knock_tekton():
# ... legacy or helper function ...
pass
if not is_multiplayer_authority() or is_frozen:
if not is_multiplayer_authority() or is_frozen or is_stop_frozen:
return
# Requirement: Full Powerup Bar