Simplify Item RPC calls

main
copygirl 10 months ago
parent a618b58989
commit fdc737a3de
  1. 24
      objects/Item.cs
  2. 2
      scenes/ItemManager.cs

@ -61,19 +61,13 @@ public partial class Item : RigidBody3D
public void TryPickup() public void TryPickup()
{ {
if (this.IsAuthority())
RPC.ToAll().Send(Manager.RelayAccept, GetPath(),
ItemManager.AcceptFunc.AcceptPickup,
new Godot.Collections.Array { Multiplayer.GetUniqueId() });
// RPC.ToAll().Send(AcceptPickup, Multiplayer.GetUniqueId());
else
RPC.To(GetMultiplayerAuthority()).Send(Manager.RelayRequest, GetPath(), RPC.To(GetMultiplayerAuthority()).Send(Manager.RelayRequest, GetPath(),
ItemManager.RequestFunc.RequestPickup, ItemManager.RequestFunc.RequestPickup,
new Godot.Collections.Array()); new Godot.Collections.Array());
// RPC.To(GetMultiplayerAuthority()).Send(RequestPickup); // RPC.To(GetMultiplayerAuthority()).Send(RequestPickup);
} }
[Rpc(RpcMode.AnyPeer)] [Rpc(RpcMode.AnyPeer, CallLocal = true)]
void RequestPickup() void RequestPickup()
{ {
// Pickup will be requested by any player to the owner of the item. // Pickup will be requested by any player to the owner of the item.
@ -101,19 +95,13 @@ public partial class Item : RigidBody3D
public void TryPlace(Grid grid, Transform3D localTransform) public void TryPlace(Grid grid, Transform3D localTransform)
{ {
if (this.IsAuthority())
RPC.ToAll().Send(Manager.RelayAccept, GetPath(),
ItemManager.AcceptFunc.AcceptPlace,
new Godot.Collections.Array { grid.GetPath(), localTransform });
// RPC.ToAll().Send(AcceptPlace, grid.GetPath(), localTransform);
else
RPC.To(GetMultiplayerAuthority()).Send(Manager.RelayRequest, GetPath(), RPC.To(GetMultiplayerAuthority()).Send(Manager.RelayRequest, GetPath(),
ItemManager.RequestFunc.RequestPlace, ItemManager.RequestFunc.RequestPlace,
new Godot.Collections.Array { grid.GetPath(), localTransform }); new Godot.Collections.Array { grid.GetPath(), localTransform });
// RPC.To(GetMultiplayerAuthority()).Send(RequestPlace, grid.GetPath(), localTransform); // RPC.To(GetMultiplayerAuthority()).Send(RequestPlace, grid.GetPath(), localTransform);
} }
[Rpc(RpcMode.AnyPeer)] [Rpc(RpcMode.AnyPeer, CallLocal = true)]
void RequestPlace(NodePath gridPath, Transform3D localTransform) void RequestPlace(NodePath gridPath, Transform3D localTransform)
{ {
// Must be received by the owner of this item. // Must be received by the owner of this item.
@ -144,19 +132,13 @@ public partial class Item : RigidBody3D
public void TryThrow() public void TryThrow()
{ {
if (this.IsAuthority())
RPC.ToAll().Send(Manager.RelayAccept, GetPath(),
ItemManager.AcceptFunc.AcceptThrow,
new Godot.Collections.Array());
// RPC.ToAll().Send(AcceptThrow);
else
RPC.To(GetMultiplayerAuthority()).Send(Manager.RelayRequest, GetPath(), RPC.To(GetMultiplayerAuthority()).Send(Manager.RelayRequest, GetPath(),
ItemManager.RequestFunc.RequestThrow, ItemManager.RequestFunc.RequestThrow,
new Godot.Collections.Array()); new Godot.Collections.Array());
// RPC.To(GetMultiplayerAuthority()).Send(RequestThrow); // RPC.To(GetMultiplayerAuthority()).Send(RequestThrow);
} }
[Rpc(RpcMode.AnyPeer)] [Rpc(RpcMode.AnyPeer, CallLocal = true)]
void RequestThrow() void RequestThrow()
{ {
if (!IsMultiplayerAuthority()) return; if (!IsMultiplayerAuthority()) return;

@ -40,7 +40,7 @@ public partial class ItemManager : Node
internal enum RequestFunc { RequestPickup, RequestPlace, RequestThrow } internal enum RequestFunc { RequestPickup, RequestPlace, RequestThrow }
internal enum AcceptFunc { AcceptPickup, AcceptPlace, AcceptThrow } internal enum AcceptFunc { AcceptPickup, AcceptPlace, AcceptThrow }
[Rpc(RpcMode.AnyPeer)] [Rpc(RpcMode.AnyPeer, CallLocal = true)]
internal void RelayRequest(NodePath itemPath, RequestFunc func, Godot.Collections.Array args) internal void RelayRequest(NodePath itemPath, RequestFunc func, Godot.Collections.Array args)
{ {
var item = this.GetNodeOrThrow<Item>(itemPath); var item = this.GetNodeOrThrow<Item>(itemPath);

Loading…
Cancel
Save