コード例 #1
0
ファイル: Inventory.cs プロジェクト: ktndrnl/unitystation
    /// <summary>
    /// Client tells server to transfer items between 2 item slots, with client side prediction.
    /// One of the item slots must be either in this player's slot tree (i.e. currently owned by them
    /// even if nested within an item storage).
    ///
    /// This method has validations to check this precondition before sending the message to the server,
    /// so feel free to just call this and not do any validation. It will fail with a Trace level
    /// message in Category.Inventory if it fails validation. It will also output an examine
    /// message to the player telling them why it failed.
    /// </summary>
    /// <param name="from">
    /// o</param>
    /// <param name="to"></param>
    /// <returns></returns>
    public static void ClientRequestTransfer(ItemSlot from, ItemSlot to)
    {
        if (!Validations.CanPutItemToSlot(PlayerManager.LocalPlayerScript, to, from.Item,
                                          NetworkSide.Client, PlayerManager.LocalPlayer, examineRecipient: PlayerManager.LocalPlayer))
        {
            Logger.LogTraceFormat("Client cannot request transfer from {0} to {1} because" +
                                  " validation failed.", Category.Inventory,
                                  from, to);
            return;
        }

        //client side prediction, just change the sprite of the ui slots
        if (from.LocalUISlot != null)
        {
            from.LocalUISlot.Clear();
        }

        if (to.LocalUISlot != null)
        {
            to.LocalUISlot.UpdateImage(from.ItemObject);
        }

        //send the actual message.
        RequestInventoryTransferMessage.Send(from, to);
    }
コード例 #2
0
    /// <summary>
    /// For internal inventory system use only. Use Inventory.ClientRequestTransfer to properly request
    /// a transfer.
    ///
    /// Client tells server to transfer items between 2 item slots.
    /// One of the item slots must be either in this player's slot tree (i.e. currently owned by them
    /// even if nested within an item storage).
    /// </summary>
    /// <param name="fromSlot">
    /// o</param>
    /// <param name="toSlot"></param>
    /// <returns></returns>
    public static void _Send(ItemSlot fromSlot, ItemSlot toSlot)
    {
        RequestInventoryTransferMessage msg = new RequestInventoryTransferMessage
        {
            FromStorage   = fromSlot.ItemStorageNetID,
            FromSlotIndex = fromSlot.SlotIdentifier.SlotIndex,
            FromNamedSlot = fromSlot.SlotIdentifier.NamedSlot.GetValueOrDefault(NamedSlot.back),
            ToStorage     = toSlot.ItemStorageNetID,
            ToSlotIndex   = toSlot.SlotIdentifier.SlotIndex,
            ToNamedSlot   = toSlot.SlotIdentifier.NamedSlot.GetValueOrDefault(NamedSlot.back)
        };

        msg.Send();
    }