Ejemplo n.º 1
0
    /// <summary>
    /// NOTE: Please use Inventory instead for moving inventory around.
    ///
    /// Server-side only. Adds the specified item to the slot, updating any observers.
    /// Note that this doesn't do anything other than saying the item is now in the slot.
    /// </summary>
    public void _ServerSetItem(Pickupable newItem)
    {
        var removedItem = item;

        item = newItem;
        OnSlotContentsChangeServer.Invoke();

        //server has to call their own client side hooks because by the time the message is received,
        //the server will not be able to determine what slot the item came from.
        OnSlotContentsChangeClient.Invoke();
        if (removedItem != null)
        {
            //we displaced an item
            var info = ClientInventoryMove.OfType(ClientInventoryMoveType.Removed);
            foreach (var hook in removedItem.GetComponents <IClientInventoryMove>())
            {
                hook.OnInventoryMoveClient(info);
            }
        }

        if (newItem != null)
        {
            //we are adding an item to this slot
            var info = ClientInventoryMove.OfType(ClientInventoryMoveType.Added);
            foreach (var hook in newItem.GetComponents <IClientInventoryMove>())
            {
                hook.OnInventoryMoveClient(info);
            }
        }

        UpdateItemSlotMessage.Send(serverObserverPlayers, this);
    }
Ejemplo n.º 2
0
 /// <summary>
 /// Server side only (can be called client side but has no effect). Add this player to the list of players currently observing this slot and
 /// informs this observer of the current state of the slot. This observer will be informed of any updates
 /// to this slot.
 /// </summary>
 /// <param name="observerPlayer"></param>
 public void ServerAddObserverPlayer(GameObject observerPlayer)
 {
     if (!CustomNetworkManager.IsServer)
     {
         return;
     }
     serverObserverPlayers.Add(observerPlayer);
     UpdateItemSlotMessage.Send(observerPlayer, this);
 }
    private void HandleFail(ItemSlot fromSlot, ItemSlot toSlot)
    {
        Logger.LogWarningFormat(
            "Possible hacking attempt (or bad clientside logic), {0} tried to transfer from slot {1} to {2} when they" +
            " are not allowed.", Category.Inventory, SentByPlayer.GameObject.name, fromSlot, toSlot);

        //roll back the client prediction
        UpdateItemSlotMessage.Send(SentByPlayer.GameObject, fromSlot);
        UpdateItemSlotMessage.Send(SentByPlayer.GameObject, toSlot);
    }
Ejemplo n.º 4
0
 /// <summary>
 /// Server only (can be called client side but has no effect). Remove this player from the list of players currently observing this slot.
 /// This observer will not longer recieve updates as they happen to this slot.
 /// </summary>
 /// <param name="observerPlayer"></param>
 public void ServerRemoveObserverPlayer(GameObject observerPlayer)
 {
     if (!CustomNetworkManager.IsServer)
     {
         return;
     }
     serverObserverPlayers.Remove(observerPlayer);
     //tell the client the slot is now empty
     UpdateItemSlotMessage.Send(observerPlayer, this, true);
 }
Ejemplo n.º 5
0
    /// <summary>
    /// Inform the client about this slot's current status.
    /// </summary>
    /// <param name="recipient">client to inform</param>
    /// <param name="inventorySlot">slot to tell them about</param>
    /// <param name="informEmpty">if true, regardless of the slot's actual status, it
    /// will be reported to the client as empty.</param>
    /// <returns></returns>
    public static void Send(GameObject recipient, ItemSlot itemSlot, bool informEmpty = false)
    {
        UpdateItemSlotMessage msg = new UpdateItemSlotMessage
        {
            Storage   = itemSlot.ItemStorageNetID,
            Item      = informEmpty ? NetId.Invalid : (itemSlot.Item != null ? itemSlot.Item.GetComponent <NetworkIdentity>().netId : NetId.Invalid),
            SlotIndex = itemSlot.SlotIdentifier.SlotIndex,
            NamedSlot = itemSlot.SlotIdentifier.NamedSlot.GetValueOrDefault(NamedSlot.none)
        };

        msg.SendTo(recipient);
    }
Ejemplo n.º 6
0
    /// <summary>
    /// Inform the clients about this slot's current status.
    /// </summary>
    /// <param name="recipients">clients to inform</param>
    /// <param name="inventorySlot">slot to tell them about</param>
    /// <returns></returns>
    public static void Send(IEnumerable <GameObject> recipients, ItemSlot itemSlot)
    {
        UpdateItemSlotMessage msg = new UpdateItemSlotMessage
        {
            Storage   = itemSlot.ItemStorageNetID,
            Item      = itemSlot.Item != null?itemSlot.Item.GetComponent <NetworkIdentity>().netId : NetId.Invalid,
            SlotIndex = itemSlot.SlotIdentifier.SlotIndex,
            NamedSlot = itemSlot.SlotIdentifier.NamedSlot.GetValueOrDefault(NamedSlot.none)
        };

        foreach (var recipient in recipients)
        {
            msg.SendTo(recipient);
        }
    }