/// <summary> /// Requests the server to transfer an item /// </summary> /// <param name="item">The item to transfer</param> /// <param name="targetContainer">Into which container to move the item</param> public void ClientTransferItem(Item item, Vector2Int position, AttachedContainer targetContainer) { NetworkedContainerReference?reference = NetworkedContainerReference.CreateReference(targetContainer); if (reference == null) { Debug.LogError("Couldn't create reference for container in item transfer", targetContainer); return; } CmdTransferItem(item.gameObject, position, (NetworkedContainerReference)reference); }
private void CmdTransferItem(GameObject itemObject, Vector2Int position, NetworkedContainerReference reference) { var item = itemObject.GetComponent <Item>(); if (item == null) { return; } Container itemContainer = item.Container; if (itemContainer == null) { return; } AttachedContainer attachedTo = itemContainer.AttachedTo; if (attachedTo == null) { return; } AttachedContainer attachedContainer = reference.FindContainer(); if (attachedContainer == null) { Debug.LogError($"Client sent invalid container reference: NetId {reference.SyncNetworkId}, Container {reference.ContainerIndex}"); return; } if (!CanModifyContainer(attachedTo) || !CanModifyContainer(attachedContainer)) { return; } var creature = GetComponent <Entity>(); if (creature == null || !creature.CanInteract(attachedContainer.gameObject)) { return; } attachedContainer.Container.AddItem(item, position); }