NPCs can now carry objects.

This commit is contained in:
Patrick 2024-12-13 21:18:52 +01:00
parent a6c9909f26
commit c0d3c68fb3
8 changed files with 130 additions and 23 deletions
scripts/utils

View file

@ -271,7 +271,7 @@ func player_sync_call(position: Vector3, rotation: Vector3) -> void:
Log.warning("Couldn't send RPC to %d!" % peer)
# Synchronizes the player state.
@rpc("any_peer", "call_local", "reliable")
@rpc("any_peer", "call_remote", "reliable")
func player_sync(position: Vector3, rotation: Vector3) -> void:
if verify_id(multiplayer.get_remote_sender_id()):
for peer: String in peers:
@ -287,9 +287,35 @@ func npc_sync_call(position: Vector3, rotation: Vector3, node_name: String) -> v
Log.warning("Couldn't send RPC to %d!" % peer)
# Synchronizes the npc state.
@rpc("any_peer", "call_local", "reliable")
@rpc("any_peer", "call_remote", "reliable")
func npc_sync(position: Vector3, rotation: Vector3, node_name: String) -> void:
if managerID == multiplayer.get_remote_sender_id():
var npc: CharacterBody3D = get_node("/root/"+Game.mapname+"/"+node_name)
npc.position = position
npc.rotation = rotation
func pick_up_sync_call(npc: NPC, carryable: Carryable) -> void:
var npc_path: NodePath = npc.get_path()
var carryable_path: NodePath = carryable.get_path()
for peer: int in Networking.get_ids():
if rpc_id(peer, "pick_up_sync", npc_path, carryable_path) != OK:
Log.warning("Couldn't send RPC to %d!" % peer)
# Synchronizes the object that is picked up by the npc.
@rpc("any_peer", "call_local", "reliable")
func pick_up_sync(npc: NodePath, carryable: NodePath) -> void:
if managerID == multiplayer.get_remote_sender_id():
(get_node(npc) as NPC).pick_up(get_node(carryable) as Carryable)
func set_down_sync_call(npc: NPC, carryable: Carryable) -> void:
var npc_path: NodePath = npc.get_path()
var carryable_path: NodePath = carryable.get_path()
for peer: int in Networking.get_ids():
if rpc_id(peer, "set_down_sync", npc_path, carryable_path) != OK:
Log.warning("Couldn't send RPC to %d!" % peer)
# Synchronizes the object that is picked up by the npc.
@rpc("any_peer", "call_local", "reliable")
func set_down_sync(npc: NodePath, carryable: NodePath) -> void:
if managerID == multiplayer.get_remote_sender_id():
(get_node(npc) as NPC).set_down(get_node(carryable) as Carryable)