diff --git a/src/scripts/Autoloads/multiplayer_manager.gd b/src/scripts/Autoloads/multiplayer_manager.gd index a63c12d..517d758 100644 --- a/src/scripts/Autoloads/multiplayer_manager.gd +++ b/src/scripts/Autoloads/multiplayer_manager.gd @@ -291,6 +291,25 @@ func request_lift_pot(pot_path: NodePath, peer_id: int): else: Console.print("MultiplayerManager denied lift request - pot: ", pot, " liftable: ", pot.liftable if pot else "null", " player: ", player) +@rpc("any_peer", "reliable") +func request_put_down_pot(pot_path: NodePath, peer_id: int): + Console.print("MultiplayerManager received request_put_down_pot from peer ", peer_id, " for pot at ", pot_path) + if multiplayer.is_server(): + var pot = get_node_or_null(pot_path) + var player = get_tree().get_current_scene().get_node("SpawnRoot").get_node_or_null(str(peer_id)) + Console.print("MultiplayerManager found pot: ", pot, " player: ", player) + if pot and player: + # Check if the pot is being held by this player + if pot.holder_peer_id == peer_id or (pot.holder != null and pot.holder.get_multiplayer_authority() == peer_id): + Console.print("MultiplayerManager authorizing put_down for peer ", peer_id) + if pot.put_down(): + player.held_entity = null + # Use RPC to clear held_entity_path on all players + player.set_held_entity_path_rpc.rpc("") + player.is_lifting = false + else: + Console.print("MultiplayerManager denied put_down - holder_peer_id mismatch or holder not found") + @rpc("any_peer", "reliable") func request_throw_pot(pot_path: NodePath, peer_id: int, direction: Vector2): Console.print("MultiplayerManager received request_throw_pot from peer ", peer_id, " for pot at ", pot_path) diff --git a/src/scripts/entities/player/player.gd b/src/scripts/entities/player/player.gd index 76cb7af..7f28d20 100644 --- a/src/scripts/entities/player/player.gd +++ b/src/scripts/entities/player/player.gd @@ -308,7 +308,10 @@ func _apply_movement_from_input(_delta: float) -> void: time_since_last_frame = 0 current_frame = 0 current_animation = "RUN" + extraString - if grabbed_entity == null: + if grabbed_entity == null and held_entity == null: + last_direction = direction + elif held_entity != null: + # Update last_direction when holding a pot for synchronization last_direction = direction is_moving = true else: @@ -417,9 +420,12 @@ func _apply_movement_from_input(_delta: float) -> void: else: MultiplayerManager.request_throw_pot.rpc_id(1, held_entity.get_path(), multiplayer.get_unique_id(), last_direction) else: - if held_entity.put_down(): - held_entity = null - held_entity_path = "" + if multiplayer.is_server(): + if held_entity.put_down(): + held_entity = null + held_entity_path = "" + else: + MultiplayerManager.request_put_down_pot.rpc_id(1, held_entity.get_path(), multiplayer.get_unique_id()) if grabbed_entity != null and "release" in grabbed_entity: grabbed_entity.release() grabbed_entity = null @@ -510,11 +516,14 @@ func _apply_movement_from_input(_delta: float) -> void: else: MultiplayerManager.request_throw_pot.rpc_id(1, held_entity.get_path(), multiplayer.get_unique_id(), last_direction) else: - if held_entity.put_down(): - held_entity = null - held_entity_path = "" + if multiplayer.is_server(): + if held_entity.put_down(): + held_entity = null + held_entity_path = "" + else: + is_lifting = true else: - is_lifting = true + MultiplayerManager.request_put_down_pot.rpc_id(1, held_entity.get_path(), multiplayer.get_unique_id()) if grabbed_entity != null and "release" in grabbed_entity: grabbed_entity.release() grabbed_entity = null